[icinga-checkins] icinga.org: icinga2/master: Add lag thresholds to cluster-zone check

git at icinga.org git at icinga.org
Fri Jun 24 10:33:09 CEST 2016


Module: icinga2
Branch: master
Commit: 1451a0e5adabb7c69161a324c37c445f9a977c9d
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=1451a0e5adabb7c69161a324c37c445f9a977c9d

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Fri Jun 24 10:17:45 2016 +0200

Add lag thresholds to cluster-zone check

fixes #11772

---

 doc/7-icinga-template-library.md     |    8 +++++---
 lib/methods/clusterzonechecktask.cpp |   22 +++++++++++++++++++++-
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/doc/7-icinga-template-library.md b/doc/7-icinga-template-library.md
index 3f8f036..a039c06 100644
--- a/doc/7-icinga-template-library.md
+++ b/doc/7-icinga-template-library.md
@@ -54,9 +54,11 @@ Check command for the built-in `cluster-zone` check.
 
 Custom attributes passed as [command parameters](3-monitoring-basics.md#command-passing-parameters):
 
-Name         | Description
--------------|---------------
-cluster_zone | **Optional.** The zone name. Defaults to "$host.name$".
+Name                 | Description
+---------------------|---------------
+cluster_zone         | **Required.** The zone name.
+cluster_lag_warning  | **Optional.** Warning threshold for log lag in seconds.
+cluster_lag_critical | **Optional.** Critical threshold for log lag in seconds.
 
 ### <a id="itl-icinga-ido"></a> ido
 
diff --git a/lib/methods/clusterzonechecktask.cpp b/lib/methods/clusterzonechecktask.cpp
index 7c36764..03e3321 100644
--- a/lib/methods/clusterzonechecktask.cpp
+++ b/lib/methods/clusterzonechecktask.cpp
@@ -61,6 +61,15 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
 	String zoneName = MacroProcessor::ResolveMacros("$cluster_zone$", resolvers, checkable->GetLastCheckResult(),
 	    NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
 
+	String missingLagWarning;
+	String missingLagCritical;
+
+	double lagWarning = MacroProcessor::ResolveMacros("$cluster_lag_warning$", resolvers, checkable->GetLastCheckResult(),
+	    &missingLagWarning, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
+
+	double lagCritical = MacroProcessor::ResolveMacros("$cluster_lag_critical$", resolvers, checkable->GetLastCheckResult(),
+	    &missingLagCritical, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
+
 	if (resolvedMacros && !useResolvedMacros)
 		return;
 
@@ -101,8 +110,19 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
 		cr->SetOutput("Zone '" + zoneName + "' is connected. Log lag: " + Utility::FormatDuration(zoneLag));
 	}
 
+	/* Check whether the thresholds have been resolved and compare them */
+	if (missingLagCritical.IsEmpty() && zoneLag > lagCritical) {
+		cr->SetState(ServiceCritical);
+		cr->SetOutput("Zone '" + zoneName + "' is connected. Log lag: " + Utility::FormatDuration(zoneLag)
+		    + " greater than critical threshold: " + Utility::FormatDuration(lagCritical));
+	} else if (missingLagWarning.IsEmpty() && zoneLag > lagWarning) {
+		cr->SetState(ServiceWarning);
+		cr->SetOutput("Zone '" + zoneName + "' is connected. Log lag: " + Utility::FormatDuration(zoneLag)
+		    + " greater than warning threshold: " + Utility::FormatDuration(lagWarning));
+	}
+
 	Array::Ptr perfdata = new Array();
-	perfdata->Add(new PerfdataValue("slave_lag", zoneLag));
+	perfdata->Add(new PerfdataValue("slave_lag", zoneLag, false, "s", lagWarning, lagCritical));
 	cr->SetPerformanceData(perfdata);
 
 	checkable->ProcessCheckResult(cr);



More information about the icinga-checkins mailing list