summaryrefslogtreecommitdiffstats
path: root/plugins/check_apt.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_apt.c')
-rw-r--r--plugins/check_apt.c175
1 files changed, 97 insertions, 78 deletions
diff --git a/plugins/check_apt.c b/plugins/check_apt.c
index 528dd60..9bc1249 100644
--- a/plugins/check_apt.c
+++ b/plugins/check_apt.c
@@ -1,22 +1,35 @@
1/****************************************************************************** 1/******************************************************************************
2 * check_apt.c: check for available updates in apt package management systems 2*
3 * original author: sean finney <seanius@seanius.net> 3* Nagios check_apt plugin
4 * (with some common bits stolen from check_nagios.c) 4*
5 ****************************************************************************** 5* License: GPL
6 6* Copyright (c) 1999-2006 nagios-plugins team
7 This program is free software; you can redistribute it and/or modify 7*
8 it under the terms of the GNU General Public License as published by 8* Original author: sean finney
9 the Free Software Foundation; either version 2 of the License, or 9*
10 (at your option) any later version. 10* Last Modified: $Date$
11 11*
12 This program is distributed in the hope that it will be useful, 12* Description:
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13*
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14* This file contains the check_apt plugin
15 GNU General Public License for more details. 15*
16 16* check for available updates in apt package management systems
17 You should have received a copy of the GNU General Public License 17*
18 along with this program; if not, write to the Free Software 18* License Information:
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19*
20* This program is free software; you can redistribute it and/or modify
21* it under the terms of the GNU General Public License as published by
22* the Free Software Foundation; either version 2 of the License, or
23* (at your option) any later version.
24*
25* This program is distributed in the hope that it will be useful,
26* but WITHOUT ANY WARRANTY; without even the implied warranty of
27* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28* GNU General Public License for more details.
29*
30* You should have received a copy of the GNU General Public License
31* along with this program; if not, write to the Free Software
32* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 33
21 $Id$ 34 $Id$
22 35
@@ -196,66 +209,6 @@ int process_arguments (int argc, char **argv) {
196} 209}
197 210
198 211
199/* informative help message */
200void print_help(void){
201 print_revision(progname, revision);
202 printf(_(COPYRIGHT), copyright, email);
203 printf(_("\
204This plugin checks for software updates on systems that use\n\
205package management systems based on the apt-get(8) command\n\
206found in Debian GNU/Linux\n\
207\n\n"));
208 print_usage();
209 printf(_(UT_HELP_VRSN));
210 printf(_(UT_TIMEOUT), timeout_interval);
211 printf(_("\n\
212 -U, --upgrade=OPTS\n\
213 [Default] Perform an upgrade. If an optional OPTS argument is provided,\n\
214 apt-get will be run with these command line options instead of the\n\
215 default (%s).\n\
216 Note that you may be required to have root privileges if you do not use\n\
217 the default options.\n\
218 -d, --dist-upgrade=OPTS\n\
219 Perform a dist-upgrade instead of normal upgrade. Like with -U OPTS\n\
220 can be provided to override the default options.\n\
221 -n, --no-upgrade\n\
222 Do not run the upgrade. Probably not useful (without -u at least).\n\
223 -i, --include=REGEXP\n\
224 Include only packages matching REGEXP. Can be specified multiple times;\n\
225 the values will be combined together. Any patches matching this list\n\
226 cause the plugin to return WARNING status. Others will be ignored.\n\
227 Default is to include all packages.\n\
228 -e, --exclude=REGEXP\n\
229 Exclude packages matching REGEXP from the list of packages that would\n\
230 otherwise be included. Can be specified multiple times; the values\n\
231 will be combined together. Default is to exclude no packages.\n\
232 -c, --critical=REGEXP\n\
233 If the full package information of any of the upgradable packages match\n\
234 this REGEXP, the plugin will return CRITICAL status. Can be specified\n\
235 multiple times like above. Default is a regexp matching security\n\
236 upgrades for Debian and Ubuntu:\n\
237 \t%s\n\
238 Note that the package must first match the include list before its\n\
239 information is compared against the critical list.\n\
240 \n\n"),
241 UPGRADE_DEFAULT_OPTS, SECURITY_RE);
242 printf(_("\
243The following options require root privileges and should be used with care: \
244\n\n"));
245 printf(_("\
246 -u, --update=OPTS\n\
247 First perform an 'apt-get update'. An optional OPTS parameter overrides\n\
248 the default options. Note: you may also need to adjust the global \n\
249 timeout (with -t) to prevent the plugin from timing out if apt-get\n\
250 upgrade is expected to take longer than the default timeout.\n\
251\n\n"));
252}
253
254/* simple usage heading */
255void print_usage(void){
256 printf ("Usage: %s [[-d|-u|-U]opts] [-n] [-t timeout]\n", progname);
257}
258
259/* run an apt-get upgrade */ 212/* run an apt-get upgrade */
260int run_upgrade(int *pkgcount, int *secpkgcount){ 213int run_upgrade(int *pkgcount, int *secpkgcount){
261 int i=0, result=STATE_UNKNOWN, regres=0, pc=0, spc=0; 214 int i=0, result=STATE_UNKNOWN, regres=0, pc=0, spc=0;
@@ -445,3 +398,69 @@ char* construct_cmdline(upgrade_type u, const char *opts){
445 sprintf(cmd, "%s %s %s", PATH_TO_APTGET, opts_ptr, aptcmd); 398 sprintf(cmd, "%s %s %s", PATH_TO_APTGET, opts_ptr, aptcmd);
446 return cmd; 399 return cmd;
447} 400}
401
402/* informative help message */
403void
404print_help (void)
405{
406 print_revision(progname, revision);
407
408 printf(_(COPYRIGHT), copyright, email);
409
410 printf("%s\n", _("This plugin checks for software updates on systems that use"));
411 printf("%s\n", _("package management systems based on the apt-get(8) command"));
412 printf("%s\n", _("found in Debian GNU/Linux"));
413
414 print_usage();
415
416 printf(_(UT_HELP_VRSN));
417
418 printf(_(UT_TIMEOUT), timeout_interval);
419
420 printf(_("\n\
421 -U, --upgrade=OPTS\n\
422 [Default] Perform an upgrade. If an optional OPTS argument is provided,\n\
423 apt-get will be run with these command line options instead of the\n\
424 default (%s).\n\
425 Note that you may be required to have root privileges if you do not use\n\
426 the default options.\n\
427 -d, --dist-upgrade=OPTS\n\
428 Perform a dist-upgrade instead of normal upgrade. Like with -U OPTS\n\
429 can be provided to override the default options.\n\
430 -n, --no-upgrade\n\
431 Do not run the upgrade. Probably not useful (without -u at least).\n\
432 -i, --include=REGEXP\n\
433 Include only packages matching REGEXP. Can be specified multiple times;\n\
434 the values will be combined together. Any patches matching this list\n\
435 cause the plugin to return WARNING status. Others will be ignored.\n\
436 Default is to include all packages.\n\
437 -e, --exclude=REGEXP\n\
438 Exclude packages matching REGEXP from the list of packages that would\n\
439 otherwise be included. Can be specified multiple times; the values\n\
440 will be combined together. Default is to exclude no packages.\n\
441 -c, --critical=REGEXP\n\
442 If the full package information of any of the upgradable packages match\n\
443 this REGEXP, the plugin will return CRITICAL status. Can be specified\n\
444 multiple times like above. Default is a regexp matching security\n\
445 upgrades for Debian and Ubuntu:\n\
446 \t%s\n\
447 Note that the package must first match the include list before its\n\
448 information is compared against the critical list.\n\
449 \n\n"),
450 UPGRADE_DEFAULT_OPTS, SECURITY_RE);
451
452 printf ("%s\n\n", _("The following options require root privileges and should be used with care:"));
453 printf (" %s\n", "-u, --update=OPTS");
454 printf (" %s\n", _("First perform an 'apt-get update'. An optional OPTS parameter overrides"));
455 printf (" %s\n", _("the default options. Note: you may also need to adjust the global"));
456 printf (" %s\n", _("timeout (with -t) to prevent the plugin from timing out if apt-get"));
457 printf (" %s\n", _("upgrade is expected to take longer than the default timeout."));
458}
459
460
461/* simple usage heading */
462void
463print_usage(void)
464{
465 printf ("Usage: %s [[-d|-u|-U]opts] [-n] [-t timeout]\n", progname);
466}