New upstream version 2.3
This commit is contained in:
parent
c845af032a
commit
5c6ba24b61
129 changed files with 14313 additions and 2999 deletions
|
@ -42,6 +42,8 @@ const char *email = "devel@monitoring-plugins.org";
|
|||
int process_arguments (int, char **);
|
||||
int validate_arguments (void);
|
||||
int error_scan (char *);
|
||||
int ip_match_cidr(const char *, const char *);
|
||||
unsigned long ip2long(const char *);
|
||||
void print_help (void);
|
||||
void print_usage (void);
|
||||
|
||||
|
@ -54,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
|
||||
|
@ -126,7 +129,7 @@ main (int argc, char **argv)
|
|||
if (verbose)
|
||||
puts(chld_out.line[i]);
|
||||
|
||||
if (strcasestr (chld_out.line[i], ".in-addr.arpa")) {
|
||||
if (strcasestr (chld_out.line[i], ".in-addr.arpa") || strcasestr (chld_out.line[i], ".ip6.arpa")) {
|
||||
if ((temp_buffer = strstr (chld_out.line[i], "name = ")))
|
||||
addresses[n_addresses++] = strdup (temp_buffer + 7);
|
||||
else {
|
||||
|
@ -166,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) {
|
||||
|
@ -199,7 +202,10 @@ main (int argc, char **argv)
|
|||
if (error_scan (chld_err.line[i]) != STATE_OK) {
|
||||
result = max_state (result, error_scan (chld_err.line[i]));
|
||||
msg = strchr(input_buffer, ':');
|
||||
if(msg) msg++;
|
||||
if(msg)
|
||||
msg++;
|
||||
else
|
||||
msg = input_buffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,11 +232,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++) {
|
||||
/* check if we get a match and prepare an error string */
|
||||
if (strcmp(address, expected_address[i]) == 0) result = STATE_OK;
|
||||
int j;
|
||||
/* check if we get a match on 'raw' ip or cidr */
|
||||
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';
|
||||
|
@ -289,7 +311,32 @@ main (int argc, char **argv)
|
|||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
ip_match_cidr(const char *addr, const char *cidr_ro)
|
||||
{
|
||||
char *subnet, *mask_c, *cidr = strdup(cidr_ro);
|
||||
int mask;
|
||||
subnet = strtok(cidr, "/");
|
||||
mask_c = strtok(NULL, "\0");
|
||||
if (!subnet || !mask_c)
|
||||
return FALSE;
|
||||
mask = atoi(mask_c);
|
||||
|
||||
/* https://www.cryptobells.com/verifying-ips-in-a-subnet-in-php/ */
|
||||
return (ip2long(addr) & ~((1 << (32 - mask)) - 1)) == (ip2long(subnet) >> (32 - mask)) << (32 - mask);
|
||||
}
|
||||
|
||||
unsigned long
|
||||
ip2long(const char* src) {
|
||||
unsigned long ip[4];
|
||||
/* http://computer-programming-forum.com/47-c-language/1376ffb92a12c471.htm */
|
||||
return (sscanf(src, "%3lu.%3lu.%3lu.%3lu",
|
||||
&ip[0], &ip[1], &ip[2], &ip[3]) == 4 &&
|
||||
ip[0] < 256 && ip[1] < 256 &&
|
||||
ip[2] < 256 && ip[3] < 256)
|
||||
? ip[0] << 24 | ip[1] << 16 | ip[2] << 8 | ip[3]
|
||||
: 0;
|
||||
}
|
||||
|
||||
int
|
||||
error_scan (char *input_buffer)
|
||||
|
@ -304,6 +351,8 @@ error_scan (char *input_buffer)
|
|||
/* DNS server is not running... */
|
||||
else if (strstr (input_buffer, "No response from server"))
|
||||
die (STATE_CRITICAL, _("No response from DNS %s\n"), dns_server);
|
||||
else if (strstr (input_buffer, "no servers could be reached"))
|
||||
die (STATE_CRITICAL, _("No response from DNS %s\n"), dns_server);
|
||||
|
||||
/* Host name is valid, but server doesn't have records... */
|
||||
else if (strstr (input_buffer, "No records"))
|
||||
|
@ -328,6 +377,7 @@ error_scan (char *input_buffer)
|
|||
/* Host or domain name does not exist */
|
||||
else if (strstr (input_buffer, "Non-existent") ||
|
||||
strstr (input_buffer, "** server can't find") ||
|
||||
strstr (input_buffer, "** Can't find") ||
|
||||
strstr (input_buffer,"NXDOMAIN"))
|
||||
die (STATE_CRITICAL, _("Domain %s was not found by the server\n"), query_address);
|
||||
|
||||
|
@ -368,6 +418,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}
|
||||
|
@ -381,7 +432,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;
|
||||
|
@ -429,6 +480,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;
|
||||
|
@ -494,17 +548,19 @@ print_help (void)
|
|||
printf (" %s\n", _("The name or address you want to query"));
|
||||
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", _("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 (" -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 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 if the list of expected addresses does not match all addresses"));
|
||||
printf (" %s\n", _("returned. Default off"));
|
||||
|
||||
printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
|
||||
|
||||
|
@ -516,5 +572,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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue