Code

Fix compilation with GCC 2.96 (Konstantin Khomoutov - #2977105)
[nagiosplug.git] / plugins / check_apt.c
index 2de8e77637fc0994807793212e4f6c5193040a4a..3da54bcfcd03c7623cb4bf67f9ddbe673330dcb0 100644 (file)
@@ -1,43 +1,36 @@
-/******************************************************************************
-*
+/*****************************************************************************
+* 
 * Nagios check_apt plugin
-*
+* 
 * License: GPL
-* Copyright (c) 1999-2006 nagios-plugins team
-*
-* Original author: sean finney
-*
-* Last Modified: $Date$
-*
+* Copyright (c) 2006-2008 Nagios Plugins Development Team
+* 
+* Original author: Sean Finney
+* 
 * Description:
-*
+* 
 * This file contains the check_apt plugin
 * 
-* check for available updates in apt package management systems
-*
-* License Information:
-*
-* This program is free software; you can redistribute it and/or modify
+* Check for available updates in apt package management systems
+* 
+* 
+* This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
+* the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
-*
+* 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
-*
+* 
 * You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- $Id$
-******************************************************************************/
+* along with this program.  If not, see <http://www.gnu.org/licenses/>.
+* 
+*****************************************************************************/
 
 const char *progname = "check_apt";
-const char *revision = "$Revision$";
-const char *copyright = "2006";
+const char *copyright = "2006-2008";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
@@ -90,6 +83,9 @@ static int exec_warning = 0;     /* if a cmd exited non-zero */
 int main (int argc, char **argv) {
        int result=STATE_UNKNOWN, packages_available=0, sec_count=0;
 
+       /* Parse extra opts if any */
+       argv=np_extra_opts(&argc, argv, progname);
+
        if (process_arguments(argc, argv) == ERROR)
                usage_va(_("Could not parse arguments"));
 
@@ -115,7 +111,7 @@ int main (int argc, char **argv) {
                result = max_state(result, STATE_OK);
        }
 
-       printf("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s\n", 
+       printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s\n"),
               state_text(result),
               packages_available,
               (upgrade==DIST_UPGRADE)?"dist-upgrade":"upgrade",
@@ -158,7 +154,7 @@ int process_arguments (int argc, char **argv) {
                        print_help();
                        exit(STATE_OK);
                case 'V':
-                       print_revision(progname, revision);
+                       print_revision(progname, NP_VERSION);
                        exit(STATE_OK);
                case 'v':
                        verbose++;
@@ -201,7 +197,7 @@ int process_arguments (int argc, char **argv) {
                        break;
                default:
                        /* print short usage statement if args not parsable */
-                       usage_va(_("Unknown argument - %s"), optarg);
+                       usage5();
                }
        }
 
@@ -228,21 +224,21 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
        regres=regcomp(&ireg, include_ptr, REG_EXTENDED);
        if(regres!=0) {
                regerror(regres, &ireg, rerrbuf, 64);
-               die(STATE_UNKNOWN, "%s: Error compiling regexp: %s", progname, rerrbuf);
+               die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf);
        }
 
        if(do_exclude!=NULL){
                regres=regcomp(&ereg, do_exclude, REG_EXTENDED);
                if(regres!=0) {
                        regerror(regres, &ereg, rerrbuf, 64);
-                       die(STATE_UNKNOWN, "%s: Error compiling regexp: %s",
+                       die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"),
                            progname, rerrbuf);
                }
        }
        regres=regcomp(&sreg, crit_ptr, REG_EXTENDED);
        if(regres!=0) {
                regerror(regres, &ereg, rerrbuf, 64);
-               die(STATE_UNKNOWN, "%s: Error compiling regexp: %s",
+               die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"),
                    progname, rerrbuf);
        }
 
@@ -255,7 +251,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
        if(result != 0){
                exec_warning=1;
                result = STATE_UNKNOWN;
-               fprintf(stderr, "'%s' exited with non-zero status.\n",
+               fprintf(stderr, _("'%s' exited with non-zero status.\n"),
                    cmdline);
        }
 
@@ -304,7 +300,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
        }
        regfree(&ireg);
        regfree(&sreg);
-       if(do_exclude!=NULL) regfree(&ereg); 
+       if(do_exclude!=NULL) regfree(&ereg);
        free(cmdline);
        return result;
 }
@@ -324,7 +320,7 @@ int run_update(void){
        if(result != 0){
                exec_warning=1;
                result = STATE_CRITICAL;
-               fprintf(stderr, "'%s' exited with non-zero status.\n",
+               fprintf(stderr, _("'%s' exited with non-zero status.\n"),
                        cmdline);
        }
 
@@ -363,7 +359,7 @@ char* add_to_regexp(char *expr, const char *next){
                sprintf((char*)(re+strlen(re)-2), "|%s) ", next);
        }
 
-       return re;      
+       return re;
 }
 
 char* construct_cmdline(upgrade_type u, const char *opts){
@@ -403,10 +399,10 @@ char* construct_cmdline(upgrade_type u, const char *opts){
 void
 print_help (void)
 {
-  print_revision(progname, revision);
-  
+  print_revision(progname, NP_VERSION);
+
   printf(_(COPYRIGHT), copyright, email);
-  
+
   printf("%s\n", _("This plugin checks for software updates on systems that use"));
   printf("%s\n", _("package management systems based on the apt-get(8) command"));
   printf("%s\n", _("found in Debian GNU/Linux"));
@@ -414,52 +410,59 @@ print_help (void)
   printf ("\n\n");
 
   print_usage();
-  
+
   printf(_(UT_HELP_VRSN));
-  
+  printf(_(UT_EXTRA_OPTS));
+
   printf(_(UT_TIMEOUT), timeout_interval);
-  
-  printf(_("\n\
- -U, --upgrade=OPTS\n\
-   [Default] Perform an upgrade.  If an optional OPTS argument is provided,\n\
-   apt-get will be run with these command line options instead of the\n\
-   default (%s).\n\
-   Note that you may be required to have root privileges if you do not use\n\
-   the default options.\n\
- -d, --dist-upgrade=OPTS\n\
-   Perform a dist-upgrade instead of normal upgrade. Like with -U OPTS\n\
-   can be provided to override the default options.\n\
- -n, --no-upgrade\n\
-   Do not run the upgrade.  Probably not useful (without -u at least).\n\
- -i, --include=REGEXP\n\
-   Include only packages matching REGEXP.  Can be specified multiple times;\n\
-   the values will be combined together.  Any patches matching this list\n\
-   cause the plugin to return WARNING status.  Others will be ignored.\n\
-   Default is to include all packages.\n\
- -e, --exclude=REGEXP\n\
-   Exclude packages matching REGEXP from the list of packages that would\n\
-   otherwise be included.  Can be specified multiple times; the values\n\
-   will be combined together.  Default is to exclude no packages.\n\
- -c, --critical=REGEXP\n\
-   If the full package information of any of the upgradable packages match\n\
-   this REGEXP, the plugin will return CRITICAL status.  Can be specified\n\
-   multiple times like above.  Default is a regexp matching security\n\
-   upgrades for Debian and Ubuntu:\n\
-   \t%s\n\
-   Note that the package must first match the include list before its\n\
-   information is compared against the critical list.\n\
-   \n\n"),
-         UPGRADE_DEFAULT_OPTS, SECURITY_RE);
-         
+
+  printf (" %s\n", "-U, --upgrade=OPTS");
+  printf ("    %s\n", _("[Default] Perform an upgrade.  If an optional OPTS argument is provided,"));
+  printf ("    %s\n", _("apt-get will be run with these command line options instead of the"));
+  printf ("    %s", _("default "));
+  printf ("(%s).\n", UPGRADE_DEFAULT_OPTS);
+  printf ("    %s\n", _("Note that you may be required to have root privileges if you do not use"));
+  printf ("    %s\n", _("the default options."));
+  printf (" %s\n", "-d, --dist-upgrade=OPTS");
+  printf ("    %s\n", _("Perform a dist-upgrade instead of normal upgrade. Like with -U OPTS"));
+  printf ("    %s\n", _("can be provided to override the default options."));
+  printf (" %s\n", " -n, --no-upgrade");
+  printf ("    %s\n", _("Do not run the upgrade.  Probably not useful (without -u at least)."));
+  printf (" %s\n", "-i, --include=REGEXP");
+  printf ("    %s\n", _("Include only packages matching REGEXP.  Can be specified multiple times"));
+  printf ("    %s\n", _("the values will be combined together.  Any patches matching this list"));
+  printf ("    %s\n", _("cause the plugin to return WARNING status.  Others will be ignored."));
+  printf ("    %s\n", _("Default is to include all packages."));
+  printf (" %s\n", "-e, --exclude=REGEXP");
+  printf ("    %s\n", _("Exclude packages matching REGEXP from the list of packages that would"));
+  printf ("    %s\n", _("otherwise be included.  Can be specified multiple times; the values"));
+  printf ("    %s\n", _("will be combined together.  Default is to exclude no packages."));
+  printf (" %s\n", "-c, --critical=REGEXP");
+  printf ("    %s\n", _("If the full package information of any of the upgradable packages match"));
+  printf ("    %s\n", _("this REGEXP, the plugin will return CRITICAL status.  Can be specified"));
+  printf ("    %s\n", _("multiple times like above.  Default is a regexp matching security"));
+  printf ("    %s\n", _("upgrades for Debian and Ubuntu:"));
+  printf ("    \t\%s\n", SECURITY_RE);
+  printf ("    %s\n", _("Note that the package must first match the include list before its"));
+  printf ("    %s\n\n", _("information is compared against the critical list."));
+
   printf ("%s\n\n", _("The following options require root privileges and should be used with care:"));
   printf (" %s\n", "-u, --update=OPTS");
   printf ("    %s\n", _("First perform an 'apt-get update'.  An optional OPTS parameter overrides"));
   printf ("    %s\n", _("the default options.  Note: you may also need to adjust the global"));
   printf ("    %s\n", _("timeout (with -t) to prevent the plugin from timing out if apt-get"));
   printf ("    %s\n", _("upgrade is expected to take longer than the default timeout."));
+
+#ifdef NP_EXTRA_OPTS
+  printf("\n");
+  printf("%s\n", _("Notes:"));
+  printf(_(UT_EXTRA_OPTS_NOTES));
+#endif
+
+  printf(_(UT_SUPPORT));
 }
 
-  
+
 /* simple usage heading */
 void
 print_usage(void)