[icinga-checkins] icinga.org: icinga2/master: Don' t load the replication component on standalone instances.

git at icinga.org git at icinga.org
Mon Feb 11 23:38:52 CET 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon Feb 11 23:37:39 2013 +0100

Don't load the replication component on standalone instances.

Fixes #3687

---

 components/replication/replicationcomponent.cpp |   18 +++---------------
 itl/cluster.conf                                |   20 ++++++++++++++++++++
 lib/icinga/icingaapplication.cpp                |   10 +---------
 lib/icinga/service-check.cpp                    |   22 +++++++++++++++++++++-
 lib/icinga/service.h                            |    2 +-
 5 files changed, 46 insertions(+), 26 deletions(-)

diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp
index 3d97e03..e35a6e3 100644
--- a/components/replication/replicationcomponent.cpp
+++ b/components/replication/replicationcomponent.cpp
@@ -63,26 +63,14 @@ void ReplicationComponent::CheckResultRequestHandler(const RequestMessage& reque
 	String svcname = params.GetService();
 	Service::Ptr service = Service::GetByName(svcname);
 
-	Service::OnCheckResultReceived(service, params);
-
 	Dictionary::Ptr cr = params.GetCheckResult();
 	if (!cr)
 		return;
 
-	Value active = cr->Get("active");
-
-	time_t ts;
-	Value schedule_end = cr->Get("schedule_end");
-
-	if (!schedule_end.IsEmpty())
-		ts = static_cast<time_t>(schedule_end);
-	else
-		ts = static_cast<time_t>(Utility::GetTime());
+	if (cr->Contains("checker") && cr->Get("checker") == EndpointManager::GetInstance()->GetIdentity())
+		return;
 
-	if (active.IsEmpty() || static_cast<long>(active))
-		CIB::UpdateActiveChecksStatistics(ts, 1);
-	else
-		CIB::UpdatePassiveChecksStatistics(ts, 1);
+	Service::UpdateStatistics(cr);
 }
 
 void ReplicationComponent::EndpointConnectedHandler(const Endpoint::Ptr& endpoint)
diff --git a/itl/cluster.conf b/itl/cluster.conf
new file mode 100644
index 0000000..a469457
--- /dev/null
+++ b/itl/cluster.conf
@@ -0,0 +1,20 @@
+/******************************************************************************
+ * Icinga 2                                                                   *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
+ *                                                                            *
+ * This program is free software; you can redistribute it and/or              *
+ * modify it under the terms of the GNU General Public License                *
+ * as published by the Free Software Foundation; either version 2             *
+ * of the License, or (at your option) any later version.                     *
+ *                                                                            *
+ * This program is distributed in the hope that it will be useful,            *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
+ * GNU General Public License for more details.                               *
+ *                                                                            *
+ * You should have received a copy of the GNU General Public License          *
+ * along with this program; if not, write to the Free Software Foundation     *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
+ ******************************************************************************/
+
+local object Component "replication" {}
diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp
index b3614dd..a961d9b 100644
--- a/lib/icinga/icingaapplication.cpp
+++ b/lib/icinga/icingaapplication.cpp
@@ -32,15 +32,7 @@ REGISTER_TYPE(IcingaApplication, NULL);
 
 IcingaApplication::IcingaApplication(const Dictionary::Ptr& serializedUpdate)
 	: Application(serializedUpdate)
-{
-	/* load replication config component */
-	ConfigItemBuilder::Ptr replicationComponentConfig = boost::make_shared<ConfigItemBuilder>();
-	replicationComponentConfig->SetType("Component");
-	replicationComponentConfig->SetName("replication");
-	replicationComponentConfig->SetLocal(true);
-	replicationComponentConfig->Compile()->Commit();
-	replicationComponentConfig.reset();
-}
+{ }
 
 /**
  * The entry point for the Icinga application.
diff --git a/lib/icinga/service-check.cpp b/lib/icinga/service-check.cpp
index a27d567..b702040 100644
--- a/lib/icinga/service-check.cpp
+++ b/lib/icinga/service-check.cpp
@@ -25,7 +25,6 @@ const int Service::DefaultMaxCheckAttempts = 3;
 const int Service::DefaultCheckInterval = 5 * 60;
 const int Service::CheckIntervalDivisor = 5;
 
-boost::signal<void (const Service::Ptr&, const CheckResultMessage&)> Service::OnCheckResultReceived;
 boost::signal<void (const Service::Ptr&, const String&)> Service::OnCheckerChanged;
 boost::signal<void (const Service::Ptr&, const Value&)> Service::OnNextCheckChanged;
 
@@ -500,6 +499,9 @@ void Service::CheckCompletedHandler(const Dictionary::Ptr& scheduleInfo,
 		if (!result->Contains("active"))
 			result->Set("active", 1);
 
+		if (!result->Contains("checker"))
+			result->Set("checker", EndpointManager::GetInstance()->GetIdentity());
+
 		ProcessCheckResult(result);
 	}
 
@@ -515,6 +517,8 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
 {
 	ApplyCheckResult(cr);
 
+	Service::UpdateStatistics(cr);
+
 	/* flush the current transaction so other instances see the service's
 	 * new state when they receive the CheckResult message */
 	DynamicObject::FlushTx();
@@ -531,3 +535,19 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
 
 	EndpointManager::GetInstance()->SendMulticastMessage(rm);
 }
+
+void Service::UpdateStatistics(const Dictionary::Ptr& cr)
+{
+	time_t ts;
+	Value schedule_end = cr->Get("schedule_end");
+	if (!schedule_end.IsEmpty())
+		ts = static_cast<time_t>(schedule_end);
+	else
+		ts = static_cast<time_t>(Utility::GetTime());
+
+	Value active = cr->Get("active");
+	if (active.IsEmpty() || static_cast<long>(active))
+		CIB::UpdateActiveChecksStatistics(ts, 1);
+	else
+		CIB::UpdatePassiveChecksStatistics(ts, 1);
+}
diff --git a/lib/icinga/service.h b/lib/icinga/service.h
index 1882647..88796d3 100644
--- a/lib/icinga/service.h
+++ b/lib/icinga/service.h
@@ -169,6 +169,7 @@ public:
 	void SetAcknowledgementExpiry(double timestamp);
 
 	void ApplyCheckResult(const Dictionary::Ptr& cr);
+	static void UpdateStatistics(const Dictionary::Ptr& cr);
 
 	void BeginExecuteCheck(const function<void (void)>& callback);
 	void ProcessCheckResult(const Dictionary::Ptr& cr);
@@ -179,7 +180,6 @@ public:
 	static ServiceStateType StateTypeFromString(const String& state);
 	static String StateTypeToString(ServiceStateType state);
 
-	static boost::signal<void (const Service::Ptr& service, const CheckResultMessage&)> OnCheckResultReceived;
 	static boost::signal<void (const Service::Ptr&, const String&)> OnCheckerChanged;
 	static boost::signal<void (const Service::Ptr&, const Value&)> OnNextCheckChanged;
 





More information about the icinga-checkins mailing list