[monitoring-plugins] check_ntp_peer - Added specific state output for ...
Jan Wagner
git at monitoring-plugins.org
Mon Jul 21 00:20:07 CEST 2014
Module: monitoring-plugins
Branch: master
Commit: 495cf3b2f8047815cc7de4f8238660f4609e97ca
Author: abrist <abrist at nagios.com>
Committer: Jan Wagner <waja at cyconet.org>
Date: Fri Feb 14 15:04:37 2014 -0500
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=495cf3b
check_ntp_peer - Added specific state output for each metric. It now should be easy to see which check caused the alert.
---
plugins/check_ntp_peer.c | 49 ++++++++++++++++++++++++++++++++++++------------
1 file changed, 37 insertions(+), 12 deletions(-)
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c
index 8dc1978..d3ae599 100644
--- a/plugins/check_ntp_peer.c
+++ b/plugins/check_ntp_peer.c
@@ -560,7 +560,7 @@ char *perfd_truechimers (int num_truechimers)
}
int main(int argc, char *argv[]){
- int result, offset_result, stratum, num_truechimers;
+ int result, offset_result, stratum, num_truechimers, oresult, jresult, sresult, tresult;
double offset=0, jitter=0;
char *result_line, *perfdata_line;
@@ -597,15 +597,19 @@ int main(int argc, char *argv[]){
result = STATE_UNKNOWN;
result = max_state_alt(result, get_status(fabs(offset), offset_thresholds));
}
-
+ oresult = result;
+
if(do_truechimers)
- result = max_state_alt(result, get_status(num_truechimers, truechimer_thresholds));
+ tresult = get_status(num_truechimers, truechimer_thresholds);
+ result = max_state_alt(result, tresult);
if(do_stratum)
- result = max_state_alt(result, get_status(stratum, stratum_thresholds));
+ sresult = get_status(stratum, stratum_thresholds);
+ result = max_state_alt(result, sresult);
if(do_jitter)
- result = max_state_alt(result, get_status(jitter, jitter_thresholds));
+ jresult = get_status(jitter, jitter_thresholds);
+ result = max_state_alt(result, jresult);
switch (result) {
case STATE_CRITICAL :
@@ -629,20 +633,43 @@ int main(int argc, char *argv[]){
if(offset_result == STATE_UNKNOWN){
xasprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
xasprintf(&perfdata_line, "");
+ } else if (oresult == STATE_WARNING) {
+ xasprintf(&result_line, "%s %s %.10g secs (WARNING)", result_line, _("Offset"), offset);
+ } else if (oresult == STATE_CRITICAL) {
+ xasprintf(&result_line, "%s %s %.10g secs (CRITICAL)", result_line, _("Offset"), offset);
} else {
xasprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset);
- xasprintf(&perfdata_line, "%s", perfd_offset(offset));
- }
+ }
+ xasprintf(&perfdata_line, "%s", perfd_offset(offset));
+
if (do_jitter) {
- xasprintf(&result_line, "%s, jitter=%f", result_line, jitter);
+ if (jresult == STATE_WARNING) {
+ xasprintf(&result_line, "%s, jitter=%f (WARNING)", result_line, jitter);
+ } else if (jresult == STATE_CRITICAL) {
+ xasprintf(&result_line, "%s, jitter=%f (CRITICAL)", result_line, jitter);
+ } else {
+ xasprintf(&result_line, "%s, jitter=%f", result_line, jitter);
+ }
xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter));
}
if (do_stratum) {
- xasprintf(&result_line, "%s, stratum=%i", result_line, stratum);
+ if (sresult == STATE_WARNING) {
+ xasprintf(&result_line, "%s, stratum=%i (WARNING)", result_line, stratum);
+ } else if (sresult == STATE_CRITICAL) {
+ xasprintf(&result_line, "%s, stratum=%i (CRITICAL)", result_line, stratum);
+ } else {
+ xasprintf(&result_line, "%s, stratum=%i", result_line, stratum);
+ }
xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum));
}
if (do_truechimers) {
- xasprintf(&result_line, "%s, truechimers=%i", result_line, num_truechimers);
+ if (tresult == STATE_WARNING) {
+ xasprintf(&result_line, "%s, truechimers=%i (WARNING)", result_line, num_truechimers);
+ } else if (tresult == STATE_CRITICAL) {
+ xasprintf(&result_line, "%s, truechimers=%i (CRITICAL)", result_line, num_truechimers);
+ } else {
+ xasprintf(&result_line, "%s, truechimers=%i", result_line, num_truechimers);
+ }
xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_truechimers(num_truechimers));
}
printf("%s|%s\n", result_line, perfdata_line);
@@ -651,8 +678,6 @@ int main(int argc, char *argv[]){
return result;
}
-
-
void print_help(void){
print_revision(progname, NP_VERSION);
More information about the Commits
mailing list