]> granicus.if.org Git - icinga2/commitdiff
Build fixes and code cleanup.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 3 Aug 2012 11:19:55 +0000 (13:19 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 3 Aug 2012 11:19:55 +0000 (13:19 +0200)
24 files changed:
base/application.cpp
base/dictionary.cpp
base/dynamicobject.cpp
base/dynamicobject.h
base/event.cpp
base/logger.cpp
base/object.cpp
base/object.h
base/qstring.cpp
base/qstring.h
base/timer.cpp
base/value.cpp
base/value.h
cib/host.cpp
cib/hostgroup.cpp
cib/service.cpp
cib/servicegroup.cpp
components/checker/checkercomponent.cpp
components/cibsync/cibsynccomponent.cpp
components/convenience/conveniencecomponent.cpp
components/convenience/conveniencecomponent.h
components/discovery/discoverycomponent.cpp
icinga-app/Makefile.am
icinga/icingaapplication.cpp

index c841110d666b8883331db9b39b448d808d5e7d60..496a719a2abd340632f582cd0371fbb35f06dfa9 100644 (file)
@@ -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 */
        }
 }
 
index 986e3d70a4e8f03c88f3dd835d5c7fbb3cbe9a90..3ac9845fbca443abea12b5b245ee0623f277e66c 100644 (file)
@@ -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);
 }
 
 /**
index de63cff7d2619ba03d6cf5e5620f769d370fd3c3..95f66f6fd3f54a92833a982d4b8c1086598db0e0 100644 (file)
@@ -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<DynamicObject::NameMap::iterator, DynamicObject::NameMap::iterator> Dynamic
 ScriptTask::Ptr DynamicObject::InvokeMethod(const String& method,
     const vector<Value>& arguments, ScriptTask::CompletionCallback callback)
 {
-       Dictionary::Ptr methods;
-       if (!GetAttribute("methods", &methods) || !methods->Contains(method))
+       Value value = Get("methods");
+
+       if (!value.IsObjectType<Dictionary>())
+               return ScriptTask::Ptr();
+
+       Dictionary::Ptr methods = value;
+       if (!methods->Contains(method))
                return ScriptTask::Ptr();
 
        String funcName = methods->Get(method);
index 36f4e89f6739a2174935cff8614ef3a096123399..5a663e1a3d88dea8d8e60583f649c28bef209663 100644 (file)
@@ -76,21 +76,8 @@ public:
 
        void RegisterAttribute(const String& name, DynamicAttributeType type);
 
-       void SetAttribute(const String& name, const Value& data);
-
-       template<typename T>
-       bool GetAttribute(const String& name, T *retval) const
-       {
-               Value data = InternalGetAttribute(name);
-
-               if (data.IsEmpty())
-                       return false;
-
-               *retval = static_cast<T>(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;
 
index 83ac4f0155c93adee0542282135161522ddc9e9c..404ad5c6ed334693c056e34be5e8e9eca152d830 100644 (file)
@@ -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());
+               }
        }
 }
 
index f3dea58cce3d294439aaf6515ef25004be9b7036..632442d6a2729af6571a798875b997aaad4a66fd 100644 (file)
@@ -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<StreamLogger>();
@@ -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);
 }
 
 /**
index 3344804678978394a82f90c45547ddf26b0d0540..20d9b2c784e55228f33f54fb6fab883d40b84e79 100644 (file)
 
 using namespace icinga;
 
+mutex Object::m_Mutex;
 vector<Object::Ptr> Object::m_HeldObjects;
+#ifdef _DEBUG
+set<Object *> 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<String, int> types;
+
+       ofstream dictfp("dictionaries.dump.tmp");
+
+       {
+               mutex::scoped_lock lock(m_Mutex);
+               set<Object *>::iterator it;
+               BOOST_FOREACH(Object *obj, m_AliveObjects) {
+                       pair<map<String, int>::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 */
index 5232f7c534e4ced58cdb1b54b49c33e400fec368..571b7d5d86e5762f40f0636d944f3acb0d93be95 100644 (file)
@@ -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<Object::Ptr> m_HeldObjects;
+#ifdef _DEBUG
+       static set<Object *> m_AliveObjects;
+#endif /* _DEBUG */
 };
 
 /**
index 6a511842a398f3e983aefe2752568791506330b0..bd26dc30e3138c9341e434b339f590183aefe004 100644 (file)
@@ -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<std::string>(rhs);
 }
 
+bool icinga::operator!=(const String& lhs, const String& rhs)
+{
+       return static_cast<std::string>(lhs) != static_cast<std::string>(rhs);
+}
+
+bool icinga::operator!=(const String& lhs, const char *rhs)
+{
+       return static_cast<std::string>(lhs) != rhs;
+}
+
+bool icinga::operator!=(const char *lhs, const String& rhs)
+{
+       return lhs != static_cast<std::string>(rhs);
+}
+
 String::Iterator icinga::range_begin(String& x)
 {
        return x.Begin();
index cfb6e89d04060ddc5f8d3e2a4ab23f175c5465c6..6f18540620394cb1c4e5138bb215f6d62444644a 100644 (file)
@@ -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);
index 75b927f62976336e9c35697e952f6dc12bf344a1..cf2eac609d6ccc1dbfe4f033b15afd174668f488 100644 (file)
@@ -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());
index 9229e7ab0744954589c0b03e2714debb22e1a155..90446c8310b1869e654e624b51d586a941c6312f 100644 (file)
@@ -22,6 +22,8 @@
 
 using namespace icinga;
 
+Value Empty;
+
 /**
  * Checks whether the variant is empty.
  *
index 8cd2a6d24c913e56992f991e65e621ef664a1d80..5c52e79cc44631598299cf02a4782d3b661a22cf 100644 (file)
@@ -131,6 +131,8 @@ private:
        mutable boost::variant<boost::blank, double, String, Object::Ptr> m_Value;
 };
 
+static Value Empty;
+
 }
 
 #endif /* VALUE_H */
index eb4c1444746693e7933f742c082ce2180d60f68d..6211520c5508a3b36b25dd53354562d3cf85830f 100644 (file)
@@ -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<String> Host::GetParents(void)
 {
        set<String> parents;
 
-       Dictionary::Ptr dependencies;
-       GetAttribute("dependencies", &dependencies);
+       Dictionary::Ptr dependencies = Get("dependencies");
        if (dependencies) {
                dependencies = Service::ResolveDependencies(GetSelf(), dependencies);
 
@@ -89,15 +86,12 @@ set<String> 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);
 
index 7ce53877bdcfaffe2165d370a204dd5e25b0509a..10a59124177708fd7cb565fb60914dc0103905c0 100644 (file)
@@ -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)
index 959ac1c7fa1764f27a63963da63294110a90a31c..16ace8eb356a4991b2aef12aba9073ec6c41e176 100644 (file)
@@ -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", &macros);
-       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<long>(state));
+       Set("state", static_cast<long>(state));
 }
 
 ServiceState Service::GetState(void) const
 {
-       long value = StateUnknown;
-       GetAttribute("state", &value);
-       return static_cast<ServiceState>(value);
+       Value value = Get("state");
+
+       if (value.IsEmpty())
+               return StateUnknown;
+
+       int ivalue = static_cast<int>(value);
+       return static_cast<ServiceState>(ivalue);
 }
 
 void Service::SetStateType(ServiceStateType type)
 {
-       SetAttribute("state_type", static_cast<long>(type));
+       Set("state_type", static_cast<long>(type));
 }
 
 ServiceStateType Service::GetStateType(void) const
 {
-       long value = StateTypeHard;
-       GetAttribute("state_type", &value);
-       return static_cast<ServiceStateType>(value);
+       Value value = Get("state_type");
+
+       if (value.IsEmpty())
+               return StateTypeHard;
+
+       int ivalue = static_cast<int>(value);
+       return static_cast<ServiceStateType>(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<long>(ts));
+       Set("last_state_change", static_cast<long>(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<Dictionary>();
 
index 79b4e07ea9378fb9f1d00cdc8fbe134aa1df361c..c435d6bec1c74e632d07139dc950403c8481c98b 100644 (file)
@@ -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)
index 7bd888ff8ca840b85abd564061e6bf658dc363de..c67ea518e10e9e439032245cfbaba5924e64d803 100644 (file)
@@ -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();
index db8cab626d87c8acd00c6eb9abea6c898aceda11..71de26a834f2b39098c2620b90554391ed9a6a3c 100644 (file)
@@ -174,6 +174,9 @@ void CIBSyncComponent::LocalObjectUnregisteredHandler(const DynamicObject::Ptr&
 
 void CIBSyncComponent::TransactionClosingHandler(const set<DynamicObject::Ptr>& 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<DynamicObject::Ptr>&
                                continue;
 
                RequestMessage request = MakeObjectMessage(object, "config::ObjectUpdate", DynamicObject::GetCurrentTx(), true);
-
                EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, request);
        }
 }
index 5f9c6391f756e6bfc0ad60904bee27a7a879ae76..50d55ac4b5a09c7336ab33f3b9ef103e01f94adf 100644 (file)
@@ -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<typename TDict>
+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", &macros))
+       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>();
 
-       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>()) {
                                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;
index 3fe0c91806568d6d1a771429ea19e503639b9587..2a5807df8ccbef073c3ae3c77b00908eddc45ad8 100644 (file)
@@ -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);
index ab82a7906c60797470862a0254c464860736e022..a34f1ed8210f8e57b2b838eafee1d04f4370b343 100644 (file)
@@ -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);
                }
index 0f5d58eafe603f25343b30b34381f6f0a4e18f89..d7edd113f0d3c1d79aeb0d7feacdf7d924d28f81 100644 (file)
@@ -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 \
index 17ed3ce56418945a7e325b3fb72f8fc312951c98..582dc79a51026ea649c506613798faba06033d72 100644 (file)
@@ -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<String>& 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<Timer>();
-       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<String>& args)
        cibsyncComponentConfig->SetName("cibsync");
        cibsyncComponentConfig->SetLocal(true);
        cibsyncComponentConfig->Compile()->Commit();
+       cibsyncComponentConfig.reset();
 
        /* load convenience config component */
        ConfigItemBuilder::Ptr convenienceComponentConfig = boost::make_shared<ConfigItemBuilder>();
        convenienceComponentConfig->SetType("Component");
        convenienceComponentConfig->SetName("convenience");
        convenienceComponentConfig->SetLocal(true);
-       //convenienceComponentConfig->Compile()->Commit();
+       convenienceComponentConfig->Compile()->Commit();
+       convenienceComponentConfig.reset();
 
        /* load config file */
        vector<ConfigItem::Ptr> configItems = ConfigCompiler::CompileFile(configFile);
@@ -144,15 +146,18 @@ int IcingaApplication::Main(const vector<String>& 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<ConfigItemBuilder>();
                fileLogConfig->SetType("Logger");