DynamicObject::FinishTx();
DynamicObject::BeginTx();
+
+#ifdef _DEBUG
+ stringstream msgbuf;
+ msgbuf << "Active objects: " << Object::GetAliveObjects();
+ Logger::Write(LogInformation, "base", msgbuf.str());
+
+ Object::PrintMemoryProfile();
+#endif /* _DEBUG */
}
}
it = m_Data.find(key);
if (it == m_Data.end())
- return Value();
+ return Empty;
return it->second;
}
m_Data.erase(it);
- OnItemModified(key, Value());
+ OnItemModified(key, Empty);
}
/**
String key = it->first;
m_Data.erase(it);
- OnItemModified(key, Value());
+ OnItemModified(key, Empty);
}
/**
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;
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
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)
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);
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;
}
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());
+ }
}
}
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;
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>();
*/
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);
}
/**
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
*/
void Object::Hold(void)
{
+ mutex::scoped_lock lock(m_Mutex);
m_HeldObjects.push_back(GetSelf());
}
*/
void Object::ClearHeldObjects(void)
{
+ mutex::scoped_lock lock(m_Mutex);
m_HeldObjects.clear();
}
{
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 */
SharedPtrHolder GetSelf(void);
+#ifdef _DEBUG
+ static int GetAliveObjects(void);
+ static void PrintMemoryProfile(void);
+#endif /* _DEBUG */
+
protected:
Object(void);
virtual ~Object(void);
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 */
};
/**
const size_t String::NPos = std::string::npos;
String::String(void)
+ : m_Data()
{ }
String::String(const char *data)
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();
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);
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());
using namespace icinga;
+Value Empty;
+
/**
* Checks whether the variant is empty.
*
mutable boost::variant<boost::blank, double, String, Object::Ptr> m_Value;
};
+static Value Empty;
+
}
#endif /* VALUE_H */
String Host::GetAlias(void) const
{
- String value;
- if (GetAttribute("alias", &value))
+ String value = Get("alias");
+ if (!value.IsEmpty())
return value;
else
return GetName();
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);
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);
bool Host::IsUp(void)
{
- Dictionary::Ptr hostchecks;
- GetAttribute("hostchecks", &hostchecks);
+ Dictionary::Ptr hostchecks = Get("hostchecks");
if (hostchecks) {
hostchecks = Service::ResolveDependencies(GetSelf(), hostchecks);
String HostGroup::GetAlias(void) const
{
- String value;
- GetAttribute("alias", &value);
+ String value = Get("alias");
if (!value.IsEmpty())
return value;
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)
String Service::GetAlias(void) const
{
- String value;
+ String value = Get("alias");
- if (GetAttribute("alias", &value))
+ if (!value.IsEmpty())
return value;
return GetName();
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);
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;
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 {
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
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;
}
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;
}
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>();
String ServiceGroup::GetAlias(void) const
{
- String value;
- GetAttribute("alias", &value);
+ String value = Get("alias");
if (!value.IsEmpty())
return value;
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)
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++;
}
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();
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());
continue;
RequestMessage request = MakeObjectMessage(object, "config::ObjectUpdate", DynamicObject::GetCurrentTx(), true);
-
EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, request);
}
}
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", ¯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));
}
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;
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);
}
}
- host->SetAttribute("convenience_services", newServices);
+ host->Set("convenience_services", newServices);
}
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;
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);
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;
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);
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);
}
icinga_CPPFLAGS = \
-DI2_ICINGALAUNCHER_BUILD \
+ $(LTDLINCL) \
$(BOOST_CPPFLAGS) \
-I${top_srcdir}/base \
-I${top_srcdir}/dyn \
$(BOOST_LDFLAGS)
icinga_LDADD = \
+ $(LIBLTDL) \
$(BOOST_SIGNALS_LIB) \
$(BOOST_THREAD_LIB) \
${top_builddir}/base/libbase.la \
const String IcingaApplication::DefaultPidPath = "icinga.pid";
IcingaApplication::IcingaApplication(void)
- : m_PidPath(DefaultPidPath)
{ }
/**
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();
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);
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");