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