aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_dns.c
diff options
context:
space:
mode:
authorGravatar Sven Nierlein <sven@nierlein.org> 2019-02-15 09:00:45 +0100
committerGravatar GitHub <noreply@github.com> 2019-02-15 09:00:45 +0100
commit8f1d3de0b7ee8385a450019f63f91a7149899aa0 (patch)
treecd32d9edd778970ff560d4d8301c74d7b0f95b57 /plugins/check_dns.c
parent49a0583bffe03617ad91c17dc7a6465a10c8ccdd (diff)
parentfd9a7d2e00b2acf66ec9aa48d7f51daa817f3457 (diff)
downloadmonitoring-plugins-8f1d3de0b7ee8385a450019f63f91a7149899aa0.tar.gz
Merge pull request #1545 from DerDakon/dns_order
check_dns: improve support for checking multiple addresses
Diffstat (limited to 'plugins/check_dns.c')
-rw-r--r--plugins/check_dns.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index f2061636..25bd31dc 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -56,6 +56,7 @@ char **expected_address = NULL;
int expected_address_cnt = 0;
int expect_authority = FALSE;
+int all_match = FALSE;
thresholds *time_thresholds = NULL;
static int
@@ -168,8 +169,8 @@ main (int argc, char **argv)
temp_buffer++;
/* Strip leading spaces */
- for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++)
- /* NOOP */;
+ while (*temp_buffer == ' ')
+ temp_buffer++;
strip(temp_buffer);
if (temp_buffer==NULL || strlen(temp_buffer)==0) {
@@ -228,16 +229,27 @@ main (int argc, char **argv)
if (result == STATE_OK && expected_address_cnt > 0) {
result = STATE_CRITICAL;
temp_buffer = "";
+ unsigned long expect_match = (1 << expected_address_cnt) - 1;
+ unsigned long addr_match = (1 << n_addresses) - 1;
for (i=0; i<expected_address_cnt; i++) {
+ int j;
/* check if we get a match on 'raw' ip or cidr */
- if ( strcmp(address, expected_address[i]) == 0
- || ip_match_cidr(address, expected_address[i]) )
- result = STATE_OK;
+ for (j=0; j<n_addresses; j++) {
+ if ( strcmp(addresses[j], expected_address[i]) == 0
+ || ip_match_cidr(addresses[j], expected_address[i]) ) {
+ result = STATE_OK;
+ addr_match &= ~(1 << j);
+ expect_match &= ~(1 << i);
+ }
+ }
/* prepare an error string */
xasprintf(&temp_buffer, "%s%s; ", temp_buffer, expected_address[i]);
}
+ /* check if expected_address must cover all in addresses and none may be missing */
+ if (all_match && (expect_match != 0 || addr_match != 0))
+ result = STATE_CRITICAL;
if (result == STATE_CRITICAL) {
/* Strip off last semicolon... */
temp_buffer[strlen(temp_buffer)-2] = '\0';
@@ -401,6 +413,7 @@ process_arguments (int argc, char **argv)
{"reverse-server", required_argument, 0, 'r'},
{"expected-address", required_argument, 0, 'a'},
{"expect-authority", no_argument, 0, 'A'},
+ {"all", no_argument, 0, 'L'},
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
{0, 0, 0, 0}
@@ -414,7 +427,7 @@ process_arguments (int argc, char **argv)
strcpy (argv[c], "-t");
while (1) {
- c = getopt_long (argc, argv, "hVvAt:H:s:r:a:w:c:", long_opts, &opt_index);
+ c = getopt_long (argc, argv, "hVvALt:H:s:r:a:w:c:", long_opts, &opt_index);
if (c == -1 || c == EOF)
break;
@@ -462,6 +475,9 @@ process_arguments (int argc, char **argv)
case 'A': /* expect authority */
expect_authority = TRUE;
break;
+ case 'L': /* all must match */
+ all_match = TRUE;
+ break;
case 'w':
warning = optarg;
break;
@@ -530,14 +546,16 @@ print_help (void)
printf (" -a, --expected-address=IP-ADDRESS|CIDR|HOST\n");
printf (" %s\n", _("Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end"));
printf (" %s\n", _("with a dot (.). This option can be repeated multiple times (Returns OK if any"));
- printf (" %s\n", _("value match). If multiple addresses are returned at once, you have to match"));
- printf (" %s\n", _("the whole string of addresses separated with commas (sorted alphabetically)."));
+ printf (" %s\n", _("value matches)."));
printf (" -A, --expect-authority\n");
printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup"));
printf (" -w, --warning=seconds\n");
printf (" %s\n", _("Return warning if elapsed time exceeds value. Default off"));
printf (" -c, --critical=seconds\n");
printf (" %s\n", _("Return critical if elapsed time exceeds value. Default off"));
+ printf (" -L, --all\n");
+ printf (" %s\n", _("Return critical the list of expected addresses does not match all addresses"));
+ printf (" %s\n", _("returned. Default off"));
printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
@@ -549,5 +567,5 @@ void
print_usage (void)
{
printf ("%s\n", _("Usage:"));
- printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit]\n", progname);
+ printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit] [-L]\n", progname);
}