diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-11 12:44:10 +0100 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-11 12:44:10 +0100 |
| commit | 4d81e7942081834a5ef5334ae840d9f2843a4c5b (patch) | |
| tree | ea0b8e9474344c6e923651dfde6d2d2201849054 | |
| parent | 74c3f4811ccc10911cdeff5cd793a8f3a7dd74e5 (diff) | |
| download | monitoring-plugins-4d81e7942081834a5ef5334ae840d9f2843a4c5b.tar.gz | |
check_mrtgraf: clang-format
| -rw-r--r-- | plugins/check_mrtgtraf.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c index e5a2e2ad..78dcda0d 100644 --- a/plugins/check_mrtgtraf.c +++ b/plugins/check_mrtgtraf.c | |||
| @@ -56,13 +56,15 @@ int main(int argc, char **argv) { | |||
| 56 | /* Parse extra opts if any */ | 56 | /* Parse extra opts if any */ |
| 57 | argv = np_extra_opts(&argc, argv, progname); | 57 | argv = np_extra_opts(&argc, argv, progname); |
| 58 | 58 | ||
| 59 | if (process_arguments(argc, argv) == ERROR) | 59 | if (process_arguments(argc, argv) == ERROR) { |
| 60 | usage4(_("Could not parse arguments")); | 60 | usage4(_("Could not parse arguments")); |
| 61 | } | ||
| 61 | 62 | ||
| 62 | /* open the MRTG log file for reading */ | 63 | /* open the MRTG log file for reading */ |
| 63 | FILE *mrtg_log_file_ptr = fopen(log_file, "r"); | 64 | FILE *mrtg_log_file_ptr = fopen(log_file, "r"); |
| 64 | if (mrtg_log_file_ptr == NULL) | 65 | if (mrtg_log_file_ptr == NULL) { |
| 65 | usage4(_("Unable to open MRTG log file")); | 66 | usage4(_("Unable to open MRTG log file")); |
| 67 | } | ||
| 66 | 68 | ||
| 67 | time_t timestamp = 0L; | 69 | time_t timestamp = 0L; |
| 68 | char input_buffer[MAX_INPUT_BUFFER]; | 70 | char input_buffer[MAX_INPUT_BUFFER]; |
| @@ -76,13 +78,15 @@ int main(int argc, char **argv) { | |||
| 76 | line++; | 78 | line++; |
| 77 | 79 | ||
| 78 | /* skip the first line of the log file */ | 80 | /* skip the first line of the log file */ |
| 79 | if (line == 1) | 81 | if (line == 1) { |
| 80 | continue; | 82 | continue; |
| 83 | } | ||
| 81 | 84 | ||
| 82 | /* break out of read loop */ | 85 | /* break out of read loop */ |
| 83 | /* if we've passed the number of entries we want to read */ | 86 | /* if we've passed the number of entries we want to read */ |
| 84 | if (line > 2) | 87 | if (line > 2) { |
| 85 | break; | 88 | break; |
| 89 | } | ||
| 86 | 90 | ||
| 87 | /* grab the timestamp */ | 91 | /* grab the timestamp */ |
| 88 | char *temp_buffer = strtok(input_buffer, " "); | 92 | char *temp_buffer = strtok(input_buffer, " "); |
| @@ -109,14 +113,16 @@ int main(int argc, char **argv) { | |||
| 109 | fclose(mrtg_log_file_ptr); | 113 | fclose(mrtg_log_file_ptr); |
| 110 | 114 | ||
| 111 | /* if we couldn't read enough data, return an unknown error */ | 115 | /* if we couldn't read enough data, return an unknown error */ |
| 112 | if (line <= 2) | 116 | if (line <= 2) { |
| 113 | usage4(_("Unable to process MRTG log file")); | 117 | usage4(_("Unable to process MRTG log file")); |
| 118 | } | ||
| 114 | 119 | ||
| 115 | /* make sure the MRTG data isn't too old */ | 120 | /* make sure the MRTG data isn't too old */ |
| 116 | time_t current_time; | 121 | time_t current_time; |
| 117 | time(¤t_time); | 122 | time(¤t_time); |
| 118 | if ((expire_minutes > 0) && (current_time - timestamp) > (expire_minutes * 60)) | 123 | if ((expire_minutes > 0) && (current_time - timestamp) > (expire_minutes * 60)) { |
| 119 | die(STATE_WARNING, _("MRTG data has expired (%d minutes old)\n"), (int)((current_time - timestamp) / 60)); | 124 | die(STATE_WARNING, _("MRTG data has expired (%d minutes old)\n"), (int)((current_time - timestamp) / 60)); |
| 125 | } | ||
| 120 | 126 | ||
| 121 | unsigned long incoming_rate = 0L; | 127 | unsigned long incoming_rate = 0L; |
| 122 | unsigned long outgoing_rate = 0L; | 128 | unsigned long outgoing_rate = 0L; |
| @@ -201,16 +207,18 @@ int process_arguments(int argc, char **argv) { | |||
| 201 | {"help", no_argument, 0, 'h'}, | 207 | {"help", no_argument, 0, 'h'}, |
| 202 | {0, 0, 0, 0}}; | 208 | {0, 0, 0, 0}}; |
| 203 | 209 | ||
| 204 | if (argc < 2) | 210 | if (argc < 2) { |
| 205 | return ERROR; | 211 | return ERROR; |
| 212 | } | ||
| 206 | 213 | ||
| 207 | for (int i = 1; i < argc; i++) { | 214 | for (int i = 1; i < argc; i++) { |
| 208 | if (strcmp("-to", argv[i]) == 0) | 215 | if (strcmp("-to", argv[i]) == 0) { |
| 209 | strcpy(argv[i], "-t"); | 216 | strcpy(argv[i], "-t"); |
| 210 | else if (strcmp("-wt", argv[i]) == 0) | 217 | } else if (strcmp("-wt", argv[i]) == 0) { |
| 211 | strcpy(argv[i], "-w"); | 218 | strcpy(argv[i], "-w"); |
| 212 | else if (strcmp("-ct", argv[i]) == 0) | 219 | } else if (strcmp("-ct", argv[i]) == 0) { |
| 213 | strcpy(argv[i], "-c"); | 220 | strcpy(argv[i], "-c"); |
| 221 | } | ||
| 214 | } | 222 | } |
| 215 | 223 | ||
| 216 | int option_char; | 224 | int option_char; |
| @@ -218,8 +226,9 @@ int process_arguments(int argc, char **argv) { | |||
| 218 | while (1) { | 226 | while (1) { |
| 219 | option_char = getopt_long(argc, argv, "hVF:e:a:c:w:", longopts, &option); | 227 | option_char = getopt_long(argc, argv, "hVF:e:a:c:w:", longopts, &option); |
| 220 | 228 | ||
| 221 | if (option_char == -1 || option_char == EOF) | 229 | if (option_char == -1 || option_char == EOF) { |
| 222 | break; | 230 | break; |
| 231 | } | ||
| 223 | 232 | ||
| 224 | switch (option_char) { | 233 | switch (option_char) { |
| 225 | case 'F': /* input file */ | 234 | case 'F': /* input file */ |
| @@ -229,10 +238,11 @@ int process_arguments(int argc, char **argv) { | |||
| 229 | expire_minutes = atoi(optarg); | 238 | expire_minutes = atoi(optarg); |
| 230 | break; | 239 | break; |
| 231 | case 'a': /* aggregation (AVE or MAX) */ | 240 | case 'a': /* aggregation (AVE or MAX) */ |
| 232 | if (!strcmp(optarg, "MAX")) | 241 | if (!strcmp(optarg, "MAX")) { |
| 233 | use_average = false; | 242 | use_average = false; |
| 234 | else | 243 | } else { |
| 235 | use_average = true; | 244 | use_average = true; |
| 245 | } | ||
| 236 | break; | 246 | break; |
| 237 | case 'c': /* warning threshold */ | 247 | case 'c': /* warning threshold */ |
| 238 | sscanf(optarg, "%lu,%lu", &incoming_critical_threshold, &outgoing_critical_threshold); | 248 | sscanf(optarg, "%lu,%lu", &incoming_critical_threshold, &outgoing_critical_threshold); |
