From d789cee4437017132d22b114a047468076c551c3 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 3 Aug 2012 13:19:55 +0200 Subject: [PATCH] Build fixes and code cleanup. --- base/application.cpp | 8 ++ base/dictionary.cpp | 6 +- base/dynamicobject.cpp | 57 ++++---- base/dynamicobject.h | 17 +-- base/event.cpp | 10 ++ base/logger.cpp | 16 ++- base/object.cpp | 60 +++++++- base/object.h | 9 ++ base/qstring.cpp | 16 +++ base/qstring.h | 4 + base/timer.cpp | 2 +- base/value.cpp | 2 + base/value.h | 2 + cib/host.cpp | 21 +-- cib/hostgroup.cpp | 11 +- cib/service.cpp | 135 ++++++++++-------- cib/servicegroup.cpp | 11 +- components/checker/checkercomponent.cpp | 4 +- components/cibsync/cibsynccomponent.cpp | 4 +- .../convenience/conveniencecomponent.cpp | 49 ++++--- components/convenience/conveniencecomponent.h | 1 - components/discovery/discoverycomponent.cpp | 11 +- icinga-app/Makefile.am | 2 + icinga/icingaapplication.cpp | 27 ++-- 24 files changed, 295 insertions(+), 190 deletions(-) diff --git a/base/application.cpp b/base/application.cpp index c841110d6..496a719a2 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -94,6 +94,14 @@ void Application::RunEventLoop(void) DynamicObject::FinishTx(); DynamicObject::BeginTx(); + +#ifdef _DEBUG + stringstream msgbuf; + msgbuf << "Active objects: " << Object::GetAliveObjects(); + Logger::Write(LogInformation, "base", msgbuf.str()); + + Object::PrintMemoryProfile(); +#endif /* _DEBUG */ } } diff --git a/base/dictionary.cpp b/base/dictionary.cpp index 986e3d70a..3ac9845fb 100644 --- a/base/dictionary.cpp +++ b/base/dictionary.cpp @@ -34,7 +34,7 @@ Value Dictionary::Get(const String& key) const it = m_Data.find(key); if (it == m_Data.end()) - return Value(); + return Empty; return it->second; } @@ -140,7 +140,7 @@ void Dictionary::Remove(const String& key) m_Data.erase(it); - OnItemModified(key, Value()); + OnItemModified(key, Empty); } /** @@ -153,7 +153,7 @@ void Dictionary::Remove(Dictionary::Iterator it) String key = it->first; m_Data.erase(it); - OnItemModified(key, Value()); + OnItemModified(key, Empty); } /** diff --git a/base/dynamicobject.cpp b/base/dynamicobject.cpp index de63cff7d..95f66f6fd 100644 --- a/base/dynamicobject.cpp +++ b/base/dynamicobject.cpp @@ -168,11 +168,16 @@ void DynamicObject::RegisterAttribute(const String& name, DynamicAttributeType t tt.first->second.Type = type; } -void DynamicObject::SetAttribute(const String& name, const Value& data) +void DynamicObject::Set(const String& name, const Value& data) { InternalSetAttribute(name, data, GetCurrentTx()); } +Value DynamicObject::Get(const String& name) const +{ + return InternalGetAttribute(name); +} + void DynamicObject::InternalSetAttribute(const String& name, const Value& data, double tx, bool suppressEvent) { DynamicAttribute attr; @@ -203,14 +208,9 @@ Value DynamicObject::InternalGetAttribute(const String& name) const it = m_Attributes.find(name); if (it == m_Attributes.end()) - return Value(); - else - return it->second.Data; -} + return Empty; -void DynamicObject::ClearAttribute(const String& name) -{ - SetAttribute(name, Value()); + return it->second.Data; } bool DynamicObject::HasAttribute(const String& name) const @@ -246,42 +246,42 @@ DynamicObject::AttributeConstIterator DynamicObject::AttributeEnd(void) const String DynamicObject::GetType(void) const { - String type; - GetAttribute("__type", &type); - return type; + return Get("__type"); } String DynamicObject::GetName(void) const { - String name; - GetAttribute("__name", &name); - return name; + return Get("__name"); } bool DynamicObject::IsLocal(void) const { - long local = 0; - GetAttribute("__local", &local); - return (local != 0); + Value value = Get("__local"); + + if (value.IsEmpty()) + return false; + + return (value != 0); } bool DynamicObject::IsAbstract(void) const { - long abstract = 0; - GetAttribute("__abstract", &abstract); - return (abstract != 0); + Value value = Get("__abstract"); + + if (value.IsEmpty()) + return false; + + return (value != 0); } void DynamicObject::SetSource(const String& value) { - SetAttribute("__source", value); + Set("__source", value); } String DynamicObject::GetSource(void) const { - String source; - GetAttribute("__source", &source); - return source; + return Get("__source"); } void DynamicObject::Register(void) @@ -351,8 +351,13 @@ pair Dynamic ScriptTask::Ptr DynamicObject::InvokeMethod(const String& method, const vector& arguments, ScriptTask::CompletionCallback callback) { - Dictionary::Ptr methods; - if (!GetAttribute("methods", &methods) || !methods->Contains(method)) + Value value = Get("methods"); + + if (!value.IsObjectType()) + return ScriptTask::Ptr(); + + Dictionary::Ptr methods = value; + if (!methods->Contains(method)) return ScriptTask::Ptr(); String funcName = methods->Get(method); diff --git a/base/dynamicobject.h b/base/dynamicobject.h index 36f4e89f6..5a663e1a3 100644 --- a/base/dynamicobject.h +++ b/base/dynamicobject.h @@ -76,21 +76,8 @@ public: void RegisterAttribute(const String& name, DynamicAttributeType type); - void SetAttribute(const String& name, const Value& data); - - template - bool GetAttribute(const String& name, T *retval) const - { - Value data = InternalGetAttribute(name); - - if (data.IsEmpty()) - return false; - - *retval = static_cast(data); - return true; - } - - void ClearAttribute(const String& name); + void Set(const String& name, const Value& data); + Value Get(const String& name) const; bool HasAttribute(const String& name) const; diff --git a/base/event.cpp b/base/event.cpp index 83ac4f015..404ad5c6e 100644 --- a/base/event.cpp +++ b/base/event.cpp @@ -45,7 +45,17 @@ void Event::ProcessEvents(const system_time& wait_until) } BOOST_FOREACH(const Event& ev, events) { + double st = Utility::GetTime(); + ev.m_Callback(); + + double et = Utility::GetTime(); + + if (et - st > 1.0) { + stringstream msgbuf; + msgbuf << "Event call took " << et - st << " seconds."; + Logger::Write(LogWarning, "base", msgbuf.str()); + } } } diff --git a/base/logger.cpp b/base/logger.cpp index f3dea58cc..632442d6a 100644 --- a/base/logger.cpp +++ b/base/logger.cpp @@ -39,8 +39,8 @@ Logger::Logger(const Dictionary::Ptr& properties) if (!IsLocal()) throw_exception(runtime_error("Logger objects must be local.")); - String type; - if (!GetAttribute("type", &type)) + String type = Get("type"); + if (type.IsEmpty()) throw_exception(runtime_error("Logger objects must have a 'type' property.")); ILogger::Ptr impl; @@ -52,8 +52,8 @@ Logger::Logger(const Dictionary::Ptr& properties) throw_exception(invalid_argument("Syslog is not supported on Windows.")); #endif /* _WIN32 */ } else if (type == "file") { - String path; - if (!GetAttribute("path", &path)) + String path = Get("path"); + if (path.IsEmpty()) throw_exception(invalid_argument("'log' object of type 'file' must have a 'path' property")); StreamLogger::Ptr slogger = boost::make_shared(); @@ -96,9 +96,11 @@ void Logger::Write(LogSeverity severity, const String& facility, */ LogSeverity Logger::GetMinSeverity(void) const { - String strSeverity = "information"; - GetAttribute("severity", &strSeverity); - return Logger::StringToSeverity(strSeverity); + String severity = Get("severity"); + if (severity.IsEmpty()) + return LogInformation; + else + return Logger::StringToSeverity(severity); } /** diff --git a/base/object.cpp b/base/object.cpp index 334480467..20d9b2c78 100644 --- a/base/object.cpp +++ b/base/object.cpp @@ -21,19 +21,33 @@ using namespace icinga; +mutex Object::m_Mutex; vector Object::m_HeldObjects; +#ifdef _DEBUG +set Object::m_AliveObjects; +#endif /* _DEBUG */ /** * Default constructor for the Object class. */ Object::Object(void) -{ } +{ +#ifdef _DEBUG + mutex::scoped_lock lock(m_Mutex); + m_AliveObjects.insert(this); +#endif /* _DEBUG */ +} /** * Destructor for the Object class. */ Object::~Object(void) -{ } +{ +#ifdef _DEBUG + mutex::scoped_lock lock(m_Mutex); + m_AliveObjects.erase(this); +#endif /* _DEBUG */ +} /** * Temporarily holds onto a reference for an object. This can @@ -42,6 +56,7 @@ Object::~Object(void) */ void Object::Hold(void) { + mutex::scoped_lock lock(m_Mutex); m_HeldObjects.push_back(GetSelf()); } @@ -50,6 +65,7 @@ void Object::Hold(void) */ void Object::ClearHeldObjects(void) { + mutex::scoped_lock lock(m_Mutex); m_HeldObjects.clear(); } @@ -57,3 +73,43 @@ Object::SharedPtrHolder Object::GetSelf(void) { return Object::SharedPtrHolder(shared_from_this()); } + +#ifdef _DEBUG +int Object::GetAliveObjects(void) +{ + mutex::scoped_lock lock(m_Mutex); + return m_AliveObjects.size(); +} + +void Object::PrintMemoryProfile(void) +{ + map types; + + ofstream dictfp("dictionaries.dump.tmp"); + + { + mutex::scoped_lock lock(m_Mutex); + set::iterator it; + BOOST_FOREACH(Object *obj, m_AliveObjects) { + pair::iterator, bool> tt; + tt = types.insert(make_pair(Utility::GetTypeName(typeid(*obj)), 1)); + if (!tt.second) + tt.first->second++; + + if (typeid(*obj) == typeid(Dictionary)) { + Dictionary::Ptr dict = obj->GetSelf(); + dictfp << Value(dict).Serialize() << std::endl; + } + } + } + + dictfp.close(); + rename("dictionaries.dump.tmp", "dictionaries.dump"); + + String type; + int count; + BOOST_FOREACH(tie(type, count), types) { + std::cerr << type << ": " << count << std::endl; + } +} +#endif /* _DEBUG */ diff --git a/base/object.h b/base/object.h index 5232f7c53..571b7d5d8 100644 --- a/base/object.h +++ b/base/object.h @@ -75,6 +75,11 @@ public: SharedPtrHolder GetSelf(void); +#ifdef _DEBUG + static int GetAliveObjects(void); + static void PrintMemoryProfile(void); +#endif /* _DEBUG */ + protected: Object(void); virtual ~Object(void); @@ -83,7 +88,11 @@ private: Object(const Object& other); Object operator=(const Object& rhs); + static mutex m_Mutex; static vector m_HeldObjects; +#ifdef _DEBUG + static set m_AliveObjects; +#endif /* _DEBUG */ }; /** diff --git a/base/qstring.cpp b/base/qstring.cpp index 6a511842a..bd26dc30e 100644 --- a/base/qstring.cpp +++ b/base/qstring.cpp @@ -5,6 +5,7 @@ using namespace icinga; const size_t String::NPos = std::string::npos; String::String(void) + : m_Data() { } String::String(const char *data) @@ -183,6 +184,21 @@ bool icinga::operator==(const char *lhs, const String& rhs) return lhs == static_cast(rhs); } +bool icinga::operator!=(const String& lhs, const String& rhs) +{ + return static_cast(lhs) != static_cast(rhs); +} + +bool icinga::operator!=(const String& lhs, const char *rhs) +{ + return static_cast(lhs) != rhs; +} + +bool icinga::operator!=(const char *lhs, const String& rhs) +{ + return lhs != static_cast(rhs); +} + String::Iterator icinga::range_begin(String& x) { return x.Begin(); diff --git a/base/qstring.h b/base/qstring.h index cfb6e89d0..6f1854062 100644 --- a/base/qstring.h +++ b/base/qstring.h @@ -85,6 +85,10 @@ I2_BASE_API bool operator==(const String& lhs, const String& rhs); I2_BASE_API bool operator==(const String& lhs, const char *rhs); I2_BASE_API bool operator==(const char *lhs, const String& rhs); +I2_BASE_API bool operator!=(const String& lhs, const String& rhs); +I2_BASE_API bool operator!=(const String& lhs, const char *rhs); +I2_BASE_API bool operator!=(const char *lhs, const String& rhs); + I2_BASE_API String::Iterator range_begin(String& x); I2_BASE_API String::ConstIterator range_begin(const String& x); I2_BASE_API String::Iterator range_end(String& x); diff --git a/base/timer.cpp b/base/timer.cpp index 75b927f62..cf2eac609 100644 --- a/base/timer.cpp +++ b/base/timer.cpp @@ -96,7 +96,7 @@ void Timer::Call(void) double et = Utility::GetTime(); - if (et - st > 3) { + if (et - st > 1.0) { stringstream msgbuf; msgbuf << "Timer call took " << et - st << " seconds."; Logger::Write(LogWarning, "base", msgbuf.str()); diff --git a/base/value.cpp b/base/value.cpp index 9229e7ab0..90446c831 100644 --- a/base/value.cpp +++ b/base/value.cpp @@ -22,6 +22,8 @@ using namespace icinga; +Value Empty; + /** * Checks whether the variant is empty. * diff --git a/base/value.h b/base/value.h index 8cd2a6d24..5c52e79cc 100644 --- a/base/value.h +++ b/base/value.h @@ -131,6 +131,8 @@ private: mutable boost::variant m_Value; }; +static Value Empty; + } #endif /* VALUE_H */ diff --git a/cib/host.cpp b/cib/host.cpp index eb4c14447..6211520c5 100644 --- a/cib/host.cpp +++ b/cib/host.cpp @@ -32,8 +32,8 @@ Host::Host(const Dictionary::Ptr& properties) String Host::GetAlias(void) const { - String value; - if (GetAttribute("alias", &value)) + String value = Get("alias"); + if (!value.IsEmpty()) return value; else return GetName(); @@ -56,17 +56,14 @@ Host::Ptr Host::GetByName(const String& name) Dictionary::Ptr Host::GetGroups(void) const { - Dictionary::Ptr value; - GetAttribute("hostgroups", &value); - return value; + return Get("hostgroups"); } set Host::GetParents(void) { set parents; - Dictionary::Ptr dependencies; - GetAttribute("dependencies", &dependencies); + Dictionary::Ptr dependencies = Get("dependencies"); if (dependencies) { dependencies = Service::ResolveDependencies(GetSelf(), dependencies); @@ -89,15 +86,12 @@ set Host::GetParents(void) Dictionary::Ptr Host::GetMacros(void) const { - Dictionary::Ptr value; - GetAttribute("macros", &value); - return value; + return Get("macros"); } bool Host::IsReachable(void) { - Dictionary::Ptr dependencies; - GetAttribute("dependencies", &dependencies); + Dictionary::Ptr dependencies = Get("dependencies"); if (dependencies) { dependencies = Service::ResolveDependencies(GetSelf(), dependencies); @@ -117,8 +111,7 @@ bool Host::IsReachable(void) bool Host::IsUp(void) { - Dictionary::Ptr hostchecks; - GetAttribute("hostchecks", &hostchecks); + Dictionary::Ptr hostchecks = Get("hostchecks"); if (hostchecks) { hostchecks = Service::ResolveDependencies(GetSelf(), hostchecks); diff --git a/cib/hostgroup.cpp b/cib/hostgroup.cpp index 7ce53877b..10a591241 100644 --- a/cib/hostgroup.cpp +++ b/cib/hostgroup.cpp @@ -25,8 +25,7 @@ REGISTER_CLASS(HostGroup); String HostGroup::GetAlias(void) const { - String value; - GetAttribute("alias", &value); + String value = Get("alias"); if (!value.IsEmpty()) return value; @@ -36,16 +35,12 @@ String HostGroup::GetAlias(void) const String HostGroup::GetNotesUrl(void) const { - String value; - GetAttribute("notes_url", &value); - return value; + return Get("notes_url"); } String HostGroup::GetActionUrl(void) const { - String value; - GetAttribute("action_url", &value); - return value; + return Get("action_url"); } bool HostGroup::Exists(const String& name) diff --git a/cib/service.cpp b/cib/service.cpp index 959ac1c7f..16ace8eb3 100644 --- a/cib/service.cpp +++ b/cib/service.cpp @@ -52,9 +52,9 @@ Service::Service(const Dictionary::Ptr& serializedObject) String Service::GetAlias(void) const { - String value; + String value = Get("alias"); - if (GetAttribute("alias", &value)) + if (!value.IsEmpty()) return value; return GetName(); @@ -77,8 +77,9 @@ Service::Ptr Service::GetByName(const String& name) Host::Ptr Service::GetHost(void) const { - String hostname; - if (!GetAttribute("host_name", &hostname)) + String hostname = Get("host_name"); + + if (hostname.IsEmpty()) throw_exception(runtime_error("Service object is missing the 'host_name' property.")); return Host::GetByName(hostname); @@ -86,29 +87,30 @@ Host::Ptr Service::GetHost(void) const Dictionary::Ptr Service::GetMacros(void) const { - Dictionary::Ptr macros; - GetAttribute("macros", ¯os); - return macros; + return Get("macros"); } String Service::GetCheckCommand(void) const { - String value; - GetAttribute("check_command", &value); - return value; + return Get("check_command"); } long Service::GetMaxCheckAttempts(void) const { - long value = 3; - GetAttribute("max_check_attempts", &value); + Value value = Get("max_check_attempts"); + + if (value.IsEmpty()) + return 3; + return value; } long Service::GetCheckInterval(void) const { - long value = 300; - GetAttribute("check_interval", &value); + Value value = Get("check_interval"); + + if (value.IsEmpty()) + return 300; if (value < 15) value = 15; @@ -118,18 +120,17 @@ long Service::GetCheckInterval(void) const long Service::GetRetryInterval(void) const { - long value; - if (!GetAttribute("retry_interval", &value)) - value = GetCheckInterval() / 5; + Value value = Get("retry_interval"); + + if (value.IsEmpty()) + return GetCheckInterval() / 5; return value; } Dictionary::Ptr Service::GetDependencies(void) const { - Dictionary::Ptr value; - GetAttribute("dependencies", &value); - return value; + return Get("dependencies"); } void Service::GetDependenciesRecursive(const Dictionary::Ptr& result) const { @@ -154,16 +155,12 @@ void Service::GetDependenciesRecursive(const Dictionary::Ptr& result) const { Dictionary::Ptr Service::GetGroups(void) const { - Dictionary::Ptr value; - GetAttribute("servicegroups", &value); - return value; + return Get("servicegroups"); } Dictionary::Ptr Service::GetCheckers(void) const { - Dictionary::Ptr value; - GetAttribute("checkers", &value); - return value; + return Get("checkers"); } bool Service::IsReachable(void) const @@ -200,33 +197,39 @@ bool Service::IsReachable(void) const void Service::SetSchedulingOffset(long offset) { - SetAttribute("scheduling_offset", offset); + Set("scheduling_offset", offset); } long Service::GetSchedulingOffset(void) { - long value; - if (!GetAttribute("scheduling_offset", &value)) { + Value value = Get("scheduling_offset"); + + if (value.IsEmpty()) { value = rand(); SetSchedulingOffset(value); } + return value; } void Service::SetNextCheck(double nextCheck) { - SetAttribute("next_check", nextCheck); + Set("next_check", nextCheck); } double Service::GetNextCheck(void) { - double value; - if (!GetAttribute("next_check", &value)) { + Value value = Get("next_check"); + + if (value.IsEmpty()) { UpdateNextCheck(); - if (!GetAttribute("next_check", &value)) + value = Get("next_check"); + + if (value.IsEmpty()) throw_exception(runtime_error("Failed to schedule next check.")); } + return value; } @@ -246,87 +249,98 @@ void Service::UpdateNextCheck(void) void Service::SetChecker(const String& checker) { - SetAttribute("checker", checker); + Set("checker", checker); } String Service::GetChecker(void) const { - String value; - GetAttribute("checker", &value); - return value; + return Get("checker"); } void Service::SetCurrentCheckAttempt(long attempt) { - SetAttribute("check_attempt", attempt); + Set("check_attempt", attempt); } long Service::GetCurrentCheckAttempt(void) const { - long value = 1; - GetAttribute("check_attempt", &value); + Value value = Get("check_attempt"); + + if (value.IsEmpty()) + return 1; + return value; } void Service::SetState(ServiceState state) { - SetAttribute("state", static_cast(state)); + Set("state", static_cast(state)); } ServiceState Service::GetState(void) const { - long value = StateUnknown; - GetAttribute("state", &value); - return static_cast(value); + Value value = Get("state"); + + if (value.IsEmpty()) + return StateUnknown; + + int ivalue = static_cast(value); + return static_cast(ivalue); } void Service::SetStateType(ServiceStateType type) { - SetAttribute("state_type", static_cast(type)); + Set("state_type", static_cast(type)); } ServiceStateType Service::GetStateType(void) const { - long value = StateTypeHard; - GetAttribute("state_type", &value); - return static_cast(value); + Value value = Get("state_type"); + + if (value.IsEmpty()) + return StateTypeHard; + + int ivalue = static_cast(value); + return static_cast(ivalue); } void Service::SetLastCheckResult(const Dictionary::Ptr& result) { - SetAttribute("last_result", result); + Set("last_result", result); } Dictionary::Ptr Service::GetLastCheckResult(void) const { - Dictionary::Ptr value; - GetAttribute("last_result", &value); - return value; + return Get("last_result"); } void Service::SetLastStateChange(double ts) { - SetAttribute("last_state_change", static_cast(ts)); + Set("last_state_change", static_cast(ts)); } double Service::GetLastStateChange(void) const { - long value; - if (!GetAttribute("last_state_change", &value)) - value = IcingaApplication::GetInstance()->GetStartTime(); + Value value = Get("last_state_change"); + + if (value.IsEmpty()) + return IcingaApplication::GetInstance()->GetStartTime(); + return value; } void Service::SetLastHardStateChange(double ts) { - SetAttribute("last_hard_state_change", ts); + Set("last_hard_state_change", ts); } double Service::GetLastHardStateChange(void) const { - double value; - if (!GetAttribute("last_hard_state_change", &value)) + Value value = Get("last_hard_state_change"); + + if (value.IsEmpty()) value = IcingaApplication::GetInstance()->GetStartTime(); + return value; } @@ -442,8 +456,7 @@ bool Service::IsAllowedChecker(const String& checker) const Dictionary::Ptr Service::ResolveDependencies(const Host::Ptr& host, const Dictionary::Ptr& dependencies) { - Dictionary::Ptr services; - host->GetAttribute("services", &services); + Dictionary::Ptr services = host->Get("services"); Dictionary::Ptr result = boost::make_shared(); diff --git a/cib/servicegroup.cpp b/cib/servicegroup.cpp index 79b4e07ea..c435d6bec 100644 --- a/cib/servicegroup.cpp +++ b/cib/servicegroup.cpp @@ -25,8 +25,7 @@ REGISTER_CLASS(ServiceGroup); String ServiceGroup::GetAlias(void) const { - String value; - GetAttribute("alias", &value); + String value = Get("alias"); if (!value.IsEmpty()) return value; @@ -36,16 +35,12 @@ String ServiceGroup::GetAlias(void) const String ServiceGroup::GetNotesUrl(void) const { - String value; - GetAttribute("notes_url", &value); - return value; + return Get("notes_url"); } String ServiceGroup::GetActionUrl(void) const { - String value; - GetAttribute("action_url", &value); - return value; + return Get("action_url"); } bool ServiceGroup::Exists(const String& name) diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 7bd888ff8..c67ea518e 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -78,7 +78,7 @@ void CheckerComponent::CheckTimerHandler(void) task = service->InvokeMethod("check", arguments, boost::bind(&CheckerComponent::CheckCompletedHandler, this, service, _1)); assert(task); /* TODO: gracefully handle missing methods */ - service->SetAttribute("current_task", task); + service->Set("current_task", task); tasks++; } @@ -92,7 +92,7 @@ void CheckerComponent::CheckTimerHandler(void) void CheckerComponent::CheckCompletedHandler(const Service::Ptr& service, const ScriptTask::Ptr& task) { - service->ClearAttribute("current_task"); + service->Set("current_task", Empty); try { Value vresult = task->GetResult(); diff --git a/components/cibsync/cibsynccomponent.cpp b/components/cibsync/cibsynccomponent.cpp index db8cab626..71de26a83 100644 --- a/components/cibsync/cibsynccomponent.cpp +++ b/components/cibsync/cibsynccomponent.cpp @@ -174,6 +174,9 @@ void CIBSyncComponent::LocalObjectUnregisteredHandler(const DynamicObject::Ptr& void CIBSyncComponent::TransactionClosingHandler(const set& modifiedObjects) { + if (modifiedObjects.empty()) + return; + stringstream msgbuf; msgbuf << "Sending " << modifiedObjects.size() << " replication updates."; Logger::Write(LogInformation, "cibsync", msgbuf.str()); @@ -183,7 +186,6 @@ void CIBSyncComponent::TransactionClosingHandler(const set& continue; RequestMessage request = MakeObjectMessage(object, "config::ObjectUpdate", DynamicObject::GetCurrentTx(), true); - EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, request); } } diff --git a/components/convenience/conveniencecomponent.cpp b/components/convenience/conveniencecomponent.cpp index 5f9c6391f..50d55ac4b 100644 --- a/components/convenience/conveniencecomponent.cpp +++ b/components/convenience/conveniencecomponent.cpp @@ -30,38 +30,40 @@ void ConvenienceComponent::Start(void) ConfigItem::OnRemoved.connect(boost::bind(&ConvenienceComponent::HostRemovedHandler, this, _1)); } -void ConvenienceComponent::CopyServiceAttributes(const Host::Ptr& host, const Dictionary::Ptr& serviceDesc, const ConfigItemBuilder::Ptr& builder) +template +static void CopyServiceAttributes(const Host::Ptr& host, TDict serviceDesc, + const ConfigItemBuilder::Ptr& builder) { /* TODO: we only need to copy macros if this is an inline definition, * i.e. host->GetProperties() != service, however for now we just * copy them anyway. */ - Dictionary::Ptr macros; - if (serviceDesc->Get("macros", ¯os)) + Value macros = serviceDesc->Get("macros"); + if (!macros.IsEmpty()) builder->AddExpression("macros", OperatorPlus, macros); - long checkInterval; - if (serviceDesc->Get("check_interval", &checkInterval)) + Value checkInterval = serviceDesc->Get("check_interval"); + if (!checkInterval.IsEmpty()) builder->AddExpression("check_interval", OperatorSet, checkInterval); - long retryInterval; - if (serviceDesc->Get("retry_interval", &retryInterval)) + Value retryInterval = serviceDesc->Get("retry_interval"); + if (!retryInterval.IsEmpty()) builder->AddExpression("retry_interval", OperatorSet, retryInterval); - Dictionary::Ptr sgroups; - if (serviceDesc->Get("servicegroups", &sgroups)) + Value sgroups = serviceDesc->Get("servicegroups"); + if (!sgroups.IsEmpty()) builder->AddExpression("servicegroups", OperatorPlus, sgroups); - Dictionary::Ptr checkers; - if (serviceDesc->Get("checkers", &checkers)) + Value checkers = serviceDesc->Get("checkers"); + if (!checkers.IsEmpty()) builder->AddExpression("checkers", OperatorSet, checkers); - Dictionary::Ptr dependencies; - if (serviceDesc->Get("dependencies", &dependencies)) + Value dependencies = serviceDesc->Get("dependencies"); + if (!dependencies.IsEmpty()) builder->AddExpression("dependencies", OperatorPlus, Service::ResolveDependencies(host, dependencies)); - Dictionary::Ptr hostchecks; - if (serviceDesc->Get("hostchecks", &hostchecks)) + Value hostchecks = serviceDesc->Get("hostchecks"); + if (!hostchecks.IsEmpty()) builder->AddExpression("dependencies", OperatorPlus, Service::ResolveDependencies(host, hostchecks)); } @@ -77,14 +79,12 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item) if (!host) return; - Dictionary::Ptr oldServices; - host->GetAttribute("convenience_services", &oldServices); + Dictionary::Ptr oldServices = host->Get("convenience_services"); Dictionary::Ptr newServices; newServices = boost::make_shared(); - Dictionary::Ptr serviceDescs; - host->GetAttribute("services", &serviceDescs); + Dictionary::Ptr serviceDescs = host->Get("services"); if (serviceDescs) { String svcname; @@ -100,15 +100,15 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item) builder->AddExpression("host_name", OperatorSet, item->GetName()); builder->AddExpression("alias", OperatorSet, svcname); - CopyServiceAttributes(host, host->GetProperties(), builder); + CopyServiceAttributes(host, host, builder); if (svcdesc.IsScalar()) { builder->AddParent(svcdesc); } else if (svcdesc.IsObjectType()) { Dictionary::Ptr service = svcdesc; - String parent; - if (!service->Get("service", &parent)) + String parent = service->Get("service"); + if (parent.IsEmpty()) parent = svcname; builder->AddParent(parent); @@ -136,7 +136,7 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item) } } - host->SetAttribute("convenience_services", newServices); + host->Set("convenience_services", newServices); } void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item) @@ -149,8 +149,7 @@ void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item) if (!host) return; - Dictionary::Ptr services; - host->GetAttribute("convenience_services", &services); + Dictionary::Ptr services = host->Get("convenience_services"); if (!services) return; diff --git a/components/convenience/conveniencecomponent.h b/components/convenience/conveniencecomponent.h index 3fe0c9180..2a5807df8 100644 --- a/components/convenience/conveniencecomponent.h +++ b/components/convenience/conveniencecomponent.h @@ -32,7 +32,6 @@ public: virtual void Start(void); private: - void CopyServiceAttributes(const Host::Ptr& host, const Dictionary::Ptr& serviceDesc, const ConfigItemBuilder::Ptr& builder); void HostAddedHandler(const ConfigItem::Ptr& item); void HostCommittedHandler(const ConfigItem::Ptr& item); void HostRemovedHandler(const ConfigItem::Ptr& item); diff --git a/components/discovery/discoverycomponent.cpp b/components/discovery/discoverycomponent.cpp index ab82a7906..a34f1ed82 100644 --- a/components/discovery/discoverycomponent.cpp +++ b/components/discovery/discoverycomponent.cpp @@ -316,8 +316,8 @@ bool DiscoveryComponent::HasMessagePermission(const Dictionary::Ptr& roles, cons Value roleName; BOOST_FOREACH(tie(tuples::ignore, roleName), roles) { DynamicObject::Ptr role = DynamicObject::GetObject("Role", roleName); - Dictionary::Ptr permissions; - if (!role->GetAttribute(messageType, &permissions)) + Dictionary::Ptr permissions = role->Get(messageType); + if (!permissions) continue; Value permission; @@ -359,7 +359,7 @@ void DiscoveryComponent::ProcessDiscoveryMessage(const String& identity, const D DynamicObject::Ptr endpointConfig = DynamicObject::GetObject("Endpoint", identity); Dictionary::Ptr roles; if (endpointConfig) - endpointConfig->GetAttribute("roles", &roles); + roles = endpointConfig->Get("roles"); Endpoint::Ptr endpoint = EndpointManager::GetInstance()->GetEndpointByIdentity(identity); @@ -449,8 +449,9 @@ void DiscoveryComponent::DiscoveryTimerHandler(void) if (endpointManager->GetEndpointByIdentity(object->GetName())) continue; - String node, service; - if (object->GetAttribute("node", &node) && object->GetAttribute("service", &service)) { + String node = object->Get("node"); + String service = object->Get("service"); + if (!node.IsEmpty() && !service.IsEmpty()) { /* reconnect to this endpoint */ endpointManager->AddConnection(node, service); } diff --git a/icinga-app/Makefile.am b/icinga-app/Makefile.am index 0f5d58eaf..d7edd113f 100644 --- a/icinga-app/Makefile.am +++ b/icinga-app/Makefile.am @@ -9,6 +9,7 @@ icinga_SOURCES = \ icinga_CPPFLAGS = \ -DI2_ICINGALAUNCHER_BUILD \ + $(LTDLINCL) \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/base \ -I${top_srcdir}/dyn \ @@ -20,6 +21,7 @@ icinga_LDFLAGS = \ $(BOOST_LDFLAGS) icinga_LDADD = \ + $(LIBLTDL) \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/base/libbase.la \ diff --git a/icinga/icingaapplication.cpp b/icinga/icingaapplication.cpp index 17ed3ce56..582dc79a5 100644 --- a/icinga/icingaapplication.cpp +++ b/icinga/icingaapplication.cpp @@ -31,7 +31,6 @@ using namespace icinga; const String IcingaApplication::DefaultPidPath = "icinga.pid"; IcingaApplication::IcingaApplication(void) - : m_PidPath(DefaultPidPath) { } /** @@ -49,13 +48,14 @@ int IcingaApplication::Main(const vector& args) consoleLogConfig->SetLocal(true); consoleLogConfig->AddExpression("type", OperatorSet, "console"); consoleLogConfig->Compile()->Commit(); + consoleLogConfig.reset(); /* restore the previous program state */ DynamicObject::RestoreObjects("retention.dat"); /* periodically dump the program state */ m_RetentionTimer = boost::make_shared(); - m_RetentionTimer->SetInterval(10); + m_RetentionTimer->SetInterval(60); m_RetentionTimer->OnTimerExpired.connect(boost::bind(&IcingaApplication::DumpProgramState, this)); m_RetentionTimer->Start(); @@ -119,13 +119,15 @@ int IcingaApplication::Main(const vector& args) cibsyncComponentConfig->SetName("cibsync"); cibsyncComponentConfig->SetLocal(true); cibsyncComponentConfig->Compile()->Commit(); + cibsyncComponentConfig.reset(); /* load convenience config component */ ConfigItemBuilder::Ptr convenienceComponentConfig = boost::make_shared(); convenienceComponentConfig->SetType("Component"); convenienceComponentConfig->SetName("convenience"); convenienceComponentConfig->SetLocal(true); - //convenienceComponentConfig->Compile()->Commit(); + convenienceComponentConfig->Compile()->Commit(); + convenienceComponentConfig.reset(); /* load config file */ vector configItems = ConfigCompiler::CompileFile(configFile); @@ -144,15 +146,18 @@ int IcingaApplication::Main(const vector& args) if (!icingaConfig->IsLocal()) throw_exception(runtime_error("'icinga' application object must be 'local'.")); - icingaConfig->GetAttribute("cert", &m_CertificateFile); - icingaConfig->GetAttribute("ca", &m_CAFile); - icingaConfig->GetAttribute("node", &m_Node); - icingaConfig->GetAttribute("service", &m_Service); - icingaConfig->GetAttribute("pidpath", &m_PidPath); - icingaConfig->GetAttribute("macros", &m_Macros); + m_CertificateFile = icingaConfig->Get("cert"); + m_CAFile = icingaConfig->Get("ca"); + m_Node = icingaConfig->Get("node"); + m_Service = icingaConfig->Get("service"); + m_PidPath = icingaConfig->Get("pidpath"); - String logpath; - icingaConfig->GetAttribute("logpath", &logpath); + if (m_PidPath.IsEmpty()) + m_PidPath = DefaultPidPath; + + m_Macros = icingaConfig->Get("macros"); + + String logpath = icingaConfig->Get("logpath"); if (!logpath.IsEmpty()) { ConfigItemBuilder::Ptr fileLogConfig = boost::make_shared(); fileLogConfig->SetType("Logger"); -- 2.40.0