diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-11 10:50:02 +0100 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-11 10:50:02 +0100 |
commit | e001fe5b3e50461b79b7b5ea3180cd11507fd615 (patch) | |
tree | 4ff5b70f5a2e9f2bb62079e13eaac58c16824671 | |
parent | df0d6ee5e0c870d50934eb095a88587547697953 (diff) | |
download | monitoring-plugins-e001fe5b3e50461b79b7b5ea3180cd11507fd615.tar.gz |
check_hpjd: clang-format
-rw-r--r-- | plugins/check_hpjd.c | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index b39bccff..78f55b7f 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c | |||
@@ -97,8 +97,9 @@ int main(int argc, char **argv) { | |||
97 | /* Parse extra opts if any */ | 97 | /* Parse extra opts if any */ |
98 | argv = np_extra_opts(&argc, argv, progname); | 98 | argv = np_extra_opts(&argc, argv, progname); |
99 | 99 | ||
100 | if (process_arguments(argc, argv) == ERROR) | 100 | if (process_arguments(argc, argv) == ERROR) { |
101 | usage4(_("Could not parse arguments")); | 101 | usage4(_("Could not parse arguments")); |
102 | } | ||
102 | 103 | ||
103 | /* removed ' 2>1' at end of command 10/27/1999 - EG */ | 104 | /* removed ' 2>1' at end of command 10/27/1999 - EG */ |
104 | /* create the query string */ | 105 | /* create the query string */ |
@@ -127,8 +128,9 @@ int main(int argc, char **argv) { | |||
127 | while (fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 128 | while (fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { |
128 | 129 | ||
129 | /* strip the newline character from the end of the input */ | 130 | /* strip the newline character from the end of the input */ |
130 | if (input_buffer[strlen(input_buffer) - 1] == '\n') | 131 | if (input_buffer[strlen(input_buffer) - 1] == '\n') { |
131 | input_buffer[strlen(input_buffer) - 1] = 0; | 132 | input_buffer[strlen(input_buffer) - 1] = 0; |
133 | } | ||
132 | 134 | ||
133 | line++; | 135 | line++; |
134 | 136 | ||
@@ -186,16 +188,18 @@ int main(int argc, char **argv) { | |||
186 | } | 188 | } |
187 | 189 | ||
188 | /* break out of the read loop if we encounter an error */ | 190 | /* break out of the read loop if we encounter an error */ |
189 | if (result != STATE_OK) | 191 | if (result != STATE_OK) { |
190 | break; | 192 | break; |
193 | } | ||
191 | } | 194 | } |
192 | 195 | ||
193 | /* WARNING if output found on stderr */ | 196 | /* WARNING if output found on stderr */ |
194 | if (fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | 197 | if (fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { |
195 | result = max_state(result, STATE_WARNING); | 198 | result = max_state(result, STATE_WARNING); |
196 | /* remove CRLF */ | 199 | /* remove CRLF */ |
197 | if (input_buffer[strlen(input_buffer) - 1] == '\n') | 200 | if (input_buffer[strlen(input_buffer) - 1] == '\n') { |
198 | input_buffer[strlen(input_buffer) - 1] = 0; | 201 | input_buffer[strlen(input_buffer) - 1] = 0; |
202 | } | ||
199 | sprintf(errmsg, "%s", input_buffer); | 203 | sprintf(errmsg, "%s", input_buffer); |
200 | } | 204 | } |
201 | 205 | ||
@@ -203,8 +207,9 @@ int main(int argc, char **argv) { | |||
203 | (void)fclose(child_stderr); | 207 | (void)fclose(child_stderr); |
204 | 208 | ||
205 | /* close the pipe */ | 209 | /* close the pipe */ |
206 | if (spclose(child_process)) | 210 | if (spclose(child_process)) { |
207 | result = max_state(result, STATE_WARNING); | 211 | result = max_state(result, STATE_WARNING); |
212 | } | ||
208 | 213 | ||
209 | /* if there wasn't any output, display an error */ | 214 | /* if there wasn't any output, display an error */ |
210 | if (line == 0) { | 215 | if (line == 0) { |
@@ -221,8 +226,9 @@ int main(int argc, char **argv) { | |||
221 | result = STATE_WARNING; | 226 | result = STATE_WARNING; |
222 | strcpy(errmsg, _("Paper Jam")); | 227 | strcpy(errmsg, _("Paper Jam")); |
223 | } else if (paper_out) { | 228 | } else if (paper_out) { |
224 | if (check_paper_out) | 229 | if (check_paper_out) { |
225 | result = STATE_WARNING; | 230 | result = STATE_WARNING; |
231 | } | ||
226 | strcpy(errmsg, _("Out of Paper")); | 232 | strcpy(errmsg, _("Out of Paper")); |
227 | } else if (line_status == OFFLINE) { | 233 | } else if (line_status == OFFLINE) { |
228 | if (strcmp(errmsg, "POWERSAVE ON") != 0) { | 234 | if (strcmp(errmsg, "POWERSAVE ON") != 0) { |
@@ -256,20 +262,23 @@ int main(int argc, char **argv) { | |||
256 | } | 262 | } |
257 | } | 263 | } |
258 | 264 | ||
259 | if (result == STATE_OK) | 265 | if (result == STATE_OK) { |
260 | printf(_("Printer ok - (%s)\n"), display_message); | 266 | printf(_("Printer ok - (%s)\n"), display_message); |
267 | } | ||
261 | 268 | ||
262 | else if (result == STATE_UNKNOWN) { | 269 | else if (result == STATE_UNKNOWN) { |
263 | 270 | ||
264 | printf("%s\n", errmsg); | 271 | printf("%s\n", errmsg); |
265 | 272 | ||
266 | /* if printer could not be reached, escalate to critical */ | 273 | /* if printer could not be reached, escalate to critical */ |
267 | if (strstr(errmsg, "Timeout")) | 274 | if (strstr(errmsg, "Timeout")) { |
268 | result = STATE_CRITICAL; | 275 | result = STATE_CRITICAL; |
276 | } | ||
269 | } | 277 | } |
270 | 278 | ||
271 | else if (result == STATE_WARNING) | 279 | else if (result == STATE_WARNING) { |
272 | printf("%s (%s)\n", errmsg, display_message); | 280 | printf("%s (%s)\n", errmsg, display_message); |
281 | } | ||
273 | 282 | ||
274 | return result; | 283 | return result; |
275 | } | 284 | } |
@@ -288,14 +297,16 @@ int process_arguments(int argc, char **argv) { | |||
288 | {"help", no_argument, 0, 'h'}, | 297 | {"help", no_argument, 0, 'h'}, |
289 | {0, 0, 0, 0}}; | 298 | {0, 0, 0, 0}}; |
290 | 299 | ||
291 | if (argc < 2) | 300 | if (argc < 2) { |
292 | return ERROR; | 301 | return ERROR; |
302 | } | ||
293 | 303 | ||
294 | while (1) { | 304 | while (1) { |
295 | c = getopt_long(argc, argv, "+hVH:C:p:D", longopts, &option); | 305 | c = getopt_long(argc, argv, "+hVH:C:p:D", longopts, &option); |
296 | 306 | ||
297 | if (c == -1 || c == EOF || c == 1) | 307 | if (c == -1 || c == EOF || c == 1) { |
298 | break; | 308 | break; |
309 | } | ||
299 | 310 | ||
300 | switch (c) { | 311 | switch (c) { |
301 | case 'H': /* hostname */ | 312 | case 'H': /* hostname */ |
@@ -309,10 +320,11 @@ int process_arguments(int argc, char **argv) { | |||
309 | community = strscpy(community, optarg); | 320 | community = strscpy(community, optarg); |
310 | break; | 321 | break; |
311 | case 'p': | 322 | case 'p': |
312 | if (!is_intpos(optarg)) | 323 | if (!is_intpos(optarg)) { |
313 | usage2(_("Port must be a positive short integer"), optarg); | 324 | usage2(_("Port must be a positive short integer"), optarg); |
314 | else | 325 | } else { |
315 | port = atoi(optarg); | 326 | port = atoi(optarg); |
327 | } | ||
316 | break; | 328 | break; |
317 | case 'D': /* disable paper out check*/ | 329 | case 'D': /* disable paper out check*/ |
318 | check_paper_out = 0; | 330 | check_paper_out = 0; |
@@ -338,10 +350,11 @@ int process_arguments(int argc, char **argv) { | |||
338 | } | 350 | } |
339 | 351 | ||
340 | if (community == NULL) { | 352 | if (community == NULL) { |
341 | if (argv[c] != NULL) | 353 | if (argv[c] != NULL) { |
342 | community = argv[c]; | 354 | community = argv[c]; |
343 | else | 355 | } else { |
344 | community = strdup(DEFAULT_COMMUNITY); | 356 | community = strdup(DEFAULT_COMMUNITY); |
357 | } | ||
345 | } | 358 | } |
346 | 359 | ||
347 | if (port == 0) { | 360 | if (port == 0) { |