Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue Dec 3, 2015 · 1 comment
Open

Comments

@ghost
Copy link

ghost commented Dec 3, 2015

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
Copy link
Contributor

sni commented Dec 3, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant