Code

check_tcp code cleanup from andreas plus fix to andreas' patch from sean
[nagiosplug.git] / plugins / check_nagios.c
index 694c069c5cfdd895835a74ac9d435f1665c14c00..089ff669702a96bb0d0a2b297f3ba7a9e9fb3a2b 100644 (file)
@@ -49,6 +49,7 @@ main (int argc, char **argv)
        char *temp_ptr;
        FILE *fp;
        int procuid = 0;
+       int procpid = 0;
        int procppid = 0;
        int procvsz = 0;
        int procrss = 0;
@@ -66,7 +67,7 @@ main (int argc, char **argv)
        bindtextdomain (PACKAGE, LOCALEDIR);
        textdomain (PACKAGE);
 
-       if (process_arguments (argc, argv) != TRUE)
+       if (process_arguments (argc, argv) == ERROR)
                usage4 (_("Could not parse arguments"));
 
        /* Set signal handling and alarm timeout */
@@ -95,7 +96,7 @@ main (int argc, char **argv)
        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);
@@ -134,7 +135,7 @@ main (int argc, char **argv)
                         }
 
                        /* 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);
@@ -206,8 +207,7 @@ process_arguments (int argc, char **argv)
                        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;
        }
@@ -220,9 +220,7 @@ process_arguments (int argc, char **argv)
 
                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);
@@ -240,8 +238,7 @@ process_arguments (int argc, char **argv)
                                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++;
@@ -252,12 +249,10 @@ process_arguments (int argc, char **argv)
 
        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,
-                                                        _("You must provide a process string\nType '%s -h' for additional help\n"),
-                                                        progname);
+                                                        _("You must provide a process string\n"));
 
        return OK;
 }
@@ -272,29 +267,26 @@ print_help (void)
        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\
-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 (_("\
--F, --filename=FILE\n\
+ -F, --filename=FILE\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\
-   ./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"));
 }
 
 
@@ -303,8 +295,5 @@ void
 print_usage (void)
 {
        printf ("\
-Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n",
-               progname);
-                                       
-       printf (UT_HLP_VRS, progname, progname);
+Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n", progname);
 }