diff options
Diffstat (limited to 'plugins/negate.c')
-rw-r--r-- | plugins/negate.c | 188 |
1 files changed, 91 insertions, 97 deletions
diff --git a/plugins/negate.c b/plugins/negate.c index 3ef5ee7..c24658a 100644 --- a/plugins/negate.c +++ b/plugins/negate.c | |||
@@ -14,84 +14,12 @@ | |||
14 | along with this program; if not, write to the Free Software | 14 | along with this program; if not, write to the Free Software |
15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | 16 | ||
17 | ******************************************************************************/ | ||
18 | |||
19 | const char *progname = "negate"; | ||
20 | const char *revision = "$Revision$"; | ||
21 | const char *copyright = "2002-2003"; | ||
22 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | ||
23 | |||
24 | #define DEFAULT_TIMEOUT 9 | ||
25 | |||
26 | #include "common.h" | ||
27 | #include "utils.h" | ||
28 | #include "popen.h" | ||
29 | |||
30 | void | ||
31 | print_usage (void) | ||
32 | { | ||
33 | printf (_("Usage: %s [-t timeout] <definition of wrapped plugin>\n"), | ||
34 | progname); | ||
35 | printf (_(UT_HLP_VRS), progname, progname); | ||
36 | } | ||
37 | |||
38 | void | ||
39 | print_help (void) | ||
40 | { | ||
41 | print_revision (progname, revision); | ||
42 | |||
43 | printf (_(COPYRIGHT), copyright, email); | ||
44 | |||
45 | printf (_("\ | ||
46 | Negates the status of a plugin (returns OK for CRITICAL, and vice-versa).\n\ | ||
47 | \n")); | ||
48 | |||
49 | print_usage (); | ||
50 | |||
51 | printf (_(UT_HELP_VRSN)); | ||
52 | |||
53 | printf (_(UT_TIMEOUT), DEFAULT_TIMEOUT); | ||
54 | |||
55 | printf (_("\ | ||
56 | [keep timeout than the plugin timeout to retain CRITICAL status]\n")); | ||
57 | |||
58 | printf (_("\ | ||
59 | negate \"/usr/local/nagios/libexec/check_ping -H host\"\n\ | ||
60 | Run check_ping and invert result. Must use full path to plugin\n\ | ||
61 | negate \"/usr/local/nagios/libexec/check_procs -a 'vi negate.c'\"\n\ | ||
62 | Use single quotes if you need to retain spaces\n")); | ||
63 | |||
64 | printf (_("\ | ||
65 | This plugin is a wrapper to take the output of another plugin and invert it.\n\ | ||
66 | If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL.\n\ | ||
67 | If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK.\n\ | ||
68 | Otherwise, the output state of the wrapped plugin is unchanged.\n")); | ||
69 | |||
70 | printf (_(UT_SUPPORT)); | ||
71 | } | ||
72 | |||
73 | char *command_line; | ||
74 | |||
75 | int process_arguments (int, char **); | ||
76 | int validate_arguments (void); | ||
77 | /****************************************************************************** | ||
78 | |||
79 | The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ | ||
80 | tags in the comments. With in the tags, the XML is assembled sequentially. | ||
81 | You can define entities in tags. You also have all the #defines available as | ||
82 | entities. | ||
83 | |||
84 | Please note that all tags must be lowercase to use the DocBook XML DTD. | ||
85 | |||
86 | @@-<article> | 17 | @@-<article> |
87 | 18 | ||
88 | <sect1> | 19 | <sect1> |
89 | <title>Quick Reference</title> | 20 | <title>Quick Reference</title> |
90 | <!-- The refentry forms a manpage --> | ||
91 | <refentry> | 21 | <refentry> |
92 | <refmeta> | 22 | <refmeta><manvolnum>5<manvolnum></refmeta> |
93 | <manvolnum>5<manvolnum> | ||
94 | </refmeta> | ||
95 | <refnamdiv> | 23 | <refnamdiv> |
96 | <refname>&progname;</refname> | 24 | <refname>&progname;</refname> |
97 | <refpurpose>&SUMMARY;</refpurpose> | 25 | <refpurpose>&SUMMARY;</refpurpose> |
@@ -119,19 +47,33 @@ Please note that all tags must be lowercase to use the DocBook XML DTD. | |||
119 | <itemizedlist> | 47 | <itemizedlist> |
120 | <listitem>Add option to do regex substitution in output text</listitem> | 48 | <listitem>Add option to do regex substitution in output text</listitem> |
121 | </itemizedlist> | 49 | </itemizedlist> |
122 | </sect2> | 50 | </sect2>-@@ |
123 | |||
124 | 51 | ||
125 | <sect2> | ||
126 | <title>Functions</title> | ||
127 | -@@ | ||
128 | ******************************************************************************/ | 52 | ******************************************************************************/ |
129 | 53 | ||
54 | const char *progname = "negate"; | ||
55 | const char *revision = "$Revision$"; | ||
56 | const char *copyright = "2002-2003"; | ||
57 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | ||
58 | |||
59 | #define DEFAULT_TIMEOUT 9 | ||
60 | |||
61 | #include "common.h" | ||
62 | #include "utils.h" | ||
63 | #include "popen.h" | ||
64 | |||
65 | char *command_line; | ||
66 | |||
67 | int process_arguments (int, char **); | ||
68 | int validate_arguments (void); | ||
69 | void print_help (void); | ||
70 | void print_usage (void); | ||
71 | |||
130 | int | 72 | int |
131 | main (int argc, char **argv) | 73 | main (int argc, char **argv) |
132 | { | 74 | { |
133 | int found = 0, result = STATE_UNKNOWN; | 75 | int found = 0, result = STATE_UNKNOWN; |
134 | char input_buffer[MAX_INPUT_BUFFER]; | 76 | char *buf; |
135 | 77 | ||
136 | if (process_arguments (argc, argv) == ERROR) | 78 | if (process_arguments (argc, argv) == ERROR) |
137 | usage (_("Could not parse arguments\n")); | 79 | usage (_("Could not parse arguments\n")); |
@@ -151,27 +93,22 @@ main (int argc, char **argv) | |||
151 | printf (_("Could not open stderr for %s\n"), command_line); | 93 | printf (_("Could not open stderr for %s\n"), command_line); |
152 | } | 94 | } |
153 | 95 | ||
154 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 96 | buf = malloc(MAX_INPUT_BUFFER); |
97 | while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) { | ||
155 | found++; | 98 | found++; |
156 | if (strchr (input_buffer, '\n')) { | 99 | printf ("%s", buf); |
157 | input_buffer[strcspn (input_buffer, "\n")] = 0; | ||
158 | printf ("%s\n", input_buffer); | ||
159 | } | ||
160 | else { | ||
161 | printf ("%s\n", input_buffer); | ||
162 | } | ||
163 | } | 100 | } |
164 | 101 | ||
165 | if (!found) | 102 | if (!found) |
166 | die (STATE_UNKNOWN,\ | 103 | die (STATE_UNKNOWN, |
167 | _("%s problem - No data recieved from host\nCMD: %s\n"),\ | 104 | _("%s problem - No data recieved from host\nCMD: %s\n"),\ |
168 | argv[0], command_line); | 105 | argv[0], command_line); |
169 | 106 | ||
170 | /* close the pipe */ | 107 | /* close the pipe */ |
171 | result = spclose (child_process); | 108 | result = spclose (child_process); |
172 | 109 | ||
173 | /* WARNING if output found on stderr */ | 110 | /* WARNING if output found on stderr */ |
174 | if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) | 111 | if (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr)) |
175 | result = max_state (result, STATE_WARNING); | 112 | result = max_state (result, STATE_WARNING); |
176 | 113 | ||
177 | /* close stderr */ | 114 | /* close stderr */ |
@@ -189,6 +126,9 @@ main (int argc, char **argv) | |||
189 | 126 | ||
190 | /****************************************************************************** | 127 | /****************************************************************************** |
191 | @@- | 128 | @@- |
129 | <sect2> | ||
130 | <title>Functions</title> | ||
131 | |||
192 | <sect3> | 132 | <sect3> |
193 | <title>process_arguments</title> | 133 | <title>process_arguments</title> |
194 | 134 | ||
@@ -196,7 +136,7 @@ main (int argc, char **argv) | |||
196 | variables.</para> | 136 | variables.</para> |
197 | 137 | ||
198 | <para>Aside from the standard 'help' and 'version' options, there | 138 | <para>Aside from the standard 'help' and 'version' options, there |
199 | is a only a 'timeout' option.No validation is currently done.</para> | 139 | is a only a 'timeout' option.</para> |
200 | 140 | ||
201 | </sect3> | 141 | </sect3> |
202 | -@@ | 142 | -@@ |
@@ -208,8 +148,8 @@ process_arguments (int argc, char **argv) | |||
208 | { | 148 | { |
209 | int c; | 149 | int c; |
210 | 150 | ||
211 | int option_index = 0; | 151 | int option = 0; |
212 | static struct option long_options[] = { | 152 | static struct option longopts[] = { |
213 | {"help", no_argument, 0, 'h'}, | 153 | {"help", no_argument, 0, 'h'}, |
214 | {"version", no_argument, 0, 'V'}, | 154 | {"version", no_argument, 0, 'V'}, |
215 | {"timeout", required_argument, 0, 't'}, | 155 | {"timeout", required_argument, 0, 't'}, |
@@ -218,7 +158,7 @@ process_arguments (int argc, char **argv) | |||
218 | 158 | ||
219 | while (1) { | 159 | while (1) { |
220 | c = getopt_long (argc, argv, "+hVt:", | 160 | c = getopt_long (argc, argv, "+hVt:", |
221 | long_options, &option_index); | 161 | longopts, &option); |
222 | 162 | ||
223 | if (c == -1 || c == EOF) | 163 | if (c == -1 || c == EOF) |
224 | break; | 164 | break; |
@@ -226,16 +166,19 @@ process_arguments (int argc, char **argv) | |||
226 | switch (c) { | 166 | switch (c) { |
227 | case '?': /* help */ | 167 | case '?': /* help */ |
228 | usage3 (_("Unknown argument"), optopt); | 168 | usage3 (_("Unknown argument"), optopt); |
169 | break; | ||
229 | case 'h': /* help */ | 170 | case 'h': /* help */ |
230 | print_help (); | 171 | print_help (); |
231 | exit (EXIT_SUCCESS); | 172 | exit (EXIT_SUCCESS); |
173 | break; | ||
232 | case 'V': /* version */ | 174 | case 'V': /* version */ |
233 | print_revision (progname, revision); | 175 | print_revision (progname, revision); |
234 | exit (EXIT_SUCCESS); | 176 | exit (EXIT_SUCCESS); |
235 | case 't': /* timeout period */ | 177 | case 't': /* timeout period */ |
236 | if (!is_integer (optarg)) | 178 | if (!is_integer (optarg)) |
237 | usage2 (_("Timeout Interval must be an integer"), optarg); | 179 | usage2 (_("Timeout Interval must be an integer"), optarg); |
238 | timeout_interval = atoi (optarg); | 180 | else |
181 | timeout_interval = atoi (optarg); | ||
239 | break; | 182 | break; |
240 | } | 183 | } |
241 | } | 184 | } |
@@ -267,7 +210,6 @@ validate_arguments () | |||
267 | return ERROR; | 210 | return ERROR; |
268 | return STATE_OK; | 211 | return STATE_OK; |
269 | } | 212 | } |
270 | |||
271 | 213 | ||
272 | /****************************************************************************** | 214 | /****************************************************************************** |
273 | @@- | 215 | @@- |
@@ -276,3 +218,55 @@ validate_arguments () | |||
276 | </article> | 218 | </article> |
277 | -@@ | 219 | -@@ |
278 | ******************************************************************************/ | 220 | ******************************************************************************/ |
221 | |||
222 | |||
223 | |||
224 | |||
225 | |||
226 | |||
227 | void | ||
228 | print_help (void) | ||
229 | { | ||
230 | print_revision (progname, revision); | ||
231 | |||
232 | printf (_(COPYRIGHT), copyright, email); | ||
233 | |||
234 | printf (_("\ | ||
235 | Negates the status of a plugin (returns OK for CRITICAL, and vice-versa).\n\ | ||
236 | \n")); | ||
237 | |||
238 | print_usage (); | ||
239 | |||
240 | printf (_(UT_HELP_VRSN)); | ||
241 | |||
242 | printf (_(UT_TIMEOUT), DEFAULT_TIMEOUT); | ||
243 | |||
244 | printf (_("\ | ||
245 | [keep timeout than the plugin timeout to retain CRITICAL status]\n")); | ||
246 | |||
247 | printf (_("\ | ||
248 | negate \"/usr/local/nagios/libexec/check_ping -H host\"\n\ | ||
249 | Run check_ping and invert result. Must use full path to plugin\n\ | ||
250 | negate \"/usr/local/nagios/libexec/check_procs -a 'vi negate.c'\"\n\ | ||
251 | Use single quotes if you need to retain spaces\n")); | ||
252 | |||
253 | printf (_("\ | ||
254 | This plugin is a wrapper to take the output of another plugin and invert it.\n\ | ||
255 | If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL.\n\ | ||
256 | If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK.\n\ | ||
257 | Otherwise, the output state of the wrapped plugin is unchanged.\n")); | ||
258 | |||
259 | printf (_(UT_SUPPORT)); | ||
260 | } | ||
261 | |||
262 | |||
263 | |||
264 | |||
265 | |||
266 | void | ||
267 | print_usage (void) | ||
268 | { | ||
269 | printf (_("Usage: %s [-t timeout] <definition of wrapped plugin>\n"), | ||
270 | progname); | ||
271 | printf (_(UT_HLP_VRS), progname, progname); | ||
272 | } | ||