summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_nagios.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c
index 27bb010..d9d18d9 100644
--- a/plugins/check_nagios.c
+++ b/plugins/check_nagios.c
@@ -55,6 +55,9 @@ main (int argc, char **argv)
55 char procprog[MAX_INPUT_BUFFER]; 55 char procprog[MAX_INPUT_BUFFER];
56 char *procargs; 56 char *procargs;
57 int pos, cols; 57 int pos, cols;
58 int expected_cols = PS_COLS - 1;
59 const char *zombie = "Z";
60 char *temp_string;
58 61
59 setlocale (LC_ALL, ""); 62 setlocale (LC_ALL, "");
60 bindtextdomain (PACKAGE, LOCALEDIR); 63 bindtextdomain (PACKAGE, LOCALEDIR);
@@ -89,6 +92,9 @@ main (int argc, char **argv)
89 } 92 }
90 fclose (fp); 93 fclose (fp);
91 94
95 if (verbose >= 2)
96 printf("command: %s\n", PS_COMMAND);
97
92 /* run the command to check for the Nagios process.. */ 98 /* run the command to check for the Nagios process.. */
93 child_process = spopen (PS_COMMAND); 99 child_process = spopen (PS_COMMAND);
94 if (child_process == NULL) { 100 if (child_process == NULL) {
@@ -106,14 +112,31 @@ main (int argc, char **argv)
106 /* count the number of matching Nagios processes... */ 112 /* count the number of matching Nagios processes... */
107 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { 113 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
108 cols = sscanf (input_buffer, PS_FORMAT, PS_VARLIST); 114 cols = sscanf (input_buffer, PS_FORMAT, PS_VARLIST);
109 if ( cols >= 6 ) { 115 /* Zombie processes do not give a procprog command */
116 if ( cols == (expected_cols - 1) && strstr(procstat, zombie) ) {
117 cols = expected_cols;
118 /* Set some value for procargs for the strip command further below
119 Seen to be a problem on some Solaris 7 and 8 systems */
120 input_buffer[pos] = '\n';
121 input_buffer[pos+1] = 0x0;
122 }
123 if ( cols >= expected_cols ) {
110 asprintf (&procargs, "%s", input_buffer + pos); 124 asprintf (&procargs, "%s", input_buffer + pos);
111 strip (procargs); 125 strip (procargs);
112 126
113 if (!strstr(procargs, argv[0]) && strstr(procargs, process_string)) { 127 /* Some ps return full pathname for command. This removes path */
128 temp_string = strtok ((char *)procprog, "/");
129 while (temp_string) {
130 strcpy(procprog, temp_string);
131 temp_string = strtok (NULL, "/");
132 }
133
134 /* May get empty procargs */
135 if (!strstr(procargs, argv[0]) && strstr(procprog, process_string) && strcmp(procargs,"")) {
114 proc_entries++; 136 proc_entries++;
115 if (verbose) 137 if (verbose >= 2) {
116 printf (_("Found process: %s\n"), procargs); 138 printf (_("Found process: %s %s\n"), procprog, procargs);
139 }
117 } 140 }
118 } 141 }
119 } 142 }