diff options
Diffstat (limited to 'plugins/check_hpjd.c')
-rw-r--r-- | plugins/check_hpjd.c | 419 |
1 files changed, 183 insertions, 236 deletions
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index c34bb08..b39bccf 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c | |||
@@ -1,36 +1,36 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_hpjd plugin | 3 | * Monitoring check_hpjd plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2000-2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 2000-2024 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains the check_hpjd plugin | 10 | * This file contains the check_hpjd plugin |
11 | * | 11 | * |
12 | * This plugin tests the STATUS of an HP printer with a JetDirect card. | 12 | * This plugin tests the STATUS of an HP printer with a JetDirect card. |
13 | * Net-SNMP must be installed on the computer running the plugin. | 13 | * Net-SNMP must be installed on the computer running the plugin. |
14 | * | 14 | * |
15 | * | 15 | * |
16 | * This program is free software: you can redistribute it and/or modify | 16 | * This program is free software: you can redistribute it and/or modify |
17 | * it under the terms of the GNU General Public License as published by | 17 | * it under the terms of the GNU General Public License as published by |
18 | * the Free Software Foundation, either version 3 of the License, or | 18 | * the Free Software Foundation, either version 3 of the License, or |
19 | * (at your option) any later version. | 19 | * (at your option) any later version. |
20 | * | 20 | * |
21 | * This program is distributed in the hope that it will be useful, | 21 | * This program is distributed in the hope that it will be useful, |
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24 | * GNU General Public License for more details. | 24 | * GNU General Public License for more details. |
25 | * | 25 | * |
26 | * You should have received a copy of the GNU General Public License | 26 | * You should have received a copy of the GNU General Public License |
27 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 27 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
28 | * | 28 | * |
29 | * | 29 | * |
30 | *****************************************************************************/ | 30 | *****************************************************************************/ |
31 | 31 | ||
32 | const char *progname = "check_hpjd"; | 32 | const char *progname = "check_hpjd"; |
33 | const char *copyright = "2000-2007"; | 33 | const char *copyright = "2000-2024"; |
34 | const char *email = "devel@monitoring-plugins.org"; | 34 | const char *email = "devel@monitoring-plugins.org"; |
35 | 35 | ||
36 | #include "common.h" | 36 | #include "common.h" |
@@ -39,9 +39,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
39 | #include "netutils.h" | 39 | #include "netutils.h" |
40 | 40 | ||
41 | #define DEFAULT_COMMUNITY "public" | 41 | #define DEFAULT_COMMUNITY "public" |
42 | #define DEFAULT_PORT "161" | 42 | #define DEFAULT_PORT "161" |
43 | |||
44 | const char *option_summary = "-H host [-C community]\n"; | ||
45 | 43 | ||
46 | #define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1" | 44 | #define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1" |
47 | #define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2" | 45 | #define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2" |
@@ -56,22 +54,20 @@ const char *option_summary = "-H host [-C community]\n"; | |||
56 | #define HPJD_GD_PAPER_OUTPUT ".1.3.6.1.4.1.11.2.3.9.1.1.2.19" | 54 | #define HPJD_GD_PAPER_OUTPUT ".1.3.6.1.4.1.11.2.3.9.1.1.2.19" |
57 | #define HPJD_GD_STATUS_DISPLAY ".1.3.6.1.4.1.11.2.3.9.1.1.3" | 55 | #define HPJD_GD_STATUS_DISPLAY ".1.3.6.1.4.1.11.2.3.9.1.1.3" |
58 | 56 | ||
59 | #define ONLINE 0 | 57 | #define ONLINE 0 |
60 | #define OFFLINE 1 | 58 | #define OFFLINE 1 |
61 | 59 | ||
62 | int process_arguments (int, char **); | 60 | static int process_arguments(int /*argc*/, char ** /*argv*/); |
63 | int validate_arguments (void); | 61 | static int validate_arguments(void); |
64 | void print_help (void); | 62 | static void print_help(void); |
65 | void print_usage (void); | 63 | void print_usage(void); |
66 | 64 | ||
67 | char *community = NULL; | 65 | static char *community = NULL; |
68 | char *address = NULL; | 66 | static char *address = NULL; |
69 | unsigned int port = 0; | 67 | static unsigned int port = 0; |
70 | int check_paper_out = 1; | 68 | static int check_paper_out = 1; |
71 | 69 | ||
72 | int | 70 | int main(int argc, char **argv) { |
73 | main (int argc, char **argv) | ||
74 | { | ||
75 | char command_line[1024]; | 71 | char command_line[1024]; |
76 | int result = STATE_UNKNOWN; | 72 | int result = STATE_UNKNOWN; |
77 | int line; | 73 | int line; |
@@ -94,116 +90,99 @@ main (int argc, char **argv) | |||
94 | 90 | ||
95 | errmsg = malloc(MAX_INPUT_BUFFER); | 91 | errmsg = malloc(MAX_INPUT_BUFFER); |
96 | 92 | ||
97 | setlocale (LC_ALL, ""); | 93 | setlocale(LC_ALL, ""); |
98 | bindtextdomain (PACKAGE, LOCALEDIR); | 94 | bindtextdomain(PACKAGE, LOCALEDIR); |
99 | textdomain (PACKAGE); | 95 | textdomain(PACKAGE); |
100 | 96 | ||
101 | /* Parse extra opts if any */ | 97 | /* Parse extra opts if any */ |
102 | argv=np_extra_opts (&argc, argv, progname); | 98 | argv = np_extra_opts(&argc, argv, progname); |
103 | 99 | ||
104 | if (process_arguments (argc, argv) == ERROR) | 100 | if (process_arguments(argc, argv) == ERROR) |
105 | usage4 (_("Could not parse arguments")); | 101 | usage4(_("Could not parse arguments")); |
106 | 102 | ||
107 | /* removed ' 2>1' at end of command 10/27/1999 - EG */ | 103 | /* removed ' 2>1' at end of command 10/27/1999 - EG */ |
108 | /* create the query string */ | 104 | /* create the query string */ |
109 | sprintf | 105 | sprintf(query_string, "%s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0", HPJD_LINE_STATUS, HPJD_PAPER_STATUS, |
110 | (query_string, | 106 | HPJD_INTERVENTION_REQUIRED, HPJD_GD_PERIPHERAL_ERROR, HPJD_GD_PAPER_JAM, HPJD_GD_PAPER_OUT, HPJD_GD_TONER_LOW, |
111 | "%s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0", | 107 | HPJD_GD_PAGE_PUNT, HPJD_GD_MEMORY_OUT, HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY); |
112 | HPJD_LINE_STATUS, | ||
113 | HPJD_PAPER_STATUS, | ||
114 | HPJD_INTERVENTION_REQUIRED, | ||
115 | HPJD_GD_PERIPHERAL_ERROR, | ||
116 | HPJD_GD_PAPER_JAM, | ||
117 | HPJD_GD_PAPER_OUT, | ||
118 | HPJD_GD_TONER_LOW, | ||
119 | HPJD_GD_PAGE_PUNT, | ||
120 | HPJD_GD_MEMORY_OUT, | ||
121 | HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY); | ||
122 | 108 | ||
123 | /* get the command to run */ | 109 | /* get the command to run */ |
124 | sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s:%u %s", | 110 | sprintf(command_line, "%s -OQa -m : -v 1 -c %s %s:%u %s", PATH_TO_SNMPGET, community, address, port, query_string); |
125 | PATH_TO_SNMPGET, | ||
126 | community, | ||
127 | address, | ||
128 | port, | ||
129 | query_string); | ||
130 | 111 | ||
131 | /* run the command */ | 112 | /* run the command */ |
132 | child_process = spopen (command_line); | 113 | child_process = spopen(command_line); |
133 | if (child_process == NULL) { | 114 | if (child_process == NULL) { |
134 | printf (_("Could not open pipe: %s\n"), command_line); | 115 | printf(_("Could not open pipe: %s\n"), command_line); |
135 | return STATE_UNKNOWN; | 116 | return STATE_UNKNOWN; |
136 | } | 117 | } |
137 | 118 | ||
138 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | 119 | child_stderr = fdopen(child_stderr_array[fileno(child_process)], "r"); |
139 | if (child_stderr == NULL) { | 120 | if (child_stderr == NULL) { |
140 | printf (_("Could not open stderr for %s\n"), command_line); | 121 | printf(_("Could not open stderr for %s\n"), command_line); |
141 | } | 122 | } |
142 | 123 | ||
143 | result = STATE_OK; | 124 | result = STATE_OK; |
144 | 125 | ||
145 | line = 0; | 126 | line = 0; |
146 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 127 | while (fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { |
147 | 128 | ||
148 | /* strip the newline character from the end of the input */ | 129 | /* strip the newline character from the end of the input */ |
149 | if (input_buffer[strlen (input_buffer) - 1] == '\n') | 130 | if (input_buffer[strlen(input_buffer) - 1] == '\n') |
150 | input_buffer[strlen (input_buffer) - 1] = 0; | 131 | input_buffer[strlen(input_buffer) - 1] = 0; |
151 | 132 | ||
152 | line++; | 133 | line++; |
153 | 134 | ||
154 | temp_buffer = strtok (input_buffer, "="); | 135 | temp_buffer = strtok(input_buffer, "="); |
155 | temp_buffer = strtok (NULL, "="); | 136 | temp_buffer = strtok(NULL, "="); |
156 | 137 | ||
157 | if (temp_buffer == NULL && line < 13) { | 138 | if (temp_buffer == NULL && line < 13) { |
158 | 139 | ||
159 | result = STATE_UNKNOWN; | 140 | result = STATE_UNKNOWN; |
160 | strcpy (errmsg, input_buffer); | 141 | strcpy(errmsg, input_buffer); |
161 | 142 | ||
162 | } else { | 143 | } else { |
163 | 144 | ||
164 | switch (line) { | 145 | switch (line) { |
165 | 146 | ||
166 | case 1: /* 1st line should contain the line status */ | 147 | case 1: /* 1st line should contain the line status */ |
167 | line_status = atoi (temp_buffer); | 148 | line_status = atoi(temp_buffer); |
168 | break; | 149 | break; |
169 | case 2: /* 2nd line should contain the paper status */ | 150 | case 2: /* 2nd line should contain the paper status */ |
170 | paper_status = atoi (temp_buffer); | 151 | paper_status = atoi(temp_buffer); |
171 | break; | 152 | break; |
172 | case 3: /* 3rd line should be intervention required */ | 153 | case 3: /* 3rd line should be intervention required */ |
173 | intervention_required = atoi (temp_buffer); | 154 | intervention_required = atoi(temp_buffer); |
174 | break; | 155 | break; |
175 | case 4: /* 4th line should be peripheral error */ | 156 | case 4: /* 4th line should be peripheral error */ |
176 | peripheral_error = atoi (temp_buffer); | 157 | peripheral_error = atoi(temp_buffer); |
177 | break; | 158 | break; |
178 | case 5: /* 5th line should contain the paper jam status */ | 159 | case 5: /* 5th line should contain the paper jam status */ |
179 | paper_jam = atoi (temp_buffer); | 160 | paper_jam = atoi(temp_buffer); |
180 | break; | 161 | break; |
181 | case 6: /* 6th line should contain the paper out status */ | 162 | case 6: /* 6th line should contain the paper out status */ |
182 | paper_out = atoi (temp_buffer); | 163 | paper_out = atoi(temp_buffer); |
183 | break; | 164 | break; |
184 | case 7: /* 7th line should contain the toner low status */ | 165 | case 7: /* 7th line should contain the toner low status */ |
185 | toner_low = atoi (temp_buffer); | 166 | toner_low = atoi(temp_buffer); |
186 | break; | 167 | break; |
187 | case 8: /* did data come too slow for engine */ | 168 | case 8: /* did data come too slow for engine */ |
188 | page_punt = atoi (temp_buffer); | 169 | page_punt = atoi(temp_buffer); |
189 | break; | 170 | break; |
190 | case 9: /* did we run out of memory */ | 171 | case 9: /* did we run out of memory */ |
191 | memory_out = atoi (temp_buffer); | 172 | memory_out = atoi(temp_buffer); |
192 | break; | 173 | break; |
193 | case 10: /* is there a door open */ | 174 | case 10: /* is there a door open */ |
194 | door_open = atoi (temp_buffer); | 175 | door_open = atoi(temp_buffer); |
195 | break; | 176 | break; |
196 | case 11: /* is output tray full */ | 177 | case 11: /* is output tray full */ |
197 | paper_output = atoi (temp_buffer); | 178 | paper_output = atoi(temp_buffer); |
198 | break; | 179 | break; |
199 | case 12: /* display panel message */ | 180 | case 12: /* display panel message */ |
200 | strcpy (display_message, temp_buffer + 1); | 181 | strcpy(display_message, temp_buffer + 1); |
201 | break; | 182 | break; |
202 | default: /* fold multiline message */ | 183 | default: /* fold multiline message */ |
203 | strncat (display_message, input_buffer, | 184 | strncat(display_message, input_buffer, sizeof(display_message) - strlen(display_message) - 1); |
204 | sizeof (display_message) - strlen (display_message) - 1); | ||
205 | } | 185 | } |
206 | |||
207 | } | 186 | } |
208 | 187 | ||
209 | /* break out of the read loop if we encounter an error */ | 188 | /* break out of the read loop if we encounter an error */ |
@@ -212,29 +191,27 @@ main (int argc, char **argv) | |||
212 | } | 191 | } |
213 | 192 | ||
214 | /* WARNING if output found on stderr */ | 193 | /* WARNING if output found on stderr */ |
215 | if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | 194 | if (fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { |
216 | result = max_state (result, STATE_WARNING); | 195 | result = max_state(result, STATE_WARNING); |
217 | /* remove CRLF */ | 196 | /* remove CRLF */ |
218 | if (input_buffer[strlen (input_buffer) - 1] == '\n') | 197 | if (input_buffer[strlen(input_buffer) - 1] == '\n') |
219 | input_buffer[strlen (input_buffer) - 1] = 0; | 198 | input_buffer[strlen(input_buffer) - 1] = 0; |
220 | sprintf (errmsg, "%s", input_buffer ); | 199 | sprintf(errmsg, "%s", input_buffer); |
221 | |||
222 | } | 200 | } |
223 | 201 | ||
224 | /* close stderr */ | 202 | /* close stderr */ |
225 | (void) fclose (child_stderr); | 203 | (void)fclose(child_stderr); |
226 | 204 | ||
227 | /* close the pipe */ | 205 | /* close the pipe */ |
228 | if (spclose (child_process)) | 206 | if (spclose(child_process)) |
229 | result = max_state (result, STATE_WARNING); | 207 | result = max_state(result, STATE_WARNING); |
230 | 208 | ||
231 | /* if there wasn't any output, display an error */ | 209 | /* if there wasn't any output, display an error */ |
232 | if (line == 0) { | 210 | if (line == 0) { |
233 | 211 | ||
234 | /* might not be the problem, but most likely is. */ | 212 | /* might not be the problem, but most likely is. */ |
235 | result = STATE_UNKNOWN ; | 213 | result = STATE_UNKNOWN; |
236 | xasprintf (&errmsg, "%s : Timeout from host %s\n", errmsg, address ); | 214 | xasprintf(&errmsg, "%s : Timeout from host %s\n", errmsg, address); |
237 | |||
238 | } | 215 | } |
239 | 216 | ||
240 | /* if we had no read errors, check the printer status results... */ | 217 | /* if we had no read errors, check the printer status results... */ |
@@ -242,201 +219,171 @@ main (int argc, char **argv) | |||
242 | 219 | ||
243 | if (paper_jam) { | 220 | if (paper_jam) { |
244 | result = STATE_WARNING; | 221 | result = STATE_WARNING; |
245 | strcpy (errmsg, _("Paper Jam")); | 222 | strcpy(errmsg, _("Paper Jam")); |
246 | } | 223 | } else if (paper_out) { |
247 | else if (paper_out) { | ||
248 | if (check_paper_out) | 224 | if (check_paper_out) |
249 | result = STATE_WARNING; | 225 | result = STATE_WARNING; |
250 | strcpy (errmsg, _("Out of Paper")); | 226 | strcpy(errmsg, _("Out of Paper")); |
251 | } | 227 | } else if (line_status == OFFLINE) { |
252 | else if (line_status == OFFLINE) { | 228 | if (strcmp(errmsg, "POWERSAVE ON") != 0) { |
253 | if (strcmp (errmsg, "POWERSAVE ON") != 0) { | ||
254 | result = STATE_WARNING; | 229 | result = STATE_WARNING; |
255 | strcpy (errmsg, _("Printer Offline")); | 230 | strcpy(errmsg, _("Printer Offline")); |
256 | } | 231 | } |
257 | } | 232 | } else if (peripheral_error) { |
258 | else if (peripheral_error) { | ||
259 | result = STATE_WARNING; | 233 | result = STATE_WARNING; |
260 | strcpy (errmsg, _("Peripheral Error")); | 234 | strcpy(errmsg, _("Peripheral Error")); |
261 | } | 235 | } else if (intervention_required) { |
262 | else if (intervention_required) { | ||
263 | result = STATE_WARNING; | 236 | result = STATE_WARNING; |
264 | strcpy (errmsg, _("Intervention Required")); | 237 | strcpy(errmsg, _("Intervention Required")); |
265 | } | 238 | } else if (toner_low) { |
266 | else if (toner_low) { | ||
267 | result = STATE_WARNING; | 239 | result = STATE_WARNING; |
268 | strcpy (errmsg, _("Toner Low")); | 240 | strcpy(errmsg, _("Toner Low")); |
269 | } | 241 | } else if (memory_out) { |
270 | else if (memory_out) { | ||
271 | result = STATE_WARNING; | 242 | result = STATE_WARNING; |
272 | strcpy (errmsg, _("Insufficient Memory")); | 243 | strcpy(errmsg, _("Insufficient Memory")); |
273 | } | 244 | } else if (door_open) { |
274 | else if (door_open) { | ||
275 | result = STATE_WARNING; | 245 | result = STATE_WARNING; |
276 | strcpy (errmsg, _("A Door is Open")); | 246 | strcpy(errmsg, _("A Door is Open")); |
277 | } | 247 | } else if (paper_output) { |
278 | else if (paper_output) { | ||
279 | result = STATE_WARNING; | 248 | result = STATE_WARNING; |
280 | strcpy (errmsg, _("Output Tray is Full")); | 249 | strcpy(errmsg, _("Output Tray is Full")); |
281 | } | 250 | } else if (page_punt) { |
282 | else if (page_punt) { | ||
283 | result = STATE_WARNING; | 251 | result = STATE_WARNING; |
284 | strcpy (errmsg, _("Data too Slow for Engine")); | 252 | strcpy(errmsg, _("Data too Slow for Engine")); |
285 | } | 253 | } else if (paper_status) { |
286 | else if (paper_status) { | ||
287 | result = STATE_WARNING; | 254 | result = STATE_WARNING; |
288 | strcpy (errmsg, _("Unknown Paper Error")); | 255 | strcpy(errmsg, _("Unknown Paper Error")); |
289 | } | 256 | } |
290 | } | 257 | } |
291 | 258 | ||
292 | if (result == STATE_OK) | 259 | if (result == STATE_OK) |
293 | printf (_("Printer ok - (%s)\n"), display_message); | 260 | printf(_("Printer ok - (%s)\n"), display_message); |
294 | 261 | ||
295 | else if (result == STATE_UNKNOWN) { | 262 | else if (result == STATE_UNKNOWN) { |
296 | 263 | ||
297 | printf ("%s\n", errmsg); | 264 | printf("%s\n", errmsg); |
298 | 265 | ||
299 | /* if printer could not be reached, escalate to critical */ | 266 | /* if printer could not be reached, escalate to critical */ |
300 | if (strstr (errmsg, "Timeout")) | 267 | if (strstr(errmsg, "Timeout")) |
301 | result = STATE_CRITICAL; | 268 | result = STATE_CRITICAL; |
302 | } | 269 | } |
303 | 270 | ||
304 | else if (result == STATE_WARNING) | 271 | else if (result == STATE_WARNING) |
305 | printf ("%s (%s)\n", errmsg, display_message); | 272 | printf("%s (%s)\n", errmsg, display_message); |
306 | 273 | ||
307 | return result; | 274 | return result; |
308 | } | 275 | } |
309 | 276 | ||
310 | |||
311 | /* process command-line arguments */ | 277 | /* process command-line arguments */ |
312 | int | 278 | int process_arguments(int argc, char **argv) { |
313 | process_arguments (int argc, char **argv) | ||
314 | { | ||
315 | int c; | 279 | int c; |
316 | 280 | ||
317 | int option = 0; | 281 | int option = 0; |
318 | static struct option longopts[] = { | 282 | static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, |
319 | {"hostname", required_argument, 0, 'H'}, | 283 | {"community", required_argument, 0, 'C'}, |
320 | {"community", required_argument, 0, 'C'}, | 284 | /* {"critical", required_argument,0,'c'}, */ |
321 | /* {"critical", required_argument,0,'c'}, */ | 285 | /* {"warning", required_argument,0,'w'}, */ |
322 | /* {"warning", required_argument,0,'w'}, */ | 286 | {"port", required_argument, 0, 'p'}, |
323 | {"port", required_argument,0,'p'}, | 287 | {"version", no_argument, 0, 'V'}, |
324 | {"version", no_argument, 0, 'V'}, | 288 | {"help", no_argument, 0, 'h'}, |
325 | {"help", no_argument, 0, 'h'}, | 289 | {0, 0, 0, 0}}; |
326 | {0, 0, 0, 0} | ||
327 | }; | ||
328 | 290 | ||
329 | if (argc < 2) | 291 | if (argc < 2) |
330 | return ERROR; | 292 | return ERROR; |
331 | 293 | ||
332 | |||
333 | while (1) { | 294 | while (1) { |
334 | c = getopt_long (argc, argv, "+hVH:C:p:D", longopts, &option); | 295 | c = getopt_long(argc, argv, "+hVH:C:p:D", longopts, &option); |
335 | 296 | ||
336 | if (c == -1 || c == EOF || c == 1) | 297 | if (c == -1 || c == EOF || c == 1) |
337 | break; | 298 | break; |
338 | 299 | ||
339 | switch (c) { | 300 | switch (c) { |
340 | case 'H': /* hostname */ | 301 | case 'H': /* hostname */ |
341 | if (is_host (optarg)) { | 302 | if (is_host(optarg)) { |
342 | address = strscpy(address, optarg) ; | 303 | address = strscpy(address, optarg); |
343 | } | 304 | } else { |
344 | else { | 305 | usage2(_("Invalid hostname/address"), optarg); |
345 | usage2 (_("Invalid hostname/address"), optarg); | ||
346 | } | 306 | } |
347 | break; | 307 | break; |
348 | case 'C': /* community */ | 308 | case 'C': /* community */ |
349 | community = strscpy (community, optarg); | 309 | community = strscpy(community, optarg); |
350 | break; | 310 | break; |
351 | case 'p': | 311 | case 'p': |
352 | if (!is_intpos(optarg)) | 312 | if (!is_intpos(optarg)) |
353 | usage2 (_("Port must be a positive short integer"), optarg); | 313 | usage2(_("Port must be a positive short integer"), optarg); |
354 | else | 314 | else |
355 | port = atoi(optarg); | 315 | port = atoi(optarg); |
356 | break; | 316 | break; |
357 | case 'D': /* disable paper out check*/ | 317 | case 'D': /* disable paper out check*/ |
358 | check_paper_out = 0; | 318 | check_paper_out = 0; |
359 | break; | 319 | break; |
360 | case 'V': /* version */ | 320 | case 'V': /* version */ |
361 | print_revision (progname, NP_VERSION); | 321 | print_revision(progname, NP_VERSION); |
362 | exit (STATE_UNKNOWN); | 322 | exit(STATE_UNKNOWN); |
363 | case 'h': /* help */ | 323 | case 'h': /* help */ |
364 | print_help (); | 324 | print_help(); |
365 | exit (STATE_UNKNOWN); | 325 | exit(STATE_UNKNOWN); |
366 | case '?': /* help */ | 326 | case '?': /* help */ |
367 | usage5 (); | 327 | usage5(); |
368 | } | 328 | } |
369 | } | 329 | } |
370 | 330 | ||
371 | c = optind; | 331 | c = optind; |
372 | if (address == NULL) { | 332 | if (address == NULL) { |
373 | if (is_host (argv[c])) { | 333 | if (is_host(argv[c])) { |
374 | address = argv[c++]; | 334 | address = argv[c++]; |
375 | } | 335 | } else { |
376 | else { | 336 | usage2(_("Invalid hostname/address"), argv[c]); |
377 | usage2 (_("Invalid hostname/address"), argv[c]); | ||
378 | } | 337 | } |
379 | } | 338 | } |
380 | 339 | ||
381 | if (community == NULL) { | 340 | if (community == NULL) { |
382 | if (argv[c] != NULL ) | 341 | if (argv[c] != NULL) |
383 | community = argv[c]; | 342 | community = argv[c]; |
384 | else | 343 | else |
385 | community = strdup (DEFAULT_COMMUNITY); | 344 | community = strdup(DEFAULT_COMMUNITY); |
386 | } | 345 | } |
387 | 346 | ||
388 | if (port == 0) { | 347 | if (port == 0) { |
389 | port = atoi(DEFAULT_PORT); | 348 | port = atoi(DEFAULT_PORT); |
390 | } | 349 | } |
391 | 350 | ||
392 | return validate_arguments (); | 351 | return validate_arguments(); |
393 | } | ||
394 | |||
395 | |||
396 | int | ||
397 | validate_arguments (void) | ||
398 | { | ||
399 | return OK; | ||
400 | } | 352 | } |
401 | 353 | ||
354 | int validate_arguments(void) { return OK; } | ||
402 | 355 | ||
403 | void | 356 | void print_help(void) { |
404 | print_help (void) | 357 | print_revision(progname, NP_VERSION); |
405 | { | ||
406 | print_revision (progname, NP_VERSION); | ||
407 | 358 | ||
408 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); | 359 | printf("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); |
409 | printf (COPYRIGHT, copyright, email); | 360 | printf(COPYRIGHT, copyright, email); |
410 | 361 | ||
411 | printf ("%s\n", _("This plugin tests the STATUS of an HP printer with a JetDirect card.")); | 362 | printf("%s\n", _("This plugin tests the STATUS of an HP printer with a JetDirect card.")); |
412 | printf ("%s\n", _("Net-snmp must be installed on the computer running the plugin.")); | 363 | printf("%s\n", _("Net-snmp must be installed on the computer running the plugin.")); |
413 | 364 | ||
414 | printf ("\n\n"); | 365 | printf("\n\n"); |
415 | 366 | ||
416 | print_usage (); | 367 | print_usage(); |
417 | 368 | ||
418 | printf (UT_HELP_VRSN); | 369 | printf(UT_HELP_VRSN); |
419 | printf (UT_EXTRA_OPTS); | 370 | printf(UT_EXTRA_OPTS); |
420 | 371 | ||
421 | printf (" %s\n", "-C, --community=STRING"); | 372 | printf(" %s\n", "-C, --community=STRING"); |
422 | printf (" %s", _("The SNMP community name ")); | 373 | printf(" %s", _("The SNMP community name ")); |
423 | printf (_("(default=%s)"), DEFAULT_COMMUNITY); | 374 | printf(_("(default=%s)"), DEFAULT_COMMUNITY); |
424 | printf ("\n"); | 375 | printf("\n"); |
425 | printf (" %s\n", "-p, --port=STRING"); | 376 | printf(" %s\n", "-p, --port=STRING"); |
426 | printf (" %s", _("Specify the port to check ")); | 377 | printf(" %s", _("Specify the port to check ")); |
427 | printf (_("(default=%s)"), DEFAULT_PORT); | 378 | printf(_("(default=%s)"), DEFAULT_PORT); |
428 | printf ("\n"); | 379 | printf("\n"); |
429 | printf (" %s\n", "-D"); | 380 | printf(" %s\n", "-D"); |
430 | printf (" %s", _("Disable paper check ")); | 381 | printf(" %s", _("Disable paper check ")); |
431 | 382 | ||
432 | printf (UT_SUPPORT); | 383 | printf(UT_SUPPORT); |
433 | } | 384 | } |
434 | 385 | ||
435 | 386 | void print_usage(void) { | |
436 | 387 | printf("%s\n", _("Usage:")); | |
437 | void | 388 | printf("%s -H host [-C community] [-p port] [-D]\n", progname); |
438 | print_usage (void) | ||
439 | { | ||
440 | printf ("%s\n", _("Usage:")); | ||
441 | printf ("%s -H host [-C community] [-p port] [-D]\n", progname); | ||
442 | } | 389 | } |