summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2020-09-09 14:25:34 +0200
committerGitHub <noreply@github.com>2020-09-09 14:25:34 +0200
commit9d1b15abb56a9d2d00ed56cabfae4d176bd1e955 (patch)
treeb01b5c521ff22a842521c6ccb95d91aab729eda1
parentf1e3e739775d5781553c207f856b618df9467a85 (diff)
parent0b62478ad269cc6042dfc411619cfe0f6c9517aa (diff)
downloadmonitoring-plugin-perl-9d1b15abb56a9d2d00ed56cabfae4d176bd1e955.tar.gz
Merge pull request #22 from infraweavers/ImplicitThreshold
Implicitly creating a threshold object in getopts rather than check_threshold
-rw-r--r--lib/Monitoring/Plugin.pm13
1 files changed, 5 insertions, 8 deletions
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 {
131 131
132 # in order of preference, get warning and critical from 132 # in order of preference, get warning and critical from
133 # 1. explicit arguments to check_threshold 133 # 1. explicit arguments to check_threshold
134 # 2. previously explicitly set threshold object 134 # 2. previously explicitly set threshold object or implicit theshold object created by warning and critical
135 # 3. implicit options from Getopts object
136 if ( exists $args{warning} || exists $args{critical} ) { 135 if ( exists $args{warning} || exists $args{critical} ) {
137 $self->set_thresholds( 136 $self->set_thresholds(
138 warning => $args{warning}, 137 warning => $args{warning},
@@ -142,12 +141,6 @@ sub check_threshold {
142 elsif ( defined $self->threshold ) { 141 elsif ( defined $self->threshold ) {
143 # noop 142 # noop
144 } 143 }
145 elsif ( defined $self->opts ) {
146 $self->set_thresholds(
147 warning => $self->opts->warning,
148 critical => $self->opts->critical,
149 );
150 }
151 else { 144 else {
152 return UNKNOWN; 145 return UNKNOWN;
153 } 146 }
@@ -163,6 +156,10 @@ sub add_arg {
163sub getopts { 156sub getopts {
164 my $self = shift; 157 my $self = shift;
165 $self->opts->getopts(@_) if $self->_check_for_opts; 158 $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 );
166} 163}
167 164
168sub _check_for_opts { 165sub _check_for_opts {