Nagios-Plugin-WWW-Mechanize and nagios_exit

Anders.DaSilva at softronic.se Anders.DaSilva at softronic.se
Sun Apr 10 09:10:33 CEST 2011


Hi.
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])

Nagios-Plugin-WWW-Mechanize automatically outputs performance data, but only the time taken to load a webpage, without the warn etc..:
time=2.137s;; - so i think i need to get warn and crit in there aswell.

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()

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?


#!/usr/bin/perl -w
#Returvärden från nagios
#%ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4)

  use strict;
  use Nagios::Plugin::WWW::Mechanize;

  use lib "/usr/lib/nagios/plugins";
  use utils qw(%ERRORS $TIMEOUT);

  use lib "/usr/lib/nagios/plugins";
  use utils qw(%ERRORS $TIMEOUT);

  BEGIN {*Nagios::Plugin::WWW::Mechanize::nagios_exit = sub {
  my ($self, @args) = @_;

        #I want to use Nagios::Plugin::nagios_exit here!!
        nagios_exit( @args );
}};

  my $loadtime = 0;
  my $np = Nagios::Plugin::WWW::Mechanize->new(
    usage => "Checks loadtime of list", shortname => "test list"
  );
  $np->add_arg(
    spec=> 'warning|w=s',
    help=> "-w, --warning=RANGE",
    required=> 1
  );
  $np->getopts;

  $np->get( "http://example.com/site" );
  $np->submit_form( form_name => "login", fields => { userId => "*******", password => "*******" } );
  my $content = $np->content;

  #printf("%.3f %.3f %3f", time() - $^T, time(), $^T);
  $loadtime = time() - $^T;
  my $res = '';
($res) = ($content =~ /name/);
  $np->nagios_exit( CRITICAL, "problem" ) unless defined $res;

  $np->add_perfdata(
    label => "time",
    value => $loadtime
  );
  $np->nagios_exit( OK,"");


regards
Anders
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20110410/6c7cb1fe/attachment.html>
-------------- next part --------------
------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
-------------- 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