diff options
Diffstat (limited to 'plugins/check_dig.c')
-rw-r--r-- | plugins/check_dig.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c index 2bbd1e05..abca6b24 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c | |||
@@ -80,14 +80,16 @@ int main(int argc, char **argv) { | |||
80 | textdomain(PACKAGE); | 80 | textdomain(PACKAGE); |
81 | 81 | ||
82 | /* Set signal handling and alarm */ | 82 | /* Set signal handling and alarm */ |
83 | if (signal(SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) | 83 | if (signal(SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { |
84 | usage_va(_("Cannot catch SIGALRM")); | 84 | usage_va(_("Cannot catch SIGALRM")); |
85 | } | ||
85 | 86 | ||
86 | /* Parse extra opts if any */ | 87 | /* Parse extra opts if any */ |
87 | argv = np_extra_opts(&argc, argv, progname); | 88 | argv = np_extra_opts(&argc, argv, progname); |
88 | 89 | ||
89 | if (process_arguments(argc, argv) == ERROR) | 90 | if (process_arguments(argc, argv) == ERROR) { |
90 | usage_va(_("Could not parse arguments")); | 91 | usage_va(_("Could not parse arguments")); |
92 | } | ||
91 | 93 | ||
92 | /* dig applies the timeout to each try, so we need to work around this */ | 94 | /* dig applies the timeout to each try, so we need to work around this */ |
93 | timeout_interval_dig = timeout_interval / number_tries + number_tries; | 95 | timeout_interval_dig = timeout_interval / number_tries + number_tries; |
@@ -121,8 +123,9 @@ int main(int argc, char **argv) { | |||
121 | /* loop through the whole 'ANSWER SECTION' */ | 123 | /* loop through the whole 'ANSWER SECTION' */ |
122 | for (; i < chld_out.lines; i++) { | 124 | for (; i < chld_out.lines; i++) { |
123 | /* get the host address */ | 125 | /* get the host address */ |
124 | if (verbose) | 126 | if (verbose) { |
125 | printf("%s\n", chld_out.line[i]); | 127 | printf("%s\n", chld_out.line[i]); |
128 | } | ||
126 | 129 | ||
127 | if (strcasestr(chld_out.line[i], (expected_address == NULL ? query_address : expected_address)) != NULL) { | 130 | if (strcasestr(chld_out.line[i], (expected_address == NULL ? query_address : expected_address)) != NULL) { |
128 | msg = chld_out.line[i]; | 131 | msg = chld_out.line[i]; |
@@ -130,8 +133,9 @@ int main(int argc, char **argv) { | |||
130 | 133 | ||
131 | /* Translate output TAB -> SPACE */ | 134 | /* Translate output TAB -> SPACE */ |
132 | t = msg; | 135 | t = msg; |
133 | while ((t = strchr(t, '\t')) != NULL) | 136 | while ((t = strchr(t, '\t')) != NULL) { |
134 | *t = ' '; | 137 | *t = ' '; |
138 | } | ||
135 | break; | 139 | break; |
136 | } | 140 | } |
137 | } | 141 | } |
@@ -154,7 +158,7 @@ int main(int argc, char **argv) { | |||
154 | /* If we get anything on STDERR, at least set warning */ | 158 | /* If we get anything on STDERR, at least set warning */ |
155 | if (chld_err.buflen > 0) { | 159 | if (chld_err.buflen > 0) { |
156 | result = max_state(result, STATE_WARNING); | 160 | result = max_state(result, STATE_WARNING); |
157 | if (!msg) | 161 | if (!msg) { |
158 | for (i = 0; i < chld_err.lines; i++) { | 162 | for (i = 0; i < chld_err.lines; i++) { |
159 | msg = strchr(chld_err.line[0], ':'); | 163 | msg = strchr(chld_err.line[0], ':'); |
160 | if (msg) { | 164 | if (msg) { |
@@ -162,16 +166,19 @@ int main(int argc, char **argv) { | |||
162 | break; | 166 | break; |
163 | } | 167 | } |
164 | } | 168 | } |
169 | } | ||
165 | } | 170 | } |
166 | 171 | ||
167 | microsec = deltime(tv); | 172 | microsec = deltime(tv); |
168 | elapsed_time = (double)microsec / 1.0e6; | 173 | elapsed_time = (double)microsec / 1.0e6; |
169 | 174 | ||
170 | if (critical_interval > UNDEFINED && elapsed_time > critical_interval) | 175 | if (critical_interval > UNDEFINED && elapsed_time > critical_interval) { |
171 | result = STATE_CRITICAL; | 176 | result = STATE_CRITICAL; |
177 | } | ||
172 | 178 | ||
173 | else if (warning_interval > UNDEFINED && elapsed_time > warning_interval) | 179 | else if (warning_interval > UNDEFINED && elapsed_time > warning_interval) { |
174 | result = STATE_WARNING; | 180 | result = STATE_WARNING; |
181 | } | ||
175 | 182 | ||
176 | printf("DNS %s - %.3f seconds response time (%s)|%s\n", state_text(result), elapsed_time, | 183 | printf("DNS %s - %.3f seconds response time (%s)|%s\n", state_text(result), elapsed_time, |
177 | msg ? msg : _("Probably a non-existent host/domain"), | 184 | msg ? msg : _("Probably a non-existent host/domain"), |
@@ -201,14 +208,16 @@ int process_arguments(int argc, char **argv) { | |||
201 | {"use-ipv6", no_argument, 0, '6'}, | 208 | {"use-ipv6", no_argument, 0, '6'}, |
202 | {0, 0, 0, 0}}; | 209 | {0, 0, 0, 0}}; |
203 | 210 | ||
204 | if (argc < 2) | 211 | if (argc < 2) { |
205 | return ERROR; | 212 | return ERROR; |
213 | } | ||
206 | 214 | ||
207 | while (1) { | 215 | while (1) { |
208 | c = getopt_long(argc, argv, "hVvt:l:H:w:c:T:p:a:A:46", longopts, &option); | 216 | c = getopt_long(argc, argv, "hVvt:l:H:w:c:T:p:a:A:46", longopts, &option); |
209 | 217 | ||
210 | if (c == -1 || c == EOF) | 218 | if (c == -1 || c == EOF) { |
211 | break; | 219 | break; |
220 | } | ||
212 | 221 | ||
213 | switch (c) { | 222 | switch (c) { |
214 | case 'h': /* help */ | 223 | case 'h': /* help */ |
@@ -281,10 +290,11 @@ int process_arguments(int argc, char **argv) { | |||
281 | host_or_die(argv[c]); | 290 | host_or_die(argv[c]); |
282 | dns_server = argv[c]; | 291 | dns_server = argv[c]; |
283 | } else { | 292 | } else { |
284 | if (strcmp(query_transport, "-6") == 0) | 293 | if (strcmp(query_transport, "-6") == 0) { |
285 | dns_server = strdup("::1"); | 294 | dns_server = strdup("::1"); |
286 | else | 295 | } else { |
287 | dns_server = strdup("127.0.0.1"); | 296 | dns_server = strdup("127.0.0.1"); |
297 | } | ||
288 | } | 298 | } |
289 | } | 299 | } |
290 | 300 | ||
@@ -292,8 +302,9 @@ int process_arguments(int argc, char **argv) { | |||
292 | } | 302 | } |
293 | 303 | ||
294 | int validate_arguments(void) { | 304 | int validate_arguments(void) { |
295 | if (query_address != NULL) | 305 | if (query_address != NULL) { |
296 | return OK; | 306 | return OK; |
307 | } | ||
297 | return ERROR; | 308 | return ERROR; |
298 | } | 309 | } |
299 | 310 | ||