diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_ups.c | 118 |
1 files changed, 72 insertions, 46 deletions
diff --git a/plugins/check_ups.c b/plugins/check_ups.c index 391c1db..335cb99 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c | |||
@@ -52,8 +52,8 @@ char *server_address; | |||
52 | char *ups_name = NULL; | 52 | char *ups_name = NULL; |
53 | double warning_value = 0.0; | 53 | double warning_value = 0.0; |
54 | double critical_value = 0.0; | 54 | double critical_value = 0.0; |
55 | int check_warning_value = FALSE; | 55 | int check_warn = FALSE; |
56 | int check_critical_value = FALSE; | 56 | int check_crit = FALSE; |
57 | int check_variable = UPS_NONE; | 57 | int check_variable = UPS_NONE; |
58 | int supported_options = UPS_NONE; | 58 | int supported_options = UPS_NONE; |
59 | int status = UPSSTATUS_NONE; | 59 | int status = UPSSTATUS_NONE; |
@@ -78,6 +78,7 @@ main (int argc, char **argv) | |||
78 | { | 78 | { |
79 | int result = STATE_OK; | 79 | int result = STATE_OK; |
80 | char *message; | 80 | char *message; |
81 | char *data; | ||
81 | char temp_buffer[MAX_INPUT_BUFFER]; | 82 | char temp_buffer[MAX_INPUT_BUFFER]; |
82 | double ups_utility_deviation = 0.0; | 83 | double ups_utility_deviation = 0.0; |
83 | 84 | ||
@@ -140,6 +141,7 @@ main (int argc, char **argv) | |||
140 | asprintf (&ups_status, "%s%s", ups_status, ", Unknown"); | 141 | asprintf (&ups_status, "%s%s", ups_status, ", Unknown"); |
141 | } | 142 | } |
142 | } | 143 | } |
144 | asprintf (&message, "%sStatus=%s ", message, ups_status); | ||
143 | } | 145 | } |
144 | 146 | ||
145 | /* get the ups utility voltage if possible */ | 147 | /* get the ups utility voltage if possible */ |
@@ -149,6 +151,7 @@ main (int argc, char **argv) | |||
149 | return STATE_CRITICAL; | 151 | return STATE_CRITICAL; |
150 | 152 | ||
151 | ups_utility_voltage = atof (temp_buffer); | 153 | ups_utility_voltage = atof (temp_buffer); |
154 | asprintf (&message, "%sUtility=%3.1fV ", message, ups_utility_voltage); | ||
152 | 155 | ||
153 | if (ups_utility_voltage > 120.0) | 156 | if (ups_utility_voltage > 120.0) |
154 | ups_utility_deviation = 120.0 - ups_utility_voltage; | 157 | ups_utility_deviation = 120.0 - ups_utility_voltage; |
@@ -156,11 +159,21 @@ main (int argc, char **argv) | |||
156 | ups_utility_deviation = ups_utility_voltage - 120.0; | 159 | ups_utility_deviation = ups_utility_voltage - 120.0; |
157 | 160 | ||
158 | if (check_variable == UPS_UTILITY) { | 161 | if (check_variable == UPS_UTILITY) { |
159 | if (check_critical_value == TRUE | 162 | if (check_crit==TRUE && ups_utility_deviation>=critical_value) { |
160 | && ups_utility_deviation >= critical_value) result = STATE_CRITICAL; | 163 | result = STATE_CRITICAL; |
161 | else if (check_warning_value == TRUE | 164 | } |
162 | && ups_utility_deviation >= warning_value | 165 | else if (check_warn==TRUE && ups_utility_deviation>=warning_value) { |
163 | && result < STATE_WARNING) result = STATE_WARNING; | 166 | result = max_state (result, STATE_WARNING); |
167 | } | ||
168 | asprintf (&data, "%s ", | ||
169 | perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", | ||
170 | check_warn, (long)(1000*warning_value), | ||
171 | check_crit, (long)(1000*critical_value), | ||
172 | TRUE, 0, FALSE, 0)); | ||
173 | } else { | ||
174 | asprintf (&data, "%s ", | ||
175 | perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", | ||
176 | FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); | ||
164 | } | 177 | } |
165 | } | 178 | } |
166 | 179 | ||
@@ -171,13 +184,24 @@ main (int argc, char **argv) | |||
171 | return STATE_CRITICAL; | 184 | return STATE_CRITICAL; |
172 | 185 | ||
173 | ups_battery_percent = atof (temp_buffer); | 186 | ups_battery_percent = atof (temp_buffer); |
187 | asprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent); | ||
174 | 188 | ||
175 | if (check_variable == UPS_BATTPCT) { | 189 | if (check_variable == UPS_BATTPCT) { |
176 | if (check_critical_value == TRUE | 190 | if (check_crit==TRUE && ups_battery_percent <= critical_value) { |
177 | && ups_battery_percent <= critical_value) result = STATE_CRITICAL; | 191 | result = STATE_CRITICAL; |
178 | else if (check_warning_value == TRUE | 192 | } |
179 | && ups_battery_percent <= warning_value | 193 | else if (check_warn==TRUE && ups_battery_percent<=warning_value) { |
180 | && result < STATE_WARNING) result = STATE_WARNING; | 194 | result = max_state (result, STATE_WARNING); |
195 | } | ||
196 | asprintf (&data, "%s ", | ||
197 | perfdata ("battery", (long)ups_battery_percent, "%", | ||
198 | check_warn, (long)(1000*warning_value), | ||
199 | check_crit, (long)(1000*critical_value), | ||
200 | TRUE, 0, TRUE, 100)); | ||
201 | } else { | ||
202 | asprintf (&data, "%s ", | ||
203 | perfdata ("battery", (long)ups_battery_percent, "%", | ||
204 | FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); | ||
181 | } | 205 | } |
182 | } | 206 | } |
183 | 207 | ||
@@ -188,13 +212,24 @@ main (int argc, char **argv) | |||
188 | return STATE_CRITICAL; | 212 | return STATE_CRITICAL; |
189 | 213 | ||
190 | ups_load_percent = atof (temp_buffer); | 214 | ups_load_percent = atof (temp_buffer); |
215 | asprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent); | ||
191 | 216 | ||
192 | if (check_variable == UPS_LOADPCT) { | 217 | if (check_variable == UPS_LOADPCT) { |
193 | if (check_critical_value == TRUE && ups_load_percent >= critical_value) | 218 | if (check_crit==TRUE && ups_load_percent>=critical_value) { |
194 | result = STATE_CRITICAL; | 219 | result = STATE_CRITICAL; |
195 | else if (check_warning_value == TRUE | 220 | } |
196 | && ups_load_percent >= warning_value && result < STATE_WARNING) | 221 | else if (check_warn==TRUE && ups_load_percent>=warning_value) { |
197 | result = STATE_WARNING; | 222 | result = max_state (result, STATE_WARNING); |
223 | } | ||
224 | asprintf (&data, "%s ", | ||
225 | perfdata ("load", (long)ups_load_percent, "%", | ||
226 | check_warn, (long)(1000*warning_value), | ||
227 | check_crit, (long)(1000*critical_value), | ||
228 | TRUE, 0, TRUE, 100)); | ||
229 | } else { | ||
230 | asprintf (&data, "%s ", | ||
231 | perfdata ("load", (long)ups_load_percent, "%", | ||
232 | FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); | ||
198 | } | 233 | } |
199 | } | 234 | } |
200 | 235 | ||
@@ -205,46 +240,37 @@ main (int argc, char **argv) | |||
205 | return STATE_CRITICAL; | 240 | return STATE_CRITICAL; |
206 | 241 | ||
207 | ups_temperature = (atof (temp_buffer) * 1.8) + 32; | 242 | ups_temperature = (atof (temp_buffer) * 1.8) + 32; |
243 | asprintf (&message, "%sTemp=%3.1fF", message, ups_temperature); | ||
208 | 244 | ||
209 | if (check_variable == UPS_TEMP) { | 245 | if (check_variable == UPS_TEMP) { |
210 | if (check_critical_value == TRUE && ups_temperature >= critical_value) | 246 | if (check_crit==TRUE && ups_temperature>=critical_value) { |
211 | result = STATE_CRITICAL; | 247 | result = STATE_CRITICAL; |
212 | else if (check_warning_value == TRUE && ups_temperature >= warning_value | 248 | } |
213 | && result < STATE_WARNING) | 249 | else if (check_warn == TRUE && ups_temperature>=warning_value) { |
214 | result = STATE_WARNING; | 250 | result = max_state (result, STATE_WARNING); |
251 | } | ||
252 | asprintf (&data, "%s ", | ||
253 | perfdata ("temp", (long)ups_temperature, "degF", | ||
254 | check_warn, (long)(1000*warning_value), | ||
255 | check_crit, (long)(1000*critical_value), | ||
256 | TRUE, 0, FALSE, 0)); | ||
257 | } else { | ||
258 | asprintf (&data, "%s ", | ||
259 | perfdata ("temp", (long)ups_temperature, "degF", | ||
260 | FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); | ||
215 | } | 261 | } |
216 | } | 262 | } |
217 | 263 | ||
218 | /* if the UPS does not support any options we are looking for, report an error */ | 264 | /* if the UPS does not support any options we are looking for, report an error */ |
219 | if (supported_options == UPS_NONE) | 265 | if (supported_options == UPS_NONE) { |
220 | result = STATE_CRITICAL; | 266 | result = STATE_CRITICAL; |
267 | asprintf (&message, "UPS does not support any available options\n"); | ||
268 | } | ||
221 | 269 | ||
222 | /* reset timeout */ | 270 | /* reset timeout */ |
223 | alarm (0); | 271 | alarm (0); |
224 | 272 | ||
225 | 273 | printf ("UPS %s - %s|%s\n", state_text(result), message, data); | |
226 | asprintf (&message, "UPS %s - ", (result == STATE_OK) ? "ok" : "problem"); | ||
227 | |||
228 | if (supported_options & UPS_STATUS) | ||
229 | asprintf (&message, "%sStatus=%s ", message, ups_status); | ||
230 | |||
231 | if (supported_options & UPS_UTILITY) | ||
232 | asprintf (&message, "%sUtility=%3.1fV ", message, ups_utility_voltage); | ||
233 | |||
234 | if (supported_options & UPS_BATTPCT) | ||
235 | asprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent); | ||
236 | |||
237 | if (supported_options & UPS_LOADPCT) | ||
238 | asprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent); | ||
239 | |||
240 | if (supported_options & UPS_TEMP) | ||
241 | asprintf (&message, "%sTemp=%3.1fF", message, ups_temperature); | ||
242 | |||
243 | if (supported_options == UPS_NONE) | ||
244 | asprintf (&message, "UPS does not support any available options\n"); | ||
245 | |||
246 | printf ("%s\n", message); | ||
247 | |||
248 | return result; | 274 | return result; |
249 | } | 275 | } |
250 | 276 | ||
@@ -462,7 +488,7 @@ process_arguments (int argc, char **argv) | |||
462 | case 'c': /* critical time threshold */ | 488 | case 'c': /* critical time threshold */ |
463 | if (is_intnonneg (optarg)) { | 489 | if (is_intnonneg (optarg)) { |
464 | critical_value = atoi (optarg); | 490 | critical_value = atoi (optarg); |
465 | check_critical_value = TRUE; | 491 | check_crit = TRUE; |
466 | } | 492 | } |
467 | else { | 493 | else { |
468 | usage2 ("Critical time must be a nonnegative integer", optarg); | 494 | usage2 ("Critical time must be a nonnegative integer", optarg); |
@@ -471,7 +497,7 @@ process_arguments (int argc, char **argv) | |||
471 | case 'w': /* warning time threshold */ | 497 | case 'w': /* warning time threshold */ |
472 | if (is_intnonneg (optarg)) { | 498 | if (is_intnonneg (optarg)) { |
473 | warning_value = atoi (optarg); | 499 | warning_value = atoi (optarg); |
474 | check_warning_value = TRUE; | 500 | check_warn = TRUE; |
475 | } | 501 | } |
476 | else { | 502 | else { |
477 | usage2 ("Warning time must be a nonnegative integer", optarg); | 503 | usage2 ("Warning time must be a nonnegative integer", optarg); |