How to use `Nagios::Plugin::WWW::Mechanize`

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
bostonangus
Posts: 10
Joined: Tue Jun 30, 2015 2:17 pm

How to use `Nagios::Plugin::WWW::Mechanize`

Post by bostonangus »

I'm writing a simple Perl plugin to check the response times of a few different webpages. I want to extract links from a url using Mechanize. The documentation seems pretty straight forward but my test is already failing to run with only a few simple lines:

This test runs fine:

Code: Select all

#!/usr/bin/perl

use strict;
use warnings;

use LWP::Simple;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new();

my $response = $ua->get("somewebsite.com");

if ($response->is_success) {
    print $response->status_line;
    exit(0);
} else {
    print $response->status_line;
    exit(2);
}
But with the addition of these Mechanize related lines, the test fails:

Code: Select all

#!/usr/bin/perl

use strict;
use warnings;

use LWP::Simple;
use LWP::UserAgent;
use Nagios::Plugin::WWW::Mechanize;    # new line

my $mech = Nagios::Plugin::WWW::Mechanize->new();    # new line
$mech->get("somewebsite.com");    # new line

my $ua = LWP::UserAgent->new();

my $response = $ua->get("somewebsite.com");

if ($response->is_success) {
    print $response->status_line;
    exit(0);
} else {
    print $response->status_line;
    exit(2);
}
I realize the addition of Mechanize at this point doesn't add any functionality or do anything, but I don't think it should be failing.
Do I need to add the Mechanize plugin to my plugins folder on the server? I thought they worked like Ruby gems in that you can just require them and they work.

Any help would be great, thanks!
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: How to use `Nagios::Plugin::WWW::Mechanize`

Post by tmcdonald »

Can you show the output of running the script?

I want to point out that the Nagios::Plugin::WWW::Mechanize perl module was not created by us, so any support we can offer is based mostly on trial and error. I'm a bit of a perl guy myself so I'll do what I can, but at some point posting to a dedicated perl forum or contacting the author directly might be necessary.

Also, moving this from the Nagios Core section to Nagios Plugin Development.
Former Nagios employee
Locked