<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Times New Roman; font-size: 12pt; color: #000000'><span>That's easy, just use the Getopt<br><br>-----<br>use Getopt::Long;<br>use vars qw($opt_h $opt_C $opt_H);<br><br># Get the options<br>Getopt::Long::Configure('bundling');<br>GetOptions<br>        ("h"    => \$opt_h, "help"              => \$opt_h,     # Help Flag<br>         "H=s"  => \$opt_H, "hostname=s"        => \$opt_H);    # Hostname<br><br># Validate the options<br>if ($opt_h) {<br>        &print_help();<br>        exit $ERRORS{OK};<br>}<br><br>$opt_H = shift unless ($opt_H);<br>$host = $1 if ($opt_H && $opt_H =~ m/^([a-zA-Z][-a-zA-Z0-9]+(\.[a-zA-Z][-a-zA-Z0-9]+)*)$/);<br>unless ($host) {<br>        print "No target host specified\n";<br>        &print_usage();<br>        exit $ERRORS{UNKNOWN};<br>}<br>-----<br><br><br><div style="text-align: center;"><strong>Eng. Alexandro Conde Martínez ---------></strong><span style="font-weight: bold;"> <em>Alcon</em></span><br style="font-weight: bold;"><span style="font-weight: bold;">CTO, Fonet Global Inc.</span><br style="font-weight: bold;"><span style="font-weight: bold;">Phone: +1.972.749.9970 Voip: 523663800</span><br style="font-weight: bold;"><a style="font-weight: bold;" href="http://mailto:acm@fonetglobal.com">acm@fonetglobal.com</a><span style="font-weight: bold;"> </span><a style="font-weight: bold;" href="http://www.fonetglobal.com">http://www.fonetglobal.com</a><br style="font-weight: bold;"><span style="font-weight: bold;">Stop Spam: </span><a style="font-weight: bold;" href="http://www.cauce.org">http://www.cauce.org</a> <br></div><br></span><br>----- Original Message -----<br>From: "Nibin VM" <nibin.vm@piserve.com><br>To: "Nagios Users List" <nagios-users@lists.sourceforge.net><br>Sent: Monday, January 24, 2011 9:16:51 AM<br>Subject: Re: [Nagios-users] Trying to develop a new perl plugin<br><br>Thanks for your reply folks.. :)<br><br>Finally I have concluded that the portion which reads the argument has issues.<br><br>$host=$ARGV[0];<br> <br>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 ./<a href="http://test.pl" target="_blank">test.pl</a> -H "hostname"?<br>
 <br><div class="gmail_quote">On Sun, Jan 23, 2011 at 10:44 PM, Boyer, Timothy A. <span dir="ltr"><<a href="mailto:Timothy.Boyer@opm.gov" target="_blank">Timothy.Boyer@opm.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Permissions problem?  You're running the command line as root; try running the command line as your Nagios username.<br>
________________________________________<br>
From: Nibin VM [<a href="mailto:nibin.vm@piserve.com" target="_blank">nibin.vm@piserve.com</a>]<br>
Sent: Sunday, January 23, 2011 10:46 AM<br>
To: <a href="mailto:nagios-users@lists.sourceforge.net" target="_blank">nagios-users@lists.sourceforge.net</a><br>
Subject: [Nagios-users] Trying to develop a new perl plugin<br>
<div><div></div><div class="h5"><br>
Hello guys,<br>
<br>
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.<br>
<br>
===========<br>
#!/usr/bin/perl -w<br>
<br>
use strict;<br>
use Net::SNMP;<br>
use Getopt::Long;<br>
<br>
use lib "/usr/lib64/nagios/libexec";<br>
my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3);<br>
my $host = undef;<br>
my $result = undef;<br>
my @array = undef;<br>
<br>
$host=$ARGV[0];<br>
$result=`/usr/lib64/nagios/plugins/check_snmp -H $host -C "community" -o extOutput.1`;<br>
<br>
@array = split(/\ /, $result);<br>
chomp($array[3]);<br>
<br>
if ( $array[3] le "19999" )<br>
{<br>
 print "OK: current emails queue is $array[3]\n";<br>
 exit $ERRORS{"OK"};<br>
}<br>
<br>
elsif ( $array[3] ge "20000"  &&  $array[3] le "29999" )<br>
{<br>
 print "Warning: current emails queue is $array[3]\n";<br>
 exit $ERRORS{"WARNING"};<br>
}<br>
<br>
elsif ( $array[3] ge "30000" )<br>
{<br>
 print "Critical: current emails queue is $array[3]\n";<br>
 exit $ERRORS{"CRITICAL"};<br>
}<br>
<br>
else<br>
{<br>
 print "Unknown";<br>
 exit $ERRORS{"UNKNOWN"};<br>
}<br>
================<br>
<br>
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.<br>
<br>
</div></div>]# ./<a href="http://test.pl" target="_blank">test.pl</a><<a href="http://test.pl" target="_blank">http://test.pl</a>> "server name"<br>
<div class="im">OK: current emails queue is 264<br>
<br>
But from the nagios from end it shows as critical and it shows "Critical: current emails queue is Unknown" error :(<br>
<br>
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 :) ).<br>
<br>
Thanks in advance!<br>
<br>
--<br>
Regards,<br>
Nibin.<br>
<br>
<br>
<br>
<br>
</div><div><div></div><div class="h5">------------------------------------------------------------------------------<br>
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!<br>
Finally, a world-class log management solution at an even better price-free!<br>
Download using promo code Free_Logger_4_Dev2Dev. Offer expires<br>
February 28th, so secure your free ArcSight Logger TODAY!<br>
<a href="http://p.sf.net/sfu/arcsight-sfd2d" target="_blank">http://p.sf.net/sfu/arcsight-sfd2d</a><br>
_______________________________________________<br>
Nagios-users mailing list<br>
<a href="mailto:Nagios-users@lists.sourceforge.net" target="_blank">Nagios-users@lists.sourceforge.net</a><br>
<a href="https://lists.sourceforge.net/lists/listinfo/nagios-users" target="_blank">https://lists.sourceforge.net/lists/listinfo/nagios-users</a><br>
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.<br>
::: Messages without supporting info will risk being sent to /dev/null<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Regards,<br>Nibin.<br><br><br><br><br><div style="display: inline;"></div><br>
<br>------------------------------------------------------------------------------<br>Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!<br>Finally, a world-class log management solution at an even better price-free!<br>Download using promo code Free_Logger_4_Dev2Dev. Offer expires <br>February 28th, so secure your free ArcSight Logger TODAY! <br>http://p.sf.net/sfu/arcsight-sfd2d<br>_______________________________________________<br>Nagios-users mailing list<br>Nagios-users@lists.sourceforge.net<br>https://lists.sourceforge.net/lists/listinfo/nagios-users<br>::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. <br>::: Messages without supporting info will risk being sent to /dev/null</div></body></html>