Trying to develop a new perl plugin

Nibin VM nibin.vm at piserve.com
Tue Jan 25 09:58:43 CET 2011


thanks guys.... :)

On Mon, Jan 24, 2011 at 11:08 PM, Alexandro Conde Martínez <
acm at fonetglobal.com> wrote:

> That's easy, just use the Getopt
>
> -----
> use Getopt::Long;
> use vars qw($opt_h $opt_C $opt_H);
>
> # Get the options
> Getopt::Long::Configure('bundling');
> GetOptions
>         ("h"    => \$opt_h, "help"              => \$opt_h,     # Help Flag
>          "H=s"  => \$opt_H, "hostname=s"        => \$opt_H);    # Hostname
>
> # Validate the options
> if ($opt_h) {
>         &print_help();
>         exit $ERRORS{OK};
> }
>
> $opt_H = shift unless ($opt_H);
> $host = $1 if ($opt_H && $opt_H =~
> m/^([a-zA-Z][-a-zA-Z0-9]+(\.[a-zA-Z][-a-zA-Z0-9]+)*)$/);
> unless ($host) {
>         print "No target host specified\n";
>         &print_usage();
>         exit $ERRORS{UNKNOWN};
> }
> -----
>
>
> *Eng. Alexandro Conde Martínez --------->* *Alcon*
> CTO, Fonet Global Inc.
> Phone: +1.972.749.9970 Voip: 523663800
> acm at fonetglobal.com <http://mailto:acm@fonetglobal.com>
> http://www.fonetglobal.com
> Stop Spam: http://www.cauce.org
>
>
> ----- Original Message -----
> From: "Nibin VM" <nibin.vm at piserve.com>
> To: "Nagios Users List" <nagios-users at lists.sourceforge.net>
> Sent: Monday, January 24, 2011 9:16:51 AM
> Subject: Re: [Nagios-users] Trying to develop a new perl plugin
>
> Thanks for your reply folks.. :)
>
> Finally I have concluded that the portion which reads the argument has
> issues.
>
> $host=$ARGV[0];
>
> It isn't taken correctly when its executed from nagios. Please somebody
> tell me what code should I put if I need to specify the host name like ./
> test.pl -H "hostname"?
>
> On Sun, Jan 23, 2011 at 10:44 PM, Boyer, Timothy A. <Timothy.Boyer at opm.gov
> > wrote:
>
>> Permissions problem?  You're running the command line as root; try running
>> the command line as your Nagios username.
>> ________________________________________
>> From: Nibin VM [nibin.vm at piserve.com]
>>
>> Sent: Sunday, January 23, 2011 10:46 AM
>> To: nagios-users at lists.sourceforge.net
>> Subject: [Nagios-users] Trying to develop a new perl plugin
>>
>> Hello guys,
>>
>> I am trying to write some nagios perl plugin to monitor some services  I'm
>> responsible for. Initially I tried to write  custom plugin to monitor mail
>> queue using the following script.
>>
>> ===========
>> #!/usr/bin/perl -w
>>
>> use strict;
>> use Net::SNMP;
>> use Getopt::Long;
>>
>> use lib "/usr/lib64/nagios/libexec";
>> my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3);
>> my $host = undef;
>> my $result = undef;
>> my @array = undef;
>>
>> $host=$ARGV[0];
>> $result=`/usr/lib64/nagios/plugins/check_snmp -H $host -C "community" -o
>> extOutput.1`;
>>
>> @array = split(/\ /, $result);
>> chomp($array[3]);
>>
>> if ( $array[3] le "19999" )
>> {
>>  print "OK: current emails queue is $array[3]\n";
>>  exit $ERRORS{"OK"};
>> }
>>
>> elsif ( $array[3] ge "20000"  &&  $array[3] le "29999" )
>> {
>>  print "Warning: current emails queue is $array[3]\n";
>>  exit $ERRORS{"WARNING"};
>> }
>>
>> elsif ( $array[3] ge "30000" )
>> {
>>  print "Critical: current emails queue is $array[3]\n";
>>  exit $ERRORS{"CRITICAL"};
>> }
>>
>> else
>> {
>>  print "Unknown";
>>  exit $ERRORS{"UNKNOWN"};
>> }
>> ================
>>
>> As you can see, I use snmp to pull mail queue from the remote server. When
>> I try the command from command line it work fine.
>>
>> ]# ./test.pl<http://test.pl> "server name"
>>
>> OK: current emails queue is 264
>>
>> But from the nagios from end it shows as critical and it shows "Critical:
>> current emails queue is Unknown" error :(
>>
>> Please somebody help me to sort this out. Obviously its the first perl
>> script that  I ever wrote and I really interested to write more plugins in
>> perl(I am in love with perl now :) ).
>>
>> Thanks in advance!
>>
>> --
>> Regards,
>> Nibin.
>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>>
>> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
>> Finally, a world-class log management solution at an even better
>> price-free!
>> Download using promo code Free_Logger_4_Dev2Dev. Offer expires
>> February 28th, so secure your free ArcSight Logger TODAY!
>> http://p.sf.net/sfu/arcsight-sfd2d
>> _______________________________________________
>> Nagios-users mailing list
>> Nagios-users at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/nagios-users
>> ::: Please include Nagios version, plugin version (-v) and OS when
>> reporting any issue.
>> ::: Messages without supporting info will risk being sent to /dev/null
>>
>
>
>
> --
> Regards,
> Nibin.
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
> Finally, a world-class log management solution at an even better
> price-free!
> Download using promo code Free_Logger_4_Dev2Dev. Offer expires
> February 28th, so secure your free ArcSight Logger TODAY!
> http://p.sf.net/sfu/arcsight-sfd2d
> _______________________________________________
> Nagios-users mailing list
> Nagios-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nagios-users
> ::: Please include Nagios version, plugin version (-v) and OS when
> reporting any issue.
> ::: Messages without supporting info will risk being sent to /dev/null
>
>
> ------------------------------------------------------------------------------
> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
> Finally, a world-class log management solution at an even better
> price-free!
> Download using promo code Free_Logger_4_Dev2Dev. Offer expires
> February 28th, so secure your free ArcSight Logger TODAY!
> http://p.sf.net/sfu/arcsight-sfd2d
> _______________________________________________
> Nagios-users mailing list
> Nagios-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nagios-users
> ::: Please include Nagios version, plugin version (-v) and OS when
> reporting any issue.
> ::: Messages without supporting info will risk being sent to /dev/null
>



-- 
Regards,
Nibin.
---------------------------------
Nibin.V.M
Operations Engineer(Unix)
PiServe.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20110125/255400de/attachment.html>
-------------- next part --------------
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
-------------- next part --------------
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null


More information about the Users mailing list