diff options
author | Benoit Mortier <opensides@users.sourceforge.net> | 2005-11-14 00:51:44 +0000 |
---|---|---|
committer | Benoit Mortier <opensides@users.sourceforge.net> | 2005-11-14 00:51:44 +0000 |
commit | c68d99cee2d1b3de6a7e800440433a39a7436313 (patch) | |
tree | becb58a009fd3b7016d16a44139f13d6f7b511d7 /plugins/check_dig.c | |
parent | 7741c005fa10be018264f17e685d5bde34bc92a3 (diff) | |
download | monitoring-plugins-c68d99cee2d1b3de6a7e800440433a39a7436313.tar.gz |
start of the cleaning of the localization
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1282 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_dig.c')
-rw-r--r-- | plugins/check_dig.c | 481 |
1 files changed, 247 insertions, 234 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c index bc4dcd5c..c9fce613 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c | |||
@@ -26,7 +26,7 @@ | |||
26 | 26 | ||
27 | const char *progname = "check_dig"; | 27 | const char *progname = "check_dig"; |
28 | const char *revision = "$Revision$"; | 28 | const char *revision = "$Revision$"; |
29 | const char *copyright = "2002-2004"; | 29 | const char *copyright = "2002-2005"; |
30 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 30 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
31 | 31 | ||
32 | #include "common.h" | 32 | #include "common.h" |
@@ -55,113 +55,113 @@ struct timeval tv; | |||
55 | int | 55 | int |
56 | main (int argc, char **argv) | 56 | main (int argc, char **argv) |
57 | { | 57 | { |
58 | char *command_line; | 58 | char *command_line; |
59 | output chld_out, chld_err; | 59 | output chld_out, chld_err; |
60 | char *msg = NULL; | 60 | char *msg = NULL; |
61 | size_t i; | 61 | size_t i; |
62 | char *t; | 62 | char *t; |
63 | long microsec; | 63 | long microsec; |
64 | double elapsed_time; | 64 | double elapsed_time; |
65 | int result = STATE_UNKNOWN; | 65 | int result = STATE_UNKNOWN; |
66 | 66 | ||
67 | setlocale (LC_ALL, ""); | 67 | setlocale (LC_ALL, ""); |
68 | bindtextdomain (PACKAGE, LOCALEDIR); | 68 | bindtextdomain (PACKAGE, LOCALEDIR); |
69 | textdomain (PACKAGE); | 69 | textdomain (PACKAGE); |
70 | 70 | ||
71 | /* Set signal handling and alarm */ | 71 | /* Set signal handling and alarm */ |
72 | if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) | 72 | if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) |
73 | usage_va(_("Cannot catch SIGALRM")); | 73 | usage_va(_("Cannot catch SIGALRM")); |
74 | 74 | ||
75 | if (process_arguments (argc, argv) == ERROR) | 75 | if (process_arguments (argc, argv) == ERROR) |
76 | usage_va(_("Could not parse arguments")); | 76 | usage_va(_("Could not parse arguments")); |
77 | 77 | ||
78 | /* get the command to run */ | 78 | /* get the command to run */ |
79 | asprintf (&command_line, "%s @%s -p %d %s -t %s", | 79 | asprintf (&command_line, "%s @%s -p %d %s -t %s", |
80 | PATH_TO_DIG, dns_server, server_port, query_address, record_type); | 80 | PATH_TO_DIG, dns_server, server_port, query_address, record_type); |
81 | 81 | ||
82 | alarm (timeout_interval); | 82 | alarm (timeout_interval); |
83 | gettimeofday (&tv, NULL); | 83 | gettimeofday (&tv, NULL); |
84 | 84 | ||
85 | if (verbose) { | 85 | if (verbose) { |
86 | printf ("%s\n", command_line); | 86 | printf ("%s\n", command_line); |
87 | if(expected_address != NULL) { | 87 | if(expected_address != NULL) { |
88 | printf (_("Looking for: '%s'\n"), expected_address); | 88 | printf (_("Looking for: '%s'\n"), expected_address); |
89 | } else { | 89 | } else { |
90 | printf (_("Looking for: '%s'\n"), query_address); | 90 | printf (_("Looking for: '%s'\n"), query_address); |
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | /* run the command */ | 94 | /* run the command */ |
95 | if(np_runcmd(command_line, &chld_out, &chld_err, 0) != 0) { | 95 | if(np_runcmd(command_line, &chld_out, &chld_err, 0) != 0) { |
96 | result = STATE_WARNING; | 96 | result = STATE_WARNING; |
97 | msg = (char *)_("dig returned an error status"); | 97 | msg = (char *)_("dig returned an error status"); |
98 | } | 98 | } |
99 | 99 | ||
100 | for(i = 0; i < chld_out.lines; i++) { | 100 | for(i = 0; i < chld_out.lines; i++) { |
101 | /* the server is responding, we just got the host name... */ | 101 | /* the server is responding, we just got the host name... */ |
102 | if (strstr (chld_out.line[i], ";; ANSWER SECTION:")) { | 102 | if (strstr (chld_out.line[i], ";; ANSWER SECTION:")) { |
103 | 103 | ||
104 | /* loop through the whole 'ANSWER SECTION' */ | 104 | /* loop through the whole 'ANSWER SECTION' */ |
105 | for(; i < chld_out.lines; i++) { | 105 | for(; i < chld_out.lines; i++) { |
106 | /* get the host address */ | 106 | /* get the host address */ |
107 | if (verbose) | 107 | if (verbose) |
108 | printf ("%s\n", chld_out.line[i]); | 108 | printf ("%s\n", chld_out.line[i]); |
109 | 109 | ||
110 | if (strstr (chld_out.line[i], (expected_address == NULL ? query_address : expected_address)) != NULL) { | 110 | if (strstr (chld_out.line[i], (expected_address == NULL ? query_address : expected_address)) != NULL) { |
111 | msg = chld_out.line[i]; | 111 | msg = chld_out.line[i]; |
112 | result = STATE_OK; | 112 | result = STATE_OK; |
113 | 113 | ||
114 | /* Translate output TAB -> SPACE */ | 114 | /* Translate output TAB -> SPACE */ |
115 | t = msg; | 115 | t = msg; |
116 | while ((t = strchr(t, '\t')) != NULL) *t = ' '; | 116 | while ((t = strchr(t, '\t')) != NULL) *t = ' '; |
117 | break; | 117 | break; |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | if (result == STATE_UNKNOWN) { | 121 | if (result == STATE_UNKNOWN) { |
122 | msg = (char *)_("Server not found in ANSWER SECTION"); | 122 | msg = (char *)_("Server not found in ANSWER SECTION"); |
123 | result = STATE_WARNING; | 123 | result = STATE_WARNING; |
124 | } | 124 | } |
125 | 125 | ||
126 | /* we found the answer section, so break out of the loop */ | 126 | /* we found the answer section, so break out of the loop */ |
127 | break; | 127 | break; |
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
131 | if (result == STATE_UNKNOWN) | 131 | if (result == STATE_UNKNOWN) |
132 | msg = (char *)_("No ANSWER SECTION found"); | 132 | msg = (char *)_("No ANSWER SECTION found"); |
133 | 133 | ||
134 | /* If we get anything on STDERR, at least set warning */ | 134 | /* If we get anything on STDERR, at least set warning */ |
135 | if(chld_err.buflen > 0) { | 135 | if(chld_err.buflen > 0) { |
136 | result = max_state(result, STATE_WARNING); | 136 | result = max_state(result, STATE_WARNING); |
137 | if(!msg) for(i = 0; i < chld_err.lines; i++) { | 137 | if(!msg) for(i = 0; i < chld_err.lines; i++) { |
138 | msg = strchr(chld_err.line[0], ':'); | 138 | msg = strchr(chld_err.line[0], ':'); |
139 | if(msg) { | 139 | if(msg) { |
140 | msg++; | 140 | msg++; |
141 | break; | 141 | break; |
142 | } | 142 | } |
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | microsec = deltime (tv); | 146 | microsec = deltime (tv); |
147 | elapsed_time = (double)microsec / 1.0e6; | 147 | elapsed_time = (double)microsec / 1.0e6; |
148 | 148 | ||
149 | if (critical_interval > UNDEFINED && elapsed_time > critical_interval) | 149 | if (critical_interval > UNDEFINED && elapsed_time > critical_interval) |
150 | result = STATE_CRITICAL; | 150 | result = STATE_CRITICAL; |
151 | 151 | ||
152 | else if (warning_interval > UNDEFINED && elapsed_time > warning_interval) | 152 | else if (warning_interval > UNDEFINED && elapsed_time > warning_interval) |
153 | result = STATE_WARNING; | 153 | result = STATE_WARNING; |
154 | 154 | ||
155 | printf ("DNS %s - %.3f seconds response time (%s)|%s\n", | 155 | printf ("DNS %s - %.3f seconds response time (%s)|%s\n", |
156 | state_text (result), elapsed_time, | 156 | state_text (result), elapsed_time, |
157 | msg ? msg : _("Probably a non-existent host/domain"), | 157 | msg ? msg : _("Probably a non-existent host/domain"), |
158 | fperfdata("time", elapsed_time, "s", | 158 | fperfdata("time", elapsed_time, "s", |
159 | (warning_interval>UNDEFINED?TRUE:FALSE), | 159 | (warning_interval>UNDEFINED?TRUE:FALSE), |
160 | warning_interval, | 160 | warning_interval, |
161 | (critical_interval>UNDEFINED?TRUE:FALSE), | 161 | (critical_interval>UNDEFINED?TRUE:FALSE), |
162 | critical_interval, | 162 | critical_interval, |
163 | TRUE, 0, FALSE, 0)); | 163 | TRUE, 0, FALSE, 0)); |
164 | return result; | 164 | return result; |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
@@ -170,104 +170,104 @@ main (int argc, char **argv) | |||
170 | int | 170 | int |
171 | process_arguments (int argc, char **argv) | 171 | process_arguments (int argc, char **argv) |
172 | { | 172 | { |
173 | int c; | 173 | int c; |
174 | 174 | ||
175 | int option = 0; | 175 | int option = 0; |
176 | static struct option longopts[] = { | 176 | static struct option longopts[] = { |
177 | {"hostname", required_argument, 0, 'H'}, | 177 | {"hostname", required_argument, 0, 'H'}, |
178 | {"query_address", required_argument, 0, 'l'}, | 178 | {"query_address", required_argument, 0, 'l'}, |
179 | {"warning", required_argument, 0, 'w'}, | 179 | {"warning", required_argument, 0, 'w'}, |
180 | {"critical", required_argument, 0, 'c'}, | 180 | {"critical", required_argument, 0, 'c'}, |
181 | {"timeout", required_argument, 0, 't'}, | 181 | {"timeout", required_argument, 0, 't'}, |
182 | {"verbose", no_argument, 0, 'v'}, | 182 | {"verbose", no_argument, 0, 'v'}, |
183 | {"version", no_argument, 0, 'V'}, | 183 | {"version", no_argument, 0, 'V'}, |
184 | {"help", no_argument, 0, 'h'}, | 184 | {"help", no_argument, 0, 'h'}, |
185 | {"record_type", required_argument, 0, 'T'}, | 185 | {"record_type", required_argument, 0, 'T'}, |
186 | {"expected_address", required_argument, 0, 'a'}, | 186 | {"expected_address", required_argument, 0, 'a'}, |
187 | {0, 0, 0, 0} | 187 | {0, 0, 0, 0} |
188 | }; | 188 | }; |
189 | 189 | ||
190 | if (argc < 2) | 190 | if (argc < 2) |
191 | return ERROR; | 191 | return ERROR; |
192 | 192 | ||
193 | while (1) { | 193 | while (1) { |
194 | c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:a:", longopts, &option); | 194 | c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:a:", longopts, &option); |
195 | 195 | ||
196 | if (c == -1 || c == EOF) | 196 | if (c == -1 || c == EOF) |
197 | break; | 197 | break; |
198 | 198 | ||
199 | switch (c) { | 199 | switch (c) { |
200 | case 'h': /* help */ | 200 | case 'h': /* help */ |
201 | print_help (); | 201 | print_help (); |
202 | exit (STATE_OK); | 202 | exit (STATE_OK); |
203 | case 'V': /* version */ | 203 | case 'V': /* version */ |
204 | print_revision (progname, revision); | 204 | print_revision (progname, revision); |
205 | exit (STATE_OK); | 205 | exit (STATE_OK); |
206 | case 'H': /* hostname */ | 206 | case 'H': /* hostname */ |
207 | host_or_die(optarg); | 207 | host_or_die(optarg); |
208 | dns_server = optarg; | 208 | dns_server = optarg; |
209 | break; | 209 | break; |
210 | case 'p': /* server port */ | 210 | case 'p': /* server port */ |
211 | if (is_intpos (optarg)) { | 211 | if (is_intpos (optarg)) { |
212 | server_port = atoi (optarg); | 212 | server_port = atoi (optarg); |
213 | } | 213 | } |
214 | else { | 214 | else { |
215 | usage_va(_("Port must be a positive integer - %s"), optarg); | 215 | usage_va(_("Port must be a positive integer - %s"), optarg); |
216 | } | 216 | } |
217 | break; | 217 | break; |
218 | case 'l': /* address to lookup */ | 218 | case 'l': /* address to lookup */ |
219 | query_address = optarg; | 219 | query_address = optarg; |
220 | break; | 220 | break; |
221 | case 'w': /* warning */ | 221 | case 'w': /* warning */ |
222 | if (is_nonnegative (optarg)) { | 222 | if (is_nonnegative (optarg)) { |
223 | warning_interval = strtod (optarg, NULL); | 223 | warning_interval = strtod (optarg, NULL); |
224 | } | 224 | } |
225 | else { | 225 | else { |
226 | usage_va(_("Warning interval must be a positive integer - %s"), optarg); | 226 | usage_va(_("Warning interval must be a positive integer - %s"), optarg); |
227 | } | 227 | } |
228 | break; | 228 | break; |
229 | case 'c': /* critical */ | 229 | case 'c': /* critical */ |
230 | if (is_nonnegative (optarg)) { | 230 | if (is_nonnegative (optarg)) { |
231 | critical_interval = strtod (optarg, NULL); | 231 | critical_interval = strtod (optarg, NULL); |
232 | } | 232 | } |
233 | else { | 233 | else { |
234 | usage_va(_("Critical interval must be a positive integer - %s"), optarg); | 234 | usage_va(_("Critical interval must be a positive integer - %s"), optarg); |
235 | } | 235 | } |
236 | break; | 236 | break; |
237 | case 't': /* timeout */ | 237 | case 't': /* timeout */ |
238 | if (is_intnonneg (optarg)) { | 238 | if (is_intnonneg (optarg)) { |
239 | timeout_interval = atoi (optarg); | 239 | timeout_interval = atoi (optarg); |
240 | } | 240 | } |
241 | else { | 241 | else { |
242 | usage_va(_("Timeout interval must be a positive integer - %s"), optarg); | 242 | usage_va(_("Timeout interval must be a positive integer - %s"), optarg); |
243 | } | 243 | } |
244 | break; | 244 | break; |
245 | case 'v': /* verbose */ | 245 | case 'v': /* verbose */ |
246 | verbose = TRUE; | 246 | verbose = TRUE; |
247 | break; | 247 | break; |
248 | case 'T': | 248 | case 'T': |
249 | record_type = optarg; | 249 | record_type = optarg; |
250 | break; | 250 | break; |
251 | case 'a': | 251 | case 'a': |
252 | expected_address = optarg; | 252 | expected_address = optarg; |
253 | break; | 253 | break; |
254 | default: /* usage_va */ | 254 | default: /* usage_va */ |
255 | usage_va(_("Unknown argument - %s"), optarg); | 255 | usage_va(_("Unknown argument - %s"), optarg); |
256 | } | 256 | } |
257 | } | 257 | } |
258 | 258 | ||
259 | c = optind; | 259 | c = optind; |
260 | if (dns_server == NULL) { | 260 | if (dns_server == NULL) { |
261 | if (c < argc) { | 261 | if (c < argc) { |
262 | host_or_die(argv[c]); | 262 | host_or_die(argv[c]); |
263 | dns_server = argv[c]; | 263 | dns_server = argv[c]; |
264 | } | 264 | } |
265 | else { | 265 | else { |
266 | dns_server = strdup ("127.0.0.1"); | 266 | dns_server = strdup ("127.0.0.1"); |
267 | } | 267 | } |
268 | } | 268 | } |
269 | 269 | ||
270 | return validate_arguments (); | 270 | return validate_arguments (); |
271 | } | 271 | } |
272 | 272 | ||
273 | 273 | ||
@@ -275,7 +275,7 @@ process_arguments (int argc, char **argv) | |||
275 | int | 275 | int |
276 | validate_arguments (void) | 276 | validate_arguments (void) |
277 | { | 277 | { |
278 | return OK; | 278 | return OK; |
279 | } | 279 | } |
280 | 280 | ||
281 | 281 | ||
@@ -283,43 +283,56 @@ validate_arguments (void) | |||
283 | void | 283 | void |
284 | print_help (void) | 284 | print_help (void) |
285 | { | 285 | { |
286 | char *myport; | 286 | char *myport; |
287 | 287 | ||
288 | asprintf (&myport, "%d", DEFAULT_PORT); | 288 | asprintf (&myport, "%d", DEFAULT_PORT); |
289 | 289 | ||
290 | print_revision (progname, revision); | 290 | print_revision (progname, revision); |
291 | 291 | ||
292 | printf ("Copyright (c) 2000 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n"); | 292 | printf ("Copyright (c) 2000 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n"); |
293 | printf (COPYRIGHT, copyright, email); | 293 | printf (COPYRIGHT, copyright, email); |
294 | 294 | ||
295 | printf (_("Test the DNS service on the specified host using dig\n\n")); | 295 | printf (_("This plugin test the DNS service on the specified host using dig")); |
296 | 296 | ||
297 | print_usage (); | 297 | printf ("\n\n"); |
298 | 298 | ||
299 | printf (_(UT_HELP_VRSN)); | 299 | print_usage (); |
300 | 300 | ||
301 | printf (_(UT_HOST_PORT), 'P', myport); | 301 | printf (_(UT_HELP_VRSN)); |
302 | 302 | ||
303 | printf (_("\ | 303 | printf (_(UT_HOST_PORT), 'P', myport); |
304 | -l, --lookup=STRING\n\ | ||
305 | machine name to lookup\n")); | ||
306 | 304 | ||
307 | printf (_("\ | 305 | printf ("-l, --lookup=STRING"); |
308 | -T, --record_type=STRING\n\ | 306 | |
309 | record type to lookup (default: A)\n")); | 307 | printf ("\n"); |
310 | 308 | ||
311 | printf (_("\ | 309 | printf (_("machine name to lookup")); |
312 | -a, --expected_address=STRING\n\ | ||
313 | an address expected to be in the answer section.\n\ | ||
314 | if not set, uses whatever was in -l\n")); | ||
315 | 310 | ||
316 | printf (_(UT_WARN_CRIT)); | 311 | printf ("\n"); |
317 | 312 | ||
318 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | 313 | printf ("-T, --record_type=STRING"); |
319 | 314 | ||
320 | printf (_(UT_VERBOSE)); | 315 | printf ("\n"); |
321 | 316 | ||
322 | printf (_(UT_SUPPORT)); | 317 | printf (_("record type to lookup (default: A)")); |
318 | |||
319 | printf ("\n"); | ||
320 | |||
321 | printf ("-a, --expected_address=STRING"); | ||
322 | |||
323 | printf ("\n"); | ||
324 | |||
325 | printf (_("an address expected to be in the answer section.if not set, uses whatever was in -l")); | ||
326 | |||
327 | printf ("\n"); | ||
328 | |||
329 | printf (_(UT_WARN_CRIT)); | ||
330 | |||
331 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
332 | |||
333 | printf (_(UT_VERBOSE)); | ||
334 | |||
335 | printf (_(UT_SUPPORT)); | ||
323 | } | 336 | } |
324 | 337 | ||
325 | 338 | ||
@@ -327,8 +340,8 @@ print_help (void) | |||
327 | void | 340 | void |
328 | print_usage (void) | 341 | print_usage (void) |
329 | { | 342 | { |
330 | printf ("\ | 343 | printf (_("Usage:")); |
331 | Usage: %s -H host -l lookup [-p <server port>] [-T <query type>]\n\ | 344 | printf ("%s -H host -l lookup [-p <server port>] [-T <query type>]", progname); |
332 | [-w <warning interval>] [-c <critical interval>] [-t <timeout>]\n\ | 345 | printf (" [-w <warning interval>] [-c <critical interval>] [-t <timeout>]"); |
333 | [-a <expected answer address>] [-v]\n", progname); | 346 | printf (" [-a <expected answer address>] [-v]\n"); |
334 | } | 347 | } |