summaryrefslogtreecommitdiffstats
path: root/plugins/check_ide_smart.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2026-06-10 14:49:33 +0200
committerGitHub <noreply@github.com>2026-06-10 14:49:33 +0200
commitf8aad020f7c0be604da8981663b6d815f94ffaa4 (patch)
treee1c7bdeff275778b4dd324d26e826c861d143b48 /plugins/check_ide_smart.c
parent47b1b2d754d4809006f6dc1aa13ba9c80405975c (diff)
downloadmonitoring-plugins-f8aad020f7c0be604da8981663b6d815f94ffaa4.tar.gz
Run clang-format on everything once again (#2275)
Co-authored-by: Lorenz Kästle <lorenz.kaestle@netways.de>
Diffstat (limited to 'plugins/check_ide_smart.c')
-rw-r--r--plugins/check_ide_smart.c78
1 files changed, 48 insertions, 30 deletions
diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c
index 43731039..e6b29f1c 100644
--- a/plugins/check_ide_smart.c
+++ b/plugins/check_ide_smart.c
@@ -118,7 +118,8 @@ typedef struct {
118static struct { 118static struct {
119 uint8_t value; 119 uint8_t value;
120 char *text; 120 char *text;
121} offline_status_text[] = {{0x00, "NeverStarted"}, {0x02, "Completed"}, {0x04, "Suspended"}, {0x05, "Aborted"}, {0x06, "Failed"}, {0, 0}}; 121} offline_status_text[] = {{0x00, "NeverStarted"}, {0x02, "Completed"}, {0x04, "Suspended"},
122 {0x05, "Aborted"}, {0x06, "Failed"}, {0, 0}};
122 123
123static struct { 124static struct {
124 uint8_t value; 125 uint8_t value;
@@ -141,7 +142,8 @@ static int smart_read_values(int /*fd*/, smart_values * /*values*/);
141static mp_state_enum compare_values_and_thresholds(smart_values * /*p*/, smart_thresholds * /*t*/); 142static mp_state_enum compare_values_and_thresholds(smart_values * /*p*/, smart_thresholds * /*t*/);
142static void print_value(smart_value * /*p*/, smart_threshold * /*t*/); 143static void print_value(smart_value * /*p*/, smart_threshold * /*t*/);
143static void print_values(smart_values * /*p*/, smart_thresholds * /*t*/); 144static void print_values(smart_values * /*p*/, smart_thresholds * /*t*/);
144static mp_state_enum smart_cmd_simple(int /*fd*/, enum SmartCommand /*command*/, uint8_t /*val0*/, bool /*show_error*/); 145static mp_state_enum smart_cmd_simple(int /*fd*/, enum SmartCommand /*command*/, uint8_t /*val0*/,
146 bool /*show_error*/);
145static int smart_read_thresholds(int /*fd*/, smart_thresholds * /*thresholds*/); 147static int smart_read_thresholds(int /*fd*/, smart_thresholds * /*thresholds*/);
146static int verbose = 0; 148static int verbose = 0;
147 149
@@ -150,15 +152,16 @@ typedef struct {
150 check_ide_smart_config config; 152 check_ide_smart_config config;
151} check_ide_smart_config_wrapper; 153} check_ide_smart_config_wrapper;
152static check_ide_smart_config_wrapper process_arguments(int argc, char **argv) { 154static check_ide_smart_config_wrapper process_arguments(int argc, char **argv) {
153 static struct option longopts[] = {{"device", required_argument, 0, 'd'}, 155 static struct option longopts[] = {
154 {"immediate", no_argument, 0, 'i'}, 156 {"device", required_argument, 0, 'd'},
155 {"quiet-check", no_argument, 0, 'q'}, 157 {"immediate", no_argument, 0, 'i'},
156 {"auto-on", no_argument, 0, '1'}, 158 {"quiet-check", no_argument, 0, 'q'},
157 {"auto-off", no_argument, 0, '0'}, 159 {"auto-on", no_argument, 0, '1'},
158 {"nagios", no_argument, 0, 'n'}, /* DEPRECATED, but we still accept it */ 160 {"auto-off", no_argument, 0, '0'},
159 {"help", no_argument, 0, 'h'}, 161 {"nagios", no_argument, 0, 'n'}, /* DEPRECATED, but we still accept it */
160 {"version", no_argument, 0, 'V'}, 162 {"help", no_argument, 0, 'h'},
161 {0, 0, 0, 0}}; 163 {"version", no_argument, 0, 'V'},
164 {0, 0, 0, 0}};
162 165
163 check_ide_smart_config_wrapper result = { 166 check_ide_smart_config_wrapper result = {
164 .errorcode = OK, 167 .errorcode = OK,
@@ -178,18 +181,21 @@ static check_ide_smart_config_wrapper process_arguments(int argc, char **argv) {
178 result.config.device = optarg; 181 result.config.device = optarg;
179 break; 182 break;
180 case 'q': 183 case 'q':
181 fprintf(stderr, "%s\n", _("DEPRECATION WARNING: the -q switch (quiet output) is no longer \"quiet\".")); 184 fprintf(stderr, "%s\n",
185 _("DEPRECATION WARNING: the -q switch (quiet output) is no longer \"quiet\"."));
182 fprintf(stderr, "%s\n", _("Nagios-compatible output is now always returned.")); 186 fprintf(stderr, "%s\n", _("Nagios-compatible output is now always returned."));
183 break; 187 break;
184 case 'i': 188 case 'i':
185 case '1': 189 case '1':
186 case '0': 190 case '0':
187 printf("%s\n", _("SMART commands are broken and have been disabled (See Notes in --help).")); 191 printf("%s\n",
192 _("SMART commands are broken and have been disabled (See Notes in --help)."));
188 result.errorcode = ERROR; 193 result.errorcode = ERROR;
189 return result; 194 return result;
190 break; 195 break;
191 case 'n': 196 case 'n':
192 fprintf(stderr, "%s\n", _("DEPRECATION WARNING: the -n switch (Nagios-compatible output) is now the")); 197 fprintf(stderr, "%s\n",
198 _("DEPRECATION WARNING: the -n switch (Nagios-compatible output) is now the"));
193 fprintf(stderr, "%s\n", _("default and will be removed from future releases.")); 199 fprintf(stderr, "%s\n", _("default and will be removed from future releases."));
194 break; 200 break;
195 case 'v': /* verbose */ 201 case 'v': /* verbose */
@@ -348,12 +354,13 @@ mp_state_enum compare_values_and_thresholds(smart_values *values, smart_threshol
348 354
349 switch (status) { 355 switch (status) {
350 case PREFAILURE: 356 case PREFAILURE:
351 printf(_("CRITICAL - %d Harddrive PreFailure%cDetected! %d/%d tests failed.\n"), prefailure, prefailure > 1 ? 's' : ' ', failed, 357 printf(_("CRITICAL - %d Harddrive PreFailure%cDetected! %d/%d tests failed.\n"), prefailure,
352 total); 358 prefailure > 1 ? 's' : ' ', failed, total);
353 status = STATE_CRITICAL; 359 status = STATE_CRITICAL;
354 break; 360 break;
355 case ADVISORY: 361 case ADVISORY:
356 printf(_("WARNING - %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"), advisory, advisory > 1 ? "ies" : "y", failed, total); 362 printf(_("WARNING - %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"), advisory,
363 advisory > 1 ? "ies" : "y", failed, total);
357 status = STATE_WARNING; 364 status = STATE_WARNING;
358 break; 365 break;
359 case OPERATIONAL: 366 case OPERATIONAL:
@@ -369,9 +376,11 @@ mp_state_enum compare_values_and_thresholds(smart_values *values, smart_threshol
369} 376}
370 377
371void print_value(smart_value *value_pointer, smart_threshold *threshold_pointer) { 378void print_value(smart_value *value_pointer, smart_threshold *threshold_pointer) {
372 printf("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n", value_pointer->id, value_pointer->status, 379 printf("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n", value_pointer->id,
373 value_pointer->status & 1 ? "PreFailure" : "Advisory ", value_pointer->status & 2 ? "OnLine " : "OffLine", 380 value_pointer->status, value_pointer->status & 1 ? "PreFailure" : "Advisory ",
374 value_pointer->value, threshold_pointer->threshold, value_pointer->value >= threshold_pointer->threshold ? "Passed" : "Failed"); 381 value_pointer->status & 2 ? "OnLine " : "OffLine", value_pointer->value,
382 threshold_pointer->threshold,
383 value_pointer->value >= threshold_pointer->threshold ? "Passed" : "Failed");
375} 384}
376 385
377void print_values(smart_values *values, smart_thresholds *thresholds) { 386void print_values(smart_values *values, smart_thresholds *thresholds) {
@@ -382,15 +391,21 @@ void print_values(smart_values *values, smart_thresholds *thresholds) {
382 print_value(value++, threshold++); 391 print_value(value++, threshold++);
383 } 392 }
384 } 393 }
385 printf(_("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n"), values->offline_status, 394 printf(_("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n"),
386 get_offline_text(values->offline_status & 0x7f), (values->offline_status & 0x80 ? "Yes" : "No"), values->offline_timeout / 60); 395 values->offline_status, get_offline_text(values->offline_status & 0x7f),
387 printf(_("OffLineCapability=%d {%s %s %s}\n"), values->offline_capability, values->offline_capability & 1 ? "Immediate" : "", 396 (values->offline_status & 0x80 ? "Yes" : "No"), values->offline_timeout / 60);
388 values->offline_capability & 2 ? "Auto" : "", values->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd"); 397 printf(_("OffLineCapability=%d {%s %s %s}\n"), values->offline_capability,
389 printf(_("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n"), values->revision, values->checksum, values->smart_capability, 398 values->offline_capability & 1 ? "Immediate" : "",
390 values->smart_capability & 1 ? "SaveOnStandBy" : "", values->smart_capability & 2 ? "AutoSave" : ""); 399 values->offline_capability & 2 ? "Auto" : "",
400 values->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd");
401 printf(_("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n"), values->revision,
402 values->checksum, values->smart_capability,
403 values->smart_capability & 1 ? "SaveOnStandBy" : "",
404 values->smart_capability & 2 ? "AutoSave" : "");
391} 405}
392 406
393mp_state_enum smart_cmd_simple(int file_descriptor, enum SmartCommand command, uint8_t val0, bool show_error) { 407mp_state_enum smart_cmd_simple(int file_descriptor, enum SmartCommand command, uint8_t val0,
408 bool show_error) {
394 mp_state_enum result = STATE_UNKNOWN; 409 mp_state_enum result = STATE_UNKNOWN;
395#ifdef __linux__ 410#ifdef __linux__
396 uint8_t args[4] = { 411 uint8_t args[4] = {
@@ -517,15 +532,18 @@ void print_help(void) {
517 532
518 printf(" %s\n", "-d, --device=DEVICE"); 533 printf(" %s\n", "-d, --device=DEVICE");
519 printf(" %s\n", _("Select device DEVICE")); 534 printf(" %s\n", _("Select device DEVICE"));
520 printf(" %s\n", _("Note: if the device is specified without this option, any further option will")); 535 printf(" %s\n",
536 _("Note: if the device is specified without this option, any further option will"));
521 printf(" %s\n", _("be ignored.")); 537 printf(" %s\n", _("be ignored."));
522 538
523 printf(UT_VERBOSE); 539 printf(UT_VERBOSE);
524 540
525 printf("\n"); 541 printf("\n");
526 printf("%s\n", _("Notes:")); 542 printf("%s\n", _("Notes:"));
527 printf(" %s\n", _("The SMART command modes (-i/--immediate, -0/--auto-off and -1/--auto-on) were")); 543 printf(" %s\n",
528 printf(" %s\n", _("broken in an underhand manner and have been disabled. You can use smartctl")); 544 _("The SMART command modes (-i/--immediate, -0/--auto-off and -1/--auto-on) were"));
545 printf(" %s\n",
546 _("broken in an underhand manner and have been disabled. You can use smartctl"));
529 printf(" %s\n", _("instead:")); 547 printf(" %s\n", _("instead:"));
530 printf(" %s\n", _("-0/--auto-off: use \"smartctl --offlineauto=off\"")); 548 printf(" %s\n", _("-0/--auto-off: use \"smartctl --offlineauto=off\""));
531 printf(" %s\n", _("-1/--auto-on: use \"smartctl --offlineauto=on\"")); 549 printf(" %s\n", _("-1/--auto-on: use \"smartctl --offlineauto=on\""));