From: Gunnar Beutner Date: Mon, 9 Jul 2012 14:44:46 +0000 (+0200) Subject: Added GetProperty/SetTag/GetTag accessors to ConfigObjectAdapter. X-Git-Tag: v0.0.1~282 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=16e8d131fb5300085aa28da863c291960886e50a;p=icinga2 Added GetProperty/SetTag/GetTag accessors to ConfigObjectAdapter. --- diff --git a/cib/configobjectadapter.h b/cib/configobjectadapter.h index 7f94d6f36..702fa8e86 100644 --- a/cib/configobjectadapter.h +++ b/cib/configobjectadapter.h @@ -18,10 +18,28 @@ public: ConfigObject::Ptr GetConfigObject() const; + template + bool GetProperty(const string& key, T *value) const + { + return GetConfigObject()->GetProperty(key, value); + } + + template + void SetTag(const string& key, const T& value) + { + GetConfigObject()->SetTag(key, value); + } + + template + bool GetTag(const string& key, T *value) const + { + return GetConfigObject()->GetTag(key, value); + } + private: ConfigObject::Ptr m_ConfigObject; }; } -#endif /* CONFIGOBJECTADAPTER_H */ \ No newline at end of file +#endif /* CONFIGOBJECTADAPTER_H */ diff --git a/cib/host.cpp b/cib/host.cpp index a156113a4..de2787d92 100644 --- a/cib/host.cpp +++ b/cib/host.cpp @@ -6,7 +6,7 @@ string Host::GetAlias(void) const { string value; - if (GetConfigObject()->GetProperty("alias", &value)) + if (GetProperty("alias", &value)) return value; return GetName(); @@ -30,7 +30,7 @@ Host Host::GetByName(const string& name) Dictionary::Ptr Host::GetGroups(void) const { Dictionary::Ptr value; - GetConfigObject()->GetProperty("hostgroups", &value); + GetProperty("hostgroups", &value); return value; } @@ -40,7 +40,7 @@ set Host::GetParents(void) const Dictionary::Ptr dependencies; - if (GetConfigObject()->GetProperty("dependencies", &dependencies)) { + if (GetProperty("dependencies", &dependencies)) { dependencies = Service::ResolveDependencies(*this, dependencies); Dictionary::Iterator it; @@ -63,7 +63,7 @@ set Host::GetParents(void) const bool Host::IsReachable(void) const { Dictionary::Ptr dependencies; - if (GetConfigObject()->GetProperty("dependencies", &dependencies)) { + if (GetProperty("dependencies", &dependencies)) { dependencies = Service::ResolveDependencies(*this, dependencies); Dictionary::Iterator it; @@ -83,7 +83,7 @@ bool Host::IsReachable(void) const bool Host::IsUp(void) const { Dictionary::Ptr hostchecks; - if (GetConfigObject()->GetProperty("hostchecks", &hostchecks)) { + if (GetProperty("hostchecks", &hostchecks)) { hostchecks = Service::ResolveDependencies(*this, hostchecks); Dictionary::Iterator it; diff --git a/cib/hostgroup.cpp b/cib/hostgroup.cpp index 6c8f2c398..90ceb8875 100644 --- a/cib/hostgroup.cpp +++ b/cib/hostgroup.cpp @@ -6,7 +6,7 @@ string HostGroup::GetAlias(void) const { string value; - if (GetConfigObject()->GetProperty("alias", &value)) + if (GetProperty("alias", &value)) return value; return GetName(); @@ -15,14 +15,14 @@ string HostGroup::GetAlias(void) const string HostGroup::GetNotesUrl(void) const { string value; - GetConfigObject()->GetProperty("notes_url", &value); + GetProperty("notes_url", &value); return value; } string HostGroup::GetActionUrl(void) const { string value; - GetConfigObject()->GetProperty("action_url", &value); + GetProperty("action_url", &value); return value; } diff --git a/cib/service.cpp b/cib/service.cpp index ba9c4d68d..8fcc28dd5 100644 --- a/cib/service.cpp +++ b/cib/service.cpp @@ -8,7 +8,7 @@ string Service::GetAlias(void) const { string value; - if (GetConfigObject()->GetProperty("alias", &value)) + if (GetProperty("alias", &value)) return value; return GetName(); @@ -32,7 +32,7 @@ Service Service::GetByName(const string& name) Host Service::GetHost(void) const { string hostname; - if (!GetConfigObject()->GetProperty("host_name", &hostname)) + if (!GetProperty("host_name", &hostname)) throw runtime_error("Service object is missing the 'host_name' property."); return Host::GetByName(hostname); @@ -41,35 +41,35 @@ Host Service::GetHost(void) const Dictionary::Ptr Service::GetMacros(void) const { Dictionary::Ptr macros; - GetConfigObject()->GetProperty("macros", ¯os); + GetProperty("macros", ¯os); return macros; } string Service::GetCheckType(void) const { string value = "nagios"; - GetConfigObject()->GetProperty("check_type", &value); + GetProperty("check_type", &value); return value; } string Service::GetCheckCommand(void) const { string value; - GetConfigObject()->GetProperty("check_command", &value); + GetProperty("check_command", &value); return value; } long Service::GetMaxCheckAttempts(void) const { long value = 3; - GetConfigObject()->GetProperty("max_check_attempts", &value); + GetProperty("max_check_attempts", &value); return value; } long Service::GetCheckInterval(void) const { long value = 300; - GetConfigObject()->GetProperty("check_interval", &value); + GetProperty("check_interval", &value); if (value < 15) value = 15; @@ -80,7 +80,7 @@ long Service::GetCheckInterval(void) const long Service::GetRetryInterval(void) const { long value; - if (!GetConfigObject()->GetProperty("retry_interval", &value)) + if (!GetProperty("retry_interval", &value)) value = GetCheckInterval() / 5; return value; @@ -89,7 +89,7 @@ long Service::GetRetryInterval(void) const Dictionary::Ptr Service::GetDependencies(void) const { Dictionary::Ptr value; - GetConfigObject()->GetProperty("dependencies", &value); + GetProperty("dependencies", &value); return value; } @@ -116,14 +116,14 @@ void Service::GetDependenciesRecursive(const Dictionary::Ptr& result) const { Dictionary::Ptr Service::GetGroups(void) const { Dictionary::Ptr value; - GetConfigObject()->GetProperty("servicegroups", &value); + GetProperty("servicegroups", &value); return value; } Dictionary::Ptr Service::GetCheckers(void) const { Dictionary::Ptr value; - GetConfigObject()->GetProperty("checkers", &value); + GetProperty("checkers", &value); return value; } @@ -154,13 +154,13 @@ bool Service::IsReachable(void) const void Service::SetNextCheck(time_t nextCheck) { - GetConfigObject()->SetTag("next_check", (long)nextCheck); + SetTag("next_check", (long)nextCheck); } time_t Service::GetNextCheck(void) { long value; - if (!GetConfigObject()->GetTag("next_check", &value)) { + if (!GetTag("next_check", &value)) { value = time(NULL) + rand() % GetCheckInterval(); SetNextCheck(value); } @@ -180,93 +180,93 @@ void Service::UpdateNextCheck(void) void Service::SetChecker(const string& checker) { - GetConfigObject()->SetTag("checker", checker); + SetTag("checker", checker); } string Service::GetChecker(void) const { string value; - GetConfigObject()->GetTag("checker", &value); + GetTag("checker", &value); return value; } void Service::SetCurrentCheckAttempt(long attempt) { - GetConfigObject()->SetTag("check_attempt", attempt); + SetTag("check_attempt", attempt); } long Service::GetCurrentCheckAttempt(void) const { long value = 1; - GetConfigObject()->GetTag("check_attempt", &value); + GetTag("check_attempt", &value); return value; } void Service::SetState(ServiceState state) { - GetConfigObject()->SetTag("state", static_cast(state)); + SetTag("state", static_cast(state)); } ServiceState Service::GetState(void) const { long value = StateUnknown; - GetConfigObject()->GetTag("state", &value); + GetTag("state", &value); return static_cast(value); } void Service::SetStateType(ServiceStateType type) { - GetConfigObject()->SetTag("state_type", static_cast(type)); + SetTag("state_type", static_cast(type)); } ServiceStateType Service::GetStateType(void) const { long value = StateTypeHard; - GetConfigObject()->GetTag("state_type", &value); + GetTag("state_type", &value); return static_cast(value); } void Service::SetLastCheckResult(const CheckResult& result) { - GetConfigObject()->SetTag("last_result", result.GetDictionary()); + SetTag("last_result", result.GetDictionary()); } bool Service::HasLastCheckResult(void) const { Dictionary::Ptr value; - return GetConfigObject()->GetTag("last_result", &value) && value; + return GetTag("last_result", &value) && value; } CheckResult Service::GetLastCheckResult(void) const { Dictionary::Ptr value; - if (!GetConfigObject()->GetTag("last_result", &value)) + if (!GetTag("last_result", &value)) throw invalid_argument("Service has no last check result."); return CheckResult(value); } void Service::SetLastStateChange(time_t ts) { - GetConfigObject()->SetTag("last_state_change", static_cast(ts)); + SetTag("last_state_change", static_cast(ts)); } time_t Service::GetLastStateChange(void) const { long value; - if (!GetConfigObject()->GetTag("last_state_change", &value)) + if (!GetTag("last_state_change", &value)) value = IcingaApplication::GetInstance()->GetStartTime(); return value; } void Service::SetLastHardStateChange(time_t ts) { - GetConfigObject()->SetTag("last_hard_state_change", static_cast(ts)); + SetTag("last_hard_state_change", static_cast(ts)); } time_t Service::GetLastHardStateChange(void) const { long value; - if (!GetConfigObject()->GetTag("last_hard_state_change", &value)) + if (!GetTag("last_hard_state_change", &value)) value = IcingaApplication::GetInstance()->GetStartTime(); return value; } @@ -370,7 +370,7 @@ bool Service::IsAllowedChecker(const string& checker) const Dictionary::Ptr Service::ResolveDependencies(Host host, const Dictionary::Ptr& dependencies) { Dictionary::Ptr services; - host.GetConfigObject()->GetProperty("services", &services); + host.GetProperty("services", &services); Dictionary::Ptr result = boost::make_shared(); diff --git a/cib/servicegroup.cpp b/cib/servicegroup.cpp index 769f21081..39363f0a4 100644 --- a/cib/servicegroup.cpp +++ b/cib/servicegroup.cpp @@ -6,7 +6,7 @@ string ServiceGroup::GetAlias(void) const { string value; - if (GetConfigObject()->GetProperty("alias", &value)) + if (GetProperty("alias", &value)) return value; return GetName(); @@ -15,14 +15,14 @@ string ServiceGroup::GetAlias(void) const string ServiceGroup::GetNotesUrl(void) const { string value; - GetConfigObject()->GetProperty("notes_url", &value); + GetProperty("notes_url", &value); return value; } string ServiceGroup::GetActionUrl(void) const { string value; - GetConfigObject()->GetProperty("action_url", &value); + GetProperty("action_url", &value); return value; }