If you're going to be writing many of your own plugins, it might be worth the effort to use the Nagios::Plugin modules (http://search.cpan.org/~tonvoon/Nagios-Plugin-0.35/lib/Nagios/Plugin.pm). They're probably installed under the perl/lib subdirectory of your Nagios installation. Among other things, they provide a convenient wrapper for Getopt::Long and Params::Validate so you can do position independent options and argument validation for your Perl plugins. Using it could save you quite a bit of time and code maintenance headaches in the long run.
Paul Dubuc Nibin VM wrote: > 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 <http://test.pl> -H "hostname"? > > On Sun, Jan 23, 2011 at 10:44 PM, Boyer, Timothy A. > <timothy.bo...@opm.gov <mailto:timothy.bo...@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...@piserve.com <mailto:nibin...@piserve.com>] > Sent: Sunday, January 23, 2011 10:46 AM > To: nagios-users@lists.sourceforge.net > <mailto:nagios-users@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><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@lists.sourceforge.net > <mailto:Nagios-users@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@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@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