Code

starttls support for check_smtp #1041576
[nagiosplug.git] / plugins / check_nagios.c
index d9d18d9b5182c2c9e7c5be7ab8c1ec23433382de..0176983c5866f900a20587416cfe3aa9b4bab70e 100644 (file)
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+ $Id$
 ******************************************************************************/
 
 const char *progname = "check_nagios";
 const char *revision = "$Revision$";
 ******************************************************************************/
 
 const char *progname = "check_nagios";
 const char *revision = "$Revision$";
-const char *copyright = "1999-2003";
+const char *copyright = "1999-2004";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
@@ -52,6 +54,7 @@ main (int argc, char **argv)
        int procrss = 0;
        float procpcpu = 0;
        char procstat[8];
        int procrss = 0;
        float procpcpu = 0;
        char procstat[8];
+       char procetime[MAX_INPUT_BUFFER];
        char procprog[MAX_INPUT_BUFFER];
        char *procargs;
        int pos, cols;
        char procprog[MAX_INPUT_BUFFER];
        char *procargs;
        int pos, cols;
@@ -64,12 +67,11 @@ main (int argc, char **argv)
        textdomain (PACKAGE);
 
        if (process_arguments (argc, argv) == ERROR)
        textdomain (PACKAGE);
 
        if (process_arguments (argc, argv) == ERROR)
-               usage (_("Could not parse arguments\n"));
+               usage4 (_("Could not parse arguments"));
 
 
-       /* Set signal handling and alarm */
+       /* Set signal handling and alarm timeout */
        if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) {
        if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) {
-               printf (_("Cannot catch SIGALRM"));
-               return STATE_UNKNOWN;
+               usage4 (_("Cannot catch SIGALRM"));
        }
 
        /* handle timeouts gracefully... */
        }
 
        /* handle timeouts gracefully... */
@@ -78,7 +80,7 @@ main (int argc, char **argv)
        /* open the status log */
        fp = fopen (status_log, "r");
        if (fp == NULL) {
        /* open the status log */
        fp = fopen (status_log, "r");
        if (fp == NULL) {
-               printf (_("Error: Cannot open status log for reading!\n"));
+               printf (_("CRITICAL - Cannot open status log for reading!\n"));
                return STATE_CRITICAL;
        }
 
                return STATE_CRITICAL;
        }
 
@@ -93,7 +95,7 @@ main (int argc, char **argv)
        fclose (fp);
 
        if (verbose >= 2)
        fclose (fp);
 
        if (verbose >= 2)
-               printf("command: %s\n", PS_COMMAND);
+               printf(_("command: %s\n"), PS_COMMAND);
 
        /* run the command to check for the Nagios process.. */
        child_process = spopen (PS_COMMAND);
 
        /* run the command to check for the Nagios process.. */
        child_process = spopen (PS_COMMAND);
@@ -132,7 +134,7 @@ main (int argc, char **argv)
                         }
 
                        /* May get empty procargs */
                         }
 
                        /* May get empty procargs */
-                       if (!strstr(procargs, argv[0]) && strstr(procprog, process_string) && strcmp(procargs,"")) {
+                       if (!strstr(procargs, argv[0]) && strstr(procargs, process_string) && strcmp(procargs,"")) {
                                proc_entries++;
                                if (verbose >= 2) {
                                        printf (_("Found process: %s %s\n"), procprog, procargs);
                                proc_entries++;
                                if (verbose >= 2) {
                                        printf (_("Found process: %s %s\n"), procprog, procargs);
@@ -178,8 +180,6 @@ main (int argc, char **argv)
 
 
 
 
 
 
-
-
 /* process command-line arguments */
 int
 process_arguments (int argc, char **argv)
 /* process command-line arguments */
 int
 process_arguments (int argc, char **argv)
@@ -206,8 +206,7 @@ process_arguments (int argc, char **argv)
                        expire_minutes = atoi (argv[2]);
                else
                        die (STATE_UNKNOWN,
                        expire_minutes = atoi (argv[2]);
                else
                        die (STATE_UNKNOWN,
-                                                                _("Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n"),
-                                                                progname);
+                                                                _("Expiration time must be an integer (seconds)\n"));
                process_string = argv[3];
                return OK;
        }
                process_string = argv[3];
                return OK;
        }
@@ -220,14 +219,12 @@ process_arguments (int argc, char **argv)
 
                switch (c) {
                case '?':                                                                       /* print short usage statement if args not parsable */
 
                switch (c) {
                case '?':                                                                       /* print short usage statement if args not parsable */
-                       printf (_("%s: Unknown argument: %c\n\n"), progname, optopt);
-                       print_usage ();
-                       exit (STATE_UNKNOWN);
+                       usage2 (_("Unknown argument"), optarg);
                case 'h':                                                                       /* help */
                        print_help ();
                        exit (STATE_OK);
                case 'V':                                                                       /* version */
                case 'h':                                                                       /* help */
                        print_help ();
                        exit (STATE_OK);
                case 'V':                                                                       /* version */
-                       print_revision (progname, "$Revision$");
+                       print_revision (progname, revision);
                        exit (STATE_OK);
                case 'F':                                                                       /* status log */
                        status_log = optarg;
                        exit (STATE_OK);
                case 'F':                                                                       /* status log */
                        status_log = optarg;
@@ -240,8 +237,7 @@ process_arguments (int argc, char **argv)
                                expire_minutes = atoi (optarg);
                        else
                                die (STATE_UNKNOWN,
                                expire_minutes = atoi (optarg);
                        else
                                die (STATE_UNKNOWN,
-                                    _("Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n"),
-                                    progname);
+                                    _("Expiration time must be an integer (seconds)\n"));
                        break;
                case 'v':
                        verbose++;
                        break;
                case 'v':
                        verbose++;
@@ -252,21 +248,16 @@ process_arguments (int argc, char **argv)
 
        if (status_log == NULL)
                die (STATE_UNKNOWN,
 
        if (status_log == NULL)
                die (STATE_UNKNOWN,
-                    _("You must provide the status_log\nType '%s -h' for additional help\n"),
-                    progname);
+                    _("You must provide the status_log\n"));
        else if (process_string == NULL)
                die (STATE_UNKNOWN,
        else if (process_string == NULL)
                die (STATE_UNKNOWN,
-                                                        _("You must provide a process string\nType '%s -h' for additional help\n"),
-                                                        progname);
+                                                        _("You must provide a process string\n"));
 
        return OK;
 }
 
 
 
 
        return OK;
 }
 
 
 
-
-
-\f
 void
 print_help (void)
 {
 void
 print_help (void)
 {
@@ -275,38 +266,33 @@ print_help (void)
        printf (_(COPYRIGHT), copyright, email);
 
        printf (_("\
        printf (_(COPYRIGHT), copyright, email);
 
        printf (_("\
-This plugin attempts to check the status of the Nagios process on the local\n\
+This plugin checks the status of the Nagios process on the local\n\
 machine. The plugin will check to make sure the Nagios status log is no older\n\
 machine. The plugin will check to make sure the Nagios status log is no older\n\
-than the number of minutes specified by the <expire_minutes> option.  It also\n\
-uses the /bin/ps command to check for a process matching whatever you specify\n\
-by the <process_string> argument.\n"));
+than the number of minutes specified by the expires option. It also\n\
+checks the process table for a process matching the command argument.\n\n"));
 
        print_usage ();
 
        printf (_(UT_HELP_VRSN));
 
        printf (_("\
 
        print_usage ();
 
        printf (_(UT_HELP_VRSN));
 
        printf (_("\
--F, --filename=FILE\n\
+ -F, --filename=FILE\n\
    Name of the log file to check\n\
    Name of the log file to check\n\
--e, --expires=INTEGER\n\
-   Seconds aging afterwhich logfile is condsidered stale\n\
--C, --command=STRING\n\
-   Command to search for in process table\n"));
+ -e, --expires=INTEGER\n\
+   Minutes aging after which logfile is considered stale\n\
+ -C, --command=STRING\n\
+   Substring to search for in process arguments\n"));
 
        printf (_("\
 Example:\n\
 
        printf (_("\
 Example:\n\
-   ./check_nagios -e 5 \\\
-   -F /usr/local/nagios/var/status.log \\\
-   -C /usr/local/nagios/bin/nagios\n"));
+   ./check_nagios -e 5 -F /usr/local/nagios/var/status.log -C /usr/local/nagios/bin/nagios\n"));
 }
 
 
 
 }
 
 
 
-
 void
 print_usage (void)
 {
 void
 print_usage (void)
 {
-       printf (_("\
-Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n"),
-               progname);
+       printf ("\
+Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n", progname);
 }
 }