Skip to content

Conversation

@infraweavers
Copy link
Contributor

Previously, the call to check_threshold would set the threshold on the Monitoring::Plugin object, if thresholds are defined, this means that these 2 snippets have different behaviour:

my $returnCode = $mp->check_threshold($connectionCount);

$mp->add_perfdata(
        label => "OpenVPN clients",
        value => $connectionCount,
        threshold => $mp->threshold
);

$mp->plugin_exit(
        return_code => $returnCode,
        message => $connectionCount . " OpenVPN clients"
);
$mp->add_perfdata(
        label => "OpenVPN clients",
        value => $connectionCount,
        threshold => $mp->threshold
);

$mp->plugin_exit(
        return_code => $mp->check_threshold($connectionCount),
        message => $connectionCount . " OpenVPN clients"
);

To us, this is unexpected. The first snippet, will have thresholds on the perfdata, whereas the second will not. This PR should change the behaviour so that $mp->threshold will exist from as early as possible, so need to run check_threshold before add_perfdata is no longer there.

Open to alternatives if this introduces some behaviour we're not aware of

Copy link
Contributor

@sni sni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Thanks

@sni
Copy link
Contributor

sni commented Sep 9, 2020

Let me have a look at the travis tests, they seem unrelated to this PR.

@sni
Copy link
Contributor

sni commented Sep 9, 2020

could you please rebase this PR, should be fixed with f1e3e73

…eated when warning and critical is passed in, so that order of execution between $mp->check_threshold and $mp->add_perfdata doesn't matter
@infraweavers
Copy link
Contributor Author

@sni done 👍

@sni sni merged commit 9d1b15a into monitoring-plugins:master Sep 9, 2020
@sni
Copy link
Contributor

sni commented Sep 9, 2020

thanks

$self->set_thresholds(
warning => $self->opts->warning,
critical => $self->opts->critical,
) if ( defined $self->opts->warning && defined $self->opts->critical );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but what if only one of the threshold is set (warning or critical)? Maybe I'm mistaken but I though that's a valid/common use case (maybe you want to only warn, never go critical...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats a valid point. It previously checked $self->opts while it now checks critical and warning. This should at least be an or or reverted to the opts check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure, we'll switch it to an or

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Successfully merging this pull request may close these issues.

3 participants