From 0b62478ad269cc6042dfc411619cfe0f6c9517aa Mon Sep 17 00:00:00 2001 From: A Codeweavers Infrastructure Bod <36475663+infraweavers@users.noreply.github.com> Date: Wed, 9 Sep 2020 10:59:13 +0100 Subject: We think it is better to always have a threshold object implicitly created when warning and critical is passed in, so that order of execution between $mp->check_threshold and $mp->add_perfdata doesn't matter --- lib/Monitoring/Plugin.pm | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/Monitoring/Plugin.pm b/lib/Monitoring/Plugin.pm index 3b4d7b3..3660ba7 100644 --- a/lib/Monitoring/Plugin.pm +++ b/lib/Monitoring/Plugin.pm @@ -131,8 +131,7 @@ sub check_threshold { # in order of preference, get warning and critical from # 1. explicit arguments to check_threshold - # 2. previously explicitly set threshold object - # 3. implicit options from Getopts object + # 2. previously explicitly set threshold object or implicit theshold object created by warning and critical if ( exists $args{warning} || exists $args{critical} ) { $self->set_thresholds( warning => $args{warning}, @@ -142,12 +141,6 @@ sub check_threshold { elsif ( defined $self->threshold ) { # noop } - elsif ( defined $self->opts ) { - $self->set_thresholds( - warning => $self->opts->warning, - critical => $self->opts->critical, - ); - } else { return UNKNOWN; } @@ -163,6 +156,10 @@ sub add_arg { sub getopts { my $self = shift; $self->opts->getopts(@_) if $self->_check_for_opts; + $self->set_thresholds( + warning => $self->opts->warning, + critical => $self->opts->critical, + ) if ( defined $self->opts->warning && defined $self->opts->critical ); } sub _check_for_opts { -- cgit v1.2.3-74-g34f1