diff options
author | Sven Nierlein <sven@nierlein.org> | 2019-02-19 22:10:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-19 22:10:07 +0100 |
commit | 97bb142b144c7ae128cc69033e620906c95562c8 (patch) | |
tree | ef405eaf143aefa922c3e6df3427abc2dd613c0c /plugins | |
parent | af8e68d140ad5c3f40b95d995d97dc206e40bf6b (diff) | |
parent | 9671399c00fa62a708efb7371eeba64e4e73fd94 (diff) | |
download | monitoring-plugins-97bb142b144c7ae128cc69033e620906c95562c8.tar.gz |
Merge pull request #1506 from sanchezfauste/check_apt_parameters
Adding packages-warning option to check_apt plugin
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_apt.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/plugins/check_apt.c b/plugins/check_apt.c index b69680c2..d7be5750 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c | |||
@@ -86,6 +86,8 @@ static char *do_include = NULL; /* regexp to only include certain packages */ | |||
86 | static char *do_exclude = NULL; /* regexp to only exclude certain packages */ | 86 | static char *do_exclude = NULL; /* regexp to only exclude certain packages */ |
87 | static char *do_critical = NULL; /* regexp specifying critical packages */ | 87 | static char *do_critical = NULL; /* regexp specifying critical packages */ |
88 | static char *input_filename = NULL; /* input filename for testing */ | 88 | static char *input_filename = NULL; /* input filename for testing */ |
89 | /* number of packages available for upgrade to return WARNING status */ | ||
90 | static int packages_warning = 1; | ||
89 | 91 | ||
90 | /* other global variables */ | 92 | /* other global variables */ |
91 | static int stderr_warning = 0; /* if a cmd issued output on stderr */ | 93 | static int stderr_warning = 0; /* if a cmd issued output on stderr */ |
@@ -117,7 +119,7 @@ int main (int argc, char **argv) { | |||
117 | 119 | ||
118 | if(sec_count > 0){ | 120 | if(sec_count > 0){ |
119 | result = max_state(result, STATE_CRITICAL); | 121 | result = max_state(result, STATE_CRITICAL); |
120 | } else if(packages_available > 0 && only_critical == 0){ | 122 | } else if(packages_available >= packages_warning && only_critical == 0){ |
121 | result = max_state(result, STATE_WARNING); | 123 | result = max_state(result, STATE_WARNING); |
122 | } else if(result > STATE_UNKNOWN){ | 124 | } else if(result > STATE_UNKNOWN){ |
123 | result = STATE_UNKNOWN; | 125 | result = STATE_UNKNOWN; |
@@ -170,11 +172,12 @@ int process_arguments (int argc, char **argv) { | |||
170 | {"critical", required_argument, 0, 'c'}, | 172 | {"critical", required_argument, 0, 'c'}, |
171 | {"only-critical", no_argument, 0, 'o'}, | 173 | {"only-critical", no_argument, 0, 'o'}, |
172 | {"input-file", required_argument, 0, INPUT_FILE_OPT}, | 174 | {"input-file", required_argument, 0, INPUT_FILE_OPT}, |
175 | {"packages-warning", required_argument, 0, 'w'}, | ||
173 | {0, 0, 0, 0} | 176 | {0, 0, 0, 0} |
174 | }; | 177 | }; |
175 | 178 | ||
176 | while(1) { | 179 | while(1) { |
177 | c = getopt_long(argc, argv, "hVvt:u::U::d::nli:e:c:o", longopts, NULL); | 180 | c = getopt_long(argc, argv, "hVvt:u::U::d::nli:e:c:ow:", longopts, NULL); |
178 | 181 | ||
179 | if(c == -1 || c == EOF || c == 1) break; | 182 | if(c == -1 || c == EOF || c == 1) break; |
180 | 183 | ||
@@ -233,6 +236,9 @@ int process_arguments (int argc, char **argv) { | |||
233 | case INPUT_FILE_OPT: | 236 | case INPUT_FILE_OPT: |
234 | input_filename = optarg; | 237 | input_filename = optarg; |
235 | break; | 238 | break; |
239 | case 'w': | ||
240 | packages_warning = atoi(optarg); | ||
241 | break; | ||
236 | default: | 242 | default: |
237 | /* print short usage statement if args not parsable */ | 243 | /* print short usage statement if args not parsable */ |
238 | usage5(); | 244 | usage5(); |
@@ -530,7 +536,10 @@ print_help (void) | |||
530 | printf (" %s\n", "-o, --only-critical"); | 536 | printf (" %s\n", "-o, --only-critical"); |
531 | printf (" %s\n", _("Only warn about upgrades matching the critical list. The total number")); | 537 | printf (" %s\n", _("Only warn about upgrades matching the critical list. The total number")); |
532 | printf (" %s\n", _("of upgrades will be printed, but any non-critical upgrades will not cause")); | 538 | printf (" %s\n", _("of upgrades will be printed, but any non-critical upgrades will not cause")); |
533 | printf (" %s\n\n", _("the plugin to return WARNING status.")); | 539 | printf (" %s\n", _("the plugin to return WARNING status.")); |
540 | printf (" %s\n", "-w, --packages-warning"); | ||
541 | printf (" %s\n", _("Minumum number of packages available for upgrade to return WARNING status.")); | ||
542 | printf (" %s\n\n", _("Default is 1 package.")); | ||
534 | 543 | ||
535 | printf ("%s\n\n", _("The following options require root privileges and should be used with care:")); | 544 | printf ("%s\n\n", _("The following options require root privileges and should be used with care:")); |
536 | printf (" %s\n", "-u, --update=OPTS"); | 545 | printf (" %s\n", "-u, --update=OPTS"); |
@@ -548,5 +557,5 @@ void | |||
548 | print_usage(void) | 557 | print_usage(void) |
549 | { | 558 | { |
550 | printf ("%s\n", _("Usage:")); | 559 | printf ("%s\n", _("Usage:")); |
551 | printf ("%s [[-d|-u|-U]opts] [-n] [-l] [-t timeout]\n", progname); | 560 | printf ("%s [[-d|-u|-U]opts] [-n] [-l] [-t timeout] [-w packages-warning]\n", progname); |
552 | } | 561 | } |