diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2026-06-10 14:49:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-10 14:49:33 +0200 |
| commit | f8aad020f7c0be604da8981663b6d815f94ffaa4 (patch) | |
| tree | e1c7bdeff275778b4dd324d26e826c861d143b48 /plugins/check_nagios.c | |
| parent | 47b1b2d754d4809006f6dc1aa13ba9c80405975c (diff) | |
| download | monitoring-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_nagios.c')
| -rw-r--r-- | plugins/check_nagios.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c index e2f230c9..84506bb4 100644 --- a/plugins/check_nagios.c +++ b/plugins/check_nagios.c | |||
| @@ -79,7 +79,8 @@ int main(int argc, char **argv) { | |||
| 79 | /* open the status log */ | 79 | /* open the status log */ |
| 80 | FILE *log_file = fopen(config.status_log, "r"); | 80 | FILE *log_file = fopen(config.status_log, "r"); |
| 81 | if (log_file == NULL) { | 81 | if (log_file == NULL) { |
| 82 | die(STATE_CRITICAL, "NAGIOS %s: %s\n", _("CRITICAL"), _("Cannot open status log for reading!")); | 82 | die(STATE_CRITICAL, "NAGIOS %s: %s\n", _("CRITICAL"), |
| 83 | _("Cannot open status log for reading!")); | ||
| 83 | } | 84 | } |
| 84 | 85 | ||
| 85 | unsigned long latest_entry_time = 0L; | 86 | unsigned long latest_entry_time = 0L; |
| @@ -153,7 +154,8 @@ int main(int argc, char **argv) { | |||
| 153 | } | 154 | } |
| 154 | 155 | ||
| 155 | /* May get empty procargs */ | 156 | /* May get empty procargs */ |
| 156 | if (!strstr(procargs, argv[0]) && strstr(procargs, config.process_string) && strcmp(procargs, "")) { | 157 | if (!strstr(procargs, argv[0]) && strstr(procargs, config.process_string) && |
| 158 | strcmp(procargs, "")) { | ||
| 157 | proc_entries++; | 159 | proc_entries++; |
| 158 | if (verbose >= 2) { | 160 | if (verbose >= 2) { |
| 159 | printf(_("Found process: %s %s\n"), procprog, procargs); | 161 | printf(_("Found process: %s %s\n"), procprog, procargs); |
| @@ -171,11 +173,13 @@ int main(int argc, char **argv) { | |||
| 171 | alarm(0); | 173 | alarm(0); |
| 172 | 174 | ||
| 173 | if (proc_entries == 0) { | 175 | if (proc_entries == 0) { |
| 174 | die(STATE_CRITICAL, "NAGIOS %s: %s\n", _("CRITICAL"), _("Could not locate a running Nagios process!")); | 176 | die(STATE_CRITICAL, "NAGIOS %s: %s\n", _("CRITICAL"), |
| 177 | _("Could not locate a running Nagios process!")); | ||
| 175 | } | 178 | } |
| 176 | 179 | ||
| 177 | if (latest_entry_time == 0L) { | 180 | if (latest_entry_time == 0L) { |
| 178 | die(STATE_CRITICAL, "NAGIOS %s: %s\n", _("CRITICAL"), _("Cannot parse Nagios log file for valid time")); | 181 | die(STATE_CRITICAL, "NAGIOS %s: %s\n", _("CRITICAL"), |
| 182 | _("Cannot parse Nagios log file for valid time")); | ||
| 179 | } | 183 | } |
| 180 | 184 | ||
| 181 | time_t current_time; | 185 | time_t current_time; |
| @@ -189,7 +193,8 @@ int main(int argc, char **argv) { | |||
| 189 | printf("NAGIOS %s: ", (result == STATE_OK) ? _("OK") : _("WARNING")); | 193 | printf("NAGIOS %s: ", (result == STATE_OK) ? _("OK") : _("WARNING")); |
| 190 | printf(ngettext("%d process", "%d processes", proc_entries), proc_entries); | 194 | printf(ngettext("%d process", "%d processes", proc_entries), proc_entries); |
| 191 | printf(", "); | 195 | printf(", "); |
| 192 | printf(ngettext("status log updated %d second ago", "status log updated %d seconds ago", (int)(current_time - latest_entry_time)), | 196 | printf(ngettext("status log updated %d second ago", "status log updated %d seconds ago", |
| 197 | (int)(current_time - latest_entry_time)), | ||
| 193 | (int)(current_time - latest_entry_time)); | 198 | (int)(current_time - latest_entry_time)); |
| 194 | printf("\n"); | 199 | printf("\n"); |
| 195 | 200 | ||
| @@ -198,10 +203,11 @@ int main(int argc, char **argv) { | |||
| 198 | 203 | ||
| 199 | /* process command-line arguments */ | 204 | /* process command-line arguments */ |
| 200 | check_nagios_config_wrapper process_arguments(int argc, char **argv) { | 205 | check_nagios_config_wrapper process_arguments(int argc, char **argv) { |
| 201 | static struct option longopts[] = {{"filename", required_argument, 0, 'F'}, {"expires", required_argument, 0, 'e'}, | 206 | static struct option longopts[] = { |
| 202 | {"command", required_argument, 0, 'C'}, {"timeout", optional_argument, 0, 't'}, | 207 | {"filename", required_argument, 0, 'F'}, {"expires", required_argument, 0, 'e'}, |
| 203 | {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, | 208 | {"command", required_argument, 0, 'C'}, {"timeout", optional_argument, 0, 't'}, |
| 204 | {"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0}}; | 209 | {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, |
| 210 | {"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0}}; | ||
| 205 | 211 | ||
| 206 | check_nagios_config_wrapper result = { | 212 | check_nagios_config_wrapper result = { |
| 207 | .errorcode = OK, | 213 | .errorcode = OK, |
| @@ -285,7 +291,8 @@ void print_help(void) { | |||
| 285 | printf("%s\n", _("This plugin checks the status of the Nagios process on the local machine")); | 291 | printf("%s\n", _("This plugin checks the status of the Nagios process on the local machine")); |
| 286 | printf("%s\n", _("The plugin will check to make sure the Nagios status log is no older than")); | 292 | printf("%s\n", _("The plugin will check to make sure the Nagios status log is no older than")); |
| 287 | printf("%s\n", _("the number of minutes specified by the expires option.")); | 293 | printf("%s\n", _("the number of minutes specified by the expires option.")); |
| 288 | printf("%s\n", _("It also checks the process table for a process matching the command argument.")); | 294 | printf("%s\n", |
| 295 | _("It also checks the process table for a process matching the command argument.")); | ||
| 289 | 296 | ||
| 290 | printf("\n\n"); | 297 | printf("\n\n"); |
| 291 | 298 | ||
| @@ -306,12 +313,14 @@ void print_help(void) { | |||
| 306 | 313 | ||
| 307 | printf("\n"); | 314 | printf("\n"); |
| 308 | printf("%s\n", _("Examples:")); | 315 | printf("%s\n", _("Examples:")); |
| 309 | printf(" %s\n", "check_nagios -t 20 -e 5 -F /usr/local/nagios/var/status.log -C /usr/local/nagios/bin/nagios"); | 316 | printf(" %s\n", "check_nagios -t 20 -e 5 -F /usr/local/nagios/var/status.log -C " |
| 317 | "/usr/local/nagios/bin/nagios"); | ||
| 310 | 318 | ||
| 311 | printf(UT_SUPPORT); | 319 | printf(UT_SUPPORT); |
| 312 | } | 320 | } |
| 313 | 321 | ||
| 314 | void print_usage(void) { | 322 | void print_usage(void) { |
| 315 | printf("%s\n", _("Usage:")); | 323 | printf("%s\n", _("Usage:")); |
| 316 | printf("%s -F <status log file> -t <timeout_seconds> -e <expire_minutes> -C <process_string>\n", progname); | 324 | printf("%s -F <status log file> -t <timeout_seconds> -e <expire_minutes> -C <process_string>\n", |
| 325 | progname); | ||
| 317 | } | 326 | } |
