diff options
author | A Codeweavers Infrastructure Bod <36475663+infraweavers@users.noreply.github.com> | 2020-09-09 10:59:13 +0100 |
---|---|---|
committer | A Codeweavers Infrastructure Bod <36475663+infraweavers@users.noreply.github.com> | 2020-09-09 13:21:25 +0100 |
commit | 0b62478ad269cc6042dfc411619cfe0f6c9517aa (patch) | |
tree | b01b5c521ff22a842521c6ccb95d91aab729eda1 | |
parent | f1e3e739775d5781553c207f856b618df9467a85 (diff) | |
download | monitoring-plugin-perl-0b62478ad269cc6042dfc411619cfe0f6c9517aa.tar.gz |
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
-rw-r--r-- | lib/Monitoring/Plugin.pm | 13 |
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 { | |||
163 | sub getopts { | 156 | sub 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 | ||
168 | sub _check_for_opts { | 165 | sub _check_for_opts { |