diff options
author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-04-17 10:37:57 +0000 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-04-17 10:37:57 +0000 |
commit | b7ea51c6662e752b536289d033a3813a748e49a7 (patch) | |
tree | fd3a4b0b64f010a252f1f3eb2cdc98f453d8bd44 /plugins/check_dns.c | |
parent | b12edc52d6b645652f7ea813f2e6557c7f9f0fb0 (diff) | |
download | monitoring-plugins-b7ea51c6662e752b536289d033a3813a748e49a7.tar.gz |
Allow to repeat -a to set multiple possible addresses
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1978 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_dns.c')
-rw-r--r-- | plugins/check_dns.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 9322aef9..732cde7f 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c @@ -54,8 +54,9 @@ char query_address[ADDRESS_LENGTH] = ""; char dns_server[ADDRESS_LENGTH] = ""; char ptr_server[ADDRESS_LENGTH] = ""; int verbose = FALSE; -char expected_address[ADDRESS_LENGTH] = ""; -int match_expected_address = FALSE; +char **expected_address = NULL; +int expected_address_cnt = 0; + int expect_authority = FALSE; thresholds *time_thresholds = NULL; @@ -202,9 +203,19 @@ main (int argc, char **argv) NSLOOKUP_COMMAND); /* compare to expected address */ - if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { + if (result == STATE_OK && expected_address_cnt > 0) { result = STATE_CRITICAL; - asprintf(&msg, _("expected '%s' but got '%s'"), expected_address, address); + temp_buffer = ""; + for (i=0; i<expected_address_cnt; i++) { + /* check if we get a match and prepare an error string */ + if (strcmp(address, expected_address[i]) == 0) result = STATE_OK; + asprintf(&temp_buffer, "%s%s; ", temp_buffer, expected_address[i]); + } + if (result == STATE_CRITICAL) { + /* Strip off last semicolon... */ + temp_buffer[strlen(temp_buffer)-2] = '\0'; + asprintf(&msg, _("expected '%s' but got '%s'"), temp_buffer, address); + } } /* check if authoritative */ @@ -380,8 +391,9 @@ process_arguments (int argc, char **argv) case 'a': /* expected address */ if (strlen (optarg) >= ADDRESS_LENGTH) die (STATE_UNKNOWN, _("Input buffer overflow\n")); - strcpy (expected_address, optarg); - match_expected_address = TRUE; + expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**)); + expected_address[expected_address_cnt] = strdup(optarg); + expected_address_cnt++; break; case 'A': /* expect authority */ expect_authority = TRUE; @@ -451,8 +463,10 @@ print_help (void) printf (" -s, --server=HOST\n"); printf (" %s\n", _("Optional DNS server you want to use for the lookup")); printf (" -a, --expected-address=IP-ADDRESS|HOST\n"); - printf (" %s\n", _("Optional IP-ADDRESS you expect the DNS server to return. HOST must end with .")); - printf (" %s\n", _("Multiple addresses can be separated with commas, and need to be sorted.")); + printf (" %s\n", _("Optional IP-ADDRESS you expect the DNS server to return. HOST must end with")); + printf (" %s\n", _("a dot (.). This option can be repeated multiple times (Returns OK if any")); + printf (" %s\n", _("value match). If multiple are returned at once, you have to match the whole")); + printf (" %s\n", _("string of addresses separated with commas (it needs to be sorted).")); printf (" -A, --expect-authority\n"); printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); printf (" -w, --warning=seconds\n"); |