diff options
author | M. Sean Finney <seanius@users.sourceforge.net> | 2006-03-29 08:01:19 (GMT) |
---|---|---|
committer | M. Sean Finney <seanius@users.sourceforge.net> | 2006-03-29 08:01:19 (GMT) |
commit | 32ef29ef199b28e820f68db63866f64c8d53e97b (patch) | |
tree | f882aafc1b2407e7551e359aff6f53d2e8b18762 /plugins/check_apt.c | |
parent | 7dc27490479a6fe8ffeccc834f3410bbdb2d9fd9 (diff) | |
download | monitoring-plugins-32ef29ef199b28e820f68db63866f64c8d53e97b.tar.gz |
now support for detecting critical/security updates, which sets
the return code to STATE_CRITICAL instead of just STATE_WARNING
as it was previously doing.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1360 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_apt.c')
-rw-r--r-- | plugins/check_apt.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/plugins/check_apt.c b/plugins/check_apt.c index 3fdee5d..db328a0 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c | |||
@@ -38,6 +38,8 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
38 | #define APTGET_DISTUPGRADE "/usr/bin/apt-get -o 'Debug::NoLocking=true' -s -qq dist-upgrade" | 38 | #define APTGET_DISTUPGRADE "/usr/bin/apt-get -o 'Debug::NoLocking=true' -s -qq dist-upgrade" |
39 | #define APTGET_UPDATE "/usr/bin/apt-get -q update" | 39 | #define APTGET_UPDATE "/usr/bin/apt-get -q update" |
40 | 40 | ||
41 | #define SECURITY_RE "^[^\\(]*\\([^ ]* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)" | ||
42 | |||
41 | /* some standard functions */ | 43 | /* some standard functions */ |
42 | int process_arguments(int, char **); | 44 | int process_arguments(int, char **); |
43 | void print_help(void); | 45 | void print_help(void); |
@@ -46,7 +48,7 @@ void print_usage(void); | |||
46 | /* run an apt-get update */ | 48 | /* run an apt-get update */ |
47 | int run_update(void); | 49 | int run_update(void); |
48 | /* run an apt-get upgrade */ | 50 | /* run an apt-get upgrade */ |
49 | int run_upgrade(int *pkgcount); | 51 | int run_upgrade(int *pkgcount, int *secpkgcount); |
50 | /* add another clause to a regexp */ | 52 | /* add another clause to a regexp */ |
51 | char* add_to_regexp(char *expr, const char *next); | 53 | char* add_to_regexp(char *expr, const char *next); |
52 | 54 | ||
@@ -62,7 +64,7 @@ static int stderr_warning = 0; /* if a cmd issued output on stderr */ | |||
62 | static int exec_warning = 0; /* if a cmd exited non-zero */ | 64 | static int exec_warning = 0; /* if a cmd exited non-zero */ |
63 | 65 | ||
64 | int main (int argc, char **argv) { | 66 | int main (int argc, char **argv) { |
65 | int result=STATE_UNKNOWN, packages_available=0; | 67 | int result=STATE_UNKNOWN, packages_available=0, sec_count=0; |
66 | 68 | ||
67 | if (process_arguments(argc, argv) == ERROR) | 69 | if (process_arguments(argc, argv) == ERROR) |
68 | usage_va(_("Could not parse arguments")); | 70 | usage_va(_("Could not parse arguments")); |
@@ -79,18 +81,21 @@ int main (int argc, char **argv) { | |||
79 | if(do_update) result = run_update(); | 81 | if(do_update) result = run_update(); |
80 | 82 | ||
81 | /* apt-get upgrade */ | 83 | /* apt-get upgrade */ |
82 | result = max_state(result, run_upgrade(&packages_available)); | 84 | result = max_state(result, run_upgrade(&packages_available, &sec_count)); |
83 | 85 | ||
84 | if(packages_available > 0){ | 86 | if(sec_count > 0){ |
87 | result = max_state(result, STATE_CRITICAL); | ||
88 | } else if(packages_available > 0){ | ||
85 | result = max_state(result, STATE_WARNING); | 89 | result = max_state(result, STATE_WARNING); |
86 | } else { | 90 | } else { |
87 | result = max_state(result, STATE_OK); | 91 | result = max_state(result, STATE_OK); |
88 | } | 92 | } |
89 | 93 | ||
90 | printf("APT %s: %d packages available for %s.%s%s%s%s\n", | 94 | printf("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s\n", |
91 | state_text(result), | 95 | state_text(result), |
92 | packages_available, | 96 | packages_available, |
93 | (dist_upgrade)?"dist-upgrade":"upgrade", | 97 | (dist_upgrade)?"dist-upgrade":"upgrade", |
98 | sec_count, | ||
94 | (stderr_warning)?" warnings detected":"", | 99 | (stderr_warning)?" warnings detected":"", |
95 | (stderr_warning && exec_warning)?",":"", | 100 | (stderr_warning && exec_warning)?",":"", |
96 | (exec_warning)?" errors detected":"", | 101 | (exec_warning)?" errors detected":"", |
@@ -193,10 +198,10 @@ void print_usage(void){ | |||
193 | } | 198 | } |
194 | 199 | ||
195 | /* run an apt-get upgrade */ | 200 | /* run an apt-get upgrade */ |
196 | int run_upgrade(int *pkgcount){ | 201 | int run_upgrade(int *pkgcount, int *secpkgcount){ |
197 | int i=0, result=STATE_UNKNOWN, regres=0, pc=0; | 202 | int i=0, result=STATE_UNKNOWN, regres=0, pc=0, spc=0; |
198 | struct output chld_out, chld_err; | 203 | struct output chld_out, chld_err; |
199 | regex_t ireg, ereg; | 204 | regex_t ireg, ereg, sreg; |
200 | char rerrbuf[64]; | 205 | char rerrbuf[64]; |
201 | const char *default_include_expr="^Inst"; | 206 | const char *default_include_expr="^Inst"; |
202 | 207 | ||
@@ -224,6 +229,13 @@ int run_upgrade(int *pkgcount){ | |||
224 | progname, rerrbuf); | 229 | progname, rerrbuf); |
225 | } | 230 | } |
226 | } | 231 | } |
232 | regres=regcomp(&sreg, SECURITY_RE, REG_EXTENDED); | ||
233 | if(regres!=0) { | ||
234 | regerror(regres, &ereg, rerrbuf, 64); | ||
235 | die(STATE_UNKNOWN, "%s: Error compiling regexp: %s", | ||
236 | progname, rerrbuf); | ||
237 | } | ||
238 | |||
227 | 239 | ||
228 | 240 | ||
229 | /* run the upgrade */ | 241 | /* run the upgrade */ |
@@ -262,6 +274,9 @@ int run_upgrade(int *pkgcount){ | |||
262 | if(do_exclude==NULL || | 274 | if(do_exclude==NULL || |
263 | regexec(&ereg, chld_out.line[i], 0, NULL, 0)!=0){ | 275 | regexec(&ereg, chld_out.line[i], 0, NULL, 0)!=0){ |
264 | pc++; | 276 | pc++; |
277 | if(regexec(&sreg, chld_out.line[i], 0, NULL, 0)==0){ | ||
278 | spc++; | ||
279 | } | ||
265 | if(verbose){ | 280 | if(verbose){ |
266 | printf("*%s\n", chld_out.line[i]); | 281 | printf("*%s\n", chld_out.line[i]); |
267 | } | 282 | } |
@@ -269,6 +284,7 @@ int run_upgrade(int *pkgcount){ | |||
269 | } | 284 | } |
270 | } | 285 | } |
271 | *pkgcount=pc; | 286 | *pkgcount=pc; |
287 | *secpkgcount=spc; | ||
272 | 288 | ||
273 | /* If we get anything on stderr, at least set warning */ | 289 | /* If we get anything on stderr, at least set warning */ |
274 | if(chld_err.buflen){ | 290 | if(chld_err.buflen){ |