]> granicus.if.org Git - icinga2/commitdiff
Added GetProperty/SetTag/GetTag accessors to ConfigObjectAdapter.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 9 Jul 2012 14:44:46 +0000 (16:44 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 9 Jul 2012 14:44:46 +0000 (16:44 +0200)
cib/configobjectadapter.h
cib/host.cpp
cib/hostgroup.cpp
cib/service.cpp
cib/servicegroup.cpp

index 7f94d6f363b47bfe0cc8f759711d8cdc3e3a4519..702fa8e86eab91e5d0d2f315c90a3f56e33aa9b8 100644 (file)
@@ -18,10 +18,28 @@ public:
 
        ConfigObject::Ptr GetConfigObject() const;
 
+       template<typename T>
+       bool GetProperty(const string& key, T *value) const
+       {
+               return GetConfigObject()->GetProperty(key, value);
+       }
+
+       template<typename T>
+       void SetTag(const string& key, const T& value)
+       {
+               GetConfigObject()->SetTag(key, value);
+       }
+
+       template<typename T>
+       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 */
index a156113a49205a25ee71905f6a4c2668a7ae9047..de2787d92e120ee36cda858c24dd7c71979eeecd 100644 (file)
@@ -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<string> 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<string> 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;
index 6c8f2c3988dd3c95a4a62daef301e769abbc4efd..90ceb88753b0ecb1a85a9ed605b6545284b20b78 100644 (file)
@@ -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;
 }
 
index ba9c4d68d85a8d047471c2bbf897a2e18f6f9d28..8fcc28dd56744826ce70b0640b5ae8e789a07c7f 100644 (file)
@@ -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", &macros);
+       GetProperty("macros", &macros);
        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<long>(state));
+       SetTag("state", static_cast<long>(state));
 }
 
 ServiceState Service::GetState(void) const
 {
        long value = StateUnknown;
-       GetConfigObject()->GetTag("state", &value);
+       GetTag("state", &value);
        return static_cast<ServiceState>(value);
 }
 
 void Service::SetStateType(ServiceStateType type)
 {
-       GetConfigObject()->SetTag("state_type", static_cast<long>(type));
+       SetTag("state_type", static_cast<long>(type));
 }
 
 ServiceStateType Service::GetStateType(void) const
 {
        long value = StateTypeHard;
-       GetConfigObject()->GetTag("state_type", &value);
+       GetTag("state_type", &value);
        return static_cast<ServiceStateType>(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<long>(ts));
+       SetTag("last_state_change", static_cast<long>(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<long>(ts));
+       SetTag("last_hard_state_change", static_cast<long>(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<Dictionary>();
 
index 769f21081efc648da2a2633a964c35cc95c66465..39363f0a492d86e2a3af235ecb9629670ee2081a 100644 (file)
@@ -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;
 }