Implement class compiler.

Refs #4963
This commit is contained in:
Gunnar Beutner 2013-10-26 09:41:45 +02:00 committed by Gunnar Beutner
parent d14775f28f
commit db4b3b78d6
153 changed files with 3159 additions and 2800 deletions

1
.gitignore vendored
View File

@ -11,6 +11,7 @@ ipch
*.gcda *.gcda
*.o *.o
*.a *.a
*.th
.deps .deps
*.in *.in
Makefile Makefile

View File

@ -3,15 +3,22 @@
pkglib_LTLIBRARIES = \ pkglib_LTLIBRARIES = \
libchecker.la libchecker.la
BUILT_SOURCES = \
checkercomponent.th
CLEANFILES = \ CLEANFILES = \
checker-type.cpp checker-type.cpp
.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig
$(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
.ti.th: $(top_builddir)/tools/mkclass/mkclass
$(top_builddir)/tools/mkclass/mkclass $< > $@
libchecker_la_SOURCES = \ libchecker_la_SOURCES = \
checkercomponent.cpp \ checkercomponent.cpp \
checkercomponent.h \ checkercomponent.h \
checkercomponent.th \
checker-type.conf checker-type.conf
libchecker_la_CPPFLAGS = \ libchecker_la_CPPFLAGS = \

View File

@ -0,0 +1,10 @@
#include "base/dynamicobject.h"
namespace icinga
{
class CheckerComponent : DynamicObject
{
};
}

View File

@ -3,18 +3,27 @@
pkglib_LTLIBRARIES = \ pkglib_LTLIBRARIES = \
libcluster.la libcluster.la
BUILT_SOURCES = \
clusterlistener.th \
endpoint.th
CLEANFILES = \ CLEANFILES = \
cluster-type.cpp cluster-type.cpp
.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig
$(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
.ti.th: $(top_builddir)/tools/mkclass/mkclass
$(top_builddir)/tools/mkclass/mkclass $< > $@
libcluster_la_SOURCES = \ libcluster_la_SOURCES = \
clusterlistener.cpp \ clusterlistener.cpp \
clusterlistener.h \ clusterlistener.h \
clusterlistener.ti \
cluster-type.conf \ cluster-type.conf \
endpoint.cpp \ endpoint.cpp \
endpoint.h \ endpoint.h \
endpoint.ti \
jsonrpc.cpp \ jsonrpc.cpp \
jsonrpc.h jsonrpc.h

View File

@ -51,16 +51,16 @@ void ClusterListener::Start(void)
} }
/* set up SSL context */ /* set up SSL context */
shared_ptr<X509> cert = GetX509Certificate(GetCertificateFile()); shared_ptr<X509> cert = GetX509Certificate(GetCertPath());
m_Identity = GetCertificateCN(cert); SetIdentity(GetCertificateCN(cert));
Log(LogInformation, "cluster", "My identity: " + m_Identity); Log(LogInformation, "cluster", "My identity: " + GetIdentity());
Endpoint::Ptr self = Endpoint::GetByName(GetIdentity()); Endpoint::Ptr self = Endpoint::GetByName(GetIdentity());
if (!self) if (!self)
BOOST_THROW_EXCEPTION(std::invalid_argument("No configuration available for the local endpoint.")); BOOST_THROW_EXCEPTION(std::invalid_argument("No configuration available for the local endpoint."));
m_SSLContext = MakeSSLContext(GetCertificateFile(), GetKeyFile(), GetCAFile()); m_SSLContext = MakeSSLContext(GetCertPath(), GetKeyPath(), GetCaPath());
/* create the primary JSON-RPC listener */ /* create the primary JSON-RPC listener */
if (!GetBindPort().IsEmpty()) if (!GetBindPort().IsEmpty())
@ -127,62 +127,11 @@ void ClusterListener::Stop(void)
RotateLogFile(); RotateLogFile();
} }
String ClusterListener::GetCertificateFile(void) const
{
ObjectLock olock(this);
return m_CertPath;
}
String ClusterListener::GetKeyFile(void) const
{
ObjectLock olock(this);
return m_KeyPath;
}
String ClusterListener::GetCAFile(void) const
{
ObjectLock olock(this);
return m_CAPath;
}
String ClusterListener::GetBindHost(void) const
{
ObjectLock olock(this);
return m_BindHost;
}
String ClusterListener::GetBindPort(void) const
{
ObjectLock olock(this);
return m_BindPort;
}
Array::Ptr ClusterListener::GetPeers(void) const
{
ObjectLock olock(this);
return m_Peers;
}
shared_ptr<SSL_CTX> ClusterListener::GetSSLContext(void) const shared_ptr<SSL_CTX> ClusterListener::GetSSLContext(void) const
{ {
ObjectLock olock(this);
return m_SSLContext; return m_SSLContext;
} }
String ClusterListener::GetIdentity(void) const
{
ObjectLock olock(this);
return m_Identity;
}
/** /**
* Creates a new JSON-RPC listener on the specified port. * Creates a new JSON-RPC listener on the specified port.
* *
@ -270,7 +219,7 @@ void ClusterListener::PersistMessage(const Endpoint::Ptr& source, const Dictiona
String json = Value(pmessage).Serialize(); String json = Value(pmessage).Serialize();
NetString::WriteStringToStream(m_LogFile, json); NetString::WriteStringToStream(m_LogFile, json);
m_LogMessageCount++; m_LogMessageCount++;
m_LogMessageTimestamp = ts; SetLogMessageTimestamp(ts);
if (m_LogMessageCount > 50000) { if (m_LogMessageCount > 50000) {
CloseLogFile(); CloseLogFile();
@ -330,7 +279,7 @@ void ClusterListener::RelayMessage(const Endpoint::Ptr& source, const Dictionary
{ {
ObjectLock olock(endpoint); ObjectLock olock(endpoint);
if (!endpoint->IsSyncing()) if (!endpoint->GetSyncing())
endpoint->SendMessage(message); endpoint->SendMessage(message);
} }
} }
@ -361,7 +310,7 @@ void ClusterListener::OpenLogFile(void)
m_LogFile = logStream; m_LogFile = logStream;
#endif /* HAVE_BIOZLIB */ #endif /* HAVE_BIOZLIB */
m_LogMessageCount = 0; m_LogMessageCount = 0;
m_LogMessageTimestamp = 0; SetLogMessageTimestamp(0);
} }
void ClusterListener::CloseLogFile(void) void ClusterListener::CloseLogFile(void)
@ -380,7 +329,7 @@ void ClusterListener::RotateLogFile(void)
{ {
ASSERT(OwnsLock()); ASSERT(OwnsLock());
double ts = m_LogMessageTimestamp; double ts = GetLogMessageTimestamp();
if (ts == 0) if (ts == 0)
ts = Utility::GetTime(); ts = Utility::GetTime();
@ -1579,37 +1528,3 @@ bool ClusterListener::SupportsNotifications(void)
return !type->GetObjects().empty() && IcingaApplication::GetInstance()->GetEnableNotifications(); return !type->GetObjects().empty() && IcingaApplication::GetInstance()->GetEnableNotifications();
} }
void ClusterListener::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
bag->Set("cert_path", m_CertPath);
bag->Set("key_path", m_KeyPath);
bag->Set("ca_path", m_CAPath);
bag->Set("bind_host", m_BindHost);
bag->Set("bind_port", m_BindPort);
bag->Set("peers", m_Peers);
}
if (attributeTypes & Attribute_State)
bag->Set("log_message_timestamp", m_LogMessageTimestamp);
}
void ClusterListener::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
m_CertPath = bag->Get("cert_path");
m_KeyPath = bag->Get("key_path");
m_CAPath = bag->Get("ca_path");
m_BindHost = bag->Get("bind_host");
m_BindPort = bag->Get("bind_port");
m_Peers = bag->Get("peers");
}
if (attributeTypes & Attribute_State)
m_LogMessageTimestamp = bag->Get("log_message_timestamp");
}

View File

@ -20,6 +20,7 @@
#ifndef CLUSTERLISTENER_H #ifndef CLUSTERLISTENER_H
#define CLUSTERLISTENER_H #define CLUSTERLISTENER_H
#include "cluster/clusterlistener.th"
#include "base/dynamicobject.h" #include "base/dynamicobject.h"
#include "base/timer.h" #include "base/timer.h"
#include "base/array.h" #include "base/array.h"
@ -38,7 +39,7 @@ namespace icinga
/** /**
* @ingroup cluster * @ingroup cluster
*/ */
class ClusterListener : public DynamicObject class ClusterListener : public ReflectionObjectImpl<ClusterListener>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(ClusterListener); DECLARE_PTR_TYPEDEFS(ClusterListener);
@ -47,31 +48,11 @@ public:
virtual void Start(void); virtual void Start(void);
virtual void Stop(void); virtual void Stop(void);
String GetCertificateFile(void) const; shared_ptr<SSL_CTX> GetSSLContext(void) const;
String GetKeyFile(void) const;
String GetCAFile(void) const;
String GetBindHost(void) const;
String GetBindPort(void) const;
Array::Ptr GetPeers(void) const;
String GetClusterDir(void) const; String GetClusterDir(void) const;
shared_ptr<SSL_CTX> GetSSLContext(void) const;
String GetIdentity(void) const;
protected:
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private: private:
String m_CertPath;
String m_KeyPath;
String m_CAPath;
String m_BindHost;
String m_BindPort;
Array::Ptr m_Peers;
shared_ptr<SSL_CTX> m_SSLContext; shared_ptr<SSL_CTX> m_SSLContext;
String m_Identity;
WorkQueue m_RelayQueue; WorkQueue m_RelayQueue;
WorkQueue m_MessageQueue; WorkQueue m_MessageQueue;
@ -100,7 +81,6 @@ private:
void ReplayLog(const Endpoint::Ptr& endpoint, const Stream::Ptr& stream); void ReplayLog(const Endpoint::Ptr& endpoint, const Stream::Ptr& stream);
Stream::Ptr m_LogFile; Stream::Ptr m_LogFile;
double m_LogMessageTimestamp;
size_t m_LogMessageCount; size_t m_LogMessageCount;
void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr, const String& authority); void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr, const String& authority);

View File

@ -0,0 +1,18 @@
#include "base/dynamicobject.h"
namespace icinga
{
class ClusterListener : DynamicObject
{
[config] String cert_path;
[config] String key_path;
[config] String ca_path;
[config] String bind_host;
[config] String bind_port;
[config] Array::Ptr peers;
[state] double log_message_timestamp;
String identity;
};
}

View File

@ -34,10 +34,6 @@ REGISTER_TYPE(Endpoint);
boost::signals2::signal<void (const Endpoint::Ptr&)> Endpoint::OnConnected; boost::signals2::signal<void (const Endpoint::Ptr&)> Endpoint::OnConnected;
boost::signals2::signal<void (const Endpoint::Ptr&, const Dictionary::Ptr&)> Endpoint::OnMessageReceived; boost::signals2::signal<void (const Endpoint::Ptr&, const Dictionary::Ptr&)> Endpoint::OnMessageReceived;
Endpoint::Endpoint(void)
: m_Syncing(false)
{ }
/** /**
* Checks whether this endpoint is connected. * Checks whether this endpoint is connected.
* *
@ -107,86 +103,6 @@ void Endpoint::MessageThreadProc(const Stream::Ptr& stream)
} }
} }
/**
* Gets the node address for this endpoint.
*
* @returns The node address (hostname).
*/
String Endpoint::GetHost(void) const
{
return m_Host;
}
/**
* Gets the service name for this endpoint.
*
* @returns The service name (port).
*/
String Endpoint::GetPort(void) const
{
return m_Port;
}
Array::Ptr Endpoint::GetConfigFiles(void) const
{
return m_ConfigFiles;
}
Array::Ptr Endpoint::GetAcceptConfig(void) const
{
return m_AcceptConfig;
}
double Endpoint::GetSeen(void) const
{
return m_Seen;
}
void Endpoint::SetSeen(double ts)
{
m_Seen = ts;
}
double Endpoint::GetLocalLogPosition(void) const
{
return m_LocalLogPosition;
}
void Endpoint::SetLocalLogPosition(double ts)
{
m_LocalLogPosition = ts;
}
double Endpoint::GetRemoteLogPosition(void) const
{
return m_RemoteLogPosition;
}
void Endpoint::SetRemoteLogPosition(double ts)
{
m_RemoteLogPosition = ts;
}
bool Endpoint::IsSyncing(void) const
{
return m_Syncing;
}
void Endpoint::SetSyncing(bool syncing)
{
m_Syncing = syncing;
}
Dictionary::Ptr Endpoint::GetFeatures(void) const
{
return m_Features;
}
void Endpoint::SetFeatures(const Dictionary::Ptr& features)
{
m_Features = features;
}
bool Endpoint::HasFeature(const String& type) const bool Endpoint::HasFeature(const String& type) const
{ {
Dictionary::Ptr features = GetFeatures(); Dictionary::Ptr features = GetFeatures();
@ -197,40 +113,3 @@ bool Endpoint::HasFeature(const String& type) const
return features->Get(type); return features->Get(type);
} }
void Endpoint::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
bag->Set("host", m_Host);
bag->Set("port", m_Port);
bag->Set("config_files", m_ConfigFiles);
bag->Set("accept_config", m_AcceptConfig);
}
if (attributeTypes & Attribute_State) {
bag->Set("seen", m_Seen);
bag->Set("local_log_position", m_LocalLogPosition);
bag->Set("remote_log_position", m_RemoteLogPosition);
bag->Set("features", m_Features);
}
}
void Endpoint::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
m_Host = bag->Get("host");
m_Port = bag->Get("port");
m_ConfigFiles = bag->Get("config_files");
m_AcceptConfig = bag->Get("accept_config");
}
if (attributeTypes & Attribute_State) {
m_Seen = bag->Get("seen");
m_LocalLogPosition = bag->Get("local_log_position");
m_RemoteLogPosition = bag->Get("remote_log_position");
m_Features = bag->Get("features");
}
}

View File

@ -20,7 +20,7 @@
#ifndef ENDPOINT_H #ifndef ENDPOINT_H
#define ENDPOINT_H #define ENDPOINT_H
#include "base/dynamicobject.h" #include "cluster/endpoint.th"
#include "base/stream.h" #include "base/stream.h"
#include "base/array.h" #include "base/array.h"
#include <boost/signals2.hpp> #include <boost/signals2.hpp>
@ -35,14 +35,12 @@ class EndpointManager;
* *
* @ingroup cluster * @ingroup cluster
*/ */
class Endpoint : public DynamicObject class Endpoint : public ReflectionObjectImpl<Endpoint>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(Endpoint); DECLARE_PTR_TYPEDEFS(Endpoint);
DECLARE_TYPENAME(Endpoint); DECLARE_TYPENAME(Endpoint);
Endpoint(void);
static boost::signals2::signal<void (const Endpoint::Ptr&)> OnConnected; static boost::signals2::signal<void (const Endpoint::Ptr&)> OnConnected;
static boost::signals2::signal<void (const Endpoint::Ptr&, const Dictionary::Ptr&)> OnMessageReceived; static boost::signals2::signal<void (const Endpoint::Ptr&, const Dictionary::Ptr&)> OnMessageReceived;
@ -53,46 +51,10 @@ public:
void SendMessage(const Dictionary::Ptr& request); void SendMessage(const Dictionary::Ptr& request);
String GetHost(void) const;
String GetPort(void) const;
Array::Ptr GetConfigFiles(void) const;
Array::Ptr GetAcceptConfig(void) const;
double GetSeen(void) const;
void SetSeen(double ts);
double GetLocalLogPosition(void) const;
void SetLocalLogPosition(double ts);
double GetRemoteLogPosition(void) const;
void SetRemoteLogPosition(double ts);
Dictionary::Ptr GetFeatures(void) const;
void SetFeatures(const Dictionary::Ptr& features);
bool HasFeature(const String& type) const; bool HasFeature(const String& type) const;
bool IsSyncing(void) const;
void SetSyncing(bool syncing);
protected:
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private: private:
Dictionary::Ptr m_Subscriptions;
String m_Host;
String m_Port;
Array::Ptr m_ConfigFiles;
Array::Ptr m_AcceptConfig;
Stream::Ptr m_Client; Stream::Ptr m_Client;
double m_Seen;
double m_LocalLogPosition;
double m_RemoteLogPosition;
Dictionary::Ptr m_Features;
bool m_Syncing;
boost::thread m_Thread; boost::thread m_Thread;
void MessageThreadProc(const Stream::Ptr& stream); void MessageThreadProc(const Stream::Ptr& stream);

View File

@ -0,0 +1,23 @@
#include "base/dynamicobject.h"
namespace icinga
{
class Endpoint : DynamicObject
{
[config] String host;
[config] String port;
[config] Array::Ptr config_files;
[config] Array::Ptr accept_config;
[state] double seen;
[state] double local_log_position;
[state] double remote_log_position;
[state] Dictionary::Ptr features;
bool syncing {
default {{{ return false; }}}
};
};
}

View File

@ -3,21 +3,34 @@
pkglib_LTLIBRARIES = \ pkglib_LTLIBRARIES = \
libcompat.la libcompat.la
BUILT_SOURCES = \
checkresultreader.th \
externalcommandlistener.th \
statusdatawriter.th \
compatlogger.th
CLEANFILES = \ CLEANFILES = \
compat-type.cpp compat-type.cpp
.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig
$(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
.ti.th: $(top_builddir)/tools/mkclass/mkclass
$(top_builddir)/tools/mkclass/mkclass $< > $@
libcompat_la_SOURCES = \ libcompat_la_SOURCES = \
checkresultreader.cpp \ checkresultreader.cpp \
checkresultreader.h \ checkresultreader.h \
checkresultreader.th \
externalcommandlistener.cpp \ externalcommandlistener.cpp \
externalcommandlistener.h \ externalcommandlistener.h \
externalcommandlistener.th \
statusdatawriter.cpp \ statusdatawriter.cpp \
statusdatawriter.h \ statusdatawriter.h \
statusdatawriter.th \
compatlogger.cpp \ compatlogger.cpp \
compatlogger.h \ compatlogger.h \
compatlogger.th \
compat-type.conf compat-type.conf
libcompat_la_CPPFLAGS = \ libcompat_la_CPPFLAGS = \

View File

@ -44,17 +44,6 @@ void CheckResultReader::Start(void)
m_ReadTimer->Start(); m_ReadTimer->Start();
} }
/**
* @threadsafety Always.
*/
String CheckResultReader::GetSpoolDir(void) const
{
if (!m_SpoolDir.IsEmpty())
return m_SpoolDir;
else
return Application::GetLocalStateDir() + "/lib/icinga2/spool/checkresults/";
}
/** /**
* @threadsafety Always. * @threadsafety Always.
*/ */
@ -134,18 +123,3 @@ void CheckResultReader::ProcessCheckResultFile(const String& path) const
} }
} }
void CheckResultReader::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config)
bag->Set("spool_dir", m_SpoolDir);
}
void CheckResultReader::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config)
m_SpoolDir = bag->Get("spool_dir");
}

View File

@ -20,7 +20,7 @@
#ifndef CHECKRESULTREADER_H #ifndef CHECKRESULTREADER_H
#define CHECKRESULTREADER_H #define CHECKRESULTREADER_H
#include "base/dynamicobject.h" #include "compat/checkresultreader.th"
#include "base/timer.h" #include "base/timer.h"
#include <fstream> #include <fstream>
@ -32,23 +32,16 @@ namespace icinga
* *
* @ingroup compat * @ingroup compat
*/ */
class CheckResultReader : public DynamicObject class CheckResultReader : public ReflectionObjectImpl<CheckResultReader>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(CheckResultReader); DECLARE_PTR_TYPEDEFS(CheckResultReader);
DECLARE_TYPENAME(CheckResultReader); DECLARE_TYPENAME(CheckResultReader);
String GetSpoolDir(void) const;
protected: protected:
virtual void Start(void); virtual void Start(void);
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private: private:
String m_SpoolDir;
Timer::Ptr m_ReadTimer; Timer::Ptr m_ReadTimer;
void ReadTimerHandler(void) const; void ReadTimerHandler(void) const;
void ProcessCheckResultFile(const String& path) const; void ProcessCheckResultFile(const String& path) const;

View File

@ -0,0 +1,14 @@
#include "base/dynamicobject.h"
#include "base/application.h"
namespace icinga
{
class CheckResultReader : DynamicObject
{
[config] String spool_dir {
default {{{ return Application::GetLocalStateDir() + "/lib/icinga2/spool/checkresults/"; }}}
};
};
}

View File

@ -67,28 +67,6 @@ void CompatLogger::Start(void)
ScheduleNextRotation(); ScheduleNextRotation();
} }
/**
* @threadsafety Always.
*/
String CompatLogger::GetLogDir(void) const
{
if (!m_LogDir.IsEmpty())
return m_LogDir;
else
return Application::GetLocalStateDir() + "/log/icinga2/compat";
}
/**
* @threadsafety Always.
*/
String CompatLogger::GetRotationMethod(void) const
{
if (!m_RotationMethod.IsEmpty())
return m_RotationMethod;
else
return "HOURLY";
}
/** /**
* @threadsafety Always. * @threadsafety Always.
*/ */
@ -412,10 +390,8 @@ void CompatLogger::FlappingHandler(const Service::Ptr& service, FlappingState fl
ObjectLock oLock(this); ObjectLock oLock(this);
Flush(); Flush();
} }
} }
void CompatLogger::ExternalCommandHandler(const String& command, const std::vector<String>& arguments) void CompatLogger::ExternalCommandHandler(const String& command, const std::vector<String>& arguments)
{ {
std::ostringstream msgbuf; std::ostringstream msgbuf;
@ -496,7 +472,7 @@ void CompatLogger::ReopenFile(bool rotate)
<< host->GetName() << ";" << host->GetName() << ";"
<< Host::StateToString(Host::CalculateState(hc->GetState(), reachable)) << ";" << Host::StateToString(Host::CalculateState(hc->GetState(), reachable)) << ";"
<< Service::StateTypeToString(hc->GetStateType()) << ";" << Service::StateTypeToString(hc->GetStateType()) << ";"
<< hc->GetCurrentCheckAttempt() << ";" << hc->GetCheckAttempt() << ";"
<< ""; << "";
WriteLine(msgbuf.str()); WriteLine(msgbuf.str());
@ -514,7 +490,7 @@ void CompatLogger::ReopenFile(bool rotate)
<< service->GetShortName() << ";" << service->GetShortName() << ";"
<< Service::StateToString(service->GetState()) << ";" << Service::StateToString(service->GetState()) << ";"
<< Service::StateTypeToString(service->GetStateType()) << ";" << Service::StateTypeToString(service->GetStateType()) << ";"
<< service->GetCurrentCheckAttempt() << ";" << service->GetCheckAttempt() << ";"
<< ""; << "";
WriteLine(msgbuf.str()); WriteLine(msgbuf.str());
@ -599,22 +575,3 @@ void CompatLogger::ValidateRotationMethod(const String& location, const Dictiona
} }
} }
void CompatLogger::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
bag->Set("log_dir", m_LogDir);
bag->Set("rotation_method", m_RotationMethod);
}
}
void CompatLogger::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
m_LogDir = bag->Get("log_dir");
m_RotationMethod = bag->Get("rotation_method");
}
}

View File

@ -20,8 +20,8 @@
#ifndef COMPATLOGGER_H #ifndef COMPATLOGGER_H
#define COMPATLOGGER_H #define COMPATLOGGER_H
#include "compat/compatlogger.th"
#include "icinga/service.h" #include "icinga/service.h"
#include "base/dynamicobject.h"
#include "base/timer.h" #include "base/timer.h"
#include <fstream> #include <fstream>
@ -33,7 +33,7 @@ namespace icinga
* *
* @ingroup compat * @ingroup compat
*/ */
class CompatLogger : public DynamicObject class CompatLogger : public ReflectionObjectImpl<CompatLogger>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(CompatLogger); DECLARE_PTR_TYPEDEFS(CompatLogger);
@ -41,21 +41,12 @@ public:
CompatLogger(void); CompatLogger(void);
String GetLogDir(void) const;
String GetRotationMethod(void) const;
static void ValidateRotationMethod(const String& location, const Dictionary::Ptr& attrs); static void ValidateRotationMethod(const String& location, const Dictionary::Ptr& attrs);
protected: protected:
virtual void Start(void); virtual void Start(void);
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private: private:
String m_LogDir;
String m_RotationMethod;
double m_LastRotation; double m_LastRotation;
void WriteLine(const String& line); void WriteLine(const String& line);

View File

@ -0,0 +1,17 @@
#include "base/dynamicobject.h"
#include "base/application.h"
namespace icinga
{
class CompatLogger : DynamicObject
{
[config] String log_dir {
default {{{ return Application::GetLocalStateDir() + "/log/icinga2/compat"; }}}
};
[config] String rotation_method {
default {{{ return "HOURLY"; }}}
};
};
}

View File

@ -42,20 +42,6 @@ void ExternalCommandListener::Start(void)
#endif /* _WIN32 */ #endif /* _WIN32 */
} }
/**
* Retrieves the icinga.cmd path.
*
* @returns icinga.cmd path
*/
String ExternalCommandListener::GetCommandPath(void) const
{
if (m_CommandPath.IsEmpty())
return Application::GetLocalStateDir() + "/run/icinga2/cmd/icinga2.cmd";
else
return m_CommandPath;
}
#ifndef _WIN32 #ifndef _WIN32
void ExternalCommandListener::CommandPipeThread(const String& commandPath) void ExternalCommandListener::CommandPipeThread(const String& commandPath)
{ {
@ -143,19 +129,3 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
} }
} }
#endif /* _WIN32 */ #endif /* _WIN32 */
void ExternalCommandListener::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config)
bag->Set("command_path", m_CommandPath);
}
void ExternalCommandListener::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config)
m_CommandPath = bag->Get("command_path");
}

View File

@ -20,7 +20,7 @@
#ifndef EXTERNALCOMMANDLISTENER_H #ifndef EXTERNALCOMMANDLISTENER_H
#define EXTERNALCOMMANDLISTENER_H #define EXTERNALCOMMANDLISTENER_H
#include "base/dynamicobject.h" #include "compat/externalcommandlistener.th"
#include "base/objectlock.h" #include "base/objectlock.h"
#include "base/timer.h" #include "base/timer.h"
#include "base/utility.h" #include "base/utility.h"
@ -33,7 +33,7 @@ namespace icinga
/** /**
* @ingroup compat * @ingroup compat
*/ */
class ExternalCommandListener : public DynamicObject class ExternalCommandListener : public ReflectionObjectImpl<ExternalCommandListener>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(ExternalCommandListener); DECLARE_PTR_TYPEDEFS(ExternalCommandListener);
@ -41,19 +41,12 @@ public:
protected: protected:
virtual void Start(void); virtual void Start(void);
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private: private:
String m_CommandPath;
#ifndef _WIN32 #ifndef _WIN32
boost::thread m_CommandThread; boost::thread m_CommandThread;
void CommandPipeThread(const String& commandPath); void CommandPipeThread(const String& commandPath);
#endif /* _WIN32 */ #endif /* _WIN32 */
String GetCommandPath(void) const;
}; };
} }

View File

@ -0,0 +1,14 @@
#include "base/dynamicobject.h"
#include "base/application.h"
namespace icinga
{
class ExternalCommandListener : DynamicObject
{
[config] String command_path {
default {{{ return Application::GetLocalStateDir() + "/run/icinga2/cmd/icinga2.cmd"; }}}
};
};
}

View File

@ -64,40 +64,11 @@ void StatusDataWriter::Start(void)
m_StatusTimer->Reschedule(0); m_StatusTimer->Reschedule(0);
} }
/**
* Retrieves the status.dat path.
*
* @returns statuspath from config, or static default
*/
String StatusDataWriter::GetStatusPath(void) const
{
if (m_StatusPath.IsEmpty())
return Application::GetLocalStateDir() + "/cache/icinga2/status.dat";
else
return m_StatusPath;
}
/**
* Retrieves the objects.cache path.
*
* @returns objectspath from config, or static default
*/
String StatusDataWriter::GetObjectsPath(void) const
{
if (m_ObjectsPath.IsEmpty())
return Application::GetLocalStateDir() + "/cache/icinga2/objects.cache";
else
return m_ObjectsPath;
}
void StatusDataWriter::DumpComments(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type) void StatusDataWriter::DumpComments(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type)
{ {
Service::Ptr service; Service::Ptr service;
Dictionary::Ptr comments = owner->GetComments(); Dictionary::Ptr comments = owner->GetComments();
if (!comments)
return;
Host::Ptr host = owner->GetHost(); Host::Ptr host = owner->GetHost();
if (!host) if (!host)
@ -202,9 +173,6 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner
Dictionary::Ptr downtimes = owner->GetDowntimes(); Dictionary::Ptr downtimes = owner->GetDowntimes();
if (!downtimes)
return;
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
String id; String id;
@ -474,7 +442,7 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s
<< "\t" << "active_checks_enabled" << "\t" << (service->GetEnableActiveChecks() ? 1 : 0) << "\n" << "\t" << "active_checks_enabled" << "\t" << (service->GetEnableActiveChecks() ? 1 : 0) << "\n"
<< "\t" << "passive_checks_enabled" << "\t" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\n" << "\t" << "passive_checks_enabled" << "\t" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\n"
<< "\t" << "flap_detection_enabled" << "\t" << (service->GetEnableFlapping() ? 1 : 0) << "\n" << "\t" << "flap_detection_enabled" << "\t" << (service->GetEnableFlapping() ? 1 : 0) << "\n"
<< "\t" << "is_volatile" << "\t" << (service->IsVolatile() ? 1 : 0) << "\n" << "\t" << "is_volatile" << "\t" << (service->GetVolatile() ? 1 : 0) << "\n"
<< "\t" << "notifications_enabled" << "\t" << (service->GetEnableNotifications() ? 1 : 0) << "\n" << "\t" << "notifications_enabled" << "\t" << (service->GetEnableNotifications() ? 1 : 0) << "\n"
<< "\t" << "notification_options" << "\t" << "u,w,c,r" << "\n" << "\t" << "notification_options" << "\t" << "u,w,c,r" << "\n"
<< "\t" << "notification_interval" << "\t" << notification_interval / 60.0 << "\n" << "\t" << "notification_interval" << "\t" << notification_interval / 60.0 << "\n"
@ -610,7 +578,7 @@ void StatusDataWriter::StatusTimerHandler(void)
statusfp << "programstatus {" << "\n" statusfp << "programstatus {" << "\n"
<< "\t" << "icinga_pid=" << Utility::GetPid() << "\n" << "\t" << "icinga_pid=" << Utility::GetPid() << "\n"
<< "\t" << "daemon_mode=1" << "\n" << "\t" << "daemon_mode=1" << "\n"
<< "\t" << "program_start=" << static_cast<long>(IcingaApplication::GetInstance()->GetStartTime()) << "\n" << "\t" << "program_start=" << static_cast<long>(Application::GetStartTime()) << "\n"
<< "\t" << "active_service_checks_enabled=" << (IcingaApplication::GetInstance()->GetEnableChecks() ? 1 : 0) << "\n" << "\t" << "active_service_checks_enabled=" << (IcingaApplication::GetInstance()->GetEnableChecks() ? 1 : 0) << "\n"
<< "\t" << "passive_service_checks_enabled=1" << "\n" << "\t" << "passive_service_checks_enabled=1" << "\n"
<< "\t" << "active_host_checks_enabled=1" << "\n" << "\t" << "active_host_checks_enabled=1" << "\n"
@ -782,22 +750,3 @@ void StatusDataWriter::StatusTimerHandler(void)
} }
} }
void StatusDataWriter::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
bag->Set("status_path", m_StatusPath);
bag->Set("objects_path", m_ObjectsPath);
}
}
void StatusDataWriter::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
m_StatusPath = bag->Get("status_path");
m_ObjectsPath = bag->Get("objects_path");
}
}

View File

@ -20,11 +20,11 @@
#ifndef STATUSDATAWRITER_H #ifndef STATUSDATAWRITER_H
#define STATUSDATAWRITER_H #define STATUSDATAWRITER_H
#include "compat/statusdatawriter.th"
#include "icinga/host.h" #include "icinga/host.h"
#include "icinga/service.h" #include "icinga/service.h"
#include "icinga/command.h" #include "icinga/command.h"
#include "icinga/compatutility.h" #include "icinga/compatutility.h"
#include "base/dynamicobject.h"
#include "base/objectlock.h" #include "base/objectlock.h"
#include "base/timer.h" #include "base/timer.h"
#include "base/utility.h" #include "base/utility.h"
@ -37,7 +37,7 @@ namespace icinga
/** /**
* @ingroup compat * @ingroup compat
*/ */
class StatusDataWriter : public DynamicObject class StatusDataWriter : public ReflectionObjectImpl<StatusDataWriter>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(StatusDataWriter); DECLARE_PTR_TYPEDEFS(StatusDataWriter);
@ -45,18 +45,9 @@ public:
protected: protected:
virtual void Start(void); virtual void Start(void);
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private: private:
String m_StatusPath;
String m_ObjectsPath;
Timer::Ptr m_StatusTimer; Timer::Ptr m_StatusTimer;
String GetStatusPath(void) const;
String GetObjectsPath(void) const;
void DumpCommand(std::ostream& fp, const Command::Ptr& command); void DumpCommand(std::ostream& fp, const Command::Ptr& command);
void DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& tp); void DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& tp);
void DumpDowntimes(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type); void DumpDowntimes(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type);

View File

@ -0,0 +1,17 @@
#include "base/dynamicobject.h"
#include "base/application.h"
namespace icinga
{
class StatusDataWriter : DynamicObject
{
[config] String status_path {
default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/status.dat"; }}}
};
[config] String objects_path {
default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/objects.cache"; }}}
};
};
}

View File

@ -8,16 +8,23 @@ SUBDIRS = \
pkglib_LTLIBRARIES = \ pkglib_LTLIBRARIES = \
libdb_ido_mysql.la libdb_ido_mysql.la
BUILT_SOURCES = \
idomysqlconnection.th
CLEANFILES = \ CLEANFILES = \
db_ido_mysql-type.cpp db_ido_mysql-type.cpp
.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig
$(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
.ti.th: $(top_builddir)/tools/mkclass/mkclass
$(top_builddir)/tools/mkclass/mkclass $< > $@
libdb_ido_mysql_la_SOURCES = \ libdb_ido_mysql_la_SOURCES = \
db_ido_mysql-type.conf \ db_ido_mysql-type.conf \
idomysqlconnection.cpp \ idomysqlconnection.cpp \
idomysqlconnection.h idomysqlconnection.h \
idomysqlconnection.ti
libdb_ido_mysql_la_CPPFLAGS = \ libdb_ido_mysql_la_CPPFLAGS = \
$(LTDLINCL) \ $(LTDLINCL) \

View File

@ -22,6 +22,7 @@
#include "base/convert.h" #include "base/convert.h"
#include "base/utility.h" #include "base/utility.h"
#include "base/application.h" #include "base/application.h"
#include "base/dynamictype.h"
#include "db_ido/dbtype.h" #include "db_ido/dbtype.h"
#include "db_ido/dbvalue.h" #include "db_ido/dbvalue.h"
#include "db_ido_mysql/idomysqlconnection.h" #include "db_ido_mysql/idomysqlconnection.h"
@ -34,12 +35,13 @@ using namespace icinga;
REGISTER_TYPE(IdoMysqlConnection); REGISTER_TYPE(IdoMysqlConnection);
#define SCHEMA_VERSION "1.10.0"
void IdoMysqlConnection::Start(void) void IdoMysqlConnection::Start(void)
{ {
DbConnection::Start(); DbConnection::Start();
m_Connected = false; m_Connected = false;
m_RequiredSchemaVersion = "1.10.0";
m_TxTimer = boost::make_shared<Timer>(); m_TxTimer = boost::make_shared<Timer>();
m_TxTimer->SetInterval(5); m_TxTimer->SetInterval(5);
@ -99,13 +101,13 @@ void IdoMysqlConnection::ReconnectTimerHandler(void)
const char *host, *user , *passwd, *db; const char *host, *user , *passwd, *db;
long port; long port;
ihost = m_Host; ihost = GetHost();
iuser = m_User; iuser = GetUser();
ipasswd = m_Password; ipasswd = GetPassword();
idb = m_Database; idb = GetDatabase();
host = (!ihost.IsEmpty()) ? ihost.CStr() : NULL; host = (!ihost.IsEmpty()) ? ihost.CStr() : NULL;
port = m_Port; port = GetPort();
user = (!iuser.IsEmpty()) ? iuser.CStr() : NULL; user = (!iuser.IsEmpty()) ? iuser.CStr() : NULL;
passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : NULL; passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : NULL;
db = (!idb.IsEmpty()) ? idb.CStr() : NULL; db = (!idb.IsEmpty()) ? idb.CStr() : NULL;
@ -127,20 +129,17 @@ void IdoMysqlConnection::ReconnectTimerHandler(void)
Dictionary::Ptr version_row = version_rows->Get(0); Dictionary::Ptr version_row = version_rows->Get(0);
String version = version_row->Get("version"); String version = version_row->Get("version");
if (Utility::CompareVersion(m_RequiredSchemaVersion, version) < 0) { if (Utility::CompareVersion(SCHEMA_VERSION, version) < 0) {
BOOST_THROW_EXCEPTION(std::runtime_error("Schema version '" + version + "' does not match the required version '" + BOOST_THROW_EXCEPTION(std::runtime_error("Schema version '" + version + "' does not match the required version '" +
m_RequiredSchemaVersion + "'! Please check the upgrade documentation.")); SCHEMA_VERSION + "'! Please check the upgrade documentation."));
} }
String instanceName = "default"; String instanceName = GetInstanceName();
if (!m_InstanceName.IsEmpty())
instanceName = m_InstanceName;
Array::Ptr rows = Query("SELECT instance_id FROM " + GetTablePrefix() + "instances WHERE instance_name = '" + Escape(instanceName) + "'"); Array::Ptr rows = Query("SELECT instance_id FROM " + GetTablePrefix() + "instances WHERE instance_name = '" + Escape(instanceName) + "'");
if (rows->GetLength() == 0) { if (rows->GetLength() == 0) {
Query("INSERT INTO " + GetTablePrefix() + "instances (instance_name, instance_description) VALUES ('" + Escape(instanceName) + "', '" + m_InstanceDescription + "')"); Query("INSERT INTO " + GetTablePrefix() + "instances (instance_name, instance_description) VALUES ('" + Escape(instanceName) + "', '" + Escape(GetInstanceDescription()) + "')");
m_InstanceID = GetLastInsertID(); m_InstanceID = GetLastInsertID();
} else { } else {
Dictionary::Ptr row = rows->Get(0); Dictionary::Ptr row = rows->Get(0);
@ -539,32 +538,3 @@ void IdoMysqlConnection::CleanUpExecuteQuery(const String& table, const String&
"<FROM_UNIXTIME(" + Convert::ToString(static_cast<long>(time_value)) + ")"); "<FROM_UNIXTIME(" + Convert::ToString(static_cast<long>(time_value)) + ")");
} }
void IdoMysqlConnection::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DbConnection::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
bag->Set("host", m_Host);
bag->Set("port", m_Port);
bag->Set("user", m_User);
bag->Set("password", m_Password);
bag->Set("database", m_Database);
bag->Set("instance_name", m_InstanceName);
bag->Set("instance_description", m_InstanceDescription);
}
}
void IdoMysqlConnection::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DbConnection::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
m_Host = bag->Get("host");
m_Port = bag->Get("port");
m_User = bag->Get("user");
m_Password = bag->Get("password");
m_Database = bag->Get("database");
m_InstanceName = bag->Get("instance_name");
m_InstanceDescription = bag->Get("instance_description");
}
}

View File

@ -20,10 +20,9 @@
#ifndef IDOMYSQLCONNECTION_H #ifndef IDOMYSQLCONNECTION_H
#define IDOMYSQLCONNECTION_H #define IDOMYSQLCONNECTION_H
#include "db_ido_mysql/idomysqlconnection.th"
#include "base/array.h" #include "base/array.h"
#include "base/dynamictype.h"
#include "base/timer.h" #include "base/timer.h"
#include "db_ido/dbconnection.h"
#include <mysql/mysql.h> #include <mysql/mysql.h>
namespace icinga namespace icinga
@ -34,7 +33,7 @@ namespace icinga
* *
* @ingroup ido * @ingroup ido
*/ */
class IdoMysqlConnection : public DbConnection class IdoMysqlConnection : public ReflectionObjectImpl<IdoMysqlConnection>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(IdoMysqlConnection); DECLARE_PTR_TYPEDEFS(IdoMysqlConnection);
@ -54,14 +53,6 @@ protected:
virtual void CleanUpExecuteQuery(const String& table, const String& time_key, double time_value); virtual void CleanUpExecuteQuery(const String& table, const String& time_key, double time_value);
private: private:
String m_Host;
Value m_Port;
String m_User;
String m_Password;
String m_Database;
String m_InstanceName;
String m_InstanceDescription;
DbReference m_InstanceID; DbReference m_InstanceID;
DbReference m_LastNotificationID; DbReference m_LastNotificationID;
@ -69,8 +60,6 @@ private:
bool m_Connected; bool m_Connected;
MYSQL m_Connection; MYSQL m_Connection;
String m_RequiredSchemaVersion;
Timer::Ptr m_ReconnectTimer; Timer::Ptr m_ReconnectTimer;
Timer::Ptr m_TxTimer; Timer::Ptr m_TxTimer;

View File

@ -0,0 +1,19 @@
#include "db_ido/dbconnection.h"
namespace icinga
{
class IdoMysqlConnection : DbConnection
{
[config] String host;
[config] int port;
[config] String user;
[config] String password;
[config] String database;
[config] String instance_name {
default {{{ return "default"; }}}
};
[config] String instance_description;
};
}

View File

@ -3,15 +3,22 @@
pkglib_LTLIBRARIES = \ pkglib_LTLIBRARIES = \
libdemo.la libdemo.la
BUILT_SOURCES = \
demo.th
CLEANFILES = \ CLEANFILES = \
demo-type.cpp demo-type.cpp
.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig
$(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
.ti.th: $(top_builddir)/tools/mkclass/mkclass
$(top_builddir)/tools/mkclass/mkclass $< > $@
libdemo_la_SOURCES = \ libdemo_la_SOURCES = \
demo.cpp \ demo.cpp \
demo.h \ demo.h \
demo.ti \
demo-type.conf demo-type.conf
libdemo_la_CPPFLAGS = \ libdemo_la_CPPFLAGS = \

View File

@ -20,7 +20,7 @@
#ifndef DEMO_H #ifndef DEMO_H
#define DEMO_H #define DEMO_H
#include "base/dynamicobject.h" #include "demo/demo.th"
#include "base/timer.h" #include "base/timer.h"
namespace icinga namespace icinga
@ -29,7 +29,7 @@ namespace icinga
/** /**
* @ingroup demo * @ingroup demo
*/ */
class Demo : public DynamicObject class Demo : public ReflectionObjectImpl<Demo>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(Demo); DECLARE_PTR_TYPEDEFS(Demo);

10
components/demo/demo.ti Normal file
View File

@ -0,0 +1,10 @@
#include "base/dynamicobject.h"
namespace icinga
{
class Demo : DynamicObject
{
};
}

View File

@ -3,12 +3,18 @@
pkglib_LTLIBRARIES = \ pkglib_LTLIBRARIES = \
liblivestatus.la liblivestatus.la
BUILT_SOURCES = \
listener.th
CLEANFILES = \ CLEANFILES = \
livestatus-type.cpp livestatus-type.cpp
.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig
$(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
.ti.th: $(top_builddir)/tools/mkclass/mkclass
$(top_builddir)/tools/mkclass/mkclass $< > $@
liblivestatus_la_SOURCES = \ liblivestatus_la_SOURCES = \
aggregator.cpp \ aggregator.cpp \
aggregator.h \ aggregator.h \
@ -46,6 +52,7 @@ liblivestatus_la_SOURCES = \
invsumaggregator.h \ invsumaggregator.h \
listener.cpp \ listener.cpp \
listener.h \ listener.h \
listener.ti \
livestatus-type.conf \ livestatus-type.conf \
logtable.cpp \ logtable.cpp \
logtable.h \ logtable.h \

View File

@ -61,9 +61,6 @@ void CommentsTable::FetchRows(const AddRowFunction& addRowFn)
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) { BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
Dictionary::Ptr comments = service->GetComments(); Dictionary::Ptr comments = service->GetComments();
if (!comments)
continue;
ObjectLock olock(comments); ObjectLock olock(comments);
String id; String id;

View File

@ -61,9 +61,6 @@ void DowntimesTable::FetchRows(const AddRowFunction& addRowFn)
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) { BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
Dictionary::Ptr downtimes = service->GetDowntimes(); Dictionary::Ptr downtimes = service->GetDowntimes();
if (!downtimes)
continue;
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
String id; String id;

View File

@ -604,7 +604,7 @@ Value HostsTable::CurrentAttemptAccessor(const Value& row)
if (!hc) if (!hc)
return Empty; return Empty;
return hc->GetCurrentCheckAttempt(); return hc->GetCheckAttempt();
} }
Value HostsTable::LastNotificationAccessor(const Value& row) Value HostsTable::LastNotificationAccessor(const Value& row)
@ -761,7 +761,7 @@ Value HostsTable::NoMoreNotificationsAccessor(const Value& row)
notification_interval = notification->GetNotificationInterval(); notification_interval = notification->GetNotificationInterval();
} }
if (notification_interval == 0 && !hc->IsVolatile()) if (notification_interval == 0 && !hc->GetVolatile())
return 1; return 1;
return 0; return 0;
@ -1054,9 +1054,6 @@ Value HostsTable::DowntimesAccessor(const Value& row)
Dictionary::Ptr downtimes = hc->GetDowntimes(); Dictionary::Ptr downtimes = hc->GetDowntimes();
if (!downtimes)
return Empty;
Array::Ptr ids = boost::make_shared<Array>(); Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
@ -1087,9 +1084,6 @@ Value HostsTable::DowntimesWithInfoAccessor(const Value& row)
Dictionary::Ptr downtimes = hc->GetDowntimes(); Dictionary::Ptr downtimes = hc->GetDowntimes();
if (!downtimes)
return Empty;
Array::Ptr ids = boost::make_shared<Array>(); Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
@ -1124,9 +1118,6 @@ Value HostsTable::CommentsAccessor(const Value& row)
Dictionary::Ptr comments = hc->GetComments(); Dictionary::Ptr comments = hc->GetComments();
if (!comments)
return Empty;
Array::Ptr ids = boost::make_shared<Array>(); Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(comments); ObjectLock olock(comments);
@ -1157,9 +1148,6 @@ Value HostsTable::CommentsWithInfoAccessor(const Value& row)
Dictionary::Ptr comments = hc->GetComments(); Dictionary::Ptr comments = hc->GetComments();
if (!comments)
return Empty;
Array::Ptr ids = boost::make_shared<Array>(); Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(comments); ObjectLock olock(comments);
@ -1194,9 +1182,6 @@ Value HostsTable::CommentsWithExtraInfoAccessor(const Value& row)
Dictionary::Ptr comments = hc->GetComments(); Dictionary::Ptr comments = hc->GetComments();
if (!comments)
return Empty;
Array::Ptr ids = boost::make_shared<Array>(); Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(comments); ObjectLock olock(comments);

View File

@ -83,40 +83,6 @@ void LivestatusListener::Start(void)
} }
} }
String LivestatusListener::GetSocketType(void) const
{
Value socketType = m_SocketType;
if (socketType.IsEmpty())
return "unix";
else
return socketType;
}
String LivestatusListener::GetSocketPath(void) const
{
Value socketPath = m_SocketPath;
if (socketPath.IsEmpty())
return Application::GetLocalStateDir() + "/run/icinga2/cmd/livestatus";
else
return socketPath;
}
String LivestatusListener::GetBindHost(void) const
{
if (m_BindHost.IsEmpty())
return "127.0.0.1";
else
return m_BindHost;
}
String LivestatusListener::GetBindPort(void) const
{
if (m_BindPort.IsEmpty())
return "6558";
else
return m_BindPort;
}
int LivestatusListener::GetClientsConnected(void) int LivestatusListener::GetClientsConnected(void)
{ {
boost::mutex::scoped_lock lock(l_ComponentMutex); boost::mutex::scoped_lock lock(l_ComponentMutex);
@ -189,26 +155,3 @@ void LivestatusListener::ValidateSocketType(const String& location, const Dictio
} }
} }
void LivestatusListener::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
bag->Set("socket_type", m_SocketType);
bag->Set("socket_path", m_SocketPath);
bag->Set("bind_host", m_BindHost);
bag->Set("bind_port", m_BindPort);
}
}
void LivestatusListener::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
m_SocketType = bag->Get("socket_type");
m_SocketPath = bag->Get("socket_path");
m_BindHost = bag->Get("bind_host");
m_BindPort = bag->Get("bind_port");
}
}

View File

@ -20,8 +20,8 @@
#ifndef LIVESTATUSLISTENER_H #ifndef LIVESTATUSLISTENER_H
#define LIVESTATUSLISTENER_H #define LIVESTATUSLISTENER_H
#include "livestatus/listener.th"
#include "livestatus/query.h" #include "livestatus/query.h"
#include "base/dynamicobject.h"
#include "base/socket.h" #include "base/socket.h"
#include <boost/thread/thread.hpp> #include <boost/thread/thread.hpp>
@ -33,16 +33,11 @@ namespace livestatus
/** /**
* @ingroup livestatus * @ingroup livestatus
*/ */
class LivestatusListener : public DynamicObject class LivestatusListener : public ReflectionObjectImpl<LivestatusListener>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(LivestatusListener); DECLARE_PTR_TYPEDEFS(LivestatusListener);
String GetSocketType(void) const;
String GetSocketPath(void) const;
String GetBindHost(void) const;
String GetBindPort(void) const;
static int GetClientsConnected(void); static int GetClientsConnected(void);
static int GetConnections(void); static int GetConnections(void);
@ -51,15 +46,7 @@ public:
protected: protected:
virtual void Start(void); virtual void Start(void);
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private: private:
String m_SocketType;
String m_SocketPath;
String m_BindHost;
String m_BindPort;
void ServerThreadProc(const Socket::Ptr& server); void ServerThreadProc(const Socket::Ptr& server);
void ClientThreadProc(const Socket::Ptr& client); void ClientThreadProc(const Socket::Ptr& client);
}; };

View File

@ -0,0 +1,31 @@
#include "base/dynamicobject.h"
#include "base/application.h"
namespace livestatus
{
code {{{
class LivestatusListener;
}}}
}
namespace icinga
{
class livestatus::LivestatusListener : DynamicObject {
[config] String socket_type {
default {{{ return "unix"; }}}
};
[config] String socket_path {
default {{{ return Application::GetLocalStateDir() + "/run/icinga2/cmd/livestatus"; }}}
};
[config] String bind_host {
default {{{ return "127.0.0.1"; }}}
};
[config] String bind_port {
default {{{ return "6558"; }}}
};
};
}

View File

@ -407,7 +407,7 @@ Value ServicesTable::MaxCheckAttemptsAccessor(const Value& row)
Value ServicesTable::CurrentAttemptAccessor(const Value& row) Value ServicesTable::CurrentAttemptAccessor(const Value& row)
{ {
return static_cast<Service::Ptr>(row)->GetCurrentCheckAttempt(); return static_cast<Service::Ptr>(row)->GetCheckAttempt();
} }
Value ServicesTable::StateAccessor(const Value& row) Value ServicesTable::StateAccessor(const Value& row)
@ -471,7 +471,7 @@ Value ServicesTable::NoMoreNotificationsAccessor(const Value& row)
notification_interval = notification->GetNotificationInterval(); notification_interval = notification->GetNotificationInterval();
} }
if (notification_interval == 0 && !service->IsVolatile()) if (notification_interval == 0 && !service->GetVolatile())
return 1; return 1;
return 0; return 0;
@ -731,9 +731,6 @@ Value ServicesTable::DowntimesAccessor(const Value& row)
{ {
Dictionary::Ptr downtimes = static_cast<Service::Ptr>(row)->GetDowntimes(); Dictionary::Ptr downtimes = static_cast<Service::Ptr>(row)->GetDowntimes();
if (!downtimes)
return Empty;
Array::Ptr ids = boost::make_shared<Array>(); Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
@ -758,9 +755,6 @@ Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
{ {
Dictionary::Ptr downtimes = static_cast<Service::Ptr>(row)->GetDowntimes(); Dictionary::Ptr downtimes = static_cast<Service::Ptr>(row)->GetDowntimes();
if (!downtimes)
return Empty;
Array::Ptr ids = boost::make_shared<Array>(); Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
@ -789,9 +783,6 @@ Value ServicesTable::CommentsAccessor(const Value& row)
{ {
Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments(); Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments();
if (!comments)
return Empty;
Array::Ptr ids = boost::make_shared<Array>(); Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(comments); ObjectLock olock(comments);
@ -816,9 +807,6 @@ Value ServicesTable::CommentsWithInfoAccessor(const Value& row)
{ {
Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments(); Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments();
if (!comments)
return Empty;
Array::Ptr ids = boost::make_shared<Array>(); Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(comments); ObjectLock olock(comments);
@ -847,9 +835,6 @@ Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row)
{ {
Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments(); Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments();
if (!comments)
return Empty;
Array::Ptr ids = boost::make_shared<Array>(); Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(comments); ObjectLock olock(comments);

View File

@ -120,7 +120,7 @@ Value StatusTable::ConnectionsAccessor(const Value& row)
Value StatusTable::ConnectionsRateAccessor(const Value& row) Value StatusTable::ConnectionsRateAccessor(const Value& row)
{ {
return (LivestatusListener::GetConnections() / (Utility::GetTime() - IcingaApplication::GetInstance()->GetStartTime())); return (LivestatusListener::GetConnections() / (Utility::GetTime() - Application::GetStartTime()));
} }
Value StatusTable::ExternalCommandsAccessor(const Value& row) Value StatusTable::ExternalCommandsAccessor(const Value& row)
@ -130,7 +130,7 @@ Value StatusTable::ExternalCommandsAccessor(const Value& row)
Value StatusTable::ExternalCommandsRateAccessor(const Value& row) Value StatusTable::ExternalCommandsRateAccessor(const Value& row)
{ {
return (Query::GetExternalCommands() / (Utility::GetTime() - IcingaApplication::GetInstance()->GetStartTime())); return (Query::GetExternalCommands() / (Utility::GetTime() - Application::GetStartTime()));
} }
Value StatusTable::NagiosPidAccessor(const Value& row) Value StatusTable::NagiosPidAccessor(const Value& row)
@ -140,7 +140,7 @@ Value StatusTable::NagiosPidAccessor(const Value& row)
Value StatusTable::ProgramStartAccessor(const Value& row) Value StatusTable::ProgramStartAccessor(const Value& row)
{ {
return static_cast<int>(IcingaApplication::GetInstance()->GetStartTime()); return Application::GetStartTime();
} }
Value StatusTable::NumHostsAccessor(const Value& row) Value StatusTable::NumHostsAccessor(const Value& row)

View File

@ -3,15 +3,22 @@
pkglib_LTLIBRARIES = \ pkglib_LTLIBRARIES = \
libnotification.la libnotification.la
BUILT_SOURCES = \
notificationcomponent.th
CLEANFILES = \ CLEANFILES = \
notification-type.cpp notification-type.cpp
.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig
$(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
.ti.th: $(top_builddir)/tools/mkclass/mkclass
$(top_builddir)/tools/mkclass/mkclass $< > $@
libnotification_la_SOURCES = \ libnotification_la_SOURCES = \
notificationcomponent.cpp \ notificationcomponent.cpp \
notificationcomponent.h \ notificationcomponent.h \
notificationcomponent.ti \
notification-type.conf notification-type.conf
libnotification_la_CPPFLAGS = \ libnotification_la_CPPFLAGS = \

View File

@ -20,6 +20,7 @@
#ifndef NOTIFICATIONCOMPONENT_H #ifndef NOTIFICATIONCOMPONENT_H
#define NOTIFICATIONCOMPONENT_H #define NOTIFICATIONCOMPONENT_H
#include "notification/notificationcomponent.th"
#include "icinga/service.h" #include "icinga/service.h"
#include "base/dynamicobject.h" #include "base/dynamicobject.h"
#include "base/timer.h" #include "base/timer.h"
@ -30,7 +31,7 @@ namespace icinga
/** /**
* @ingroup notification * @ingroup notification
*/ */
class NotificationComponent : public DynamicObject class NotificationComponent : public ReflectionObjectImpl<NotificationComponent>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(NotificationComponent); DECLARE_PTR_TYPEDEFS(NotificationComponent);

View File

@ -0,0 +1,10 @@
#include "base/dynamicobject.h"
namespace icinga
{
class NotificationComponent : DynamicObject
{
};
}

View File

@ -4,17 +4,26 @@
pkglib_LTLIBRARIES = \ pkglib_LTLIBRARIES = \
libperfdata.la libperfdata.la
BUILT_SOURCES = \
graphitewriter.th \
perfdatawriter.th
CLEANFILES = \ CLEANFILES = \
perfdata-type.cpp perfdata-type.cpp
.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig
$(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
.ti.th: $(top_builddir)/tools/mkclass/mkclass
$(top_builddir)/tools/mkclass/mkclass $< > $@
libperfdata_la_SOURCES = \ libperfdata_la_SOURCES = \
graphitewriter.cpp \ graphitewriter.cpp \
graphitewriter.h \ graphitewriter.h \
graphitewriter.ti \
perfdatawriter.cpp \ perfdatawriter.cpp \
perfdatawriter.h \ perfdatawriter.h \
perfdatawriter.th \
perfdata-type.conf perfdata-type.conf
libperfdata_la_CPPFLAGS = \ libperfdata_la_CPPFLAGS = \

View File

@ -57,22 +57,6 @@ void GraphiteWriter::Start(void)
Service::OnNewCheckResult.connect(boost::bind(&GraphiteWriter::CheckResultHandler, this, _1, _2)); Service::OnNewCheckResult.connect(boost::bind(&GraphiteWriter::CheckResultHandler, this, _1, _2));
} }
String GraphiteWriter::GetHost(void) const
{
if (m_Host.IsEmpty())
return "127.0.0.1";
else
return m_Host;
}
String GraphiteWriter::GetPort(void) const
{
if (m_Port.IsEmpty())
return "2003";
else
return m_Port;
}
void GraphiteWriter::ReconnectTimerHandler(void) void GraphiteWriter::ReconnectTimerHandler(void)
{ {
try { try {
@ -110,7 +94,7 @@ void GraphiteWriter::CheckResultHandler(const Service::Ptr& service, const Dicti
Value metricValue; Value metricValue;
/* basic metrics */ /* basic metrics */
AddServiceMetric(metrics, service, "current_attempt", service->GetCurrentCheckAttempt()); AddServiceMetric(metrics, service, "current_attempt", service->GetCheckAttempt());
AddServiceMetric(metrics, service, "max_check_attempts", service->GetMaxCheckAttempts()); AddServiceMetric(metrics, service, "max_check_attempts", service->GetMaxCheckAttempts());
AddServiceMetric(metrics, service, "state_type", service->GetStateType()); AddServiceMetric(metrics, service, "state_type", service->GetStateType());
AddServiceMetric(metrics, service, "state", service->GetState()); AddServiceMetric(metrics, service, "state", service->GetState());
@ -267,22 +251,3 @@ void GraphiteWriter::SanitizeMetric(String& str)
boost::replace_all(str, "/", "_"); boost::replace_all(str, "/", "_");
} }
void GraphiteWriter::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
bag->Set("host", m_Host);
bag->Set("port", m_Port);
}
}
void GraphiteWriter::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
m_Host = bag->Get("host");
m_Port = bag->Get("port");
}
}

View File

@ -20,6 +20,7 @@
#ifndef GRAPHITEWRITER_H #ifndef GRAPHITEWRITER_H
#define GRAPHITEWRITER_H #define GRAPHITEWRITER_H
#include "perfdata/graphitewriter.th"
#include "icinga/service.h" #include "icinga/service.h"
#include "base/dynamicobject.h" #include "base/dynamicobject.h"
#include "base/tcpsocket.h" #include "base/tcpsocket.h"
@ -34,24 +35,16 @@ namespace icinga
* *
* @ingroup perfdata * @ingroup perfdata
*/ */
class GraphiteWriter : public DynamicObject class GraphiteWriter : public ReflectionObjectImpl<GraphiteWriter>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(GraphiteWriter); DECLARE_PTR_TYPEDEFS(GraphiteWriter);
DECLARE_TYPENAME(GraphiteWriter); DECLARE_TYPENAME(GraphiteWriter);
String GetHost(void) const;
String GetPort(void) const;
protected: protected:
virtual void Start(void); virtual void Start(void);
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private: private:
String m_Host;
String m_Port;
Stream::Ptr m_Stream; Stream::Ptr m_Stream;
Timer::Ptr m_ReconnectTimer; Timer::Ptr m_ReconnectTimer;

View File

@ -0,0 +1,16 @@
#include "base/dynamicobject.h"
namespace icinga
{
class GraphiteWriter : DynamicObject
{
[config] String host {
default {{{ return "127.0.0.1"; }}}
};
[config] String port {
default {{{ return "2003"; }}}
};
};
}

View File

@ -33,10 +33,6 @@ using namespace icinga;
REGISTER_TYPE(PerfdataWriter); REGISTER_TYPE(PerfdataWriter);
PerfdataWriter::PerfdataWriter(void)
: m_RotationInterval(30)
{ }
void PerfdataWriter::Start(void) void PerfdataWriter::Start(void)
{ {
DynamicObject::Start(); DynamicObject::Start();
@ -51,37 +47,6 @@ void PerfdataWriter::Start(void)
RotateFile(); RotateFile();
} }
String PerfdataWriter::GetPerfdataPath(void) const
{
if (!m_PerfdataPath.IsEmpty())
return m_PerfdataPath;
else
return Application::GetLocalStateDir() + "/cache/icinga2/perfdata/perfdata";
}
String PerfdataWriter::GetFormatTemplate(void) const
{
if (!m_FormatTemplate.IsEmpty()) {
return m_FormatTemplate;
} else {
return "DATATYPE::SERVICEPERFDATA\t"
"TIMET::$TIMET$\t"
"HOSTNAME::$HOSTNAME$\t"
"SERVICEDESC::$SERVICEDESC$\t"
"SERVICEPERFDATA::$SERVICEPERFDATA$\t"
"SERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\t"
"HOSTSTATE::$HOSTSTATE$\t"
"HOSTSTATETYPE::$HOSTSTATETYPE$\t"
"SERVICESTATE::$SERVICESTATE$\t"
"SERVICESTATETYPE::$SERVICESTATETYPE$";
}
}
double PerfdataWriter::GetRotationInterval(void) const
{
return m_RotationInterval;
}
void PerfdataWriter::CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr) void PerfdataWriter::CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr)
{ {
if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !service->GetEnablePerfdata()) if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !service->GetEnablePerfdata())
@ -130,24 +95,3 @@ void PerfdataWriter::RotationTimerHandler(void)
RotateFile(); RotateFile();
} }
void PerfdataWriter::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
bag->Set("perfdata_path", m_PerfdataPath);
bag->Set("format_template", m_FormatTemplate);
bag->Set("rotation_interval", m_RotationInterval);
}
}
void PerfdataWriter::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
m_PerfdataPath = bag->Get("perfdata_path");
m_FormatTemplate = bag->Get("format_template");
m_RotationInterval = bag->Get("rotation_interval");
}
}

View File

@ -20,7 +20,7 @@
#ifndef PERFDATAWRITER_H #ifndef PERFDATAWRITER_H
#define PERFDATAWRITER_H #define PERFDATAWRITER_H
#include "icinga/i2-icinga.h" #include "perfdata/perfdatawriter.th"
#include "icinga/service.h" #include "icinga/service.h"
#include "base/dynamicobject.h" #include "base/dynamicobject.h"
#include "base/timer.h" #include "base/timer.h"
@ -34,29 +34,16 @@ namespace icinga
* *
* @ingroup icinga * @ingroup icinga
*/ */
class PerfdataWriter : public DynamicObject class PerfdataWriter : public ReflectionObjectImpl<PerfdataWriter>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(PerfdataWriter); DECLARE_PTR_TYPEDEFS(PerfdataWriter);
DECLARE_TYPENAME(PerfdataWriter); DECLARE_TYPENAME(PerfdataWriter);
PerfdataWriter(void);
String GetPerfdataPath(void) const;
String GetFormatTemplate(void) const;
double GetRotationInterval(void) const;
protected: protected:
virtual void Start(void); virtual void Start(void);
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private: private:
String m_PerfdataPath;
String m_FormatTemplate;
double m_RotationInterval;
void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr); void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr);
Timer::Ptr m_RotationTimer; Timer::Ptr m_RotationTimer;

View File

@ -0,0 +1,32 @@
#include "base/dynamicobject.h"
#include "base/application.h"
namespace icinga
{
class PerfdataWriter : DynamicObject
{
[config] String perfdata_path {
default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/perfdata/perfdata"; }}}
};
[config] String format_template {
default {{{
return "DATATYPE::SERVICEPERFDATA\t"
"TIMET::$TIMET$\t"
"HOSTNAME::$HOSTNAME$\t"
"SERVICEDESC::$SERVICEDESC$\t"
"SERVICEPERFDATA::$SERVICEPERFDATA$\t"
"SERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\t"
"HOSTSTATE::$HOSTSTATE$\t"
"HOSTSTATETYPE::$HOSTSTATETYPE$\t"
"SERVICESTATE::$SERVICESTATE$\t"
"SERVICESTATETYPE::$SERVICESTATETYPE$";
}}}
};
[config] double rotation_interval {
default {{{ return 30; }}}
};
};
}

View File

@ -210,6 +210,7 @@ third-party/mmatch/Makefile
tools/Makefile tools/Makefile
tools/migration/Makefile tools/migration/Makefile
tools/icinga2-enable-feature tools/icinga2-enable-feature
tools/mkclass/Makefile
tools/mkembedconfig/Makefile tools/mkembedconfig/Makefile
]) ])

View File

@ -111,7 +111,7 @@ Attributes:
max\_check\_attempts|**Optional.** The number of times a service is re-checked before changing into a hard state. Defaults to 3. max\_check\_attempts|**Optional.** The number of times a service is re-checked before changing into a hard state. Defaults to 3.
check\_period |**Optional.** The name of a time period which determines when this service should be checked. Not set by default. check\_period |**Optional.** The name of a time period which determines when this service should be checked. Not set by default.
check\_interval |**Optional.** The check interval (in seconds). This interval is used for checks when the service is in a `HARD` state. Defaults to 5 minutes. check\_interval |**Optional.** The check interval (in seconds). This interval is used for checks when the service is in a `HARD` state. Defaults to 5 minutes.
retry\_interval |**Optional.** The retry interval (in seconds). This interval is used for checks when the service is in a `SOFT` state. Defaults to 1/5th of the check interval if not specified. retry\_interval |**Optional.** The retry interval (in seconds). This interval is used for checks when the service is in a `SOFT` state. Defaults to 1 minute.
enable\_active\_checks|**Optional.** Whether active checks are enabled. Defaults to true. enable\_active\_checks|**Optional.** Whether active checks are enabled. Defaults to true.
enable\_passive\_checks|**Optional.** Whether passive checks are enabled. Defaults to true. enable\_passive\_checks|**Optional.** Whether passive checks are enabled. Defaults to true.
enable\_event\_handler|**Optional.** Enables event handlers for this service. Defaults to true. enable\_event\_handler|**Optional.** Enables event handlers for this service. Defaults to true.

View File

@ -160,6 +160,8 @@ static bool Daemonize(const String& stderrFile)
*/ */
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
Application::SetStartTime(Utility::GetTime());
#ifndef _WIN32 #ifndef _WIN32
LTDL_SET_PRELOADED_SYMBOLS(); LTDL_SET_PRELOADED_SYMBOLS();
#endif /* _WIN32 */ #endif /* _WIN32 */

View File

@ -14,6 +14,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo", "components\demo\demo.vcxproj", "{2E6C1133-730F-4875-A72C-B455B1DD4C5C}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo", "components\demo\demo.vcxproj", "{2E6C1133-730F-4875-A72C-B455B1DD4C5C}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311}
{CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
@ -21,6 +22,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo", "components\demo\dem
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "notification", "components\notification\notification.vcxproj", "{EBEA7D10-66FB-4760-8AA8-81CD500D899E}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "notification", "components\notification\notification.vcxproj", "{EBEA7D10-66FB-4760-8AA8-81CD500D899E}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{950E8743-BB34-4F8A-99EC-C87E8FC0EB3F} = {950E8743-BB34-4F8A-99EC-C87E8FC0EB3F}
{D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
@ -34,6 +36,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "checker", "components\checker\checker.vcxproj", "{38CE81CC-2660-4EF0-A936-4A337591DA3E}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "checker", "components\checker\checker.vcxproj", "{38CE81CC-2660-4EF0-A936-4A337591DA3E}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311}
{CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
@ -42,6 +45,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "compat", "components\compat\compat.vcxproj", "{2BD1C70C-43DB-4F44-B66B-67CF5C7044AA}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "compat", "components\compat\compat.vcxproj", "{2BD1C70C-43DB-4F44-B66B-67CF5C7044AA}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311}
{CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
@ -57,6 +61,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "base", "lib\base\base.vcxpr
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{19CBCE06-3F5C-479A-BD75-E2AB6215D345} = {19CBCE06-3F5C-479A-BD75-E2AB6215D345} {19CBCE06-3F5C-479A-BD75-E2AB6215D345} = {19CBCE06-3F5C-479A-BD75-E2AB6215D345}
{66BED474-C33F-48F9-90BA-BBCFEDC006B8} = {66BED474-C33F-48F9-90BA-BBCFEDC006B8} {66BED474-C33F-48F9-90BA-BBCFEDC006B8} = {66BED474-C33F-48F9-90BA-BBCFEDC006B8}
{CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "config", "lib\config\config.vcxproj", "{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "config", "lib\config\config.vcxproj", "{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}"
@ -68,6 +73,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icinga", "lib\icinga\icinga.vcxproj", "{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icinga", "lib\icinga\icinga.vcxproj", "{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311}
{CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
EndProjectSection EndProjectSection
@ -80,6 +86,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "livestatus", "components\livestatus\livestatus.vcxproj", "{950E8743-BB34-4F8A-99EC-C87E8FC0EB3F}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "livestatus", "components\livestatus\livestatus.vcxproj", "{950E8743-BB34-4F8A-99EC-C87E8FC0EB3F}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311}
{CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
@ -90,6 +97,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cluster", "components\cluster\cluster.vcxproj", "{8732E0CD-E3D0-41F2-A538-94884543890F}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cluster", "components\cluster\cluster.vcxproj", "{8732E0CD-E3D0-41F2-A538-94884543890F}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311}
{CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
@ -107,6 +115,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "db_ido", "lib\db_ido\db_ido.vcxproj", "{87BBCE4C-36F5-4C04-90FB-9B74618AF988}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "db_ido", "lib\db_ido\db_ido.vcxproj", "{87BBCE4C-36F5-4C04-90FB-9B74618AF988}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311}
{CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
@ -114,12 +123,15 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "db_ido", "lib\db_ido\db_ido
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "perfdata", "components\perfdata\perfdata.vcxproj", "{E08A9B69-97E2-4203-B4D7-501DFF020CCF}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "perfdata", "components\perfdata\perfdata.vcxproj", "{E08A9B69-97E2-4203-B4D7-501DFF020CCF}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{950E8743-BB34-4F8A-99EC-C87E8FC0EB3F} = {950E8743-BB34-4F8A-99EC-C87E8FC0EB3F}
{D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mkclass", "tools\mkclass\mkclass.vcxproj", "{CBC9DD83-BAEB-4995-8D0B-F711898908E7}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32 Debug|Win32 = Debug|Win32
@ -265,6 +277,14 @@ Global
{E08A9B69-97E2-4203-B4D7-501DFF020CCF}.Release|Win32.Build.0 = Release|Win32 {E08A9B69-97E2-4203-B4D7-501DFF020CCF}.Release|Win32.Build.0 = Release|Win32
{E08A9B69-97E2-4203-B4D7-501DFF020CCF}.Release|x64.ActiveCfg = Release|x64 {E08A9B69-97E2-4203-B4D7-501DFF020CCF}.Release|x64.ActiveCfg = Release|x64
{E08A9B69-97E2-4203-B4D7-501DFF020CCF}.Release|x64.Build.0 = Release|x64 {E08A9B69-97E2-4203-B4D7-501DFF020CCF}.Release|x64.Build.0 = Release|x64
{CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Debug|Win32.ActiveCfg = Debug|Win32
{CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Debug|Win32.Build.0 = Debug|Win32
{CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Debug|x64.ActiveCfg = Debug|x64
{CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Debug|x64.Build.0 = Debug|x64
{CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Release|Win32.ActiveCfg = Release|Win32
{CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Release|Win32.Build.0 = Release|Win32
{CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Release|x64.ActiveCfg = Release|x64
{CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Release|x64.Build.0 = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -4,15 +4,30 @@
pkglib_LTLIBRARIES = \ pkglib_LTLIBRARIES = \
libbase.la libbase.la
BUILT_SOURCES = \
application.th \
consolelogger.th \
dynamicobject.th \
filelogger.th \
logger.th \
script.th \
streamlogger.th \
sysloglogger.th
.ti.th: $(top_builddir)/tools/mkclass/mkclass
$(top_builddir)/tools/mkclass/mkclass $< > $@
libbase_la_SOURCES = \ libbase_la_SOURCES = \
application.cpp \ application.cpp \
application.h \ application.h \
application.ti \
array.cpp \ array.cpp \
array.h \ array.h \
bufferedstream.cpp \ bufferedstream.cpp \
bufferedstream.h \ bufferedstream.h \
consolelogger.cpp \ consolelogger.cpp \
consolelogger.h \ consolelogger.h \
consolelogger.ti \
convert.cpp \ convert.cpp \
convert.h \ convert.h \
debug.h \ debug.h \
@ -20,6 +35,7 @@ libbase_la_SOURCES = \
dictionary.h \ dictionary.h \
dynamicobject.cpp \ dynamicobject.cpp \
dynamicobject.h \ dynamicobject.h \
dynamicobject.ti \
dynamictype.cpp \ dynamictype.cpp \
dynamictype.h \ dynamictype.h \
exception.cpp \ exception.cpp \
@ -28,10 +44,12 @@ libbase_la_SOURCES = \
fifo.h \ fifo.h \
filelogger.cpp \ filelogger.cpp \
filelogger.h \ filelogger.h \
filelogger.ti \
i2-base.h \ i2-base.h \
initialize.h \ initialize.h \
logger.cpp \ logger.cpp \
logger.h \ logger.h \
logger.ti \
logger_fwd.h \ logger_fwd.h \
netstring.cpp \ netstring.cpp \
netstring.h \ netstring.h \
@ -47,11 +65,14 @@ libbase_la_SOURCES = \
process.h \ process.h \
qstring.cpp \ qstring.cpp \
qstring.h \ qstring.h \
reflectionobject.cpp \
reflectionobject.h \
registry.h \ registry.h \
ringbuffer.cpp \ ringbuffer.cpp \
ringbuffer.h \ ringbuffer.h \
script.cpp \ script.cpp \
script.h \ script.h \
script.ti \
scriptfunction.cpp \ scriptfunction.cpp \
scriptfunction.h \ scriptfunction.h \
scriptfunctionwrapper.cpp \ scriptfunctionwrapper.cpp \
@ -75,8 +96,10 @@ libbase_la_SOURCES = \
stream_bio.h \ stream_bio.h \
streamlogger.cpp \ streamlogger.cpp \
streamlogger.h \ streamlogger.h \
streamlogger.ti \
sysloglogger.cpp \ sysloglogger.cpp \
sysloglogger.h \ sysloglogger.h \
sysloglogger.ti \
tcpsocket.cpp \ tcpsocket.cpp \
tcpsocket.h \ tcpsocket.h \
threadpool.cpp \ threadpool.cpp \

View File

@ -51,6 +51,7 @@ bool Application::m_Restarting = false;
bool Application::m_Debugging = false; bool Application::m_Debugging = false;
int Application::m_ArgC; int Application::m_ArgC;
char **Application::m_ArgV; char **Application::m_ArgV;
double Application::m_StartTime;
/** /**
* Constructor for the Application class. * Constructor for the Application class.
@ -718,3 +719,13 @@ String Application::GetVersion(void)
return "unspecified version"; return "unspecified version";
#endif /* _WIN32 */ #endif /* _WIN32 */
} }
double Application::GetStartTime(void)
{
return m_StartTime;
}
void Application::SetStartTime(double ts)
{
m_StartTime = ts;
}

View File

@ -21,6 +21,7 @@
#define APPLICATION_H #define APPLICATION_H
#include "base/i2-base.h" #include "base/i2-base.h"
#include "base/application.th"
#include "base/threadpool.h" #include "base/threadpool.h"
#include "base/dynamicobject.h" #include "base/dynamicobject.h"
@ -33,7 +34,7 @@ class Component;
* *
* @ingroup base * @ingroup base
*/ */
class I2_BASE_API Application : public DynamicObject { class I2_BASE_API Application : public ReflectionObjectImpl<Application> {
public: public:
DECLARE_PTR_TYPEDEFS(Application); DECLARE_PTR_TYPEDEFS(Application);
@ -94,6 +95,9 @@ public:
static String GetVersion(void); static String GetVersion(void);
static double GetStartTime(void);
static void SetStartTime(double ts);
protected: protected:
virtual void OnConfigLoaded(void); virtual void OnConfigLoaded(void);
virtual void Stop(void); virtual void Stop(void);
@ -112,6 +116,7 @@ private:
static char **m_ArgV; /**< Command-line arguments. */ static char **m_ArgV; /**< Command-line arguments. */
FILE *m_PidFile; /**< The PID file */ FILE *m_PidFile; /**< The PID file */
static bool m_Debugging; /**< Whether debugging is enabled. */ static bool m_Debugging; /**< Whether debugging is enabled. */
static double m_StartTime;
#ifndef _WIN32 #ifndef _WIN32
static void SigIntHandler(int signum); static void SigIntHandler(int signum);

10
lib/base/application.ti Normal file
View File

@ -0,0 +1,10 @@
#include "base/dynamicobject.h"
namespace icinga
{
class Application : DynamicObject
{
};
}

View File

@ -30,6 +30,7 @@
<ClCompile Include="dynamictype.cpp" /> <ClCompile Include="dynamictype.cpp" />
<ClCompile Include="filelogger.cpp" /> <ClCompile Include="filelogger.cpp" />
<ClCompile Include="networkstream.cpp" /> <ClCompile Include="networkstream.cpp" />
<ClCompile Include="reflectionobject.cpp" />
<ClCompile Include="script.cpp" /> <ClCompile Include="script.cpp" />
<ClCompile Include="scriptinterpreter.cpp" /> <ClCompile Include="scriptinterpreter.cpp" />
<ClCompile Include="scriptlanguage.cpp" /> <ClCompile Include="scriptlanguage.cpp" />
@ -78,6 +79,7 @@
<ClInclude Include="filelogger.h" /> <ClInclude Include="filelogger.h" />
<ClInclude Include="initialize.h" /> <ClInclude Include="initialize.h" />
<ClInclude Include="networkstream.h" /> <ClInclude Include="networkstream.h" />
<ClInclude Include="reflectionobject.h" />
<ClInclude Include="script.h" /> <ClInclude Include="script.h" />
<ClInclude Include="scriptinterpreter.h" /> <ClInclude Include="scriptinterpreter.h" />
<ClInclude Include="scriptlanguage.h" /> <ClInclude Include="scriptlanguage.h" />
@ -118,7 +120,105 @@
<ClInclude Include="zlibstream.h" /> <ClInclude Include="zlibstream.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="dynamicobject.ti">
<FileType>Document</FileType>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).th;%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
</CustomBuild>
<ClInclude Include="dynamicobject.th">
<FileType>Document</FileType>
</ClInclude>
<CustomBuild Include="application.ti">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).th;%(Outputs)</Outputs>
</CustomBuild>
<None Include="application.th" />
<CustomBuild Include="logger.ti">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).th;%(Outputs)</Outputs>
</CustomBuild>
<CustomBuild Include="filelogger.ti">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).th;%(Outputs)</Outputs>
</CustomBuild>
<CustomBuild Include="consolelogger.ti">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).th;%(Outputs)</Outputs>
</CustomBuild>
<None Include="consolelogger.th" />
<None Include="filelogger.th" />
<None Include="logger.th" />
<None Include="packages.config" /> <None Include="packages.config" />
<CustomBuild Include="script.ti">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).th;%(Outputs)</Outputs>
</CustomBuild>
<None Include="script.th" />
<CustomBuild Include="streamlogger.ti">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).th;%(Outputs)</Outputs>
</CustomBuild>
<None Include="streamlogger.th" />
<CustomBuild Include="sysloglogger.ti">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).th;%(Outputs)</Outputs>
</CustomBuild>
<None Include="sysloglogger.th" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{9C92DA90-FD53-43A9-A244-90F2E8AF9677}</ProjectGuid> <ProjectGuid>{9C92DA90-FD53-43A9-A244-90F2E8AF9677}</ProjectGuid>

View File

@ -133,6 +133,9 @@
<ClCompile Include="zlibstream.cpp"> <ClCompile Include="zlibstream.cpp">
<Filter>Quelldateien</Filter> <Filter>Quelldateien</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="reflectionobject.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="application.h"> <ClInclude Include="application.h">
@ -285,6 +288,12 @@
<ClInclude Include="zlibstream.h"> <ClInclude Include="zlibstream.h">
<Filter>Headerdateien</Filter> <Filter>Headerdateien</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="reflectionobject.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="dynamicobject.th">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="Quelldateien"> <Filter Include="Quelldateien">
@ -296,5 +305,52 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="script.th">
<Filter>Headerdateien</Filter>
</None>
<None Include="application.th">
<Filter>Headerdateien</Filter>
</None>
<None Include="logger.th">
<Filter>Headerdateien</Filter>
</None>
<None Include="streamlogger.th">
<Filter>Headerdateien</Filter>
</None>
<None Include="filelogger.th">
<Filter>Headerdateien</Filter>
</None>
<None Include="sysloglogger.th">
<Filter>Headerdateien</Filter>
</None>
<None Include="consolelogger.th">
<Filter>Headerdateien</Filter>
</None>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="dynamicobject.ti">
<Filter>Headerdateien</Filter>
</CustomBuild>
<CustomBuild Include="script.ti">
<Filter>Headerdateien</Filter>
</CustomBuild>
<CustomBuild Include="application.ti">
<Filter>Headerdateien</Filter>
</CustomBuild>
<CustomBuild Include="logger.ti">
<Filter>Headerdateien</Filter>
</CustomBuild>
<CustomBuild Include="streamlogger.ti">
<Filter>Headerdateien</Filter>
</CustomBuild>
<CustomBuild Include="filelogger.ti">
<Filter>Headerdateien</Filter>
</CustomBuild>
<CustomBuild Include="sysloglogger.ti">
<Filter>Headerdateien</Filter>
</CustomBuild>
<CustomBuild Include="consolelogger.ti">
<Filter>Headerdateien</Filter>
</CustomBuild>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -21,7 +21,7 @@
#define CONSOLELOGGER_H #define CONSOLELOGGER_H
#include "base/i2-base.h" #include "base/i2-base.h"
#include "base/streamlogger.h" #include "base/consolelogger.th"
namespace icinga namespace icinga
{ {
@ -31,7 +31,7 @@ namespace icinga
* *
* @ingroup base * @ingroup base
*/ */
class I2_BASE_API ConsoleLogger : public StreamLogger class I2_BASE_API ConsoleLogger : public ReflectionObjectImpl<ConsoleLogger>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(ConsoleLogger); DECLARE_PTR_TYPEDEFS(ConsoleLogger);

10
lib/base/consolelogger.ti Normal file
View File

@ -0,0 +1,10 @@
#include "base/streamlogger.h"
namespace icinga
{
class ConsoleLogger : StreamLogger
{
};
}

View File

@ -22,30 +22,45 @@
#include "i2-base.h" #include "i2-base.h"
#ifdef NDEBUG #ifndef _DEBUG
# define ASSERT(expr) ((void)0) # define ASSERT(expr) ((void)0)
#else /* NDEBUG */ #else /* _DEBUG */
# define ASSERT(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__)) # define ASSERT(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__))
#endif /* NDEBUG */ #endif /* _DEBUG */
#define VERIFY(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__)) #define VERIFY(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__))
#ifdef _MSC_VER
# define NORETURNPRE __declspec(noreturn)
#else /* _MSC_VER */
# define NORETURNPRE
#endif /* _MSC_VER */
#ifdef __GNUC__ #ifdef __GNUC__
# define NORETURN __attribute__((noreturn)) # define NORETURNPOST __attribute__((noreturn))
#else /* __GNUC__ */ #else /* __GNUC__ */
# define NORETURN # define NORETURNPOST
#endif /* __GNUC__ */ #endif /* __GNUC__ */
int icinga_assert_fail(const char *expr, const char *file, int line) NORETURN; NORETURNPRE int icinga_assert_fail(const char *expr, const char *file, int line) NORETURNPOST;
#ifdef _MSC_VER
# pragma warning( push )
# pragma warning( disable : 4646 ) /* function declared with __declspec(noreturn) has non-void return type */
#endif /* _MSC_VER */
inline int icinga_assert_fail(const char *expr, const char *file, int line) inline int icinga_assert_fail(const char *expr, const char *file, int line)
{ {
fprintf(stderr, "%s:%d: assertion failed: %s\n", file, line, expr); fprintf(stderr, "%s:%d: assertion failed: %s\n", file, line, expr);
abort(); abort();
#ifndef __GNUC__ #if !defined(__GNUC__) && !defined(_MSC_VER)
return 0; return 0;
#endif /* __GNUC__ */ #endif /* !defined(__GNUC__) && !defined(_MSC_VER) */
} }
#ifdef _MSC_VER
# pragma warning( pop )
#endif /* _MSC_VER */
#endif /* DEBUG_H */ #endif /* DEBUG_H */

View File

@ -42,90 +42,21 @@ boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnState
boost::signals2::signal<void (const DynamicObject::Ptr&, const String&, bool)> DynamicObject::OnAuthorityChanged; boost::signals2::signal<void (const DynamicObject::Ptr&, const String&, bool)> DynamicObject::OnAuthorityChanged;
DynamicObject::DynamicObject(void) DynamicObject::DynamicObject(void)
: m_Active(false) {
{ } SetActive(false);
}
DynamicObject::~DynamicObject(void) DynamicObject::~DynamicObject(void)
{ } { }
Dictionary::Ptr DynamicObject::Serialize(int attributeTypes) const
{
Dictionary::Ptr update = boost::make_shared<Dictionary>();
ASSERT(!OwnsLock());
ObjectLock olock(this);
InternalSerialize(update, attributeTypes);
/* Make sure our own InternalSerialize() method was called. */
ASSERT(update->Contains("__marker"));
update->Remove("__marker");
return update;
}
void DynamicObject::Deserialize(const Dictionary::Ptr& update, int attributeTypes)
{
ASSERT(!OwnsLock());
{
ObjectLock olock(this);
InternalDeserialize(update, attributeTypes);
}
}
void DynamicObject::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
if (attributeTypes & Attribute_Config) {
bag->Set("__name", m_Name);
bag->Set("__type", m_Type);
bag->Set("methods", m_Methods);
bag->Set("custom", m_Custom);
bag->Set("authorities", m_Authorities);
bag->Set("domains", m_Domains);
}
if (attributeTypes & Attribute_State)
bag->Set("extensions", m_Extensions);
/* This attribute is used by Serialize() to check that this
* method was called. */
bag->Set("__marker", 1);
}
void DynamicObject::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
if (attributeTypes & Attribute_Config) {
m_Name = bag->Get("__name");
m_Type = bag->Get("__type");
m_Methods = bag->Get("methods");
m_Custom = bag->Get("custom");
m_Authorities = bag->Get("authorities");
m_Domains = bag->Get("domains");
}
if (attributeTypes & Attribute_State)
m_Extensions = bag->Get("extensions");
}
DynamicType::Ptr DynamicObject::GetType(void) const DynamicType::Ptr DynamicObject::GetType(void) const
{ {
return DynamicType::GetByName(m_Type); return DynamicType::GetByName(GetTypeName());
}
String DynamicObject::GetName(void) const
{
return m_Name;
} }
bool DynamicObject::IsActive(void) const bool DynamicObject::IsActive(void) const
{ {
return m_Active; return GetActive();
}
Array::Ptr DynamicObject::GetAuthorities(void) const
{
return m_Authorities;
} }
void DynamicObject::SetAuthority(const String& type, bool value) void DynamicObject::SetAuthority(const String& type, bool value)
@ -135,15 +66,12 @@ void DynamicObject::SetAuthority(const String& type, bool value)
{ {
ObjectLock olock(this); ObjectLock olock(this);
if (!m_Authority)
m_Authority = boost::make_shared<Dictionary>();
bool old_value = HasAuthority(type); bool old_value = HasAuthority(type);
if (old_value == value) if (old_value == value)
return; return;
m_Authority->Set(type, value); GetAuthorityInfo()->Set(type, value);
} }
OnAuthorityChanged(GetSelf(), type, value); OnAuthorityChanged(GetSelf(), type, value);
@ -151,15 +79,7 @@ void DynamicObject::SetAuthority(const String& type, bool value)
bool DynamicObject::HasAuthority(const String& type) const bool DynamicObject::HasAuthority(const String& type) const
{ {
if (!m_Authority) return GetAuthorityInfo()->Get(type);
return true;
return m_Authority->Get(type);
}
Array::Ptr DynamicObject::GetDomains(void) const
{
return m_Domains;
} }
void DynamicObject::SetPrivileges(const String& instance, int privs) void DynamicObject::SetPrivileges(const String& instance, int privs)
@ -183,11 +103,11 @@ bool DynamicObject::HasPrivileges(const String& instance, int privs) const
void DynamicObject::SetExtension(const String& key, const Object::Ptr& object) void DynamicObject::SetExtension(const String& key, const Object::Ptr& object)
{ {
Dictionary::Ptr extensions = m_Extensions; Dictionary::Ptr extensions = GetExtensions();
if (!extensions) { if (!extensions) {
extensions = boost::make_shared<Dictionary>(); extensions = boost::make_shared<Dictionary>();
m_Extensions = extensions; SetExtensions(extensions);
} }
extensions->Set(key, object); extensions->Set(key, object);
@ -195,7 +115,7 @@ void DynamicObject::SetExtension(const String& key, const Object::Ptr& object)
Object::Ptr DynamicObject::GetExtension(const String& key) Object::Ptr DynamicObject::GetExtension(const String& key)
{ {
Dictionary::Ptr extensions = m_Extensions; Dictionary::Ptr extensions = GetExtensions();
if (!extensions) if (!extensions)
return Object::Ptr(); return Object::Ptr();
@ -205,7 +125,7 @@ Object::Ptr DynamicObject::GetExtension(const String& key)
void DynamicObject::ClearExtension(const String& key) void DynamicObject::ClearExtension(const String& key)
{ {
Dictionary::Ptr extensions = m_Extensions; Dictionary::Ptr extensions = GetExtensions();
if (!extensions) if (!extensions)
return; return;
@ -225,8 +145,8 @@ void DynamicObject::Start(void)
{ {
ASSERT(!OwnsLock()); ASSERT(!OwnsLock());
ASSERT(!m_Active); ASSERT(!IsActive());
m_Active = true; SetActive(true);
OnStarted(GetSelf()); OnStarted(GetSelf());
} }
@ -235,8 +155,8 @@ void DynamicObject::Stop(void)
{ {
ASSERT(!OwnsLock()); ASSERT(!OwnsLock());
ASSERT(m_Active); ASSERT(IsActive());
m_Active = false; SetActive(false);
OnStopped(GetSelf()); OnStopped(GetSelf());
} }
@ -256,7 +176,7 @@ Value DynamicObject::InvokeMethod(const String& method,
{ {
Dictionary::Ptr methods; Dictionary::Ptr methods;
methods = m_Methods; methods = GetMethods();
if (!methods) if (!methods)
BOOST_THROW_EXCEPTION(std::invalid_argument("Method '" + method + "' does not exist.")); BOOST_THROW_EXCEPTION(std::invalid_argument("Method '" + method + "' does not exist."));
@ -383,8 +303,3 @@ DynamicObject::Ptr DynamicObject::GetObject(const String& type, const String& na
DynamicType::Ptr dtype = DynamicType::GetByName(type); DynamicType::Ptr dtype = DynamicType::GetByName(type);
return dtype->GetObject(name); return dtype->GetObject(name);
} }
Dictionary::Ptr DynamicObject::GetCustom(void) const
{
return m_Custom;
}

View File

@ -21,6 +21,7 @@
#define DYNAMICOBJECT_H #define DYNAMICOBJECT_H
#include "base/i2-base.h" #include "base/i2-base.h"
#include "base/dynamicobject.th"
#include "base/object.h" #include "base/object.h"
#include "base/dictionary.h" #include "base/dictionary.h"
#include "base/array.h" #include "base/array.h"
@ -40,8 +41,8 @@ class DynamicType;
*/ */
enum AttributeType enum AttributeType
{ {
Attribute_State = 1, Attribute_State = FAState,
Attribute_Config = 2, Attribute_Config = FAConfig
}; };
enum DomainPriv enum DomainPriv
@ -57,16 +58,13 @@ enum DomainPriv
* *
* @ingroup base * @ingroup base
*/ */
class I2_BASE_API DynamicObject : public Object class I2_BASE_API DynamicObject : public ReflectionObjectImpl<DynamicObject>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(DynamicObject); DECLARE_PTR_TYPEDEFS(DynamicObject);
~DynamicObject(void); ~DynamicObject(void);
Dictionary::Ptr Serialize(int attributeTypes) const;
void Deserialize(const Dictionary::Ptr& update, int attributeTypes);
static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStarted; static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStarted;
static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStopped; static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStopped;
static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStateChanged; static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStateChanged;
@ -75,17 +73,12 @@ public:
Value InvokeMethod(const String& method, const std::vector<Value>& arguments); Value InvokeMethod(const String& method, const std::vector<Value>& arguments);
shared_ptr<DynamicType> GetType(void) const; shared_ptr<DynamicType> GetType(void) const;
String GetName(void) const;
bool IsActive(void) const; bool IsActive(void) const;
Array::Ptr GetAuthorities(void) const;
void SetAuthority(const String& type, bool value); void SetAuthority(const String& type, bool value);
bool HasAuthority(const String& type) const; bool HasAuthority(const String& type) const;
Array::Ptr GetDomains(void) const;
void SetPrivileges(const String& instance, int privs); void SetPrivileges(const String& instance, int privs);
bool HasPrivileges(const String& instance, int privs) const; bool HasPrivileges(const String& instance, int privs) const;
@ -116,27 +109,12 @@ public:
static void RestoreObjects(const String& filename, int attributeTypes = Attribute_State); static void RestoreObjects(const String& filename, int attributeTypes = Attribute_State);
static void StopObjects(void); static void StopObjects(void);
Dictionary::Ptr GetCustom(void) const;
protected: protected:
explicit DynamicObject(void); explicit DynamicObject(void);
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private: private:
String m_Name;
String m_Type;
Dictionary::Ptr m_Extensions;
Dictionary::Ptr m_Methods;
Dictionary::Ptr m_Custom;
Array::Ptr m_Authorities;
Array::Ptr m_Domains;
std::map<String, int> m_Privileges; std::map<String, int> m_Privileges;
bool m_Active;
Dictionary::Ptr m_Authority;
static DynamicObject::Ptr GetObject(const String& type, const String& name); static DynamicObject::Ptr GetObject(const String& type, const String& name);
}; };

21
lib/base/dynamicobject.ti Normal file
View File

@ -0,0 +1,21 @@
#include <boost/smart_ptr/make_shared.hpp>
namespace icinga
{
class DynamicObject
{
[config] String __name (Name);
[config, get_protected] String __type (TypeName);
[config] Dictionary::Ptr methods;
[config] Dictionary::Ptr custom;
[config] Array::Ptr domains;
[config] Array::Ptr authorities;
[get_protected] bool active;
Dictionary::Ptr authority_info {
default {{{ return boost::make_shared<Dictionary>(); }}}
};
[protected] Dictionary::Ptr extensions;
};
}

View File

@ -34,7 +34,7 @@ void FileLogger::Start()
std::ofstream *stream = new std::ofstream(); std::ofstream *stream = new std::ofstream();
String path = m_Path; String path = GetPath();
try { try {
stream->open(path.CStr(), std::fstream::out | std::fstream::trunc); stream->open(path.CStr(), std::fstream::out | std::fstream::trunc);
@ -48,19 +48,3 @@ void FileLogger::Start()
BindStream(stream, true); BindStream(stream, true);
} }
void FileLogger::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
StreamLogger::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config)
bag->Set("path", m_Path);
}
void FileLogger::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
StreamLogger::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config)
m_Path = bag->Get("path");
}

View File

@ -21,7 +21,7 @@
#define FILELOGGER_H #define FILELOGGER_H
#include "base/i2-base.h" #include "base/i2-base.h"
#include "base/streamlogger.h" #include "base/filelogger.th"
namespace icinga namespace icinga
{ {
@ -31,19 +31,12 @@ namespace icinga
* *
* @ingroup base * @ingroup base
*/ */
class I2_BASE_API FileLogger : public StreamLogger class I2_BASE_API FileLogger : public ReflectionObjectImpl<FileLogger>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(FileLogger); DECLARE_PTR_TYPEDEFS(FileLogger);
virtual void Start(void); virtual void Start(void);
protected:
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private:
String m_Path;
}; };
} }

11
lib/base/filelogger.ti Normal file
View File

@ -0,0 +1,11 @@
#include "base/streamlogger.h"
namespace icinga
{
class FileLogger : StreamLogger
{
[config] String path;
};
}

View File

@ -105,7 +105,7 @@ void icinga::Log(LogSeverity severity, const String& facility,
*/ */
LogSeverity Logger::GetMinSeverity(void) const LogSeverity Logger::GetMinSeverity(void) const
{ {
String severity = m_Severity; String severity = GetSeverity();
if (severity.IsEmpty()) if (severity.IsEmpty())
return LogInformation; return LogInformation;
else else
@ -151,19 +151,3 @@ LogSeverity Logger::StringToSeverity(const String& severity)
else else
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity)); BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity));
} }
void Logger::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config)
bag->Set("severity", m_Severity);
}
void Logger::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config)
m_Severity = bag->Get("severity");
}

View File

@ -21,6 +21,7 @@
#define LOGGER_H #define LOGGER_H
#include "base/i2-base.h" #include "base/i2-base.h"
#include "base/logger.th"
#include "base/dynamicobject.h" #include "base/dynamicobject.h"
#include "base/logger_fwd.h" #include "base/logger_fwd.h"
#include <set> #include <set>
@ -45,7 +46,7 @@ struct LogEntry {
* *
* @ingroup base * @ingroup base
*/ */
class I2_BASE_API Logger : public DynamicObject class I2_BASE_API Logger : public ReflectionObjectImpl<Logger>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(Logger); DECLARE_PTR_TYPEDEFS(Logger);
@ -69,12 +70,7 @@ protected:
virtual void Start(void); virtual void Start(void);
virtual void Stop(void); virtual void Stop(void);
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private: private:
String m_Severity;
static boost::mutex m_Mutex; static boost::mutex m_Mutex;
static std::set<Logger::Ptr> m_Loggers; static std::set<Logger::Ptr> m_Loggers;

11
lib/base/logger.ti Normal file
View File

@ -0,0 +1,11 @@
#include "base/dynamicobject.h"
namespace icinga
{
class Logger : DynamicObject
{
[config] String severity;
};
}

View File

@ -129,7 +129,7 @@ ProcessResult Process::Run(void)
(void) close(fds[0]); (void) close(fds[0]);
(void) close(fds[1]); (void) close(fds[1]);
if (execvpe(argv[0], argv, envp) < 0) { if (icinga2_execvpe(argv[0], argv, envp) < 0) {
perror("execvpe() failed."); perror("execvpe() failed.");
_exit(128); _exit(128);
} }

View File

@ -0,0 +1,54 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software Foundation *
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include "base/reflectionobject.h"
#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
Dictionary::Ptr ReflectionObject::Serialize(int attributeTypes) const
{
Dictionary::Ptr update = boost::make_shared<Dictionary>();
for (int i = 0; i < GetFieldCount(); i++) {
ReflectionField field = GetFieldInfo(i);
if ((field.Attributes & attributeTypes) == 0)
continue;
update->Set(field.Name, GetField(i));
}
return update;
}
void ReflectionObject::Deserialize(const Dictionary::Ptr& update, int attributeTypes)
{
for (int i = 0; i < GetFieldCount(); i++) {
ReflectionField field = GetFieldInfo(i);
if ((field.Attributes & attributeTypes) == 0)
continue;
if (!update->Contains(field.Name))
continue;
SetField(i, update->Get(field.Name));
}
}

View File

@ -0,0 +1,76 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software Foundation *
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#ifndef REFLECTIONOBJECT_H
#define REFLECTIONOBJECT_H
#include "base/object.h"
#include "base/dictionary.h"
#include <vector>
namespace icinga
{
enum ReflectionFieldAttribute
{
FAConfig = 1,
FAState = 2
};
struct ReflectionField
{
int ID;
String Name;
int Attributes;
Value DefaultValue;
ReflectionField(int id, const String& name, int attributes, const Value& default_value = Empty)
: ID(id), Name(name), Attributes(attributes), DefaultValue(default_value)
{ }
};
enum InvokationType
{
ITGet,
ITSet
};
class I2_BASE_API ReflectionObject : public Object
{
public:
DECLARE_PTR_TYPEDEFS(ReflectionObject);
virtual int GetFieldId(const String& name) const = 0;
virtual ReflectionField GetFieldInfo(int id) const = 0;
virtual int GetFieldCount(void) const = 0;
virtual void SetField(int id, const Value& value) = 0;
virtual Value GetField(int id) const = 0;
Dictionary::Ptr Serialize(int attributeTypes) const;
void Deserialize(const Dictionary::Ptr& update, int attributeTypes);
};
template<typename T>
class ReflectionObjectImpl
{
};
}
#endif /* REFLECTIONOBJECT_H */

View File

@ -37,20 +37,6 @@ void Script::Start(void)
SpawnInterpreter(); SpawnInterpreter();
} }
String Script::GetLanguage(void) const
{
ObjectLock olock(this);
return m_Language;
}
String Script::GetCode(void) const
{
ObjectLock olock(this);
return m_Code;
}
void Script::SpawnInterpreter(void) void Script::SpawnInterpreter(void)
{ {
Log(LogInformation, "base", "Reloading script '" + GetName() + "'"); Log(LogInformation, "base", "Reloading script '" + GetName() + "'");
@ -58,23 +44,3 @@ void Script::SpawnInterpreter(void)
ScriptLanguage::Ptr language = ScriptLanguage::GetByName(GetLanguage()); ScriptLanguage::Ptr language = ScriptLanguage::GetByName(GetLanguage());
m_Interpreter = language->CreateInterpreter(GetSelf()); m_Interpreter = language->CreateInterpreter(GetSelf());
} }
void Script::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
bag->Set("language", m_Language);
bag->Set("code", m_Code);
}
}
void Script::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
m_Language = bag->Get("language");
m_Code = bag->Get("code");
}
}

View File

@ -21,7 +21,7 @@
#define SCRIPT_H #define SCRIPT_H
#include "base/i2-base.h" #include "base/i2-base.h"
#include "base/dynamicobject.h" #include "base/script.th"
namespace icinga namespace icinga
{ {
@ -33,24 +33,14 @@ class ScriptInterpreter;
* *
* @ingroup base * @ingroup base
*/ */
class I2_BASE_API Script : public DynamicObject class I2_BASE_API Script : public ReflectionObjectImpl<Script>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(Script); DECLARE_PTR_TYPEDEFS(Script);
virtual void Start(void); virtual void Start(void);
String GetLanguage(void) const;
String GetCode(void) const;
protected:
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private: private:
String m_Language;
String m_Code;
shared_ptr<ScriptInterpreter> m_Interpreter; shared_ptr<ScriptInterpreter> m_Interpreter;
void SpawnInterpreter(void); void SpawnInterpreter(void);

12
lib/base/script.ti Normal file
View File

@ -0,0 +1,12 @@
#include "base/dynamicobject.h"
namespace icinga
{
class Script : DynamicObject
{
[config] String language;
[config] String "code";
};
}

View File

@ -21,7 +21,7 @@
#define STREAMLOGGER_H #define STREAMLOGGER_H
#include "base/i2-base.h" #include "base/i2-base.h"
#include "base/logger.h" #include "base/streamlogger.th"
#include "base/timer.h" #include "base/timer.h"
#include <ostream> #include <ostream>
@ -33,7 +33,7 @@ namespace icinga
* *
* @ingroup base * @ingroup base
*/ */
class I2_BASE_API StreamLogger : public Logger class I2_BASE_API StreamLogger : public ReflectionObjectImpl<StreamLogger>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(StreamLogger); DECLARE_PTR_TYPEDEFS(StreamLogger);
@ -53,11 +53,11 @@ private:
static boost::mutex m_Mutex; static boost::mutex m_Mutex;
std::ostream *m_Stream; std::ostream *m_Stream;
bool m_OwnsStream; bool m_OwnsStream;
bool m_Tty; bool m_Tty;
Timer::Ptr m_FlushLogTimer; Timer::Ptr m_FlushLogTimer;
void FlushLogTimerHandler(void); void FlushLogTimerHandler(void);
}; };
} }

10
lib/base/streamlogger.ti Normal file
View File

@ -0,0 +1,10 @@
#include "base/logger.h"
namespace icinga
{
class StreamLogger : Logger
{
};
}

View File

@ -21,7 +21,7 @@
#define SYSLOGLOGGER_H #define SYSLOGLOGGER_H
#include "base/i2-base.h" #include "base/i2-base.h"
#include "base/logger.h" #include "base/sysloglogger.th"
#ifndef _WIN32 #ifndef _WIN32
namespace icinga namespace icinga
@ -32,7 +32,7 @@ namespace icinga
* *
* @ingroup base * @ingroup base
*/ */
class I2_BASE_API SyslogLogger : public Logger class I2_BASE_API SyslogLogger : public ReflectionObjectImpl<SyslogLogger>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(SyslogLogger); DECLARE_PTR_TYPEDEFS(SyslogLogger);

10
lib/base/sysloglogger.ti Normal file
View File

@ -0,0 +1,10 @@
#include "base/logger.h"
namespace icinga
{
class SyslogLogger : Logger
{
};
}

View File

@ -3,17 +3,24 @@
pkglib_LTLIBRARIES = \ pkglib_LTLIBRARIES = \
libdb_ido.la libdb_ido.la
BUILT_SOURCES = \
dbconnection.th
CLEANFILES = \ CLEANFILES = \
db_ido-type.cpp db_ido-type.cpp
.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig
$(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
.ti.th: $(top_builddir)/tools/mkclass/mkclass
$(top_builddir)/tools/mkclass/mkclass $< > $@
libdb_ido_la_SOURCES = \ libdb_ido_la_SOURCES = \
commanddbobject.cpp \ commanddbobject.cpp \
commanddbobject.h \ commanddbobject.h \
dbconnection.cpp \ dbconnection.cpp \
dbconnection.h \ dbconnection.h \
dbconnection.ti \
dbobject.cpp \ dbobject.cpp \
dbobject.h \ dbobject.h \
dbquery.cpp \ dbquery.cpp \

View File

@ -74,6 +74,18 @@
</CustomBuild> </CustomBuild>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="dbconnection.ti">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" &gt; "%(Filename).th"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).th;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).th;%(Outputs)</Outputs>
</CustomBuild>
<None Include="dbconnection.th" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">

View File

@ -101,10 +101,16 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="dbconnection.th">
<Filter>Headerdateien</Filter>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="db_ido-type.conf"> <CustomBuild Include="db_ido-type.conf">
<Filter>Quelldateien</Filter> <Filter>Quelldateien</Filter>
</CustomBuild> </CustomBuild>
<CustomBuild Include="dbconnection.ti">
<Filter>Headerdateien</Filter>
</CustomBuild>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -55,14 +55,6 @@ void DbConnection::StaticInitialize(void)
m_ProgramStatusTimer->Start(); m_ProgramStatusTimer->Start();
} }
String DbConnection::GetTablePrefix(void) const
{
if (m_TablePrefix.IsEmpty())
return "icinga_";
else
return m_TablePrefix;
}
void DbConnection::InsertRuntimeVariable(const String& key, const Value& value) void DbConnection::InsertRuntimeVariable(const String& key, const Value& value)
{ {
DbQuery query; DbQuery query;
@ -91,7 +83,7 @@ void DbConnection::ProgramStatusHandler(void)
query2.Fields = boost::make_shared<Dictionary>(); query2.Fields = boost::make_shared<Dictionary>();
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */ query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
query2.Fields->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime())); query2.Fields->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
query2.Fields->Set("program_start_time", DbValue::FromTimestamp(IcingaApplication::GetInstance()->GetStartTime())); query2.Fields->Set("program_start_time", DbValue::FromTimestamp(Application::GetStartTime()));
query2.Fields->Set("is_currently_running", 1); query2.Fields->Set("is_currently_running", 1);
query2.Fields->Set("process_id", Utility::GetPid()); query2.Fields->Set("process_id", Utility::GetPid());
query2.Fields->Set("daemon_mode", 1); query2.Fields->Set("daemon_mode", 1);
@ -122,95 +114,95 @@ void DbConnection::CleanUpHandler(void)
{ {
long now = static_cast<long>(Utility::GetTime()); long now = static_cast<long>(Utility::GetTime());
if (GetCleanUpAcknowledgementsAge() > 0) { if (GetCleanupAcknowledgementsAge() > 0) {
CleanUpExecuteQuery("acknowledgements", "entry_time", now - GetCleanUpAcknowledgementsAge()); CleanUpExecuteQuery("acknowledgements", "entry_time", now - GetCleanupAcknowledgementsAge());
Log(LogDebug, "db_ido", "GetCleanUpAcknowledgementsAge: " + Convert::ToString(GetCleanUpAcknowledgementsAge()) + Log(LogDebug, "db_ido", "GetCleanupAcknowledgementsAge: " + Convert::ToString(GetCleanupAcknowledgementsAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpAcknowledgementsAge())); " old: " + Convert::ToString(now - GetCleanupAcknowledgementsAge()));
} }
if (GetCleanUpCommentHistoryAge() > 0) { if (GetCleanupCommentHistoryAge() > 0) {
CleanUpExecuteQuery("commenthistory", "entry_time", now - GetCleanUpCommentHistoryAge()); CleanUpExecuteQuery("commenthistory", "entry_time", now - GetCleanupCommentHistoryAge());
Log(LogDebug, "db_ido", "GetCleanUpCommentHistoryAge: " + Convert::ToString(GetCleanUpCommentHistoryAge()) + Log(LogDebug, "db_ido", "GetCleanupCommentHistoryAge: " + Convert::ToString(GetCleanupCommentHistoryAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpCommentHistoryAge())); " old: " + Convert::ToString(now - GetCleanupCommentHistoryAge()));
} }
if (GetCleanUpContactNotificationsAge() > 0) { if (GetCleanupContactNotificationsAge() > 0) {
CleanUpExecuteQuery("contactnotifications", "start_time", now - GetCleanUpContactNotificationsAge()); CleanUpExecuteQuery("contactnotifications", "start_time", now - GetCleanupContactNotificationsAge());
Log(LogDebug, "db_ido", "GetCleanUpContactNotificationsAge: " + Convert::ToString(GetCleanUpContactNotificationsAge()) + Log(LogDebug, "db_ido", "GetCleanupContactNotificationsAge: " + Convert::ToString(GetCleanupContactNotificationsAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpContactNotificationsAge())); " old: " + Convert::ToString(now - GetCleanupContactNotificationsAge()));
} }
if (GetCleanUpContactNotificationMethodsAge() > 0) { if (GetCleanupContactNotificationMethodsAge() > 0) {
CleanUpExecuteQuery("contactnotificationmethods", "start_time", now - GetCleanUpContactNotificationMethodsAge()); CleanUpExecuteQuery("contactnotificationmethods", "start_time", now - GetCleanupContactNotificationMethodsAge());
Log(LogDebug, "db_ido", "GetCleanUpContactNotificationMethodsAge: " + Convert::ToString(GetCleanUpContactNotificationMethodsAge()) + Log(LogDebug, "db_ido", "GetCleanupContactNotificationMethodsAge: " + Convert::ToString(GetCleanupContactNotificationMethodsAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpContactNotificationMethodsAge())); " old: " + Convert::ToString(now - GetCleanupContactNotificationMethodsAge()));
} }
if (GetCleanUpDowntimeHistoryAge() > 0) { if (GetCleanupDowntimeHistoryAge() > 0) {
CleanUpExecuteQuery("downtimehistory", "entry_time", now - GetCleanUpDowntimeHistoryAge()); CleanUpExecuteQuery("downtimehistory", "entry_time", now - GetCleanupDowntimeHistoryAge());
Log(LogDebug, "db_ido", "CleanUpDowntimeHistoryAge: " + Convert::ToString(GetCleanUpDowntimeHistoryAge()) + Log(LogDebug, "db_ido", "CleanUpDowntimeHistoryAge: " + Convert::ToString(GetCleanupDowntimeHistoryAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpDowntimeHistoryAge())); " old: " + Convert::ToString(now - GetCleanupDowntimeHistoryAge()));
} }
if (GetCleanUpEventHandlersAge() > 0) { if (GetCleanupEventHandlersAge() > 0) {
CleanUpExecuteQuery("eventhandlers", "start_time", now - GetCleanUpEventHandlersAge()); CleanUpExecuteQuery("eventhandlers", "start_time", now - GetCleanupEventHandlersAge());
Log(LogDebug, "db_ido", "GetCleanUpEventHandlersAge: " + Convert::ToString(GetCleanUpEventHandlersAge()) + Log(LogDebug, "db_ido", "GetCleanupEventHandlersAge: " + Convert::ToString(GetCleanupEventHandlersAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpEventHandlersAge())); " old: " + Convert::ToString(now - GetCleanupEventHandlersAge()));
} }
if (GetCleanUpExternalCommandsAge() > 0) { if (GetCleanupExternalCommandsAge() > 0) {
CleanUpExecuteQuery("externalcommands", "entry_time", now - GetCleanUpExternalCommandsAge()); CleanUpExecuteQuery("externalcommands", "entry_time", now - GetCleanupExternalCommandsAge());
Log(LogDebug, "db_ido", "GetCleanUpExternalCommandsAge: " + Convert::ToString(GetCleanUpExternalCommandsAge()) + Log(LogDebug, "db_ido", "GetCleanupExternalCommandsAge: " + Convert::ToString(GetCleanupExternalCommandsAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpExternalCommandsAge())); " old: " + Convert::ToString(now - GetCleanupExternalCommandsAge()));
} }
if (GetCleanUpFlappingHistoryAge() > 0) { if (GetCleanupFlappingHistoryAge() > 0) {
CleanUpExecuteQuery("flappinghistory", "event_time", now - GetCleanUpFlappingHistoryAge()); CleanUpExecuteQuery("flappinghistory", "event_time", now - GetCleanupFlappingHistoryAge());
Log(LogDebug, "db_ido", "GetCleanUpFlappingHistoryAge: " + Convert::ToString(GetCleanUpFlappingHistoryAge()) + Log(LogDebug, "db_ido", "GetCleanupFlappingHistoryAge: " + Convert::ToString(GetCleanupFlappingHistoryAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpFlappingHistoryAge())); " old: " + Convert::ToString(now - GetCleanupFlappingHistoryAge()));
} }
if (GetCleanUpHostChecksAge() > 0) { if (GetCleanupHostChecksAge() > 0) {
CleanUpExecuteQuery("hostchecks", "start_time", now - GetCleanUpHostChecksAge()); CleanUpExecuteQuery("hostchecks", "start_time", now - GetCleanupHostChecksAge());
Log(LogDebug, "db_ido", "GetCleanUpHostChecksAge: " + Convert::ToString(GetCleanUpHostChecksAge()) + Log(LogDebug, "db_ido", "GetCleanupHostChecksAge: " + Convert::ToString(GetCleanupHostChecksAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpHostChecksAge())); " old: " + Convert::ToString(now - GetCleanupHostChecksAge()));
} }
if (GetCleanUpLogEntriesAge() > 0) { if (GetCleanupLogEntriesAge() > 0) {
CleanUpExecuteQuery("logentries", "logentry_time", now - GetCleanUpLogEntriesAge()); CleanUpExecuteQuery("logentries", "logentry_time", now - GetCleanupLogEntriesAge());
Log(LogDebug, "db_ido", "GetCleanUpLogEntriesAge: " + Convert::ToString(GetCleanUpLogEntriesAge()) + Log(LogDebug, "db_ido", "GetCleanupLogEntriesAge: " + Convert::ToString(GetCleanupLogEntriesAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpLogEntriesAge())); " old: " + Convert::ToString(now - GetCleanupLogEntriesAge()));
} }
if (GetCleanUpNotificationsAge() > 0) { if (GetCleanupNotificationsAge() > 0) {
CleanUpExecuteQuery("notifications", "start_time", now - GetCleanUpNotificationsAge()); CleanUpExecuteQuery("notifications", "start_time", now - GetCleanupNotificationsAge());
Log(LogDebug, "db_ido", "GetCleanUpNotificationsAge: " + Convert::ToString(GetCleanUpNotificationsAge()) + Log(LogDebug, "db_ido", "GetCleanupNotificationsAge: " + Convert::ToString(GetCleanupNotificationsAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpNotificationsAge())); " old: " + Convert::ToString(now - GetCleanupNotificationsAge()));
} }
if (GetCleanUpProcessEventsAge() > 0) { if (GetCleanupProcessEventsAge() > 0) {
CleanUpExecuteQuery("processevents", "event_time", now - GetCleanUpProcessEventsAge()); CleanUpExecuteQuery("processevents", "event_time", now - GetCleanupProcessEventsAge());
Log(LogDebug, "db_ido", "GetCleanUpProcessEventsAge: " + Convert::ToString(GetCleanUpProcessEventsAge()) + Log(LogDebug, "db_ido", "GetCleanupProcessEventsAge: " + Convert::ToString(GetCleanupProcessEventsAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpProcessEventsAge())); " old: " + Convert::ToString(now - GetCleanupProcessEventsAge()));
} }
if (GetCleanUpStateHistoryAge() > 0) { if (GetCleanupStateHistoryAge() > 0) {
CleanUpExecuteQuery("statehistory", "state_time", now - GetCleanUpStateHistoryAge()); CleanUpExecuteQuery("statehistory", "state_time", now - GetCleanupStateHistoryAge());
Log(LogDebug, "db_ido", "GetCleanUpStateHistoryAge: " + Convert::ToString(GetCleanUpStateHistoryAge()) + Log(LogDebug, "db_ido", "GetCleanupStateHistoryAge: " + Convert::ToString(GetCleanupStateHistoryAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpStateHistoryAge())); " old: " + Convert::ToString(now - GetCleanupStateHistoryAge()));
} }
if (GetCleanUpServiceChecksAge() > 0) { if (GetCleanupServiceChecksAge() > 0) {
CleanUpExecuteQuery("servicechecks", "start_time", now - GetCleanUpServiceChecksAge()); CleanUpExecuteQuery("servicechecks", "start_time", now - GetCleanupServiceChecksAge());
Log(LogDebug, "db_ido", "GetCleanUpServiceChecksAge: " + Convert::ToString(GetCleanUpServiceChecksAge()) + Log(LogDebug, "db_ido", "GetCleanupServiceChecksAge: " + Convert::ToString(GetCleanupServiceChecksAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpServiceChecksAge())); " old: " + Convert::ToString(now - GetCleanupServiceChecksAge()));
} }
if (GetCleanUpSystemCommandsAge() > 0) { if (GetCleanupSystemCommandsAge() > 0) {
CleanUpExecuteQuery("systemcommands", "start_time", now - GetCleanUpSystemCommandsAge()); CleanUpExecuteQuery("systemcommands", "start_time", now - GetCleanupSystemCommandsAge());
Log(LogDebug, "db_ido", "GetCleanUpSystemCommandsAge: " + Convert::ToString(GetCleanUpSystemCommandsAge()) + Log(LogDebug, "db_ido", "GetCleanupSystemCommandsAge: " + Convert::ToString(GetCleanupSystemCommandsAge()) +
" now: " + Convert::ToString(now) + " now: " + Convert::ToString(now) +
" old: " + Convert::ToString(now - GetCleanUpSystemCommandsAge())); " old: " + Convert::ToString(now - GetCleanupSystemCommandsAge()));
} }
} }
@ -219,162 +211,79 @@ void DbConnection::CleanUpExecuteQuery(const String& table, const String& time_k
/* Default handler does nothing. */ /* Default handler does nothing. */
} }
Dictionary::Ptr DbConnection::GetCleanUp(void) const double DbConnection::GetCleanupAcknowledgementsAge(void) const
{ {
if (!m_CleanUp) return GetCleanup()->Get("acknowledgement_age");
return Empty;
else
return m_CleanUp;
} }
Value DbConnection::GetCleanUpAcknowledgementsAge(void) const double DbConnection::GetCleanupCommentHistoryAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("commenthistory_age");
if (!cleanup || cleanup->Get("acknowledgement_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("acknowledgement_age");
} }
Value DbConnection::GetCleanUpCommentHistoryAge(void) const double DbConnection::GetCleanupContactNotificationsAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("contactnotifications_age");
if (!cleanup || cleanup->Get("commenthistory_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("commenthistory_age");
} }
Value DbConnection::GetCleanUpContactNotificationsAge(void) const double DbConnection::GetCleanupContactNotificationMethodsAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("contactnotificationmethods_age");
if (!cleanup || cleanup->Get("contactnotifications_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("contactnotifications_age");
} }
Value DbConnection::GetCleanUpContactNotificationMethodsAge(void) const double DbConnection::GetCleanupDowntimeHistoryAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("downtimehistory_age");
if (!cleanup || cleanup->Get("contactnotificationmethods_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("contactnotificationmethods_age");
} }
Value DbConnection::GetCleanUpDowntimeHistoryAge(void) const double DbConnection::GetCleanupEventHandlersAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("eventhandlers_age");
if (!cleanup || cleanup->Get("downtimehistory_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("downtimehistory_age");
} }
Value DbConnection::GetCleanUpEventHandlersAge(void) const double DbConnection::GetCleanupExternalCommandsAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("externalcommands_age");
if (!cleanup || cleanup->Get("eventhandlers_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("eventhandlers_age");
} }
Value DbConnection::GetCleanUpExternalCommandsAge(void) const double DbConnection::GetCleanupFlappingHistoryAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("flappinghistory_age");
if (!cleanup || cleanup->Get("externalcommands_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("externalcommands_age");
} }
Value DbConnection::GetCleanUpFlappingHistoryAge(void) const double DbConnection::GetCleanupHostChecksAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("hostchecks_age");
if (!cleanup || cleanup->Get("flappinghistory_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("flappinghistory_age");
} }
Value DbConnection::GetCleanUpHostChecksAge(void) const double DbConnection::GetCleanupLogEntriesAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("logentries_age");
if (!cleanup || cleanup->Get("hostchecks_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("hostchecks_age");
} }
Value DbConnection::GetCleanUpLogEntriesAge(void) const double DbConnection::GetCleanupNotificationsAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("notifications_age");
if (!cleanup || cleanup->Get("logentries_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("logentries_age");
} }
Value DbConnection::GetCleanUpNotificationsAge(void) const double DbConnection::GetCleanupProcessEventsAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("processevents_age");
if (!cleanup || cleanup->Get("notifications_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("notifications_age");
} }
Value DbConnection::GetCleanUpProcessEventsAge(void) const double DbConnection::GetCleanupStateHistoryAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("statehistory_age");
if (!cleanup || cleanup->Get("processevents_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("processevents_age");
} }
Value DbConnection::GetCleanUpStateHistoryAge(void) const double DbConnection::GetCleanupServiceChecksAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("servicechecks_age");
if (!cleanup || cleanup->Get("statehistory_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("statehistory_age");
} }
Value DbConnection::GetCleanUpServiceChecksAge(void) const double DbConnection::GetCleanupSystemCommandsAge(void) const
{ {
Dictionary::Ptr cleanup = GetCleanUp(); return GetCleanup()->Get("systemcommands_age");
if (!cleanup || cleanup->Get("servicechecks_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("servicechecks_age");
}
Value DbConnection::GetCleanUpSystemCommandsAge(void) const
{
Dictionary::Ptr cleanup = GetCleanUp();
if (!cleanup || cleanup->Get("systemcommands_age").IsEmpty())
return CleanUpAgeNone;
else
return cleanup->Get("systemcommands_age");
} }
void DbConnection::SetObjectID(const DbObject::Ptr& dbobj, const DbReference& dbref) void DbConnection::SetObjectID(const DbObject::Ptr& dbobj, const DbReference& dbref)
@ -463,23 +372,3 @@ void DbConnection::UpdateAllObjects(void)
} }
} }
} }
void DbConnection::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
bag->Set("table_prefix", m_TablePrefix);
bag->Set("cleanup", m_CleanUp);
}
}
void DbConnection::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
m_TablePrefix = bag->Get("table_prefix");
m_CleanUp = bag->Get("cleanup");
}
}

View File

@ -20,28 +20,20 @@
#ifndef DBCONNECTION_H #ifndef DBCONNECTION_H
#define DBCONNECTION_H #define DBCONNECTION_H
#include "base/dynamicobject.h" #include "db_ido/dbconnection.th"
#include "base/timer.h"
#include "db_ido/dbobject.h" #include "db_ido/dbobject.h"
#include "db_ido/dbquery.h" #include "db_ido/dbquery.h"
#include "base/timer.h"
namespace icinga namespace icinga
{ {
enum CleanUpAge
{
CleanUpAgeNone = 0,
CleanUpAgeOneMonth = 44640,
CleanUpAgeOneMeek = 10080,
CleanUpAgeOneDay = 1440,
};
/** /**
* A database connection. * A database connection.
* *
* @ingroup db_ido * @ingroup db_ido
*/ */
class DbConnection : public DynamicObject class DbConnection : public ReflectionObjectImpl<DbConnection>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(DbConnection); DECLARE_PTR_TYPEDEFS(DbConnection);
@ -60,49 +52,41 @@ public:
void SetStatusUpdate(const DbObject::Ptr& dbobj, bool hasupdate); void SetStatusUpdate(const DbObject::Ptr& dbobj, bool hasupdate);
bool GetStatusUpdate(const DbObject::Ptr& dbobj) const; bool GetStatusUpdate(const DbObject::Ptr& dbobj) const;
String GetTablePrefix(void) const; double GetCleanupAcknowledgementsAge(void) const;
Dictionary::Ptr GetCleanUp(void) const; double GetCleanupCommentHistoryAge(void) const;
Value GetCleanUpAcknowledgementsAge(void) const; double GetCleanupContactNotificationsAge(void) const;
Value GetCleanUpCommentHistoryAge(void) const; double GetCleanupContactNotificationMethodsAge(void) const;
Value GetCleanUpContactNotificationsAge(void) const; double GetCleanupDowntimeHistoryAge(void) const;
Value GetCleanUpContactNotificationMethodsAge(void) const; double GetCleanupEventHandlersAge(void) const;
Value GetCleanUpDowntimeHistoryAge(void) const; double GetCleanupExternalCommandsAge(void) const;
Value GetCleanUpEventHandlersAge(void) const; double GetCleanupFlappingHistoryAge(void) const;
Value GetCleanUpExternalCommandsAge(void) const; double GetCleanupHostChecksAge(void) const;
Value GetCleanUpFlappingHistoryAge(void) const; double GetCleanupLogEntriesAge(void) const;
Value GetCleanUpHostChecksAge(void) const; double GetCleanupNotificationsAge(void) const;
Value GetCleanUpLogEntriesAge(void) const; double GetCleanupProcessEventsAge(void) const;
Value GetCleanUpNotificationsAge(void) const; double GetCleanupStateHistoryAge(void) const;
Value GetCleanUpProcessEventsAge(void) const; double GetCleanupServiceChecksAge(void) const;
Value GetCleanUpStateHistoryAge(void) const; double GetCleanupSystemCommandsAge(void) const;
Value GetCleanUpServiceChecksAge(void) const;
Value GetCleanUpSystemCommandsAge(void) const;
protected: protected:
virtual void Start(void); virtual void Start(void);
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
virtual void ExecuteQuery(const DbQuery& query) = 0; virtual void ExecuteQuery(const DbQuery& query) = 0;
virtual void ActivateObject(const DbObject::Ptr& dbobj) = 0; virtual void ActivateObject(const DbObject::Ptr& dbobj) = 0;
virtual void DeactivateObject(const DbObject::Ptr& dbobj) = 0; virtual void DeactivateObject(const DbObject::Ptr& dbobj) = 0;
virtual void CleanUpExecuteQuery(const String& table, const String& time_key, double time_value) = 0; virtual void CleanUpExecuteQuery(const String& table, const String& time_key, double time_value) = 0;
void UpdateAllObjects(void); void UpdateAllObjects(void);
private: private:
String m_TablePrefix;
Dictionary::Ptr m_CleanUp;
std::map<DbObject::Ptr, DbReference> m_ObjectIDs; std::map<DbObject::Ptr, DbReference> m_ObjectIDs;
std::map<DbObject::Ptr, DbReference> m_InsertIDs; std::map<DbObject::Ptr, DbReference> m_InsertIDs;
std::set<DbObject::Ptr> m_ConfigUpdates; std::set<DbObject::Ptr> m_ConfigUpdates;
std::set<DbObject::Ptr> m_StatusUpdates; std::set<DbObject::Ptr> m_StatusUpdates;
Timer::Ptr m_CleanUpTimer; Timer::Ptr m_CleanUpTimer;
void CleanUpHandler(void); void CleanUpHandler(void);
static Timer::Ptr m_ProgramStatusTimer; static Timer::Ptr m_ProgramStatusTimer;

View File

@ -0,0 +1,18 @@
#include "base/dynamicobject.h"
#include <boost/smart_ptr/make_shared.hpp>
namespace icinga
{
class DbConnection : DynamicObject
{
[config] String table_prefix {
default {{{ return "icinga_"; }}}
};
[config] Dictionary::Ptr cleanup {
default {{{ return boost::make_shared<Dictionary>(); }}}
};
};
}

View File

@ -362,9 +362,6 @@ void ServiceDbObject::AddComments(const Service::Ptr& service)
/* dump all comments */ /* dump all comments */
Dictionary::Ptr comments = service->GetComments(); Dictionary::Ptr comments = service->GetComments();
if (!comments)
return;
ObjectLock olock(comments); ObjectLock olock(comments);
String comment_id; String comment_id;
@ -532,9 +529,6 @@ void ServiceDbObject::AddDowntimes(const Service::Ptr& service)
/* dump all downtimes */ /* dump all downtimes */
Dictionary::Ptr downtimes = service->GetDowntimes(); Dictionary::Ptr downtimes = service->GetDowntimes();
if (!downtimes)
return;
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
String downtime_id; String downtime_id;
@ -926,7 +920,7 @@ void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const D
fields1->Set("state_change", 1); /* service */ fields1->Set("state_change", 1); /* service */
fields1->Set("state", service->GetState()); fields1->Set("state", service->GetState());
fields1->Set("state_type", service->GetStateType()); fields1->Set("state_type", service->GetStateType());
fields1->Set("current_check_attempt", service->GetCurrentCheckAttempt()); fields1->Set("current_check_attempt", service->GetCheckAttempt());
fields1->Set("max_check_attempts", service->GetMaxCheckAttempts()); fields1->Set("max_check_attempts", service->GetMaxCheckAttempts());
fields1->Set("last_state", service->GetLastState()); fields1->Set("last_state", service->GetLastState());
fields1->Set("last_hard_state", service->GetLastHardState()); fields1->Set("last_hard_state", service->GetLastHardState());

View File

@ -4,37 +4,63 @@
pkglib_LTLIBRARIES = \ pkglib_LTLIBRARIES = \
libicinga.la libicinga.la
BUILT_SOURCES = \
checkcommand.th \
command.th \
domain.th \
eventcommand.th \
host.th \
hostgroup.th \
icingaapplication.th \
notification.th \
notificationcommand.th \
service.th \
servicegroup.th \
timeperiod.th \
user.th \
usergroup.th
CLEANFILES = \ CLEANFILES = \
icinga-type.cpp icinga-type.cpp
.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig
$(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
.ti.th: $(top_builddir)/tools/mkclass/mkclass
$(top_builddir)/tools/mkclass/mkclass $< > $@
libicinga_la_SOURCES = \ libicinga_la_SOURCES = \
api.cpp \ api.cpp \
api.h \ api.h \
checkcommand.cpp \ checkcommand.cpp \
checkcommand.h \ checkcommand.h \
checkcommand.ti \
cib.cpp \ cib.cpp \
cib.h \ cib.h \
command.cpp \ command.cpp \
command.h \ command.h \
command.ti \
compatutility.cpp \ compatutility.cpp \
compatutility.h \ compatutility.h \
domain.cpp \ domain.cpp \
domain.h \ domain.h \
domain.ti \
eventcommand.cpp \ eventcommand.cpp \
eventcommand.h \ eventcommand.h \
eventcommand.ti \
externalcommandprocessor.cpp \ externalcommandprocessor.cpp \
externalcommandprocessor.h \ externalcommandprocessor.h \
host.cpp \ host.cpp \
host.h \
host.ti \
hostgroup.cpp \ hostgroup.cpp \
hostgroup.h \ hostgroup.h \
host.h \ hostgroup.ti \
i2-icinga.h \ i2-icinga.h \
icinga-type.conf \ icinga-type.conf \
icingaapplication.cpp \ icingaapplication.cpp \
icingaapplication.h \ icingaapplication.h \
icingaapplication.ti \
legacytimeperiod.cpp \ legacytimeperiod.cpp \
legacytimeperiod.h \ legacytimeperiod.h \
macroprocessor.cpp \ macroprocessor.cpp \
@ -43,8 +69,10 @@ libicinga_la_SOURCES = \
macroresolver.h \ macroresolver.h \
notification.cpp \ notification.cpp \
notification.h \ notification.h \
notification.ti \
notificationcommand.cpp \ notificationcommand.cpp \
notificationcommand.h \ notificationcommand.h \
notificationcommand.ti \
nullchecktask.cpp \ nullchecktask.cpp \
nullchecktask.h \ nullchecktask.h \
nulleventtask.cpp \ nulleventtask.cpp \
@ -58,21 +86,26 @@ libicinga_la_SOURCES = \
randomchecktask.cpp \ randomchecktask.cpp \
randomchecktask.h \ randomchecktask.h \
service.cpp \ service.cpp \
service.h \
service.ti \
service-check.cpp \ service-check.cpp \
service-comment.cpp \ service-comment.cpp \
service-downtime.cpp \ service-downtime.cpp \
service-event.cpp \ service-event.cpp \
service-flapping.cpp \ service-flapping.cpp \
service-notification.cpp \ service-notification.cpp \
service.h \
servicegroup.cpp \ servicegroup.cpp \
servicegroup.h \ servicegroup.h \
servicegroup.ti \
timeperiod.cpp \ timeperiod.cpp \
timeperiod.h \ timeperiod.h \
timeperiod.ti \
user.cpp \ user.cpp \
user.h \ user.h \
user.ti \
usergroup.cpp \ usergroup.cpp \
usergroup.h usergroup.h \
usergroup.ti
libicinga_la_CPPFLAGS = \ libicinga_la_CPPFLAGS = \
-DI2_ICINGA_BUILD \ -DI2_ICINGA_BUILD \

View File

@ -20,7 +20,7 @@
#ifndef CHECKCOMMAND_H #ifndef CHECKCOMMAND_H
#define CHECKCOMMAND_H #define CHECKCOMMAND_H
#include "icinga/command.h" #include "icinga/checkcommand.th"
#include "icinga/service.h" #include "icinga/service.h"
namespace icinga namespace icinga
@ -31,7 +31,7 @@ namespace icinga
* *
* @ingroup icinga * @ingroup icinga
*/ */
class I2_ICINGA_API CheckCommand : public Command class I2_ICINGA_API CheckCommand : public ReflectionObjectImpl<CheckCommand>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(CheckCommand); DECLARE_PTR_TYPEDEFS(CheckCommand);

View File

@ -0,0 +1,10 @@
#include "icinga/command.h"
namespace icinga
{
class CheckCommand : Command
{
};
}

View File

@ -21,34 +21,6 @@
using namespace icinga; using namespace icinga;
Value Command::GetCommandLine(void) const
{
return m_CommandLine;
}
double Command::GetTimeout(void) const
{
if (m_Timeout.IsEmpty())
return 300;
else
return m_Timeout;
}
Dictionary::Ptr Command::GetMacros(void) const
{
return m_Macros;
}
Array::Ptr Command::GetExportMacros(void) const
{
return m_ExportMacros;
}
Array::Ptr Command::GetEscapeMacros(void) const
{
return m_EscapeMacros;
}
bool Command::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const bool Command::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
{ {
Dictionary::Ptr macros = GetMacros(); Dictionary::Ptr macros = GetMacros();
@ -60,30 +32,3 @@ bool Command::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *
return false; return false;
} }
void Command::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
bag->Set("command", m_CommandLine);
bag->Set("timeout", m_Timeout);
bag->Set("macros", m_Macros);
bag->Set("export_macros", m_ExportMacros);
bag->Set("escape_macros", m_EscapeMacros);
}
}
void Command::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
m_CommandLine = bag->Get("command");
m_Timeout = bag->Get("timeout");
m_Macros = bag->Get("macros");
m_Macros = bag->Get("macros");
m_ExportMacros = bag->Get("export_macros");
m_EscapeMacros = bag->Get("escape_macros");
}
}

View File

@ -20,10 +20,10 @@
#ifndef COMMAND_H #ifndef COMMAND_H
#define COMMAND_H #define COMMAND_H
#include "icinga/command.th"
#include "icinga/macroresolver.h" #include "icinga/macroresolver.h"
#include "base/i2-base.h" #include "base/i2-base.h"
#include "base/array.h" #include "base/array.h"
#include "base/dynamicobject.h"
#include "base/logger_fwd.h" #include "base/logger_fwd.h"
#include <set> #include <set>
@ -35,31 +35,14 @@ namespace icinga
* *
* @ingroup icinga * @ingroup icinga
*/ */
class I2_ICINGA_API Command : public DynamicObject, public MacroResolver class I2_ICINGA_API Command : public ReflectionObjectImpl<Command>, public MacroResolver
{ {
public: public:
DECLARE_PTR_TYPEDEFS(Command); DECLARE_PTR_TYPEDEFS(Command);
//virtual Dictionary::Ptr Execute(const Object::Ptr& context) = 0; //virtual Dictionary::Ptr Execute(const Object::Ptr& context) = 0;
Value GetCommandLine(void) const;
double GetTimeout(void) const;
Dictionary::Ptr GetMacros(void) const;
Array::Ptr GetExportMacros(void) const;
Array::Ptr GetEscapeMacros(void) const;
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const; virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
protected:
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private:
Value m_CommandLine;
Value m_Timeout;
Dictionary::Ptr m_Macros;
Array::Ptr m_ExportMacros;
Array::Ptr m_EscapeMacros;
}; };
} }

17
lib/icinga/command.ti Normal file
View File

@ -0,0 +1,17 @@
#include "base/dynamicobject.h"
namespace icinga
{
class Command : DynamicObject
{
[config] Value command_line;
[config] Value timeout {
default {{{ return 300; }}}
};
[config] Dictionary::Ptr macros;
[config] Array::Ptr export_macros;
[config] Array::Ptr escape_macros;
};
}

View File

@ -263,7 +263,7 @@ Dictionary::Ptr CompatUtility::GetServiceStatusAttributes(const Service::Ptr& se
attr->Set("check_type", (service->GetEnableActiveChecks() ? 0 : 1)); attr->Set("check_type", (service->GetEnableActiveChecks() ? 0 : 1));
attr->Set("last_check", schedule_end); attr->Set("last_check", schedule_end);
attr->Set("next_check", service->GetNextCheck()); attr->Set("next_check", service->GetNextCheck());
attr->Set("current_attempt", service->GetCurrentCheckAttempt()); attr->Set("current_attempt", service->GetCheckAttempt());
attr->Set("max_attempts", service->GetMaxCheckAttempts()); attr->Set("max_attempts", service->GetMaxCheckAttempts());
attr->Set("last_state_change", service->GetLastStateChange()); attr->Set("last_state_change", service->GetLastStateChange());
attr->Set("last_hard_state_change", service->GetLastHardStateChange()); attr->Set("last_hard_state_change", service->GetLastHardStateChange());
@ -393,7 +393,7 @@ Dictionary::Ptr CompatUtility::GetServiceConfigAttributes(const Service::Ptr& se
attr->Set("high_flap_threshold", service->GetFlappingThreshold()); attr->Set("high_flap_threshold", service->GetFlappingThreshold());
attr->Set("notifications_enabled", (service->GetEnableNotifications() ? 1 : 0)); attr->Set("notifications_enabled", (service->GetEnableNotifications() ? 1 : 0));
attr->Set("eventhandler_enabled", 1); /* always 1 */ attr->Set("eventhandler_enabled", 1); /* always 1 */
attr->Set("is_volatile", (service->IsVolatile() ? 1 : 0)); attr->Set("is_volatile", (service->GetVolatile() ? 1 : 0));
attr->Set("notifications_enabled", (service->GetEnableNotifications() ? 1 : 0)); attr->Set("notifications_enabled", (service->GetEnableNotifications() ? 1 : 0));
attr->Set("notification_options", boost::algorithm::join(notification_options, ",")); attr->Set("notification_options", boost::algorithm::join(notification_options, ","));
attr->Set("notification_interval", notification_interval / 60.0); attr->Set("notification_interval", notification_interval / 60.0);

View File

@ -24,30 +24,7 @@ using namespace icinga;
REGISTER_TYPE(Domain); REGISTER_TYPE(Domain);
Dictionary::Ptr Domain::GetAcl(void) const
{
return m_Acl;
}
int Domain::GetPrivileges(const String& instance) const int Domain::GetPrivileges(const String& instance) const
{ {
return m_Acl->Get(instance); return GetAcl()->Get(instance);
}
void Domain::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
bag->Set("acl", m_Acl);
}
}
void Domain::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
DynamicObject::InternalDeserialize(bag, attributeTypes);
if (attributeTypes & Attribute_Config) {
m_Acl = bag->Get("acl");
}
} }

View File

@ -21,7 +21,7 @@
#define DOMAIN_H #define DOMAIN_H
#include "icinga/i2-icinga.h" #include "icinga/i2-icinga.h"
#include "base/dynamicobject.h" #include "icinga/domain.th"
#include "base/dictionary.h" #include "base/dictionary.h"
namespace icinga namespace icinga
@ -32,21 +32,13 @@ namespace icinga
* *
* @ingroup icinga * @ingroup icinga
*/ */
class I2_ICINGA_API Domain : public DynamicObject class I2_ICINGA_API Domain : public ReflectionObjectImpl<Domain>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(Domain); DECLARE_PTR_TYPEDEFS(Domain);
DECLARE_TYPENAME(Domain); DECLARE_TYPENAME(Domain);
Dictionary::Ptr GetAcl(void) const;
int GetPrivileges(const String& instance) const; int GetPrivileges(const String& instance) const;
protected:
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private:
Dictionary::Ptr m_Acl;
}; };
} }

11
lib/icinga/domain.ti Normal file
View File

@ -0,0 +1,11 @@
#include "base/dynamicobject.h"
namespace icinga
{
class Domain : DynamicObject
{
[config] Dictionary::Ptr acl;
};
}

View File

@ -20,7 +20,7 @@
#ifndef EVENTCOMMAND_H #ifndef EVENTCOMMAND_H
#define EVENTCOMMAND_H #define EVENTCOMMAND_H
#include "icinga/command.h" #include "icinga/eventcommand.th"
#include "icinga/service.h" #include "icinga/service.h"
namespace icinga namespace icinga
@ -31,7 +31,7 @@ namespace icinga
* *
* @ingroup icinga * @ingroup icinga
*/ */
class I2_ICINGA_API EventCommand : public Command class I2_ICINGA_API EventCommand : public ReflectionObjectImpl<EventCommand>
{ {
public: public:
DECLARE_PTR_TYPEDEFS(EventCommand); DECLARE_PTR_TYPEDEFS(EventCommand);

View File

@ -0,0 +1,10 @@
#include "icinga/command.h"
namespace icinga
{
class EventCommand : Command
{
};
}

Some files were not shown because too many files have changed in this diff Show More