<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi.<br>
Im trying to get Nagios-Plugin-WWW-Mechanize to output performancedata that nagiosgraph will recognize in the default map file. That should be: (data[,warn][,crit][,min][,max])<br>
<br>
Nagios-Plugin-WWW-Mechanize automatically outputs performance data, but only the time taken to load a webpage, without the warn etc..:<br>
time=2.137s;; - so i think i need to get warn and crit in there aswell.<br>
<br>
I would like to override nagios_exit from Nagios-Plugin-WWW-Mechanize with nagios_exit from Nagios-Plugin so that all default performancedata output are removed and i can add my own with add_perfdata()<br>
<br>
I tried the script below, but i can't get the override to function properly, maybe it's easier to just skip this plugin and use Nagios-Plugin and WWW-Mechanize separate from eachother instead? what do people think?<br>
<br>
<br>
#!/usr/bin/perl -w<br>
#Returvärden från nagios<br>
#%ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4)<br>
<br>
use strict;<br>
use Nagios::Plugin::WWW::Mechanize;<br>
<br>
use lib "/usr/lib/nagios/plugins";<br>
use utils qw(%ERRORS $TIMEOUT);<br>
<br>
use lib "/usr/lib/nagios/plugins";<br>
use utils qw(%ERRORS $TIMEOUT);<br>
<br>
BEGIN {*Nagios::Plugin::WWW::Mechanize::nagios_exit = sub {<br>
my ($self, @args) = @_;<br>
<br>
#I want to use Nagios::Plugin::nagios_exit here!!<br>
nagios_exit( @args );<br>
}};<br>
<br>
my $loadtime = 0;<br>
my $np = Nagios::Plugin::WWW::Mechanize->new(<br>
usage => "Checks loadtime of list", shortname => "test list"<br>
);<br>
$np->add_arg(<br>
spec=> 'warning|w=s',<br>
help=> "-w, --warning=RANGE",<br>
required=> 1<br>
);<br>
$np->getopts;<br>
<br>
$np->get( "http://example.com/site" );<br>
$np->submit_form( form_name => "login", fields => { userId => "*******", password => "*******" } );<br>
my $content = $np->content;<br>
<br>
#printf("%.3f %.3f %3f", time() - $^T, time(), $^T);<br>
$loadtime = time() - $^T;<br>
my $res = '';<br>
($res) = ($content =~ /name/);<br>
$np->nagios_exit( CRITICAL, "problem" ) unless defined $res;<br>
<br>
$np->add_perfdata(<br>
label => "time",<br>
value => $loadtime<br>
);<br>
$np->nagios_exit( OK,"");<br>
<br>
<br>
regards<br>
Anders<br>
</div>
</body>
</html>