Setting up Nagios plugins to run in a Sensu and Chef managed environment is straightforward and uncomplicated. For example, I recently have been interested in monitoring SSL certificate date expiration and it just so happens that the Nagios check_http plugin does exactly what I’m looking for.
The integration between Sensu and the Nagios plugins is very nice. For convenience in our Sensu environment, we like to put the additional Nagios plugins on to all of the systems we monitor because the footprint is negligible and it allows for some nice flexibility of services and checks to monitor should an additional service get added to a server in the future that we hadn’t anticipated. For the amount of effort it takes to get the checks onto the server and to get working, adding the Nagios plugins is totally worth the effort.
The first step is to add the Nagios plugins to your Chef recipe. I am using a generic Chef recipe for my Sensu clients that takes care of some of the more tedious tasks including downloading the appropriate scripts and checks for the clients to run as well as some other dependencies and items that Sensu likes to have. Luckily there is a public Debian package available for installing the Nagios plugins so it easy to add them. Just add this snippet into your Chef recipe for Sensu clients:
apt_package "nagios-plugins" do action :install end
After you run your next chef-client job you will have access to a variety of checks provided by the Nagios plugins package as illustrated below.
There are a number of examples available but to run the check_http for cert expiration by hand you can run this command:
/usr/lib/nagios/plugins/check_http -H <sitename> -C 30,10
Where <sitename> is the URL of the website you would like to check. Now that we are able to run this check manually, go ahead and roll that in to your Chef recipe for Sensu. An example of this might look similar to the following:
sensu_check "check_web" do command "/usr/lib/nagios/plugins/check_http -H localhost -C 30,10" handlers ["pagerduty", "slack"] subscribers ["core"] interval 60 standalone true additional(:notification => "Certificate will expire soon", :occurrences => 5) end
You may not want to run this check on every host so it may be a good idea to run this check as a stand alone check. It is simple enough to add this snippet in to any recipe and tack on the “standalone true” attribute to the sensu_check resource. I have an example of what this standalone attribute looks like in the example above for reference.
Adding in Nagios plugins gives you a very nice set of additional tools to add to your monitoring arsenal for not that much effort. You never know when something from the Nagios plugins might come in handy so I suggest you try them out. There are many other uses for the Nagios plugins so I suggest taking a look.