Tuesday, April 30, 2013

Add a nagios service monitor

Step 1: Write a script to monitor service using any scripting languages. In this article, I use perl to monitor port 8888
=================================
root@restmq:/usr/local/nagios/etc/objects# less ~/nagios/checkrestmq.pl

#!/usr/bin/perl -w

my $restmq_result = `netstat -na | grep 8888` ;

#print "$restmq_result" ;
# OK  WARNING  UNKNOWN CRITICAL

if ($restmq_result)
{
   print "OK\n"
}
else
{
   print "CRITICAL\n"
}

Step 2 : Add this perl into nagios command.cfg
Default location:
/usr/local/nagios/etc/objects/commands.cfg

define command{
       command_name    check_restmq
       command_line    /home/chang/nagios/checkrestmq.pl
}

Step 3: Add this command into service localhost.cfg
 #check_restmq
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             RestMQ
        check_command                   check_restmq
        notifications_enabled           0
        }



Step 4: restart nagios
  /etc/init.d/nagios stop
  /etc/init.d/nagios start

No comments:

Post a Comment