Custom Nagios Plugin - Service Status

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
ianlleva246
Posts: 5
Joined: Wed Sep 16, 2015 6:16 pm

Custom Nagios Plugin - Service Status

Post 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.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Custom Nagios Plugin - Service Status

Post 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!
Former Nagios employee
User avatar
rhassing
Posts: 412
Joined: Sat Oct 05, 2013 10:29 pm
Location: Netherlands

Re: Custom Nagios Plugin - Service Status

Post 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();
}



Rob Hassing
Image
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Custom Nagios Plugin - Service Status

Post by tmcdonald »

Thanks for the input, @rhassing!
Former Nagios employee
ianlleva246
Posts: 5
Joined: Wed Sep 16, 2015 6:16 pm

Re: Custom Nagios Plugin - Service Status

Post 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
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: Custom Nagios Plugin - Service Status

Post 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.
Former Nagios Employee.
me.
Locked