diff options
-rw-r--r-- | plugins/check_apt.c | 15 | ||||
-rw-r--r-- | plugins/t/check_apt.t | 18 |
2 files changed, 29 insertions, 4 deletions
diff --git a/plugins/check_apt.c b/plugins/check_apt.c index a639a411..c90b3df7 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c | |||
@@ -73,6 +73,7 @@ char* add_to_regexp(char *expr, const char *next); | |||
73 | /* configuration variables */ | 73 | /* configuration variables */ |
74 | static int verbose = 0; /* -v */ | 74 | static int verbose = 0; /* -v */ |
75 | static int do_update = 0; /* whether to call apt-get update */ | 75 | static int do_update = 0; /* whether to call apt-get update */ |
76 | static int only_critical = 0; /* whether to warn about non-critical updates */ | ||
76 | static upgrade_type upgrade = UPGRADE; /* which type of upgrade to do */ | 77 | static upgrade_type upgrade = UPGRADE; /* which type of upgrade to do */ |
77 | static char *upgrade_opts = NULL; /* options to override defaults for upgrade */ | 78 | static char *upgrade_opts = NULL; /* options to override defaults for upgrade */ |
78 | static char *update_opts = NULL; /* options to override defaults for update */ | 79 | static char *update_opts = NULL; /* options to override defaults for update */ |
@@ -110,7 +111,7 @@ int main (int argc, char **argv) { | |||
110 | 111 | ||
111 | if(sec_count > 0){ | 112 | if(sec_count > 0){ |
112 | result = max_state(result, STATE_CRITICAL); | 113 | result = max_state(result, STATE_CRITICAL); |
113 | } else if(packages_available > 0){ | 114 | } else if(packages_available > 0 && only_critical == 0){ |
114 | result = max_state(result, STATE_WARNING); | 115 | result = max_state(result, STATE_WARNING); |
115 | } else if(result > STATE_UNKNOWN){ | 116 | } else if(result > STATE_UNKNOWN){ |
116 | result = STATE_UNKNOWN; | 117 | result = STATE_UNKNOWN; |
@@ -148,12 +149,13 @@ int process_arguments (int argc, char **argv) { | |||
148 | {"include", required_argument, 0, 'i'}, | 149 | {"include", required_argument, 0, 'i'}, |
149 | {"exclude", required_argument, 0, 'e'}, | 150 | {"exclude", required_argument, 0, 'e'}, |
150 | {"critical", required_argument, 0, 'c'}, | 151 | {"critical", required_argument, 0, 'c'}, |
152 | {"only-critical", no_argument, 0, 'o'}, | ||
151 | {"input-file", required_argument, 0, INPUT_FILE_OPT}, | 153 | {"input-file", required_argument, 0, INPUT_FILE_OPT}, |
152 | {0, 0, 0, 0} | 154 | {0, 0, 0, 0} |
153 | }; | 155 | }; |
154 | 156 | ||
155 | while(1) { | 157 | while(1) { |
156 | c = getopt_long(argc, argv, "hVvt:u::U::d::ni:e:c:", longopts, NULL); | 158 | c = getopt_long(argc, argv, "hVvt:u::U::d::ni:e:c:o", longopts, NULL); |
157 | 159 | ||
158 | if(c == -1 || c == EOF || c == 1) break; | 160 | if(c == -1 || c == EOF || c == 1) break; |
159 | 161 | ||
@@ -203,6 +205,9 @@ int process_arguments (int argc, char **argv) { | |||
203 | case 'c': | 205 | case 'c': |
204 | do_critical=add_to_regexp(do_critical, optarg); | 206 | do_critical=add_to_regexp(do_critical, optarg); |
205 | break; | 207 | break; |
208 | case 'o': | ||
209 | only_critical=1; | ||
210 | break; | ||
206 | case INPUT_FILE_OPT: | 211 | case INPUT_FILE_OPT: |
207 | input_filename = optarg; | 212 | input_filename = optarg; |
208 | break; | 213 | break; |
@@ -463,7 +468,11 @@ print_help (void) | |||
463 | printf (" %s\n", _("upgrades for Debian and Ubuntu:")); | 468 | printf (" %s\n", _("upgrades for Debian and Ubuntu:")); |
464 | printf (" \t\%s\n", SECURITY_RE); | 469 | printf (" \t\%s\n", SECURITY_RE); |
465 | printf (" %s\n", _("Note that the package must first match the include list before its")); | 470 | printf (" %s\n", _("Note that the package must first match the include list before its")); |
466 | printf (" %s\n\n", _("information is compared against the critical list.")); | 471 | printf (" %s\n", _("information is compared against the critical list.")); |
472 | printf (" %s\n", "-o, --only-critical"); | ||
473 | printf (" %s\n", _("Only warn about upgrades matching the critical list. The total number")); | ||
474 | printf (" %s\n", _("of upgrades will be printed, but any non-critical upgrades will not cause")); | ||
475 | printf (" %s\n\n", _("the plugin to return WARNING status.")); | ||
467 | 476 | ||
468 | printf ("%s\n\n", _("The following options require root privileges and should be used with care:")); | 477 | printf ("%s\n\n", _("The following options require root privileges and should be used with care:")); |
469 | printf (" %s\n", "-u, --update=OPTS"); | 478 | printf (" %s\n", "-u, --update=OPTS"); |
diff --git a/plugins/t/check_apt.t b/plugins/t/check_apt.t index 9ba0ff8e..430eb53e 100644 --- a/plugins/t/check_apt.t +++ b/plugins/t/check_apt.t | |||
@@ -23,7 +23,7 @@ sub make_result_regexp { | |||
23 | } | 23 | } |
24 | 24 | ||
25 | if (-x "./check_apt") { | 25 | if (-x "./check_apt") { |
26 | plan tests => 28; | 26 | plan tests => 36; |
27 | } else { | 27 | } else { |
28 | plan skip_all => "No check_apt compiled"; | 28 | plan skip_all => "No check_apt compiled"; |
29 | } | 29 | } |
@@ -40,10 +40,18 @@ $result = NPTest->testCmd( sprintf($testfile_command, "", "debian2") ); | |||
40 | is( $result->return_code, 1, "Debian apt output, warning" ); | 40 | is( $result->return_code, 1, "Debian apt output, warning" ); |
41 | like( $result->output, make_result_regexp(13, 0), "Output correct" ); | 41 | like( $result->output, make_result_regexp(13, 0), "Output correct" ); |
42 | 42 | ||
43 | $result = NPTest->testCmd( sprintf($testfile_command, "-o", "debian2") ); | ||
44 | is( $result->return_code, 0, "Debian apt output, no critical" ); | ||
45 | like( $result->output, make_result_regexp(13, 0), "Output correct" ); | ||
46 | |||
43 | $result = NPTest->testCmd( sprintf($testfile_command, "", "debian3") ); | 47 | $result = NPTest->testCmd( sprintf($testfile_command, "", "debian3") ); |
44 | is( $result->return_code, 2, "Debian apt output, some critical" ); | 48 | is( $result->return_code, 2, "Debian apt output, some critical" ); |
45 | like( $result->output, make_result_regexp(19, 4), "Output correct" ); | 49 | like( $result->output, make_result_regexp(19, 4), "Output correct" ); |
46 | 50 | ||
51 | $result = NPTest->testCmd( sprintf($testfile_command, "-o", "debian3") ); | ||
52 | is( $result->return_code, 2, "Debian apt output, some critical" ); | ||
53 | like( $result->output, make_result_regexp(19, 4), "Output correct" ); | ||
54 | |||
47 | $result = NPTest->testCmd( sprintf($testfile_command, "-c '^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)'", "debian3") ); | 55 | $result = NPTest->testCmd( sprintf($testfile_command, "-c '^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)'", "debian3") ); |
48 | is( $result->return_code, 2, "Debian apt output - should have same result when default security regexp specified via -c" ); | 56 | is( $result->return_code, 2, "Debian apt output - should have same result when default security regexp specified via -c" ); |
49 | like( $result->output, make_result_regexp(19, 4), "Output correct" ); | 57 | like( $result->output, make_result_regexp(19, 4), "Output correct" ); |
@@ -52,6 +60,10 @@ $result = NPTest->testCmd( sprintf($testfile_command, "-i libc6", "debian3") ); | |||
52 | is( $result->return_code, 1, "Debian apt output, filter for libc6" ); | 60 | is( $result->return_code, 1, "Debian apt output, filter for libc6" ); |
53 | like( $result->output, make_result_regexp(3, 0), "Output correct" ); | 61 | like( $result->output, make_result_regexp(3, 0), "Output correct" ); |
54 | 62 | ||
63 | $result = NPTest->testCmd( sprintf($testfile_command, "-i libc6", "debian3") ); | ||
64 | is( $result->return_code, 1, "Debian apt output, filter for libc6, not critical" ); | ||
65 | like( $result->output, make_result_regexp(3, 0), "Output correct" ); | ||
66 | |||
55 | $result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen", "debian3") ); | 67 | $result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen", "debian3") ); |
56 | is( $result->return_code, 2, "Debian apt output, filter for libc6 and xen" ); | 68 | is( $result->return_code, 2, "Debian apt output, filter for libc6 and xen" ); |
57 | like( $result->output, make_result_regexp(9, 4), "Output correct" ); | 69 | like( $result->output, make_result_regexp(9, 4), "Output correct" ); |
@@ -64,6 +76,10 @@ $result = NPTest->testCmd( sprintf($testfile_command, "-e libc6", "debian3") ); | |||
64 | is( $result->return_code, 2, "Debian apt output, filter out libc6" ); | 76 | is( $result->return_code, 2, "Debian apt output, filter out libc6" ); |
65 | like( $result->output, make_result_regexp(16, 4), "Output correct" ); | 77 | like( $result->output, make_result_regexp(16, 4), "Output correct" ); |
66 | 78 | ||
79 | $result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -o", "debian3") ); | ||
80 | is( $result->return_code, 2, "Debian apt output, filter out libc6, critical" ); | ||
81 | like( $result->output, make_result_regexp(16, 4), "Output correct" ); | ||
82 | |||
67 | $result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen", "debian3") ); | 83 | $result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen", "debian3") ); |
68 | is( $result->return_code, 1, "Debian apt output, filter out libc6 and xen" ); | 84 | is( $result->return_code, 1, "Debian apt output, filter out libc6 and xen" ); |
69 | like( $result->output, make_result_regexp(10, 0), "Output correct" ); | 85 | like( $result->output, make_result_regexp(10, 0), "Output correct" ); |