<p class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Hi All,</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">I wrote a plugin that uses wget to check if my cgi-scripts are working properly. The plugin works well on command line but it displays "No output" in Nagios web page.
</span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Here is a copy of the script and the service file and check command: </span></font></p>
<div>################## START PROGRAM #########################</div>
<div>#!/usr/bin/perl</div>
<p>use strict;<br>use Getopt::Long;<br>use vars qw($opt_h $opt_w $opt_c);<br>use lib "/usr/local/nagios/libexec";<br>use utils qw(%ERRORS &print_revision &support &usage);</p>
<p>Getopt::Long::Configure('bundling');<br>GetOptions<br> ("h" => \$opt_h, "help" => \$opt_h, "w=s" => \$opt_w, "warning=s" => \$opt_w, "c=s" => \$opt_c, "critical=s" => \$opt_c);
</p>
<p>my $PROGNAME = "check_url";<br>my $REVISION = '$Revision: 1.1 $';</p>
<p>$ENV{'PATH'}='/usr/bin/';<br>$ENV{'BASH_ENV'}='';<br>$ENV{'ENV'}='';</p>
<p>########## Configure Section ############<br>my $url = $ARGV[0];<br>my $warning = $ARGV[1];<br>my $critical = $ARGV[2];<br>my $wget = `wget -nv --spider -o output.nagios $url`;<br>my $output_file = "output.nagios
";</p>
<p><br>######## Program Section #############<br>open(DAT, $output_file) || die ("Could not open file!");<br> my @output = <DAT>;<br>close(DAT);</p>
<p>#($opt_u) || usage("URL not specified\n");<br>#my $opt_u = $url;<br>#$url) || usage("Invalid url: $opt_u\n");<br>($opt_w) || usage("warning threshold not specified\n");<br>my $warn = $1 if ($opt_w =~ /(\d{1,2})/);
<br>($opt_c) || usage("Critical threshold not specified\n");<br>my $crit = $1 if ($opt_c =~ /(\d{1,2})/);<br></p>
<div> </div>
<p>print "HTTP: $url: @output\n";</p>
<p>if ($warning <= 2) {<br>(my @warning = grep(/Authorization Required/,@output));<br>exit $ERRORS{'WARNING'};<br>}</p>
<p>if ($critical <= 3) {<br> (my @critical = grep(/ERROR/,@output));<br>exit $ERRORS{'CRITICAL'}<br>}<br>exit $ERRORS{'OK'} if (my @ok = grep(/OK/,@output));</p>
<p>sub print_usage () {<br> print "Usage: $PROGNAME -c <crit>\n";<br>}</p>
<p>sub print_help () {<br> print_revision($PROGNAME, $REVISION);<br> print "Copyright (c) 2006 Pius Oshinuga</p>
<p>######## Help Section ##################<br>if ($opt_h) {print_help(); exit $ERRORS{'OK'};}</p>
<p>This plugin reports the script errors using the wget package.";<br> print_usage();<br> print "<br>-w, --warning=INTEGER<br> If site cannot be found or Authority required which a WARNING status will result
<br>-c, --critical=INTEGER<br> If Error occurs which a CRITICAL status will result<br>";<br>}<br></p>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font> </div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">################### END PROGRAM ######################</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font> </div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">#########################################################</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"># Checking URL</span></font>
</div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">########################################################
</span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">define service{</span></font>
</div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> host_name <a href="http://hostname.com">
hostname.com</a></span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> service_description check-url
</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> check_command check_url!hostname.com/script.cgi!1!2
</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> max_check_attempts 5</span>
</font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> normal_check_interval 5
</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> retry_check_interval 3
</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> check_period 24x7
</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> notification_interval 0
</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> notification_period 24x7
</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> notification_options c,r
</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> contact_groups web-admins
</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">}</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">##########################################################
</span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font> </div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">###### Check command ########################</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"># check_url command definition
</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">define command{</span></font>
</div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">command_name check_url</span>
</font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">command_line $USER1$/check_url -u $HOSTADDRESS$ -c $ARG1$</span></font></div>
<div class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">}</span></font></div>
<p class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Thank you for your envisaged help</span></font></p>
<p> </p>
<div><br clear="all"><br>-- <br>"I might be a slow walker but I never walk backwards" <br>-Johnny Walker </div>