[Nagiosplug-help] Output of check_http not consistent

Thomas Guyot-Sionnest dermoth at aei.ca
Wed May 23 07:35:04 CEST 2007


On 23/05/07 12:49 AM, Olivier 'Babar' Raginel wrote:
> On Tue, May 22, 2007 at 09:51:50PM -0400, Thomas Guyot-Sionnest wrote:
>> If you get the data from Nagios there's a macro that gives you only the
>> perfdata part. If you have no choice but use the full output, then you
>> should discard anything before the first pipe (including the pipe
>> itself) and any whitespace after it. The perfdata specifications are
>> explained in details here:
>>
>> http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN202
> 
> I think he's talking about some external tool, like nagiosgraph, which 
> runs some code when some patterns are matched.
> The problem is to figure out what kind of data you're receiving. As you 
> cn only check output and perfdata, you have to find some regexp which 
> matches your check_http but nothing else.
>>From what I guess, he's referring about the default map file which comes 
> with nagiosgraph:
> http://nagiosgraph.cvs.sourceforge.net/nagiosgraph/nagiosgraph/map?revision=1.10&view=markup&pathrev=HEAD
> 
>   170 # Service type: unix-www
>   171 #   ouput:HTTP OK HTTP/1.1 200 OK - 1456 bytes in 0.003 seconds
>   172 /output:HTTP.*?(\d+) byte.*?([.0-9]+) sec/
>   173 and push @s, [ http,
>   174                [ bps, GAUGE, $1/$2 ] ];

OUCH!

Why being so complicated?? And more importantly, why using service
output when everything is in the perfdata part? (and if it's not, it's a
better idea to fix the plugin than write code that will very likely
break in future release of Nagios-Plugins!).

Also, the bps calculation there is not a very useful thing since it
takes into account the response time. Many factor other than bandwidth
can influence that value, so it's totally useless. The real transfer
rate could be calculated independently within check_http but in many
case it would be infinite due to the small size of check pages.


Here's what we do in a perfdata caching daemon we use (Old version at:
http://control-alt-del.org/code/NPDaemon/ ; I guess now is a good time
to post the updated version to NagiosExchange... Should be there soon.).

This works on any kind of performance data we seen so far. The idea is
to return a label suitable for a RRD DS name that is as unique as the
original labels.

I added a lot of comments so you won't have to unscramble the regexps :)

-----
    # $data_couplets holds the unparsed performance data
    if (!$data_couplets) {
      # clear data cache for that host if there's no performance data
      print "No data\n";
      undef $DataCache->{$host}->{$service};
    } else {
      # clear data cache before re-populating it.
      undef $DataCache->{$host}->{$service};

      # Strip out characters we don't want
      $data_couplets =~ s/['"]//g;
      $DataCache->{$host}->{$service} = { TimeStamp => $timestamp };

      # This loop iterate over each performance data item and put it
      # in $1
      while ($data_couplets =~ s/^\s*(.+?=.+?)\s//) {

        # Data couplet format:
        # label=000.0000<optionalstring>;<optional garbage>
        my $dc = $1;

        # This put the label in $1 and data in $2 stripping any other
        # character
        $dc =~ /^(.+?)=(\d+(?:\.\d+)?)([^;]+)?.*/;
        my ($c,$dd) = ($1,$2);

        # Dunno; maybe labels can contain spaces? Won't hurt anyway
        $c =~ s/ /_/g;

        # Substitutes "/" to "root" since "/" isn't allowed as a RRD
        # DS name
        $c =~ s/^\/$/root/;

        # Strip out any other illegal characters for a DS
        $c =~ s/[^a-zA-Z0-9_]//g;

        # a DS can't be longer than 19 characters, since we can get
        # OIDs in here we need the LAST 19 characters.
        $c = substr($c,-19,19);
        next if (!defined($dd) || !$service);

        # Put the item in cache if it's still valid.
        $DataCache->{$host}->{$service}->{Data}->{$c} = $dd;
      }
    }
-----

Thomas




More information about the Help mailing list