summaryrefslogtreecommitdiffstats
path: root/web/attachments/121777-nagiosplug-cvs-check_hpjd.diff
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/121777-nagiosplug-cvs-check_hpjd.diff')
-rw-r--r--web/attachments/121777-nagiosplug-cvs-check_hpjd.diff332
1 files changed, 332 insertions, 0 deletions
diff --git a/web/attachments/121777-nagiosplug-cvs-check_hpjd.diff b/web/attachments/121777-nagiosplug-cvs-check_hpjd.diff
new file mode 100644
index 0000000..77d2699
--- /dev/null
+++ b/web/attachments/121777-nagiosplug-cvs-check_hpjd.diff
@@ -0,0 +1,332 @@
1diff -urN ./plugins/check_hpjd.c ../plugins/plugins/check_hpjd.c
2--- ./plugins/check_hpjd.c 2005-01-05 21:53:13.000000000 +0100
3+++ ../plugins/plugins/check_hpjd.c 2005-02-18 13:02:58.000000000 +0100
4@@ -44,6 +44,7 @@
5 #define HPJD_GD_DOOR_OPEN ".1.3.6.1.4.1.11.2.3.9.1.1.2.17"
6 #define HPJD_GD_PAPER_OUTPUT ".1.3.6.1.4.1.11.2.3.9.1.1.2.19"
7 #define HPJD_GD_STATUS_DISPLAY ".1.3.6.1.4.1.11.2.3.9.1.1.3"
8+#define SNMP_VARS 12
9
10 #define ONLINE 0
11 #define OFFLINE 1
12@@ -61,23 +62,30 @@
13 {
14 char command_line[1024];
15 int result = STATE_UNKNOWN;
16- int line;
17+ int line, val = 0;
18 char input_buffer[MAX_INPUT_BUFFER];
19 char query_string[512];
20 char *errmsg;
21 char *temp_buffer;
22 int line_status = ONLINE;
23- int paper_status = 0;
24- int intervention_required = 0;
25- int peripheral_error = 0;
26- int paper_jam = 0;
27- int paper_out = 0;
28- int toner_low = 0;
29- int page_punt = 0;
30- int memory_out = 0;
31- int door_open = 0;
32- int paper_output = 0;
33- char display_message[MAX_INPUT_BUFFER];
34+ int errorflag = 0; /* bitflag error tracker */
35+ char *display_message;
36+ char *errmsg_strings[11];
37+ int i;
38+
39+ /* get the error messages. Will complain about discarded qualifiers
40+ * with --disable-nls, but that doesn't matter since they're immutable */
41+ errmsg_strings[0] = _("Paper Jam");
42+ errmsg_strings[1] = _("Out of Paper");
43+ errmsg_strings[2] = _("Printer Offline");
44+ errmsg_strings[3] = _("Peripheral Error");
45+ errmsg_strings[4] = _("Intervention Required");
46+ errmsg_strings[5] = _("Toner Low");
47+ errmsg_strings[6] = _("Insufficient Memory");
48+ errmsg_strings[7] = _("A Door is Open");
49+ errmsg_strings[8] = _("Output Tray is Full");
50+ errmsg_strings[9] = _("Data too Slow for Engine");
51+ errmsg_strings[10] = _("Unknown Paper Error");
52
53 errmsg = malloc(MAX_INPUT_BUFFER);
54
55@@ -90,9 +98,12 @@
56
57 /* removed ' 2>1' at end of command 10/27/1999 - EG */
58 /* create the query string */
59+ /* get status display line first, so we can match line status against
60+ * powersave as we parse it */
61 sprintf
62 (query_string,
63 "%s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0",
64+ HPJD_GD_STATUS_DISPLAY,
65 HPJD_LINE_STATUS,
66 HPJD_PAPER_STATUS,
67 HPJD_INTERVENTION_REQUIRED,
68@@ -102,11 +113,11 @@
69 HPJD_GD_TONER_LOW,
70 HPJD_GD_PAGE_PUNT,
71 HPJD_GD_MEMORY_OUT,
72- HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY);
73+ HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT);
74
75 /* get the command to run */
76- sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s %s", PATH_TO_SNMPGET, community,
77- address, query_string);
78+ sprintf (command_line, "%s -Oqa -m : -v 1 -c %s %s %s", PATH_TO_SNMPGET, community,
79+ address, query_string);
80
81 /* run the command */
82 child_process = spopen (command_line);
83@@ -117,170 +128,98 @@
84
85 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
86 if (child_stderr == NULL) {
87- printf (_("Could not open stderr for %s\n"), command_line);
88+ /* don't print newline here, or we might return OK while
89+ * only printing an error message (highly confusing) */
90+ printf (_("Could not open stderr for %s :: "), command_line);
91 }
92
93 result = STATE_OK;
94
95 line = 0;
96+ /* end parsing when we have display_message, since we won't know
97+ * what to do with line 13 or more anyway */
98 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
99+ /* strip the newline character from the end of the input, if any */
100+ temp_buffer = strrchr(input_buffer, '\n');
101+ if(temp_buffer) *temp_buffer = '\0';
102+
103+ if(line == 0) {
104+ display_message = strdup(input_buffer);
105+ continue;
106+ }
107+ val = (int)strtol(input_buffer, NULL, 0);
108+ if(!val) continue; /* no errors here, so don't handle it */
109+ errorflag |= 1 << (line - 1); /* set the error flag */
110+
111+ /* this switch statement is largely for adding additional
112+ * exception handling (POWERSAVE and such) */
113+ switch (line) {
114+ case 1: /* line status */
115+ /* clear the flag if it's powersaving */
116+ if(!strstr("POWERSAVE ON", display_message) != 0)
117+ errorflag ^= 1 << (line - 1);
118+ break;
119
120- /* strip the newline character from the end of the input */
121- if (input_buffer[strlen (input_buffer) - 1] == '\n')
122- input_buffer[strlen (input_buffer) - 1] = 0;
123-
124- line++;
125-
126- temp_buffer = strtok (input_buffer, "=");
127- temp_buffer = strtok (NULL, "=");
128-
129- if (temp_buffer == NULL) {
130-
131- result = STATE_UNKNOWN;
132- strcpy (errmsg, input_buffer);
133-
134- } else {
135-
136- switch (line) {
137-
138- case 1: /* 1st line should contain the line status */
139- line_status = atoi (temp_buffer);
140- break;
141- case 2: /* 2nd line should contain the paper status */
142- paper_status = atoi (temp_buffer);
143- break;
144- case 3: /* 3rd line should be intervention required */
145- intervention_required = atoi (temp_buffer);
146- break;
147- case 4: /* 4th line should be peripheral error */
148- peripheral_error = atoi (temp_buffer);
149- break;
150- case 5: /* 5th line should contain the paper jam status */
151- paper_jam = atoi (temp_buffer);
152- break;
153- case 6: /* 6th line should contain the paper out status */
154- paper_out = atoi (temp_buffer);
155- break;
156- case 7: /* 7th line should contain the toner low status */
157- toner_low = atoi (temp_buffer);
158- break;
159- case 8: /* did data come too slow for engine */
160- page_punt = atoi (temp_buffer);
161- break;
162- case 9: /* did we run out of memory */
163- memory_out = atoi (temp_buffer);
164- break;
165- case 10: /* is there a door open */
166- door_open = atoi (temp_buffer);
167- break;
168- case 11: /* is output tray full */
169- paper_output = atoi (temp_buffer);
170- break;
171- case 12: /* display panel message */
172- strcpy (display_message, temp_buffer + 1);
173- break;
174- default:
175- break;
176- }
177-
178+ case 2: /* paper status */
179+ case 3: /* intervention required */
180+ case 4: /* peripheral error */
181+ case 5: /* paper jam */
182+ case 6: /* paper out */
183+ case 7: /* toner low */
184+ case 8: /* data came too slow for engine */
185+ case 9: /* out of memory */
186+ case 10: /* is there a door open */
187+ case 11: /* is output tray full */
188+ default: /* notreached */
189+ break;
190 }
191
192- /* break out of the read loop if we encounter an error */
193- if (result != STATE_OK)
194+ if(++line >= SNMP_VARS)
195 break;
196 }
197
198- /* WARNING if output found on stderr */
199- if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
200+ /* WARNING if output found on stderr, but only if we
201+ * haven't already found an error condition */
202+ if (!errorflag && fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
203 result = max_state (result, STATE_WARNING);
204 /* remove CRLF */
205 if (input_buffer[strlen (input_buffer) - 1] == '\n')
206 input_buffer[strlen (input_buffer) - 1] = 0;
207- sprintf (errmsg, "%s", input_buffer );
208-
209+ strncpy(errmsg, input_buffer, sizeof(errmsg));
210 }
211-
212+
213 /* close stderr */
214 (void) fclose (child_stderr);
215
216- /* close the pipe */
217+ /* close the pipe. set warning at least if snmpget didn't return 0 */
218 if (spclose (child_process))
219- result = max_state (result, STATE_WARNING);
220+ result = STATE_WARNING;
221
222 /* if there wasn't any output, display an error */
223 if (line == 0) {
224-
225- /* might not be the problem, but most likely is. */
226- result = STATE_UNKNOWN ;
227- asprintf (&errmsg, "%s : Timeout from host %s\n", errmsg, address );
228-
229- }
230-
231- /* if we had no read errors, check the printer status results... */
232- if (result == STATE_OK) {
233-
234- if (paper_jam) {
235- result = STATE_WARNING;
236- strcpy (errmsg, _("Paper Jam"));
237- }
238- else if (paper_out) {
239- result = STATE_WARNING;
240- strcpy (errmsg, _("Out of Paper"));
241- }
242- else if (line_status == OFFLINE) {
243- if (strcmp (errmsg, "POWERSAVE ON") != 0) {
244- result = STATE_WARNING;
245- strcpy (errmsg, _("Printer Offline"));
246- }
247- }
248- else if (peripheral_error) {
249- result = STATE_WARNING;
250- strcpy (errmsg, _("Peripheral Error"));
251- }
252- else if (intervention_required) {
253- result = STATE_WARNING;
254- strcpy (errmsg, _("Intervention Required"));
255- }
256- else if (toner_low) {
257- result = STATE_WARNING;
258- strcpy (errmsg, _("Toner Low"));
259- }
260- else if (memory_out) {
261- result = STATE_WARNING;
262- strcpy (errmsg, _("Insufficient Memory"));
263- }
264- else if (door_open) {
265- result = STATE_WARNING;
266- strcpy (errmsg, _("A Door is Open"));
267- }
268- else if (paper_output) {
269- result = STATE_WARNING;
270- strcpy (errmsg, _("Output Tray is Full"));
271- }
272- else if (page_punt) {
273- result = STATE_WARNING;
274- strcpy (errmsg, _("Data too Slow for Engine"));
275- }
276- else if (paper_status) {
277- result = STATE_WARNING;
278- strcpy (errmsg, _("Unknown Paper Error"));
279- }
280+ /* timeout is not necessarily the problem, and produces wildly
281+ * inaccurate error messages when it isn't, so just say
282+ * the host didn't return anything and return immediately
283+ * (old plugin unconditionally escalated STATE_UNKNOWN to
284+ * STATE_CRITICAL at the end, so this just saves a bit of
285+ * indentation. */
286+ printf (_("%s : No data returned from %s\n"), errmsg, address );
287+ return STATE_CRITICAL;
288 }
289
290- if (result == STATE_OK)
291+ /* obviously no read errors, so check the printer status results... */
292+ if (!errors) {
293+ result = STATE_OK;
294 printf (_("Printer ok - (%s)\n"), display_message);
295-
296- else if (result == STATE_UNKNOWN) {
297-
298- printf ("%s\n", errmsg);
299-
300- /* if printer could not be reached, escalate to critical */
301- if (strstr (errmsg, "Timeout"))
302- result = STATE_CRITICAL;
303 }
304-
305- else if (result == STATE_WARNING)
306- printf ("%s (%s)\n", errmsg, display_message);
307+ else {
308+ /* some error occured, so print them all */
309+ while(i < SNMP_VARS) {
310+ printf ("%s (%s)\n", errmsg ? errmsg : "", display_message);
311+ if((errorflag >> i) & 1) /* only print if flag is set */
312+ printf(":: %s", errmsg_strings[i++]);
313+ }
314+ }
315
316 return result;
317 }
318@@ -346,12 +285,12 @@
319 usage2 (_("Invalid hostname/address"), argv[c]);
320 }
321 }
322-
323+
324 if (community == NULL) {
325 if (argv[c] != NULL )
326 community = argv[c];
327 else
328- community = strdup (DEFAULT_COMMUNITY);
329+ community = DEFAULT_COMMUNITY;
330 }
331
332 return validate_arguments ();