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”.
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
M3 uses an XML file for configuration, whereas for each command you are required to specify the following:
- The command to invoke
- The regular expression that parses your interesting output
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://github.com/monitisexchange/Monitis-Linux-Scripts.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 # ./NagiosToM3Converter.pl /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:
# ./Example.pl 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!