summaryrefslogtreecommitdiffstats
path: root/web/attachments/304650-check_ntp_peer.patch
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/304650-check_ntp_peer.patch')
-rw-r--r--web/attachments/304650-check_ntp_peer.patch147
1 files changed, 147 insertions, 0 deletions
diff --git a/web/attachments/304650-check_ntp_peer.patch b/web/attachments/304650-check_ntp_peer.patch
new file mode 100644
index 0000000..632a106
--- /dev/null
+++ b/web/attachments/304650-check_ntp_peer.patch
@@ -0,0 +1,147 @@
1diff -Nur nagios-plugins-1.4.13.orig/plugins/check_ntp_peer.c nagios-plugins-1.4.13/plugins/check_ntp_peer.c
2--- nagios-plugins-1.4.13.orig/plugins/check_ntp_peer.c 2008-09-02 14:28:04.000000000 +0200
3+++ nagios-plugins-1.4.13/plugins/check_ntp_peer.c 2008-12-09 14:12:32.000000000 +0100
4@@ -60,6 +60,9 @@
5 static short do_jitter=0;
6 static char *jwarn="-1:5000";
7 static char *jcrit="-1:10000";
8+static short do_peer=0;
9+static char *pwarn="@1";
10+static char *pcrit="@1";
11 static int syncsource_found=0;
12 static int li_alarm=0;
13
14@@ -67,6 +70,7 @@
15 thresholds *offset_thresholds = NULL;
16 thresholds *jitter_thresholds = NULL;
17 thresholds *stratum_thresholds = NULL;
18+thresholds *peer_thresholds = NULL;
19 void print_help (void);
20 void print_usage (void);
21
22@@ -252,7 +256,7 @@
23 * status is pretty much useless as syncsource_found is a global variable
24 * used later in main to check is the server was synchronized. It works
25 * so I left it alone */
26-int ntp_request(const char *host, double *offset, int *offset_result, double *jitter, int *stratum){
27+int ntp_request(const char *host, double *offset, int *offset_result, double *jitter, int *stratum, int *peer){
28 int conn=-1, i, npeers=0, num_candidates=0;
29 double tmp_offset = 0;
30 int min_peer_sel=PEER_INCLUDED;
31@@ -266,7 +270,7 @@
32
33 status = STATE_OK;
34 *offset_result = STATE_UNKNOWN;
35- *jitter = *stratum = -1;
36+ *jitter = *stratum = *peer = -1;
37
38 /* Long-winded explanation:
39 * Getting the sync peer offset, jitter and stratum requires a number of
40@@ -328,6 +332,7 @@
41 }
42 }
43 if(verbose) printf("%d candiate peers available\n", num_candidates);
44+ *peer = num_candidates;
45 if(verbose && syncsource_found) printf("synchronization source found\n");
46 if(! syncsource_found){
47 status = STATE_WARNING;
48@@ -471,6 +476,8 @@
49 {"scrit", required_argument, 0, 'C'},
50 {"jwarn", required_argument, 0, 'j'},
51 {"jcrit", required_argument, 0, 'k'},
52+ {"pwarn", required_argument, 0, 'o'},
53+ {"pcrit", required_argument, 0, 'P'},
54 {"timeout", required_argument, 0, 't'},
55 {"hostname", required_argument, 0, 'H'},
56 {"port", required_argument, 0, 'p'},
57@@ -482,7 +489,7 @@
58 usage ("\n");
59
60 while (1) {
61- c = getopt_long (argc, argv, "Vhv46qw:c:W:C:j:k:t:H:p:", longopts, &option);
62+ c = getopt_long (argc, argv, "Vhv46qw:c:W:C:j:k:t:H:p:P:o:", longopts, &option);
63 if (c == -1 || c == EOF || c == 1)
64 break;
65
66@@ -525,6 +532,14 @@
67 do_jitter=1;
68 jcrit = optarg;
69 break;
70+ case 'o':
71+ do_peer=1;
72+ pwarn = optarg;
73+ break;
74+ case 'P':
75+ do_peer=1;
76+ pcrit = optarg;
77+ break;
78 case 'H':
79 if(is_host(optarg) == FALSE)
80 usage2(_("Invalid hostname/address"), optarg);
81@@ -584,8 +599,16 @@
82 TRUE, 0, TRUE, 16);
83 }
84
85+char *perfd_peer (int num_peer)
86+{
87+ return perfdata ("num_peer", num_peer, "",
88+ do_peer, (int)peer_thresholds->warning->end,
89+ do_peer, (int)peer_thresholds->critical->end,
90+ TRUE, 0, TRUE, 16);
91+}
92+
93 int main(int argc, char *argv[]){
94- int result, offset_result, stratum;
95+ int result, offset_result, stratum, peer;
96 double offset=0, jitter=0;
97 char *result_line, *perfdata_line;
98
99@@ -602,6 +625,7 @@
100 set_thresholds(&offset_thresholds, owarn, ocrit);
101 set_thresholds(&jitter_thresholds, jwarn, jcrit);
102 set_thresholds(&stratum_thresholds, swarn, scrit);
103+ set_thresholds(&peer_thresholds, pwarn, pcrit);
104
105 /* initialize alarm signal handling */
106 signal (SIGALRM, socket_timeout_alarm_handler);
107@@ -610,7 +634,7 @@
108 alarm (socket_timeout);
109
110 /* This returns either OK or WARNING (See comment preceeding ntp_request) */
111- result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum);
112+ result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum, &peer);
113
114 if(offset_result == STATE_UNKNOWN) {
115 /* if there's no sync peer (this overrides ntp_request output): */
116@@ -628,6 +652,9 @@
117 if(do_jitter)
118 result = max_state_alt(result, get_status(jitter, jitter_thresholds));
119
120+ if(do_peer)
121+ result = max_state_alt(result, get_status(peer, peer_thresholds));
122+
123 switch (result) {
124 case STATE_CRITICAL :
125 asprintf(&result_line, _("NTP CRITICAL:"));
126@@ -662,6 +689,10 @@
127 asprintf(&result_line, "%s, stratum=%i", result_line, stratum);
128 asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum));
129 }
130+ if (do_peer) {
131+ asprintf(&result_line, "%s, num_peer=%i", result_line, peer);
132+ asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_peer(peer));
133+ }
134 printf("%s|%s\n", result_line, perfdata_line);
135
136 if(server_address!=NULL) free(server_address);
137@@ -698,6 +729,10 @@
138 printf (" %s\n", _("Warning threshold for jitter"));
139 printf (" %s\n", "-k, --jcrit=THRESHOLD");
140 printf (" %s\n", _("Critical threshold for jitter"));
141+ printf (" %s\n", "-o, --pwarn=THRESHOLD");
142+ printf (" %s\n", _("Warning threshold for peer"));
143+ printf (" %s\n", "-P, --pcrit=THRESHOLD");
144+ printf (" %s\n", _("Critical threshold for peer"));
145 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
146 printf (_(UT_VERBOSE));
147