diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Makefile.am | 3 | ||||
-rw-r--r-- | plugins/check_apt.c | 151 | ||||
-rw-r--r-- | plugins/check_apt.d/config.h | 42 |
3 files changed, 120 insertions, 76 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index d40a0937..2ffb5fd0 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am | |||
@@ -53,7 +53,8 @@ EXTRA_DIST = t \ | |||
53 | check_game.d \ | 53 | check_game.d \ |
54 | check_dbi.d \ | 54 | check_dbi.d \ |
55 | check_ssh.d \ | 55 | check_ssh.d \ |
56 | check_dns.d | 56 | check_dns.d \ |
57 | check_apt.d | ||
57 | 58 | ||
58 | PLUGINHDRS = common.h | 59 | PLUGINHDRS = common.h |
59 | 60 | ||
diff --git a/plugins/check_apt.c b/plugins/check_apt.c index 1eda45dd..e840184b 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c | |||
@@ -29,6 +29,7 @@ | |||
29 | * | 29 | * |
30 | *****************************************************************************/ | 30 | *****************************************************************************/ |
31 | 31 | ||
32 | #include "states.h" | ||
32 | const char *progname = "check_apt"; | 33 | const char *progname = "check_apt"; |
33 | const char *copyright = "2006-2024"; | 34 | const char *copyright = "2006-2024"; |
34 | const char *email = "devel@monitoring-plugins.org"; | 35 | const char *email = "devel@monitoring-plugins.org"; |
@@ -37,13 +38,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
37 | #include "runcmd.h" | 38 | #include "runcmd.h" |
38 | #include "utils.h" | 39 | #include "utils.h" |
39 | #include "regex.h" | 40 | #include "regex.h" |
40 | 41 | #include "check_apt.d/config.h" | |
41 | /* some constants */ | ||
42 | typedef enum { | ||
43 | UPGRADE, | ||
44 | DIST_UPGRADE, | ||
45 | NO_UPGRADE | ||
46 | } upgrade_type; | ||
47 | 42 | ||
48 | /* Character for hidden input file option (for testing). */ | 43 | /* Character for hidden input file option (for testing). */ |
49 | #define INPUT_FILE_OPT CHAR_MAX + 1 | 44 | #define INPUT_FILE_OPT CHAR_MAX + 1 |
@@ -61,14 +56,18 @@ typedef enum { | |||
61 | #define SECURITY_RE "^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)" | 56 | #define SECURITY_RE "^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)" |
62 | 57 | ||
63 | /* some standard functions */ | 58 | /* some standard functions */ |
64 | static int process_arguments(int /*argc*/, char ** /*argv*/); | 59 | typedef struct { |
60 | int errorcode; | ||
61 | check_apt_config config; | ||
62 | } check_apt_config_wrapper; | ||
63 | static check_apt_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); | ||
65 | static void print_help(void); | 64 | static void print_help(void); |
66 | void print_usage(void); | 65 | void print_usage(void); |
67 | 66 | ||
68 | /* construct the appropriate apt-get cmdline */ | 67 | /* construct the appropriate apt-get cmdline */ |
69 | static char *construct_cmdline(upgrade_type u, const char *opts); | 68 | static char *construct_cmdline(upgrade_type /*u*/, const char * /*opts*/); |
70 | /* run an apt-get update */ | 69 | /* run an apt-get update */ |
71 | static int run_update(void); | 70 | static int run_update(char * /*update_opts*/); |
72 | 71 | ||
73 | typedef struct { | 72 | typedef struct { |
74 | int errorcode; | 73 | int errorcode; |
@@ -79,42 +78,35 @@ typedef struct { | |||
79 | } run_upgrade_result; | 78 | } run_upgrade_result; |
80 | 79 | ||
81 | /* run an apt-get upgrade */ | 80 | /* run an apt-get upgrade */ |
82 | static run_upgrade_result run_upgrade(void); | 81 | run_upgrade_result run_upgrade(upgrade_type upgrade, const char *do_include, const char *do_exclude, const char *do_critical, |
82 | const char *upgrade_opts, const char *input_filename); | ||
83 | 83 | ||
84 | /* add another clause to a regexp */ | 84 | /* add another clause to a regexp */ |
85 | static char *add_to_regexp(char *expr, const char *next); | 85 | static char *add_to_regexp(char * /*expr*/, const char * /*next*/); |
86 | /* extract package name from Inst line */ | 86 | /* extract package name from Inst line */ |
87 | static char *pkg_name(char *line); | 87 | static char *pkg_name(char * /*line*/); |
88 | /* string comparison function for qsort */ | 88 | /* string comparison function for qsort */ |
89 | static int cmpstringp(const void *p1, const void *p2); | 89 | static int cmpstringp(const void * /*p1*/, const void * /*p2*/); |
90 | 90 | ||
91 | /* configuration variables */ | 91 | /* configuration variables */ |
92 | static int verbose = 0; /* -v */ | 92 | static int verbose = 0; /* -v */ |
93 | static bool list = false; /* list packages available for upgrade */ | ||
94 | static bool do_update = false; /* whether to call apt-get update */ | ||
95 | static bool only_critical = false; /* whether to warn about non-critical updates */ | ||
96 | static upgrade_type upgrade = UPGRADE; /* which type of upgrade to do */ | ||
97 | static char *upgrade_opts = NULL; /* options to override defaults for upgrade */ | ||
98 | static char *update_opts = NULL; /* options to override defaults for update */ | ||
99 | static char *do_include = NULL; /* regexp to only include certain packages */ | ||
100 | static char *do_exclude = NULL; /* regexp to only exclude certain packages */ | ||
101 | static char *do_critical = NULL; /* regexp specifying critical packages */ | ||
102 | static char *input_filename = NULL; /* input filename for testing */ | ||
103 | /* number of packages available for upgrade to return WARNING status */ | ||
104 | static int packages_warning = 1; | ||
105 | 93 | ||
106 | /* other global variables */ | 94 | /* other global variables */ |
107 | static int stderr_warning = 0; /* if a cmd issued output on stderr */ | 95 | static bool stderr_warning = false; /* if a cmd issued output on stderr */ |
108 | static int exec_warning = 0; /* if a cmd exited non-zero */ | 96 | static bool exec_warning = false; /* if a cmd exited non-zero */ |
109 | 97 | ||
110 | int main(int argc, char **argv) { | 98 | int main(int argc, char **argv) { |
111 | /* Parse extra opts if any */ | 99 | /* Parse extra opts if any */ |
112 | argv = np_extra_opts(&argc, argv, progname); | 100 | argv = np_extra_opts(&argc, argv, progname); |
113 | 101 | ||
114 | if (process_arguments(argc, argv) == ERROR) { | 102 | check_apt_config_wrapper tmp_config = process_arguments(argc, argv); |
103 | |||
104 | if (tmp_config.errorcode == ERROR) { | ||
115 | usage_va(_("Could not parse arguments")); | 105 | usage_va(_("Could not parse arguments")); |
116 | } | 106 | } |
117 | 107 | ||
108 | const check_apt_config config = tmp_config.config; | ||
109 | |||
118 | /* Set signal handling and alarm timeout */ | 110 | /* Set signal handling and alarm timeout */ |
119 | if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) { | 111 | if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) { |
120 | usage_va(_("Cannot catch SIGALRM")); | 112 | usage_va(_("Cannot catch SIGALRM")); |
@@ -123,14 +115,15 @@ int main(int argc, char **argv) { | |||
123 | /* handle timeouts gracefully... */ | 115 | /* handle timeouts gracefully... */ |
124 | alarm(timeout_interval); | 116 | alarm(timeout_interval); |
125 | 117 | ||
126 | int result = STATE_UNKNOWN; | 118 | mp_state_enum result = STATE_UNKNOWN; |
127 | /* if they want to run apt-get update first... */ | 119 | /* if they want to run apt-get update first... */ |
128 | if (do_update) { | 120 | if (config.do_update) { |
129 | result = run_update(); | 121 | result = run_update(config.update_opts); |
130 | } | 122 | } |
131 | 123 | ||
132 | /* apt-get upgrade */ | 124 | /* apt-get upgrade */ |
133 | run_upgrade_result upgrad_res = run_upgrade(); | 125 | run_upgrade_result upgrad_res = |
126 | run_upgrade(config.upgrade, config.do_include, config.do_exclude, config.do_critical, config.upgrade_opts, config.input_filename); | ||
134 | 127 | ||
135 | result = max_state(result, upgrad_res.errorcode); | 128 | result = max_state(result, upgrad_res.errorcode); |
136 | int packages_available = upgrad_res.package_count; | 129 | int packages_available = upgrad_res.package_count; |
@@ -140,18 +133,18 @@ int main(int argc, char **argv) { | |||
140 | 133 | ||
141 | if (sec_count > 0) { | 134 | if (sec_count > 0) { |
142 | result = max_state(result, STATE_CRITICAL); | 135 | result = max_state(result, STATE_CRITICAL); |
143 | } else if (packages_available >= packages_warning && only_critical == false) { | 136 | } else if (packages_available >= config.packages_warning && !config.only_critical) { |
144 | result = max_state(result, STATE_WARNING); | 137 | result = max_state(result, STATE_WARNING); |
145 | } else if (result > STATE_UNKNOWN) { | 138 | } else if (result > STATE_UNKNOWN) { |
146 | result = STATE_UNKNOWN; | 139 | result = STATE_UNKNOWN; |
147 | } | 140 | } |
148 | 141 | ||
149 | printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s|available_upgrades=%d;;;0 critical_updates=%d;;;0\n"), | 142 | printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s|available_upgrades=%d;;;0 critical_updates=%d;;;0\n"), |
150 | state_text(result), packages_available, (upgrade == DIST_UPGRADE) ? "dist-upgrade" : "upgrade", sec_count, | 143 | state_text(result), packages_available, (config.upgrade == DIST_UPGRADE) ? "dist-upgrade" : "upgrade", sec_count, |
151 | (stderr_warning) ? " warnings detected" : "", (stderr_warning && exec_warning) ? "," : "", | 144 | (stderr_warning) ? " warnings detected" : "", (stderr_warning && exec_warning) ? "," : "", |
152 | (exec_warning) ? " errors detected" : "", (stderr_warning || exec_warning) ? "." : "", packages_available, sec_count); | 145 | (exec_warning) ? " errors detected" : "", (stderr_warning || exec_warning) ? "." : "", packages_available, sec_count); |
153 | 146 | ||
154 | if (list) { | 147 | if (config.list) { |
155 | qsort(secpackages_list, sec_count, sizeof(char *), cmpstringp); | 148 | qsort(secpackages_list, sec_count, sizeof(char *), cmpstringp); |
156 | qsort(packages_list, packages_available - sec_count, sizeof(char *), cmpstringp); | 149 | qsort(packages_list, packages_available - sec_count, sizeof(char *), cmpstringp); |
157 | 150 | ||
@@ -159,7 +152,7 @@ int main(int argc, char **argv) { | |||
159 | printf("%s (security)\n", secpackages_list[i]); | 152 | printf("%s (security)\n", secpackages_list[i]); |
160 | } | 153 | } |
161 | 154 | ||
162 | if (only_critical == false) { | 155 | if (!config.only_critical) { |
163 | for (int i = 0; i < packages_available - sec_count; i++) { | 156 | for (int i = 0; i < packages_available - sec_count; i++) { |
164 | printf("%s\n", packages_list[i]); | 157 | printf("%s\n", packages_list[i]); |
165 | } | 158 | } |
@@ -170,7 +163,7 @@ int main(int argc, char **argv) { | |||
170 | } | 163 | } |
171 | 164 | ||
172 | /* process command-line arguments */ | 165 | /* process command-line arguments */ |
173 | int process_arguments(int argc, char **argv) { | 166 | check_apt_config_wrapper process_arguments(int argc, char **argv) { |
174 | static struct option longopts[] = {{"version", no_argument, 0, 'V'}, | 167 | static struct option longopts[] = {{"version", no_argument, 0, 'V'}, |
175 | {"help", no_argument, 0, 'h'}, | 168 | {"help", no_argument, 0, 'h'}, |
176 | {"verbose", no_argument, 0, 'v'}, | 169 | {"verbose", no_argument, 0, 'v'}, |
@@ -179,7 +172,7 @@ int process_arguments(int argc, char **argv) { | |||
179 | {"upgrade", optional_argument, 0, 'U'}, | 172 | {"upgrade", optional_argument, 0, 'U'}, |
180 | {"no-upgrade", no_argument, 0, 'n'}, | 173 | {"no-upgrade", no_argument, 0, 'n'}, |
181 | {"dist-upgrade", optional_argument, 0, 'd'}, | 174 | {"dist-upgrade", optional_argument, 0, 'd'}, |
182 | {"list", no_argument, false, 'l'}, | 175 | {"list", no_argument, 0, 'l'}, |
183 | {"include", required_argument, 0, 'i'}, | 176 | {"include", required_argument, 0, 'i'}, |
184 | {"exclude", required_argument, 0, 'e'}, | 177 | {"exclude", required_argument, 0, 'e'}, |
185 | {"critical", required_argument, 0, 'c'}, | 178 | {"critical", required_argument, 0, 'c'}, |
@@ -188,6 +181,11 @@ int process_arguments(int argc, char **argv) { | |||
188 | {"packages-warning", required_argument, 0, 'w'}, | 181 | {"packages-warning", required_argument, 0, 'w'}, |
189 | {0, 0, 0, 0}}; | 182 | {0, 0, 0, 0}}; |
190 | 183 | ||
184 | check_apt_config_wrapper result = { | ||
185 | .errorcode = OK, | ||
186 | .config = check_apt_config_init(), | ||
187 | }; | ||
188 | |||
191 | while (true) { | 189 | while (true) { |
192 | int option_char = getopt_long(argc, argv, "hVvt:u::U::d::nli:e:c:ow:", longopts, NULL); | 190 | int option_char = getopt_long(argc, argv, "hVvt:u::U::d::nli:e:c:ow:", longopts, NULL); |
193 | 191 | ||
@@ -209,55 +207,55 @@ int process_arguments(int argc, char **argv) { | |||
209 | timeout_interval = atoi(optarg); | 207 | timeout_interval = atoi(optarg); |
210 | break; | 208 | break; |
211 | case 'd': | 209 | case 'd': |
212 | upgrade = DIST_UPGRADE; | 210 | result.config.upgrade = DIST_UPGRADE; |
213 | if (optarg != NULL) { | 211 | if (optarg != NULL) { |
214 | upgrade_opts = strdup(optarg); | 212 | result.config.upgrade_opts = strdup(optarg); |
215 | if (upgrade_opts == NULL) { | 213 | if (result.config.upgrade_opts == NULL) { |
216 | die(STATE_UNKNOWN, "strdup failed"); | 214 | die(STATE_UNKNOWN, "strdup failed"); |
217 | } | 215 | } |
218 | } | 216 | } |
219 | break; | 217 | break; |
220 | case 'U': | 218 | case 'U': |
221 | upgrade = UPGRADE; | 219 | result.config.upgrade = UPGRADE; |
222 | if (optarg != NULL) { | 220 | if (optarg != NULL) { |
223 | upgrade_opts = strdup(optarg); | 221 | result.config.upgrade_opts = strdup(optarg); |
224 | if (upgrade_opts == NULL) { | 222 | if (result.config.upgrade_opts == NULL) { |
225 | die(STATE_UNKNOWN, "strdup failed"); | 223 | die(STATE_UNKNOWN, "strdup failed"); |
226 | } | 224 | } |
227 | } | 225 | } |
228 | break; | 226 | break; |
229 | case 'n': | 227 | case 'n': |
230 | upgrade = NO_UPGRADE; | 228 | result.config.upgrade = NO_UPGRADE; |
231 | break; | 229 | break; |
232 | case 'u': | 230 | case 'u': |
233 | do_update = true; | 231 | result.config.do_update = true; |
234 | if (optarg != NULL) { | 232 | if (optarg != NULL) { |
235 | update_opts = strdup(optarg); | 233 | result.config.update_opts = strdup(optarg); |
236 | if (update_opts == NULL) { | 234 | if (result.config.update_opts == NULL) { |
237 | die(STATE_UNKNOWN, "strdup failed"); | 235 | die(STATE_UNKNOWN, "strdup failed"); |
238 | } | 236 | } |
239 | } | 237 | } |
240 | break; | 238 | break; |
241 | case 'l': | 239 | case 'l': |
242 | list = true; | 240 | result.config.list = true; |
243 | break; | 241 | break; |
244 | case 'i': | 242 | case 'i': |
245 | do_include = add_to_regexp(do_include, optarg); | 243 | result.config.do_include = add_to_regexp(result.config.do_include, optarg); |
246 | break; | 244 | break; |
247 | case 'e': | 245 | case 'e': |
248 | do_exclude = add_to_regexp(do_exclude, optarg); | 246 | result.config.do_exclude = add_to_regexp(result.config.do_exclude, optarg); |
249 | break; | 247 | break; |
250 | case 'c': | 248 | case 'c': |
251 | do_critical = add_to_regexp(do_critical, optarg); | 249 | result.config.do_critical = add_to_regexp(result.config.do_critical, optarg); |
252 | break; | 250 | break; |
253 | case 'o': | 251 | case 'o': |
254 | only_critical = true; | 252 | result.config.only_critical = true; |
255 | break; | 253 | break; |
256 | case INPUT_FILE_OPT: | 254 | case INPUT_FILE_OPT: |
257 | input_filename = optarg; | 255 | result.config.input_filename = optarg; |
258 | break; | 256 | break; |
259 | case 'w': | 257 | case 'w': |
260 | packages_warning = atoi(optarg); | 258 | result.config.packages_warning = atoi(optarg); |
261 | break; | 259 | break; |
262 | default: | 260 | default: |
263 | /* print short usage statement if args not parsable */ | 261 | /* print short usage statement if args not parsable */ |
@@ -265,11 +263,12 @@ int process_arguments(int argc, char **argv) { | |||
265 | } | 263 | } |
266 | } | 264 | } |
267 | 265 | ||
268 | return OK; | 266 | return result; |
269 | } | 267 | } |
270 | 268 | ||
271 | /* run an apt-get upgrade */ | 269 | /* run an apt-get upgrade */ |
272 | run_upgrade_result run_upgrade(void) { | 270 | run_upgrade_result run_upgrade(const upgrade_type upgrade, const char *do_include, const char *do_exclude, const char *do_critical, |
271 | const char *upgrade_opts, const char *input_filename) { | ||
273 | regex_t ereg; | 272 | regex_t ereg; |
274 | /* initialize ereg as it is possible it is printed while uninitialized */ | 273 | /* initialize ereg as it is possible it is printed while uninitialized */ |
275 | memset(&ereg, '\0', sizeof(ereg.buffer)); | 274 | memset(&ereg, '\0', sizeof(ereg.buffer)); |
@@ -332,7 +331,7 @@ run_upgrade_result run_upgrade(void) { | |||
332 | fprintf(stderr, _("'%s' exited with non-zero status.\n"), cmdline); | 331 | fprintf(stderr, _("'%s' exited with non-zero status.\n"), cmdline); |
333 | } | 332 | } |
334 | 333 | ||
335 | char **pkglist = malloc(sizeof(char *) * chld_out.lines); | 334 | char **pkglist = malloc(sizeof(char *) * chld_out.lines); |
336 | if (!pkglist) { | 335 | if (!pkglist) { |
337 | die(STATE_UNKNOWN, "malloc failed!\n"); | 336 | die(STATE_UNKNOWN, "malloc failed!\n"); |
338 | } | 337 | } |
@@ -385,7 +384,7 @@ run_upgrade_result run_upgrade(void) { | |||
385 | 384 | ||
386 | /* If we get anything on stderr, at least set warning */ | 385 | /* If we get anything on stderr, at least set warning */ |
387 | if (input_filename == NULL && chld_err.buflen) { | 386 | if (input_filename == NULL && chld_err.buflen) { |
388 | stderr_warning = 1; | 387 | stderr_warning = true; |
389 | result.errorcode = max_state(result.errorcode, STATE_WARNING); | 388 | result.errorcode = max_state(result.errorcode, STATE_WARNING); |
390 | if (verbose) { | 389 | if (verbose) { |
391 | for (size_t i = 0; i < chld_err.lines; i++) { | 390 | for (size_t i = 0; i < chld_err.lines; i++) { |
@@ -405,7 +404,7 @@ run_upgrade_result run_upgrade(void) { | |||
405 | } | 404 | } |
406 | 405 | ||
407 | /* run an apt-get update (needs root) */ | 406 | /* run an apt-get update (needs root) */ |
408 | int run_update(void) { | 407 | int run_update(char *update_opts) { |
409 | int result = STATE_UNKNOWN; | 408 | int result = STATE_UNKNOWN; |
410 | char *cmdline; | 409 | char *cmdline; |
411 | /* run the update */ | 410 | /* run the update */ |
@@ -418,7 +417,7 @@ int run_update(void) { | |||
418 | * since we were explicitly asked to do so, this is treated as | 417 | * since we were explicitly asked to do so, this is treated as |
419 | * a critical error. */ | 418 | * a critical error. */ |
420 | if (result != 0) { | 419 | if (result != 0) { |
421 | exec_warning = 1; | 420 | exec_warning = true; |
422 | result = STATE_CRITICAL; | 421 | result = STATE_CRITICAL; |
423 | fprintf(stderr, _("'%s' exited with non-zero status.\n"), cmdline); | 422 | fprintf(stderr, _("'%s' exited with non-zero status.\n"), cmdline); |
424 | } | 423 | } |
@@ -446,7 +445,7 @@ int run_update(void) { | |||
446 | char *pkg_name(char *line) { | 445 | char *pkg_name(char *line) { |
447 | char *start = line + strlen(PKGINST_PREFIX); | 446 | char *start = line + strlen(PKGINST_PREFIX); |
448 | 447 | ||
449 | int len = strlen(start); | 448 | size_t len = strlen(start); |
450 | 449 | ||
451 | char *space = index(start, ' '); | 450 | char *space = index(start, ' '); |
452 | if (space != NULL) { | 451 | if (space != NULL) { |
@@ -464,35 +463,37 @@ char *pkg_name(char *line) { | |||
464 | return pkg; | 463 | return pkg; |
465 | } | 464 | } |
466 | 465 | ||
467 | int cmpstringp(const void *p1, const void *p2) { return strcmp(*(char *const *)p1, *(char *const *)p2); } | 466 | int cmpstringp(const void *left_string, const void *right_string) { |
467 | return strcmp(*(char *const *)left_string, *(char *const *)right_string); | ||
468 | } | ||
468 | 469 | ||
469 | char *add_to_regexp(char *expr, const char *next) { | 470 | char *add_to_regexp(char *expr, const char *next) { |
470 | char *re = NULL; | 471 | char *regex_string = NULL; |
471 | 472 | ||
472 | if (expr == NULL) { | 473 | if (expr == NULL) { |
473 | re = malloc(sizeof(char) * (strlen("()") + strlen(next) + 1)); | 474 | regex_string = malloc(sizeof(char) * (strlen("()") + strlen(next) + 1)); |
474 | if (!re) { | 475 | if (!regex_string) { |
475 | die(STATE_UNKNOWN, "malloc failed!\n"); | 476 | die(STATE_UNKNOWN, "malloc failed!\n"); |
476 | } | 477 | } |
477 | sprintf(re, "(%s)", next); | 478 | sprintf(regex_string, "(%s)", next); |
478 | } else { | 479 | } else { |
479 | /* resize it, adding an extra char for the new '|' separator */ | 480 | /* resize it, adding an extra char for the new '|' separator */ |
480 | re = realloc(expr, sizeof(char) * (strlen(expr) + 1 + strlen(next) + 1)); | 481 | regex_string = realloc(expr, sizeof(char) * (strlen(expr) + 1 + strlen(next) + 1)); |
481 | if (!re) { | 482 | if (!regex_string) { |
482 | die(STATE_UNKNOWN, "realloc failed!\n"); | 483 | die(STATE_UNKNOWN, "realloc failed!\n"); |
483 | } | 484 | } |
484 | /* append it starting at ')' in the old re */ | 485 | /* append it starting at ')' in the old re */ |
485 | sprintf((char *)(re + strlen(re) - 1), "|%s)", next); | 486 | sprintf((char *)(regex_string + strlen(regex_string) - 1), "|%s)", next); |
486 | } | 487 | } |
487 | 488 | ||
488 | return re; | 489 | return regex_string; |
489 | } | 490 | } |
490 | 491 | ||
491 | char *construct_cmdline(upgrade_type u, const char *opts) { | 492 | char *construct_cmdline(upgrade_type upgrade, const char *opts) { |
492 | const char *opts_ptr = NULL; | 493 | const char *opts_ptr = NULL; |
493 | const char *aptcmd = NULL; | 494 | const char *aptcmd = NULL; |
494 | 495 | ||
495 | switch (u) { | 496 | switch (upgrade) { |
496 | case UPGRADE: | 497 | case UPGRADE: |
497 | if (opts == NULL) { | 498 | if (opts == NULL) { |
498 | opts_ptr = UPGRADE_DEFAULT_OPTS; | 499 | opts_ptr = UPGRADE_DEFAULT_OPTS; |
diff --git a/plugins/check_apt.d/config.h b/plugins/check_apt.d/config.h new file mode 100644 index 00000000..2c962e5a --- /dev/null +++ b/plugins/check_apt.d/config.h | |||
@@ -0,0 +1,42 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include "../../config.h" | ||
4 | #include <stddef.h> | ||
5 | |||
6 | /* some constants */ | ||
7 | typedef enum { | ||
8 | UPGRADE, | ||
9 | DIST_UPGRADE, | ||
10 | NO_UPGRADE | ||
11 | } upgrade_type; | ||
12 | |||
13 | typedef struct { | ||
14 | bool do_update; /* whether to call apt-get update */ | ||
15 | upgrade_type upgrade; /* which type of upgrade to do */ | ||
16 | bool only_critical; /* whether to warn about non-critical updates */ | ||
17 | bool list; /* list packages available for upgrade */ | ||
18 | /* number of packages available for upgrade to return WARNING status */ | ||
19 | int packages_warning; | ||
20 | |||
21 | char *upgrade_opts; /* options to override defaults for upgrade */ | ||
22 | char *update_opts; /* options to override defaults for update */ | ||
23 | char *do_include; /* regexp to only include certain packages */ | ||
24 | char *do_exclude; /* regexp to only exclude certain packages */ | ||
25 | char *do_critical; /* regexp specifying critical packages */ | ||
26 | char *input_filename; /* input filename for testing */ | ||
27 | } check_apt_config; | ||
28 | |||
29 | check_apt_config check_apt_config_init() { | ||
30 | check_apt_config tmp = {.do_update = false, | ||
31 | .upgrade = UPGRADE, | ||
32 | .only_critical = false, | ||
33 | .list = false, | ||
34 | .packages_warning = 1, | ||
35 | .update_opts = NULL, | ||
36 | .update_opts = NULL, | ||
37 | .do_include = NULL, | ||
38 | .do_exclude = NULL, | ||
39 | .do_critical = NULL, | ||
40 | .input_filename = NULL}; | ||
41 | return tmp; | ||
42 | } | ||