summaryrefslogtreecommitdiffstats
path: root/web/attachments/304650-check_ntp_peer.patch
blob: 632a106f6c287ec765da8452289a0901d9d63137 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
diff -Nur nagios-plugins-1.4.13.orig/plugins/check_ntp_peer.c nagios-plugins-1.4.13/plugins/check_ntp_peer.c
--- nagios-plugins-1.4.13.orig/plugins/check_ntp_peer.c	2008-09-02 14:28:04.000000000 +0200
+++ nagios-plugins-1.4.13/plugins/check_ntp_peer.c	2008-12-09 14:12:32.000000000 +0100
@@ -60,6 +60,9 @@
 static short do_jitter=0;
 static char *jwarn="-1:5000";
 static char *jcrit="-1:10000";
+static short do_peer=0;
+static char *pwarn="@1";
+static char *pcrit="@1";
 static int syncsource_found=0;
 static int li_alarm=0;
 
@@ -67,6 +70,7 @@
 thresholds *offset_thresholds = NULL;
 thresholds *jitter_thresholds = NULL;
 thresholds *stratum_thresholds = NULL;
+thresholds *peer_thresholds = NULL;
 void print_help (void);
 void print_usage (void);
 
@@ -252,7 +256,7 @@
  *  status is pretty much useless as syncsource_found is a global variable
  *  used later in main to check is the server was synchronized. It works
  *  so I left it alone */
-int ntp_request(const char *host, double *offset, int *offset_result, double *jitter, int *stratum){
+int ntp_request(const char *host, double *offset, int *offset_result, double *jitter, int *stratum, int *peer){
 	int conn=-1, i, npeers=0, num_candidates=0;
 	double tmp_offset = 0;
 	int min_peer_sel=PEER_INCLUDED;
@@ -266,7 +270,7 @@
 
 	status = STATE_OK;
 	*offset_result = STATE_UNKNOWN;
-	*jitter = *stratum = -1;
+	*jitter = *stratum = *peer = -1;
 
 	/* Long-winded explanation:
 	 * Getting the sync peer offset, jitter and stratum requires a number of
@@ -328,6 +332,7 @@
 		}
 	}
 	if(verbose) printf("%d candiate peers available\n", num_candidates);
+	*peer = num_candidates;
 	if(verbose && syncsource_found) printf("synchronization source found\n");
 	if(! syncsource_found){
 		status = STATE_WARNING;
@@ -471,6 +476,8 @@
 		{"scrit", required_argument, 0, 'C'},
 		{"jwarn", required_argument, 0, 'j'},
 		{"jcrit", required_argument, 0, 'k'},
+		{"pwarn", required_argument, 0, 'o'},
+		{"pcrit", required_argument, 0, 'P'},
 		{"timeout", required_argument, 0, 't'},
 		{"hostname", required_argument, 0, 'H'},
 		{"port", required_argument, 0, 'p'},
@@ -482,7 +489,7 @@
 		usage ("\n");
 
 	while (1) {
-		c = getopt_long (argc, argv, "Vhv46qw:c:W:C:j:k:t:H:p:", longopts, &option);
+		c = getopt_long (argc, argv, "Vhv46qw:c:W:C:j:k:t:H:p:P:o:", longopts, &option);
 		if (c == -1 || c == EOF || c == 1)
 			break;
 
@@ -525,6 +532,14 @@
 			do_jitter=1;
 			jcrit = optarg;
 			break;
+		case 'o':
+			do_peer=1;
+			pwarn = optarg;
+			break;
+		case 'P':
+			do_peer=1;
+			pcrit = optarg;
+			break;
 		case 'H':
 			if(is_host(optarg) == FALSE)
 				usage2(_("Invalid hostname/address"), optarg);
@@ -584,8 +599,16 @@
 		TRUE, 0, TRUE, 16);
 }
 
+char *perfd_peer (int num_peer)
+{
+	return perfdata ("num_peer", num_peer, "",
+		do_peer, (int)peer_thresholds->warning->end,
+		do_peer, (int)peer_thresholds->critical->end,
+		TRUE, 0, TRUE, 16);
+}
+
 int main(int argc, char *argv[]){
-	int result, offset_result, stratum;
+	int result, offset_result, stratum, peer;
 	double offset=0, jitter=0;
 	char *result_line, *perfdata_line;
 
@@ -602,6 +625,7 @@
 	set_thresholds(&offset_thresholds, owarn, ocrit);
 	set_thresholds(&jitter_thresholds, jwarn, jcrit);
 	set_thresholds(&stratum_thresholds, swarn, scrit);
+	set_thresholds(&peer_thresholds, pwarn, pcrit);
 
 	/* initialize alarm signal handling */
 	signal (SIGALRM, socket_timeout_alarm_handler);
@@ -610,7 +634,7 @@
 	alarm (socket_timeout);
 
 	/* This returns either OK or WARNING (See comment preceeding ntp_request) */
-	result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum);
+	result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum, &peer);
 
 	if(offset_result == STATE_UNKNOWN) {
 		/* if there's no sync peer (this overrides ntp_request output): */
@@ -628,6 +652,9 @@
 	if(do_jitter)
 		result = max_state_alt(result, get_status(jitter, jitter_thresholds));
 
+	if(do_peer)
+		result = max_state_alt(result, get_status(peer, peer_thresholds));
+
 	switch (result) {
 		case STATE_CRITICAL :
 			asprintf(&result_line, _("NTP CRITICAL:"));
@@ -662,6 +689,10 @@
 		asprintf(&result_line, "%s, stratum=%i", result_line, stratum);
 		asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum));
 	}
+	if (do_peer) {
+		asprintf(&result_line, "%s, num_peer=%i", result_line, peer);
+		asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_peer(peer));
+	}
 	printf("%s|%s\n", result_line, perfdata_line);
 
 	if(server_address!=NULL) free(server_address);
@@ -698,6 +729,10 @@
 	printf ("    %s\n", _("Warning threshold for jitter"));
 	printf (" %s\n", "-k, --jcrit=THRESHOLD");
 	printf ("    %s\n", _("Critical threshold for jitter"));
+	printf (" %s\n", "-o, --pwarn=THRESHOLD");
+	printf ("    %s\n", _("Warning threshold for peer"));
+	printf (" %s\n", "-P, --pcrit=THRESHOLD");
+	printf ("    %s\n", _("Critical threshold for peer"));
 	printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
 	printf (_(UT_VERBOSE));