monitoring-plugins / monitoring-plugin-perl

Perl module Monitoring::Plugin - Nagios::Plugin
http://search.cpan.org/dist/Monitoring-Plugin/
42 stars 20 forks source link

Performance.pm->perfoutput does not handle empty value correctly #4

Open ghost opened 8 years ago

ghost commented 8 years ago

I use check_squid.pl developed by Cyril Feraudet in Version 1.1

That uses package Nagios::Plugin which is version 0.36

The script gives out invalid performance data because value is sometimes empty and that is not handleded correctly and leads to invalid performance data output.

check_squid.pl creates a new Nagios::Plugin object and then adds the performance value with method add_perfdata

pnp4nagios claims invalid performance data, which is true, because after the = sign comes directly the UOM:

2015-11-27 11:45:06 [2996] [1] Found Performance Data for MYHOST / Squid_Cache ('Requests Hit Ratio 5min'=0.0%;; 'Requests Hit Ratio 60min'=0.2%;; 'Byte Hit Ratio 5min'=%;; 'Byte Hit Ratio 60min'=%;;)
2015-11-27 11:45:06 [2996] [1] Invalid Perfdata detected

I did a workaround for this in Performance.pm perfoutput method like so:

sub perfoutput {
    my $self = shift;
    # Add quotes if label contains a space character
    my $label = $self->label;
    if ($label =~ / /) {
        $label = "'$label'";
    }

    my $value = $self->value;

    if ($value eq '') {
        $value = 'U';
    }

    my $out = sprintf "%s=%s%s;%s;%s;%s;%s",
        $label,
        $value,
        $self->_nvl($self->uom),
        $self->_nvl($self->warning),
        $self->_nvl($self->critical),
        $self->_nvl($self->min),
        $self->_nvl($self->max);
    # Previous implementation omitted trailing ;; - do we need this?
    $out =~ s/;;$//;

    return $out;
}

So if value is empty, it is changed to value "U" which means that the value could not have been determined, according to Nagios Plugin development guidelines, section Performance data.

sni commented 8 years ago

Seems legit to me. Could you please open a pull request?