Skip to content

Commit 0b62478

Browse files
committed
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
1 parent f1e3e73 commit 0b62478

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

lib/Monitoring/Plugin.pm

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ sub check_threshold {
131131

132132
# in order of preference, get warning and critical from
133133
# 1. explicit arguments to check_threshold
134-
# 2. previously explicitly set threshold object
135-
# 3. implicit options from Getopts object
134+
# 2. previously explicitly set threshold object or implicit theshold object created by warning and critical
136135
if ( exists $args{warning} || exists $args{critical} ) {
137136
$self->set_thresholds(
138137
warning => $args{warning},
@@ -142,12 +141,6 @@ sub check_threshold {
142141
elsif ( defined $self->threshold ) {
143142
# noop
144143
}
145-
elsif ( defined $self->opts ) {
146-
$self->set_thresholds(
147-
warning => $self->opts->warning,
148-
critical => $self->opts->critical,
149-
);
150-
}
151144
else {
152145
return UNKNOWN;
153146
}
@@ -163,6 +156,10 @@ sub add_arg {
163156
sub getopts {
164157
my $self = shift;
165158
$self->opts->getopts(@_) if $self->_check_for_opts;
159+
$self->set_thresholds(
160+
warning => $self->opts->warning,
161+
critical => $self->opts->critical,
162+
) if ( defined $self->opts->warning && defined $self->opts->critical );
166163
}
167164

168165
sub _check_for_opts {

0 commit comments

Comments
 (0)