diff options
Diffstat (limited to 'plugins/check_hpjd.c')
-rw-r--r-- | plugins/check_hpjd.c | 253 |
1 files changed, 102 insertions, 151 deletions
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index cb93a36e..edde341e 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c | |||
@@ -29,36 +29,7 @@ const char *copyright = "2000-2003"; | |||
29 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 29 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
30 | 30 | ||
31 | const char *option_summary = "-H host [-C community]\n"; | 31 | const char *option_summary = "-H host [-C community]\n"; |
32 | void | ||
33 | print_usage (void) | ||
34 | { | ||
35 | printf (_("\ | ||
36 | Usage: %s -H host [-C community]\n"), progname); | ||
37 | printf (_(UT_HLP_VRS), progname, progname); | ||
38 | } | ||
39 | 32 | ||
40 | void | ||
41 | print_help (void) | ||
42 | { | ||
43 | print_revision (progname, revision); | ||
44 | |||
45 | printf (_(COPYRIGHT), copyright, email); | ||
46 | |||
47 | printf (_("\ | ||
48 | This plugin tests the STATUS of an HP printer with a JetDirect card.\n\ | ||
49 | Net-snmp must be installed on the computer running the plugin.\n\n")); | ||
50 | |||
51 | print_usage (); | ||
52 | |||
53 | printf (_(UT_HELP_VRSN)); | ||
54 | |||
55 | printf (_("\ | ||
56 | -C, --community=STRING\n\ | ||
57 | The SNMP community name (default=%s)\n"), DEFAULT_COMMUNITY); | ||
58 | |||
59 | printf (_(UT_SUPPORT)); | ||
60 | } | ||
61 | |||
62 | #define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1" | 33 | #define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1" |
63 | #define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2" | 34 | #define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2" |
64 | #define HPJD_INTERVENTION_REQUIRED ".1.3.6.1.4.1.11.2.3.9.1.1.2.3" | 35 | #define HPJD_INTERVENTION_REQUIRED ".1.3.6.1.4.1.11.2.3.9.1.1.2.3" |
@@ -77,8 +48,10 @@ Net-snmp must be installed on the computer running the plugin.\n\n")); | |||
77 | 48 | ||
78 | int process_arguments (int, char **); | 49 | int process_arguments (int, char **); |
79 | int validate_arguments (void); | 50 | int validate_arguments (void); |
51 | void print_help (void); | ||
52 | void print_usage (void); | ||
80 | 53 | ||
81 | char *community = DEFAULT_COMMUNITY; | 54 | char *community = NULL; |
82 | char *address = NULL; | 55 | char *address = NULL; |
83 | 56 | ||
84 | int | 57 | int |
@@ -89,7 +62,7 @@ main (int argc, char **argv) | |||
89 | int line; | 62 | int line; |
90 | char input_buffer[MAX_INPUT_BUFFER]; | 63 | char input_buffer[MAX_INPUT_BUFFER]; |
91 | char query_string[512]; | 64 | char query_string[512]; |
92 | char error_message[MAX_INPUT_BUFFER]; | 65 | char *errmsg; |
93 | char *temp_buffer; | 66 | char *temp_buffer; |
94 | int line_status = ONLINE; | 67 | int line_status = ONLINE; |
95 | int paper_status = 0; | 68 | int paper_status = 0; |
@@ -103,7 +76,8 @@ main (int argc, char **argv) | |||
103 | int door_open = 0; | 76 | int door_open = 0; |
104 | int paper_output = 0; | 77 | int paper_output = 0; |
105 | char display_message[MAX_INPUT_BUFFER]; | 78 | char display_message[MAX_INPUT_BUFFER]; |
106 | char *temp ; | 79 | |
80 | errmsg = malloc(MAX_INPUT_BUFFER); | ||
107 | 81 | ||
108 | if (process_arguments (argc, argv) != OK) | 82 | if (process_arguments (argc, argv) != OK) |
109 | usage (_("Invalid command arguments supplied\n")); | 83 | usage (_("Invalid command arguments supplied\n")); |
@@ -154,118 +128,55 @@ main (int argc, char **argv) | |||
154 | temp_buffer = strtok (input_buffer, "="); | 128 | temp_buffer = strtok (input_buffer, "="); |
155 | temp_buffer = strtok (NULL, "="); | 129 | temp_buffer = strtok (NULL, "="); |
156 | 130 | ||
157 | switch (line) { | 131 | if (temp_buffer != NULL) { |
158 | 132 | ||
159 | case 1: /* 1st line should contain the line status */ | ||
160 | if (temp_buffer != NULL) | ||
161 | line_status = atoi (temp_buffer); | ||
162 | else { | ||
163 | result = STATE_UNKNOWN; | 133 | result = STATE_UNKNOWN; |
164 | strcpy (error_message, input_buffer); | 134 | strcpy (errmsg, input_buffer); |
165 | } | ||
166 | break; | ||
167 | 135 | ||
168 | case 2: /* 2nd line should contain the paper status */ | 136 | } else { |
169 | if (temp_buffer != NULL) | ||
170 | paper_status = atoi (temp_buffer); | ||
171 | else { | ||
172 | result = STATE_UNKNOWN; | ||
173 | strcpy (error_message, input_buffer); | ||
174 | } | ||
175 | break; | ||
176 | 137 | ||
177 | case 3: /* 3rd line should be intervention required */ | 138 | switch (line) { |
178 | if (temp_buffer != NULL) | ||
179 | intervention_required = atoi (temp_buffer); | ||
180 | else { | ||
181 | result = STATE_UNKNOWN; | ||
182 | strcpy (error_message, input_buffer); | ||
183 | } | ||
184 | break; | ||
185 | 139 | ||
186 | case 4: /* 4th line should be peripheral error */ | 140 | case 1: /* 1st line should contain the line status */ |
187 | if (temp_buffer != NULL) | 141 | line_status = atoi (temp_buffer); |
142 | break; | ||
143 | case 2: /* 2nd line should contain the paper status */ | ||
144 | paper_status = atoi (temp_buffer); | ||
145 | break; | ||
146 | case 3: /* 3rd line should be intervention required */ | ||
147 | intervention_required = atoi (temp_buffer); | ||
148 | break; | ||
149 | case 4: /* 4th line should be peripheral error */ | ||
188 | peripheral_error = atoi (temp_buffer); | 150 | peripheral_error = atoi (temp_buffer); |
189 | else { | 151 | break; |
190 | result = STATE_UNKNOWN; | 152 | case 5: /* 5th line should contain the paper jam status */ |
191 | strcpy (error_message, input_buffer); | ||
192 | } | ||
193 | break; | ||
194 | |||
195 | case 5: /* 5th line should contain the paper jam status */ | ||
196 | if (temp_buffer != NULL) | ||
197 | paper_jam = atoi (temp_buffer); | 153 | paper_jam = atoi (temp_buffer); |
198 | else { | 154 | break; |
199 | result = STATE_UNKNOWN; | 155 | case 6: /* 6th line should contain the paper out status */ |
200 | strcpy (error_message, input_buffer); | ||
201 | } | ||
202 | break; | ||
203 | |||
204 | case 6: /* 6th line should contain the paper out status */ | ||
205 | if (temp_buffer != NULL) | ||
206 | paper_out = atoi (temp_buffer); | 156 | paper_out = atoi (temp_buffer); |
207 | else { | 157 | break; |
208 | result = STATE_UNKNOWN; | 158 | case 7: /* 7th line should contain the toner low status */ |
209 | strcpy (error_message, input_buffer); | ||
210 | } | ||
211 | break; | ||
212 | |||
213 | case 7: /* 7th line should contain the toner low status */ | ||
214 | if (temp_buffer != NULL) | ||
215 | toner_low = atoi (temp_buffer); | 159 | toner_low = atoi (temp_buffer); |
216 | else { | 160 | break; |
217 | result = STATE_UNKNOWN; | 161 | case 8: /* did data come too slow for engine */ |
218 | strcpy (error_message, input_buffer); | ||
219 | } | ||
220 | break; | ||
221 | |||
222 | case 8: /* did data come too slow for engine */ | ||
223 | if (temp_buffer != NULL) | ||
224 | page_punt = atoi (temp_buffer); | 162 | page_punt = atoi (temp_buffer); |
225 | else { | 163 | break; |
226 | result = STATE_UNKNOWN; | 164 | case 9: /* did we run out of memory */ |
227 | strcpy (error_message, input_buffer); | ||
228 | } | ||
229 | break; | ||
230 | |||
231 | case 9: /* did we run out of memory */ | ||
232 | if (temp_buffer != NULL) | ||
233 | memory_out = atoi (temp_buffer); | 165 | memory_out = atoi (temp_buffer); |
234 | else { | 166 | break; |
235 | result = STATE_UNKNOWN; | 167 | case 10: /* is there a door open */ |
236 | strcpy (error_message, input_buffer); | ||
237 | } | ||
238 | break; | ||
239 | |||
240 | case 10: /* is there a door open */ | ||
241 | if (temp_buffer != NULL) | ||
242 | door_open = atoi (temp_buffer); | 168 | door_open = atoi (temp_buffer); |
243 | else { | 169 | break; |
244 | result = STATE_UNKNOWN; | 170 | case 11: /* is output tray full */ |
245 | strcpy (error_message, input_buffer); | ||
246 | } | ||
247 | break; | ||
248 | |||
249 | case 11: /* is output tray full */ | ||
250 | if (temp_buffer != NULL) | ||
251 | paper_output = atoi (temp_buffer); | 171 | paper_output = atoi (temp_buffer); |
252 | else { | 172 | break; |
253 | result = STATE_UNKNOWN; | 173 | case 12: /* display panel message */ |
254 | strcpy (error_message, input_buffer); | ||
255 | } | ||
256 | break; | ||
257 | |||
258 | case 12: /* display panel message */ | ||
259 | if (temp_buffer != NULL) | ||
260 | strcpy (display_message, temp_buffer + 1); | 174 | strcpy (display_message, temp_buffer + 1); |
261 | else { | 175 | break; |
262 | result = STATE_UNKNOWN; | 176 | default: |
263 | strcpy (error_message, input_buffer); | 177 | break; |
264 | } | 178 | } |
265 | break; | ||
266 | 179 | ||
267 | default: | ||
268 | break; | ||
269 | } | 180 | } |
270 | 181 | ||
271 | /* break out of the read loop if we encounter an error */ | 182 | /* break out of the read loop if we encounter an error */ |
@@ -279,7 +190,7 @@ main (int argc, char **argv) | |||
279 | /* remove CRLF */ | 190 | /* remove CRLF */ |
280 | if (input_buffer[strlen (input_buffer) - 1] == '\n') | 191 | if (input_buffer[strlen (input_buffer) - 1] == '\n') |
281 | input_buffer[strlen (input_buffer) - 1] = 0; | 192 | input_buffer[strlen (input_buffer) - 1] = 0; |
282 | sprintf (error_message, "%s", input_buffer ); | 193 | sprintf (errmsg, "%s", input_buffer ); |
283 | 194 | ||
284 | } | 195 | } |
285 | 196 | ||
@@ -295,8 +206,7 @@ main (int argc, char **argv) | |||
295 | 206 | ||
296 | /* might not be the problem, but most likely is. */ | 207 | /* might not be the problem, but most likely is. */ |
297 | result = STATE_UNKNOWN ; | 208 | result = STATE_UNKNOWN ; |
298 | asprintf (&temp, error_message); | 209 | asprintf (&errmsg, "%s : Timeout from host %s\n", errmsg, address ); |
299 | sprintf (error_message, "%s : Timeout from host %s\n", temp, address ); | ||
300 | 210 | ||
301 | } | 211 | } |
302 | 212 | ||
@@ -305,49 +215,49 @@ main (int argc, char **argv) | |||
305 | 215 | ||
306 | if (paper_jam) { | 216 | if (paper_jam) { |
307 | result = STATE_WARNING; | 217 | result = STATE_WARNING; |
308 | strcpy (error_message, _("Paper Jam")); | 218 | strcpy (errmsg, _("Paper Jam")); |
309 | } | 219 | } |
310 | else if (paper_out) { | 220 | else if (paper_out) { |
311 | result = STATE_WARNING; | 221 | result = STATE_WARNING; |
312 | strcpy (error_message, _("Out of Paper")); | 222 | strcpy (errmsg, _("Out of Paper")); |
313 | } | 223 | } |
314 | else if (line_status == OFFLINE) { | 224 | else if (line_status == OFFLINE) { |
315 | if (strcmp (error_message, "POWERSAVE ON") != 0) { | 225 | if (strcmp (errmsg, "POWERSAVE ON") != 0) { |
316 | result = STATE_WARNING; | 226 | result = STATE_WARNING; |
317 | strcpy (error_message, _("Printer Offline")); | 227 | strcpy (errmsg, _("Printer Offline")); |
318 | } | 228 | } |
319 | } | 229 | } |
320 | else if (peripheral_error) { | 230 | else if (peripheral_error) { |
321 | result = STATE_WARNING; | 231 | result = STATE_WARNING; |
322 | strcpy (error_message, _("Peripheral Error")); | 232 | strcpy (errmsg, _("Peripheral Error")); |
323 | } | 233 | } |
324 | else if (intervention_required) { | 234 | else if (intervention_required) { |
325 | result = STATE_WARNING; | 235 | result = STATE_WARNING; |
326 | strcpy (error_message, _("Intervention Required")); | 236 | strcpy (errmsg, _("Intervention Required")); |
327 | } | 237 | } |
328 | else if (toner_low) { | 238 | else if (toner_low) { |
329 | result = STATE_WARNING; | 239 | result = STATE_WARNING; |
330 | strcpy (error_message, _("Toner Low")); | 240 | strcpy (errmsg, _("Toner Low")); |
331 | } | 241 | } |
332 | else if (memory_out) { | 242 | else if (memory_out) { |
333 | result = STATE_WARNING; | 243 | result = STATE_WARNING; |
334 | strcpy (error_message, _("Insufficient Memory")); | 244 | strcpy (errmsg, _("Insufficient Memory")); |
335 | } | 245 | } |
336 | else if (door_open) { | 246 | else if (door_open) { |
337 | result = STATE_WARNING; | 247 | result = STATE_WARNING; |
338 | strcpy (error_message, _("A Door is Open")); | 248 | strcpy (errmsg, _("A Door is Open")); |
339 | } | 249 | } |
340 | else if (paper_output) { | 250 | else if (paper_output) { |
341 | result = STATE_WARNING; | 251 | result = STATE_WARNING; |
342 | strcpy (error_message, _("Output Tray is Full")); | 252 | strcpy (errmsg, _("Output Tray is Full")); |
343 | } | 253 | } |
344 | else if (page_punt) { | 254 | else if (page_punt) { |
345 | result = STATE_WARNING; | 255 | result = STATE_WARNING; |
346 | strcpy (error_message, _("Data too Slow for Engine")); | 256 | strcpy (errmsg, _("Data too Slow for Engine")); |
347 | } | 257 | } |
348 | else if (paper_status) { | 258 | else if (paper_status) { |
349 | result = STATE_WARNING; | 259 | result = STATE_WARNING; |
350 | strcpy (error_message, _("Unknown Paper Error")); | 260 | strcpy (errmsg, _("Unknown Paper Error")); |
351 | } | 261 | } |
352 | } | 262 | } |
353 | 263 | ||
@@ -356,15 +266,15 @@ main (int argc, char **argv) | |||
356 | 266 | ||
357 | else if (result == STATE_UNKNOWN) { | 267 | else if (result == STATE_UNKNOWN) { |
358 | 268 | ||
359 | printf ("%s\n", error_message); | 269 | printf ("%s\n", errmsg); |
360 | 270 | ||
361 | /* if printer could not be reached, escalate to critical */ | 271 | /* if printer could not be reached, escalate to critical */ |
362 | if (strstr (error_message, "Timeout")) | 272 | if (strstr (errmsg, "Timeout")) |
363 | result = STATE_CRITICAL; | 273 | result = STATE_CRITICAL; |
364 | } | 274 | } |
365 | 275 | ||
366 | else if (result == STATE_WARNING) | 276 | else if (result == STATE_WARNING) |
367 | printf ("%s (%s)\n", error_message, display_message); | 277 | printf ("%s (%s)\n", errmsg, display_message); |
368 | 278 | ||
369 | return result; | 279 | return result; |
370 | } | 280 | } |
@@ -379,8 +289,8 @@ process_arguments (int argc, char **argv) | |||
379 | { | 289 | { |
380 | int c; | 290 | int c; |
381 | 291 | ||
382 | int option_index = 0; | 292 | int option = 0; |
383 | static struct option long_options[] = { | 293 | static struct option longopts[] = { |
384 | {"hostname", required_argument, 0, 'H'}, | 294 | {"hostname", required_argument, 0, 'H'}, |
385 | {"community", required_argument, 0, 'C'}, | 295 | {"community", required_argument, 0, 'C'}, |
386 | /* {"critical", required_argument,0,'c'}, */ | 296 | /* {"critical", required_argument,0,'c'}, */ |
@@ -396,7 +306,7 @@ process_arguments (int argc, char **argv) | |||
396 | 306 | ||
397 | 307 | ||
398 | while (1) { | 308 | while (1) { |
399 | c = getopt_long (argc, argv, "+hVH:C:", long_options, &option_index); | 309 | c = getopt_long (argc, argv, "+hVH:C:", longopts, &option); |
400 | 310 | ||
401 | if (c == -1 || c == EOF || c == 1) | 311 | if (c == -1 || c == EOF || c == 1) |
402 | break; | 312 | break; |
@@ -434,8 +344,11 @@ process_arguments (int argc, char **argv) | |||
434 | } | 344 | } |
435 | } | 345 | } |
436 | 346 | ||
437 | if (argv[c] != NULL ) { | 347 | if (community == NULL) { |
438 | community = argv[c]; | 348 | if (argv[c] != NULL ) |
349 | community = argv[c]; | ||
350 | else | ||
351 | community = strdup (DEFAULT_COMMUNITY); | ||
439 | } | 352 | } |
440 | 353 | ||
441 | return validate_arguments (); | 354 | return validate_arguments (); |
@@ -450,3 +363,41 @@ validate_arguments (void) | |||
450 | { | 363 | { |
451 | return OK; | 364 | return OK; |
452 | } | 365 | } |
366 | |||
367 | |||
368 | |||
369 | |||
370 | |||
371 | |||
372 | void | ||
373 | print_help (void) | ||
374 | { | ||
375 | print_revision (progname, revision); | ||
376 | |||
377 | printf (_(COPYRIGHT), copyright, email); | ||
378 | |||
379 | printf (_("\ | ||
380 | This plugin tests the STATUS of an HP printer with a JetDirect card.\n\ | ||
381 | Net-snmp must be installed on the computer running the plugin.\n\n")); | ||
382 | |||
383 | print_usage (); | ||
384 | |||
385 | printf (_(UT_HELP_VRSN)); | ||
386 | |||
387 | printf (_("\ | ||
388 | -C, --community=STRING\n\ | ||
389 | The SNMP community name (default=%s)\n"), DEFAULT_COMMUNITY); | ||
390 | |||
391 | printf (_(UT_SUPPORT)); | ||
392 | } | ||
393 | |||
394 | |||
395 | |||
396 | |||
397 | void | ||
398 | print_usage (void) | ||
399 | { | ||
400 | printf (_("\ | ||
401 | Usage: %s -H host [-C community]\n"), progname); | ||
402 | printf (_(UT_HLP_VRS), progname, progname); | ||
403 | } | ||