summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_nagios.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c
index 649bec4..083b502 100644
--- a/plugins/check_nagios.c
+++ b/plugins/check_nagios.c
@@ -40,6 +40,8 @@ char *status_log = NULL;
40char *process_string = NULL; 40char *process_string = NULL;
41int expire_minutes = 0; 41int expire_minutes = 0;
42 42
43int verbose = 0;
44
43int 45int
44main (int argc, char **argv) 46main (int argc, char **argv)
45{ 47{
@@ -51,6 +53,12 @@ main (int argc, char **argv)
51 time_t current_time; 53 time_t current_time;
52 char *temp_ptr; 54 char *temp_ptr;
53 FILE *fp; 55 FILE *fp;
56 int procuid = 0;
57 int procppid = 0;
58 char procstat[8];
59 char procprog[MAX_INPUT_BUFFER];
60 char *procargs;
61 int pos, cols;
54 62
55 if (process_arguments (argc, argv) == ERROR) 63 if (process_arguments (argc, argv) == ERROR)
56 usage ("Could not parse arguments\n"); 64 usage ("Could not parse arguments\n");
@@ -82,21 +90,32 @@ main (int argc, char **argv)
82 fclose (fp); 90 fclose (fp);
83 91
84 /* run the command to check for the Nagios process.. */ 92 /* run the command to check for the Nagios process.. */
85 child_process = spopen (PS_RAW_COMMAND); 93 child_process = spopen (PS_COMMAND);
86 if (child_process == NULL) { 94 if (child_process == NULL) {
87 printf ("Could not open pipe: %s\n", PS_RAW_COMMAND); 95 printf ("Could not open pipe: %s\n", PS_COMMAND);
88 return STATE_UNKNOWN; 96 return STATE_UNKNOWN;
89 } 97 }
90 98
91 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); 99 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
92 if (child_stderr == NULL) { 100 if (child_stderr == NULL) {
93 printf ("Could not open stderr for %s\n", PS_RAW_COMMAND); 101 printf ("Could not open stderr for %s\n", PS_COMMAND);
94 } 102 }
95 103
104 fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
105
96 /* count the number of matching Nagios processes... */ 106 /* count the number of matching Nagios processes... */
97 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { 107 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
98 if (!strstr(input_buffer, argv[0]) && strstr(input_buffer, process_string)) 108 cols = sscanf (input_buffer, PS_FORMAT, PS_VARLIST);
99 proc_entries++; 109 if ( cols >= 4 ) {
110 asprintf (&procargs, "%s", input_buffer + pos);
111 strip (procargs);
112
113 if (!strstr(procargs, argv[0]) && strstr(procargs, process_string)) {
114 proc_entries++;
115 if (verbose)
116 printf ("Found process: %s\n", procargs);
117 }
118 }
100 } 119 }
101 120
102 /* If we get anything on stderr, at least set warning */ 121 /* If we get anything on stderr, at least set warning */
@@ -151,6 +170,7 @@ process_arguments (int argc, char **argv)
151 {"command", required_argument, 0, 'C'}, 170 {"command", required_argument, 0, 'C'},
152 {"version", no_argument, 0, 'V'}, 171 {"version", no_argument, 0, 'V'},
153 {"help", no_argument, 0, 'h'}, 172 {"help", no_argument, 0, 'h'},
173 {"verbose", no_argument, 0, 'v'},
154 {0, 0, 0, 0} 174 {0, 0, 0, 0}
155 }; 175 };
156 176
@@ -170,7 +190,7 @@ process_arguments (int argc, char **argv)
170 } 190 }
171 191
172 while (1) { 192 while (1) {
173 c = getopt_long (argc, argv, "+hVF:C:e:", long_options, &option_index); 193 c = getopt_long (argc, argv, "+hVvF:C:e:", long_options, &option_index);
174 194
175 if (c == -1 || c == EOF || c == 1) 195 if (c == -1 || c == EOF || c == 1)
176 break; 196 break;
@@ -186,13 +206,13 @@ process_arguments (int argc, char **argv)
186 case 'V': /* version */ 206 case 'V': /* version */
187 print_revision (progname, "$Revision$"); 207 print_revision (progname, "$Revision$");
188 exit (STATE_OK); 208 exit (STATE_OK);
189 case 'F': /* hostname */ 209 case 'F': /* status log */
190 status_log = optarg; 210 status_log = optarg;
191 break; 211 break;
192 case 'C': /* hostname */ 212 case 'C': /* command */
193 process_string = optarg; 213 process_string = optarg;
194 break; 214 break;
195 case 'e': /* hostname */ 215 case 'e': /* expiry time */
196 if (is_intnonneg (optarg)) 216 if (is_intnonneg (optarg))
197 expire_minutes = atoi (optarg); 217 expire_minutes = atoi (optarg);
198 else 218 else
@@ -200,6 +220,9 @@ process_arguments (int argc, char **argv)
200 "Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n", 220 "Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n",
201 progname); 221 progname);
202 break; 222 break;
223 case 'v':
224 verbose++;
225 break;
203 } 226 }
204 } 227 }
205 228