mirror of https://github.com/Icinga/icinga2.git
Added GetProperty/SetTag/GetTag accessors to ConfigObjectAdapter.
This commit is contained in:
parent
c7788f73c2
commit
16e8d131fb
|
@ -18,6 +18,24 @@ 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;
|
||||
};
|
||||
|
|
10
cib/host.cpp
10
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<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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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>();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue