Skip to content

Commit 9d1b15a

Browse files
authored
Merge pull request #22 from infraweavers/ImplicitThreshold
Implicitly creating a threshold object in getopts rather than check_threshold
2 parents f1e3e73 + 0b62478 commit 9d1b15a

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

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)