Page 1 of 1

Custom Nagios Plugin - Service Status

Posted: Thu Oct 15, 2015 12:44 am
by ianlleva246
Hi All,

Is it possible to create custom plugin using Perl in checking if the some services like asterisk are running; same as running this command service asterisk status.

Please help. Can you help me to have sample plugin codes regarding to my concern.

Thank you so much.

Re: Custom Nagios Plugin - Service Status

Posted: Thu Oct 15, 2015 9:43 am
by tmcdonald
Plugins can absolutely be custom-made, and Perl is in my opinion a great language to use! Unfortunately, giving a Perl tutorial is a bit out of scope for this forum, but there are tons of resources online. What I can give you is our plugin development guidelines:

https://nagios-plugins.org/doc/guidelines.html

That page has just about everything you need to know about writing a plugin properly. If you have specific questions we can certainly help!

Re: Custom Nagios Plugin - Service Status

Posted: Thu Oct 15, 2015 9:44 am
by rhassing
I'm not saying its the best script ever, but I think it might work :-)

Code: Select all

#! /usr/bin/perl -w

use strict;
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_H $opt_p $procs $check $PROGNAME);
use lib "/usr/lib/nagios/plugins/"  ;
use utils qw(%ERRORS &print_revision &support &usage);

$PROGNAME = "check_proc-status";

sub print_help ();
sub print_usage ();

$ENV{'PATH'}='';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Getopt::Long::Configure('bundling');
GetOptions
        ("V"   => \$opt_V, "version"    => \$opt_V,
         "h"   => \$opt_h, "help"       => \$opt_h,
         "H=s" => \$opt_H, "hostname=s" => \$opt_H,
         "p=s" => \$opt_p, "process=s" => \$opt_p);

if ($opt_V) {
        print_revision($PROGNAME,'$Revision: 0.1 $');
        exit $ERRORS{'OK'};
}


if ($opt_h) {print_help(); exit $ERRORS{'OK'};}

($opt_H) || usage("Host name/address not specified\n");
my $host = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/);
($host) || usage("Invalid host: $opt_H\n");

($opt_p) || usage("Process name not specified\n");
my $proc = $1 if ($opt_p =~ /([-.A-Za-z0-9_]+)/);
($proc) || usage("Invalid process: $opt_p\n");

$check=`/sbin/service $proc status`;

#print $check;
#print $?;

if ($? == 0){
	print "OK - $proc"; exit $ERRORS{'OK'}};

print "CRITICAL"; exit $ERRORS{'CRITICAL'} ;



sub print_usage () {
        print "Usage: $PROGNAME -H <host> [-C community] -w <warn> -c <crit>\n";
}

sub print_help () {
        print_revision($PROGNAME,'$Revision: 0.1 $');
        print "Copyright (c) 2015 Rob Hassing

This plugin reports the usage of a Netapp Storage volume

";
        print_usage();
        print "
-H, --hostname=HOST
   Name or IP address of host to check
-p, --proc=Process
   Name of the process to check

";
#       support();
}




Re: Custom Nagios Plugin - Service Status

Posted: Thu Oct 15, 2015 3:20 pm
by tmcdonald
Thanks for the input, @rhassing!

Re: Custom Nagios Plugin - Service Status

Posted: Thu Oct 15, 2015 6:57 pm
by ianlleva246
Hi guys,

Thank you for your help. This is a great help for me as NEW in Nagios.

And if i still have any issues or concern regarding nagios hope you still help me :D

GOD BLESS to ALL of you. :ugeek: :D

Re: Custom Nagios Plugin - Service Status

Posted: Fri Oct 16, 2015 9:26 am
by hsmith
Great! I'll go ahead and lock this one to keep it nice and tidy. Please post and let us know if there is anything else we can do for you.