summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_dig.c57
1 files changed, 26 insertions, 31 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index ecd80a2b..c67da30a 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -32,6 +32,7 @@ const char *copyright = "2002-2003";
32const char *email = "nagiosplug-devel@lists.sourceforge.net"; 32const char *email = "nagiosplug-devel@lists.sourceforge.net";
33 33
34enum { 34enum {
35 UNDEFINED = 0,
35 DEFAULT_PORT = 53 36 DEFAULT_PORT = 53
36}; 37};
37 38
@@ -39,8 +40,8 @@ char *query_address = NULL;
39char *dns_server = NULL; 40char *dns_server = NULL;
40int verbose = FALSE; 41int verbose = FALSE;
41int server_port = DEFAULT_PORT; 42int server_port = DEFAULT_PORT;
42int warning_interval = -1; 43double warning_interval = UNDEFINED;
43int critical_interval = -1; 44double critical_interval = UNDEFINED;
44struct timeval tv; 45struct timeval tv;
45 46
46int 47int
@@ -140,31 +141,21 @@ main (int argc, char **argv)
140 if (output == NULL || strlen (output) == 0) 141 if (output == NULL || strlen (output) == 0)
141 asprintf (&output, _(" Probably a non-existent host/domain")); 142 asprintf (&output, _(" Probably a non-existent host/domain"));
142 143
143 if (critical_interval > 0 && elapsed_time > critical_interval) 144 if (critical_interval != UNDEFINED && elapsed_time > critical_interval)
144 printf (_("DNS OK - %.3f seconds response time (%s)"), elapsed_time, output); 145 result = STATE_CRITICAL;
145 146
146 else if (result == STATE_CRITICAL) 147 else if (warning_interval != UNDEFINED && elapsed_time > warning_interval)
147 printf (_("DNS CRITICAL - %s"), output); 148 result = STATE_WARNING;
148 149
149 else if (warning_interval > 0 && elapsed_time > warning_interval) 150 asprintf (&output, _("%.3f seconds response time (%s)"), elapsed_time, output);
150 printf (_("DNS OK - %.3f seconds response time (%s)"), elapsed_time, output);
151 151
152 else if (result == STATE_WARNING) 152 printf ("DNS %s - %s|%s\n",
153 printf (_("DNS WARNING - %s"), output); 153 state_text (result), output,
154
155 else if (result == STATE_OK)
156 printf (_("DNS OK - %.3f seconds response time (%s)"),
157 elapsed_time, output);
158
159 else
160 printf (_("DNS problem - %s"), output);
161
162 printf ("|%s\n",
163 perfdata("time", microsec, "us", 154 perfdata("time", microsec, "us",
164 (warning_interval>0?TRUE:FALSE), 155 (warning_interval!=UNDEFINED?TRUE:FALSE),
165 (int)1e6*warning_interval, 156 (int)(1e6*warning_interval),
166 (critical_interval>0?TRUE:FALSE), 157 (critical_interval!=UNDEFINED?TRUE:FALSE),
167 (int)1e6*critical_interval, 158 (int)(1e6*critical_interval),
168 TRUE, 0, FALSE, 0)); 159 TRUE, 0, FALSE, 0));
169 return result; 160 return result;
170} 161}
@@ -224,26 +215,30 @@ process_arguments (int argc, char **argv)
224 server_port = atoi (optarg); 215 server_port = atoi (optarg);
225 } 216 }
226 else { 217 else {
227 usage2 (_("Server port must be a nonnegative integer\n"), optarg); 218 usage2 (_("Server port must be a nonnegative integer"), optarg);
228 } 219 }
229 break; 220 break;
230 case 'l': /* address to lookup */ 221 case 'l': /* address to lookup */
231 query_address = optarg; 222 query_address = optarg;
232 break; 223 break;
233 case 'w': /* warning */ 224 case 'w': /* warning */
234 if (is_intnonneg (optarg)) { 225 if (is_nonnegative (optarg)) {
235 warning_interval = atoi (optarg); 226 warning_interval = strtod (optarg, NULL);
227 if (warning_interval == HUGE_VAL)
228 usage2 (_("Input causes overflow in warning interval"), optarg);
236 } 229 }
237 else { 230 else {
238 usage2 (_("Warning interval must be a nonnegative integer\n"), optarg); 231 usage2 (_("Warning interval must be a nonnegative integer"), optarg);
239 } 232 }
240 break; 233 break;
241 case 'c': /* critical */ 234 case 'c': /* critical */
242 if (is_intnonneg (optarg)) { 235 if (is_nonnegative (optarg)) {
243 critical_interval = atoi (optarg); 236 critical_interval = strtod (optarg, NULL);
237 if (critical_interval == HUGE_VAL)
238 usage2 (_("Input causes overflow in critical interval"), optarg);
244 } 239 }
245 else { 240 else {
246 usage2 (_("Critical interval must be a nonnegative integer\n"), optarg); 241 usage2 (_("Critical interval must be a nonnegative integer"), optarg);
247 } 242 }
248 break; 243 break;
249 case 't': /* timeout */ 244 case 't': /* timeout */
@@ -251,7 +246,7 @@ process_arguments (int argc, char **argv)
251 timeout_interval = atoi (optarg); 246 timeout_interval = atoi (optarg);
252 } 247 }
253 else { 248 else {
254 usage2 (_("Time interval must be a nonnegative integer\n"), optarg); 249 usage2 (_("Time interval must be a nonnegative integer"), optarg);
255 } 250 }
256 break; 251 break;
257 case 'v': /* verbose */ 252 case 'v': /* verbose */