summaryrefslogtreecommitdiffstats
path: root/web/attachments/154471-nagios_plugins-check_dns.c.patch
blob: f024078df08fc6689bcd4a47b5a7dec098b35935 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
--- ../../original_sources/nagios-plugins-1.4.2/plugins/check_dns.c	2004-12-29 19:41:39.000000000 -0500
+++ nagios-plugins-1.4.2/plugins/check_dns.c	2005-10-19 22:54:35.000000000 -0400
@@ -45,6 +45,8 @@
 char expected_address[ADDRESS_LENGTH] = "";
 int match_expected_address = FALSE;
 int expect_authority = FALSE;
+double elapsed_warn_time = 0.0;
+double elapsed_crit_time = 0.0;
 
 int
 main (int argc, char **argv)
@@ -193,6 +195,21 @@
 	microsec = deltime (tv);
 	elapsed_time = (double)microsec / 1.0e6;
 
+
+	/* check elapsed time */
+	if ((result == STATE_OK) && 
+	    ((elapsed_warn_time != 0.0) && (elapsed_warn_time <= elapsed_time)) &&
+	    ((elapsed_crit_time == 0.0) || elapsed_crit_time > elapsed_time) ) {
+                result = STATE_WARNING;
+		asprintf(&output, _("server %s responded too slowly. %.5f seconds response time."), dns_server, elapsed_time);
+	}
+
+	if ((result == STATE_OK) && (elapsed_crit_time != 0) &&
+              (elapsed_crit_time <= elapsed_time) ) {
+		result = STATE_CRITICAL;
+		asprintf(&output, _("server %s responded too slowly. %.5f seconds response time."), dns_server, elapsed_time);
+	}
+
 	if (result == STATE_OK) {
 		if (strchr (address, ',') == NULL)
 			multi_address = FALSE;
@@ -200,7 +217,7 @@
 			multi_address = TRUE;
 
 		printf ("DNS %s: ", _("OK"));
-		printf (ngettext("%.3f second response time ", "%.3f seconds response time ", elapsed_time), elapsed_time);
+		printf (ngettext("%.5f second response time ", "%.5f seconds response time ", elapsed_time), elapsed_time);
 		printf (_("%s returns %s"), query_address, address);
 		printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
 	}
@@ -294,6 +311,8 @@
 		{"reverse-server", required_argument, 0, 'r'},
 		{"expected-address", required_argument, 0, 'a'},
 		{"expect-authority", no_argument, 0, 'A'},
+		{"warning", required_argument, 0, 'w'},
+		{"critical", required_argument, 0, 'c'},
 		{0, 0, 0, 0}
 	};
 
@@ -305,7 +324,7 @@
 			strcpy (argv[c], "-t");
 
 	while (1) {
-		c = getopt_long (argc, argv, "hVvAt:H:s:r:a:", long_opts, &opt_index);
+		c = getopt_long (argc, argv, "hVvAt:H:s:r:a:w:c:", long_opts, &opt_index);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -358,6 +377,12 @@
 		case 'A': /* expect authority */
 			expect_authority = TRUE;
 			break;
+		case 'w': /* elapsed time > warning */
+			elapsed_warn_time = atof (optarg);
+			break;
+		case 'c': /* elapsed time > critical */
+			elapsed_crit_time = atof (optarg);
+			break;
 		}
 	}
 
@@ -387,11 +412,13 @@
 validate_arguments ()
 {
 	if (query_address[0] == 0)
-		return ERROR;
-	else
-		return OK;
-}
+	  usage4 (_("Can't determine/parse address to query."));
+
+	if ( elapsed_crit_time != 0.0 && elapsed_warn_time > elapsed_crit_time )
+		usage4 (_("Warning time must be less than critical time."));
 
+	return OK;
+}
 
 void
 print_help (void)
@@ -419,7 +446,13 @@
 -a, --expected-address=IP-ADDRESS\n\
    Optional IP address you expect the DNS server to return\n\
 -A, --expect-authority\n\
-   Optionally expect the DNS server to be authoritative for the lookup\n"));
+   Optionally expect the DNS server to be authoritative for the lookup\n\
+-w, --warning=seconds\n\
+   Return warning if elapsed time exceeds value. Default is 0.0 seconds (off).\n\
+-c, --critical=seconds\n\
+   Return critical if elapsed time exceeds value. Default is 0.0 seconds (off).\n\
+\n\
+seconds are floating point values. Set to 0 turn off check.\n"));
 
 	printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
 
@@ -431,5 +464,5 @@
 print_usage (void)
 {
 	printf ("\
-Usage: %s -H host [-s server] [-a expected-address] [-A] [-t timeout]\n", progname);
+Usage: %s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit]\n", progname);
 }