You are here

How to get values out of HTTP content?

2 posts / 0 new
Last post
jake_1
jake_1's picture
How to get values out of HTTP content?

I need a service check will connect to a webserver, download the default page, then look in the content and pull in values to OpsView.  The content on the website is sensor data from an Arduino board.  I just want to import the values so I can use them in performance gauges..  What service check plugin supports this functionality?

Duncan Ferguson
dferguson's picture
We have plugins such as check

We have plugins such as check_http that will check on web page contents, but none that will turn that content into performance counters.

If you have scripting skills you are best writing our own plugin to do this as it is dependant on how the data is returned in the web page.  A possible example in perl might be:

#!/usr/bin/env perl
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request;

my $ua=LWP::UserAgent->new();
my $req=HTTP::Request->new( GET => 'http://localhost' );
my $response=$ua->request($req);
my ($perfdata)=$response->content =~ m/something=(\d+)/;
say "Fetched data - something=$perfdata | something=$perfdata";
exit 0;

You can make the script as simple or as complex as you like - the above does not do error checking on fetching the page and does not accept arguments for critical or warning levels (it will only evern return an 'OK'/green status).

There are many examples of scripts within the /usr/local/nagios/libexec directory you can use to write your script and it can be written in perl, bash, bourne, python, ruby or whatever your personal favourite is.  There are guidelines on writing plugins at https://www.monitoring-plugins.org/doc/guidelines.html

  Duncs