Nagios to Monitis converter: Making life easier for sysadmins

Nagios Web SiteIn the previous article we’ve shown how easy it is to integrate popular Nagios server monitoring commands, or plugins, with Monitis M3 monitoring framework.

However, given the fact you have a working Nagios configuration, which is vast and complex – I can sympathize with your unwillingness to actually migrate to Monitis.

Porting each and every systems monitoring command manually to M3 can be a tedious task, but this is why we invented programming, didn’t we?

In the following short (but useful) article I’ll outline the design and usage of the “Nagios to M3 converter”.

Nagios to Monitis converter: Making life easier for sysadmins

The voice of reason

Why would you want to port your Nagios configuration and have Monitis handle it?
Monitis is not only a hosted service, but it’ll also let you setup more comprehensive alerts when one of your services is down. This would purely improve your server monitoring in your organization, providing higher availability and less maintenance.

M3 Universal monitoring framework – a short refresh

Monitis Monitor Manager or M3, for those of you who for any awkward reason managed to forget, is a very simple utility that would help you load command output to Monitis.

M3 uses an XML file for configuration, whereas for each command you are required to specify the following:

  1. The command to invoke
  2. The regular expression that parses your interesting output

Pretty simple indeed. In the last article about M3, I’ve provided a link to a sample M3 configuration for various Nagios commands.

Nagios to M3 converter

Also this time your loyal servant has done most of the work for you, implementing as much as possible for you. Yes, it does make the articles slimmer and your job a lot easier.
The code checkout snippet:

 # mkdir -p /usr/share/monitisexchange && cd /usr/share/monitisexchange # git clone git:// # cd Monitis-Linux-Scripts/M3 


The converter requires the perl module Nagios::Object.
The module is used for parsing nagios’ configuration. It can be easily installed via CPAN, or by downloading the module and installing it manually.
Via CPAN, the command would be:

 # perl -MCPAN -e 'install Nagios::Object' 

A simple invocation

OK, it’s checked out, how is it used? – easy:

 # cd /usr/share/monitisexchange # ./ /etc/nagios/conf.d/internet.cfg > m3_nagios_config.xml 

This will dump to STDOUT a M3 formatted XML with the relevant configuration from your nagios configuration. Essentially it’ll just port your nagios configuration to a M3 format.
Then we can invoke M3 with the newly created configuration:

 # ./ m3_nagios_config.xml 

Easy as, ain’t it?

Design of Nagios to M3 converter

I believe in reusing code snippets if they exist. As mentioned – for the implementation of the NagiosToM3Converter I used the perl module Nagios::Object.
Iterating on the various commands and hosts configured in a nagios configuration is very easy. For each command we encounter, we’ll invoke a callback function.

Throughout the invocation we have a XML context, the one we’ll dump to STDOUT in the end of the execution.

So in order to configure the “check_ping” command, we’ll call “_cb_check_ping”, which would in turn just add the relevant XML elements to our context.

The Nagios to M3 converter is still work in progress. Currently the only commands implemented are check_ping and check_http. However, more commands will be added shortly – and please contribute if you can.
Now that’s all folks, just use it – it’s plain easy!

Liked it? Sign up for Monitis and try it now! Don’t forget to check also monitisexchange – our git-hub open source repository for some more surprises.