summaryrefslogtreecommitdiffstats
path: root/plugins/check_apt.c
diff options
context:
space:
mode:
authorAlex Bradley <a.bradley@alumni.cs.ubc.ca>2012-10-03 22:54:24 (GMT)
committerAlex Bradley <a.bradley@alumni.cs.ubc.ca>2012-10-03 22:54:24 (GMT)
commit13e85a0f4f9d1ede624e1135f1646c64ecc052a4 (patch)
tree7f530ec0003cfe599da8ffa6e17472175d67ce84 /plugins/check_apt.c
parent09c25be0d1c95ce1deba7d9ee046b343cbd7ab93 (diff)
downloadmonitoring-plugins-13e85a0f4f9d1ede624e1135f1646c64ecc052a4.tar.gz
Tests for check_aptrefs/pull/20/head
Add a hidden "--input-file" option to check_apt (modelled on check_procs) so that it can take files with sample apt output as input. Add tests for my SECURITY_RE fix (debian3) and for the include, exclude and critical options.
Diffstat (limited to 'plugins/check_apt.c')
-rw-r--r--plugins/check_apt.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/plugins/check_apt.c b/plugins/check_apt.c
index a1176cf..cf18661 100644
--- a/plugins/check_apt.c
+++ b/plugins/check_apt.c
@@ -41,6 +41,8 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
41/* some constants */ 41/* some constants */
42typedef enum { UPGRADE, DIST_UPGRADE, NO_UPGRADE } upgrade_type; 42typedef enum { UPGRADE, DIST_UPGRADE, NO_UPGRADE } upgrade_type;
43 43
44/* Character for hidden input file option (for testing). */
45#define INPUT_FILE_OPT CHAR_MAX+1
44/* the default opts can be overridden via the cmdline */ 46/* the default opts can be overridden via the cmdline */
45#define UPGRADE_DEFAULT_OPTS "-o 'Debug::NoLocking=true' -s -qq" 47#define UPGRADE_DEFAULT_OPTS "-o 'Debug::NoLocking=true' -s -qq"
46#define UPDATE_DEFAULT_OPTS "-q" 48#define UPDATE_DEFAULT_OPTS "-q"
@@ -77,6 +79,7 @@ static char *update_opts = NULL; /* options to override defaults for update */
77static char *do_include = NULL; /* regexp to only include certain packages */ 79static char *do_include = NULL; /* regexp to only include certain packages */
78static char *do_exclude = NULL; /* regexp to only exclude certain packages */ 80static char *do_exclude = NULL; /* regexp to only exclude certain packages */
79static char *do_critical = NULL; /* regexp specifying critical packages */ 81static char *do_critical = NULL; /* regexp specifying critical packages */
82static char *input_filename = NULL; /* input filename for testing */
80 83
81/* other global variables */ 84/* other global variables */
82static int stderr_warning = 0; /* if a cmd issued output on stderr */ 85static int stderr_warning = 0; /* if a cmd issued output on stderr */
@@ -143,6 +146,7 @@ int process_arguments (int argc, char **argv) {
143 {"include", required_argument, 0, 'i'}, 146 {"include", required_argument, 0, 'i'},
144 {"exclude", required_argument, 0, 'e'}, 147 {"exclude", required_argument, 0, 'e'},
145 {"critical", required_argument, 0, 'c'}, 148 {"critical", required_argument, 0, 'c'},
149 {"input-file", required_argument, 0, INPUT_FILE_OPT},
146 {0, 0, 0, 0} 150 {0, 0, 0, 0}
147 }; 151 };
148 152
@@ -197,6 +201,9 @@ int process_arguments (int argc, char **argv) {
197 case 'c': 201 case 'c':
198 do_critical=add_to_regexp(do_critical, optarg); 202 do_critical=add_to_regexp(do_critical, optarg);
199 break; 203 break;
204 case INPUT_FILE_OPT:
205 input_filename = optarg;
206 break;
200 default: 207 default:
201 /* print short usage statement if args not parsable */ 208 /* print short usage statement if args not parsable */
202 usage5(); 209 usage5();
@@ -243,8 +250,14 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
243 } 250 }
244 251
245 cmdline=construct_cmdline(upgrade, upgrade_opts); 252 cmdline=construct_cmdline(upgrade, upgrade_opts);
246 /* run the upgrade */ 253 if (input_filename != NULL) {
247 result = np_runcmd(cmdline, &chld_out, &chld_err, 0); 254 /* read input from a file for testing */
255 result = cmd_file_read(input_filename, &chld_out, 0);
256 } else {
257 /* run the upgrade */
258 result = np_runcmd(cmdline, &chld_out, &chld_err, 0);
259 }
260
248 /* apt-get upgrade only changes exit status if there is an 261 /* apt-get upgrade only changes exit status if there is an
249 * internal error when run in dry-run mode. therefore we will 262 * internal error when run in dry-run mode. therefore we will
250 * treat such an error as UNKNOWN */ 263 * treat such an error as UNKNOWN */
@@ -290,7 +303,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
290 *secpkgcount=spc; 303 *secpkgcount=spc;
291 304
292 /* If we get anything on stderr, at least set warning */ 305 /* If we get anything on stderr, at least set warning */
293 if(chld_err.buflen){ 306 if (input_filename == NULL && chld_err.buflen) {
294 stderr_warning=1; 307 stderr_warning=1;
295 result = max_state(result, STATE_WARNING); 308 result = max_state(result, STATE_WARNING);
296 if(verbose){ 309 if(verbose){