*.gcda
*.o
*.a
+*.th
.deps
*.in
Makefile
pkglib_LTLIBRARIES = \
libchecker.la
+BUILT_SOURCES = \
+ checkercomponent.th
+
CLEANFILES = \
checker-type.cpp
.conf.cpp: $(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 = \
checkercomponent.cpp \
checkercomponent.h \
+ checkercomponent.th \
checker-type.conf
libchecker_la_CPPFLAGS = \
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class CheckerComponent : DynamicObject
+{
+};
+
+}
pkglib_LTLIBRARIES = \
libcluster.la
+BUILT_SOURCES = \
+ clusterlistener.th \
+ endpoint.th
+
CLEANFILES = \
cluster-type.cpp
.conf.cpp: $(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 = \
clusterlistener.cpp \
clusterlistener.h \
+ clusterlistener.ti \
cluster-type.conf \
endpoint.cpp \
endpoint.h \
+ endpoint.ti \
jsonrpc.cpp \
jsonrpc.h
}
/* set up SSL context */
- shared_ptr<X509> cert = GetX509Certificate(GetCertificateFile());
- m_Identity = GetCertificateCN(cert);
- Log(LogInformation, "cluster", "My identity: " + m_Identity);
+ shared_ptr<X509> cert = GetX509Certificate(GetCertPath());
+ SetIdentity(GetCertificateCN(cert));
+ Log(LogInformation, "cluster", "My identity: " + GetIdentity());
Endpoint::Ptr self = Endpoint::GetByName(GetIdentity());
if (!self)
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 */
if (!GetBindPort().IsEmpty())
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
{
- ObjectLock olock(this);
-
return m_SSLContext;
}
-String ClusterListener::GetIdentity(void) const
-{
- ObjectLock olock(this);
-
- return m_Identity;
-}
-
/**
* Creates a new JSON-RPC listener on the specified port.
*
String json = Value(pmessage).Serialize();
NetString::WriteStringToStream(m_LogFile, json);
m_LogMessageCount++;
- m_LogMessageTimestamp = ts;
+ SetLogMessageTimestamp(ts);
if (m_LogMessageCount > 50000) {
CloseLogFile();
{
ObjectLock olock(endpoint);
- if (!endpoint->IsSyncing())
+ if (!endpoint->GetSyncing())
endpoint->SendMessage(message);
}
}
m_LogFile = logStream;
#endif /* HAVE_BIOZLIB */
m_LogMessageCount = 0;
- m_LogMessageTimestamp = 0;
+ SetLogMessageTimestamp(0);
}
void ClusterListener::CloseLogFile(void)
{
ASSERT(OwnsLock());
- double ts = m_LogMessageTimestamp;
+ double ts = GetLogMessageTimestamp();
if (ts == 0)
ts = Utility::GetTime();
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");
-}
#ifndef CLUSTERLISTENER_H
#define CLUSTERLISTENER_H
+#include "cluster/clusterlistener.th"
#include "base/dynamicobject.h"
#include "base/timer.h"
#include "base/array.h"
/**
* @ingroup cluster
*/
-class ClusterListener : public DynamicObject
+class ClusterListener : public ReflectionObjectImpl<ClusterListener>
{
public:
DECLARE_PTR_TYPEDEFS(ClusterListener);
virtual void Start(void);
virtual void Stop(void);
- String GetCertificateFile(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;
-
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);
+ String GetClusterDir(void) const;
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;
- String m_Identity;
WorkQueue m_RelayQueue;
WorkQueue m_MessageQueue;
void ReplayLog(const Endpoint::Ptr& endpoint, const Stream::Ptr& stream);
Stream::Ptr m_LogFile;
- double m_LogMessageTimestamp;
size_t m_LogMessageCount;
void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr, const String& authority);
--- /dev/null
+#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;
+};
+
+}
boost::signals2::signal<void (const Endpoint::Ptr&)> Endpoint::OnConnected;
boost::signals2::signal<void (const Endpoint::Ptr&, const Dictionary::Ptr&)> Endpoint::OnMessageReceived;
-Endpoint::Endpoint(void)
- : m_Syncing(false)
-{ }
-
/**
* Checks whether this endpoint is connected.
*
}
}
-/**
- * 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
{
Dictionary::Ptr features = GetFeatures();
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");
- }
-}
#ifndef ENDPOINT_H
#define ENDPOINT_H
-#include "base/dynamicobject.h"
+#include "cluster/endpoint.th"
#include "base/stream.h"
#include "base/array.h"
#include <boost/signals2.hpp>
*
* @ingroup cluster
*/
-class Endpoint : public DynamicObject
+class Endpoint : public ReflectionObjectImpl<Endpoint>
{
public:
DECLARE_PTR_TYPEDEFS(Endpoint);
DECLARE_TYPENAME(Endpoint);
- Endpoint(void);
-
static boost::signals2::signal<void (const Endpoint::Ptr&)> OnConnected;
static boost::signals2::signal<void (const Endpoint::Ptr&, const Dictionary::Ptr&)> OnMessageReceived;
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 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:
- Dictionary::Ptr m_Subscriptions;
- String m_Host;
- String m_Port;
- Array::Ptr m_ConfigFiles;
- Array::Ptr m_AcceptConfig;
-
Stream::Ptr m_Client;
- double m_Seen;
- double m_LocalLogPosition;
- double m_RemoteLogPosition;
- Dictionary::Ptr m_Features;
- bool m_Syncing;
-
boost::thread m_Thread;
void MessageThreadProc(const Stream::Ptr& stream);
--- /dev/null
+#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; }}}
+ };
+};
+
+}
pkglib_LTLIBRARIES = \
libcompat.la
+BUILT_SOURCES = \
+ checkresultreader.th \
+ externalcommandlistener.th \
+ statusdatawriter.th \
+ compatlogger.th
+
CLEANFILES = \
compat-type.cpp
.conf.cpp: $(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 = \
checkresultreader.cpp \
checkresultreader.h \
+ checkresultreader.th \
externalcommandlistener.cpp \
externalcommandlistener.h \
+ externalcommandlistener.th \
statusdatawriter.cpp \
statusdatawriter.h \
+ statusdatawriter.th \
compatlogger.cpp \
compatlogger.h \
+ compatlogger.th \
compat-type.conf
libcompat_la_CPPFLAGS = \
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.
*/
}
}
-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");
-}
#ifndef CHECKRESULTREADER_H
#define CHECKRESULTREADER_H
-#include "base/dynamicobject.h"
+#include "compat/checkresultreader.th"
#include "base/timer.h"
#include <fstream>
*
* @ingroup compat
*/
-class CheckResultReader : public DynamicObject
+class CheckResultReader : public ReflectionObjectImpl<CheckResultReader>
{
public:
DECLARE_PTR_TYPEDEFS(CheckResultReader);
DECLARE_TYPENAME(CheckResultReader);
- String GetSpoolDir(void) const;
-
protected:
virtual void Start(void);
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- String m_SpoolDir;
-
Timer::Ptr m_ReadTimer;
void ReadTimerHandler(void) const;
void ProcessCheckResultFile(const String& path) const;
--- /dev/null
+#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/"; }}}
+ };
+};
+
+}
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.
*/
ObjectLock oLock(this);
Flush();
}
-
}
-
void CompatLogger::ExternalCommandHandler(const String& command, const std::vector<String>& arguments)
{
std::ostringstream msgbuf;
<< host->GetName() << ";"
<< Host::StateToString(Host::CalculateState(hc->GetState(), reachable)) << ";"
<< Service::StateTypeToString(hc->GetStateType()) << ";"
- << hc->GetCurrentCheckAttempt() << ";"
+ << hc->GetCheckAttempt() << ";"
<< "";
WriteLine(msgbuf.str());
<< service->GetShortName() << ";"
<< Service::StateToString(service->GetState()) << ";"
<< Service::StateTypeToString(service->GetStateType()) << ";"
- << service->GetCurrentCheckAttempt() << ";"
+ << service->GetCheckAttempt() << ";"
<< "";
WriteLine(msgbuf.str());
}
}
-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");
- }
-}
#ifndef COMPATLOGGER_H
#define COMPATLOGGER_H
+#include "compat/compatlogger.th"
#include "icinga/service.h"
-#include "base/dynamicobject.h"
#include "base/timer.h"
#include <fstream>
*
* @ingroup compat
*/
-class CompatLogger : public DynamicObject
+class CompatLogger : public ReflectionObjectImpl<CompatLogger>
{
public:
DECLARE_PTR_TYPEDEFS(CompatLogger);
CompatLogger(void);
- String GetLogDir(void) const;
- String GetRotationMethod(void) const;
-
static void ValidateRotationMethod(const String& location, const Dictionary::Ptr& attrs);
protected:
virtual void Start(void);
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- String m_LogDir;
- String m_RotationMethod;
-
double m_LastRotation;
void WriteLine(const String& line);
--- /dev/null
+#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"; }}}
+ };
+};
+
+}
#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
void ExternalCommandListener::CommandPipeThread(const String& commandPath)
{
}
}
#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");
-}
#ifndef EXTERNALCOMMANDLISTENER_H
#define EXTERNALCOMMANDLISTENER_H
-#include "base/dynamicobject.h"
+#include "compat/externalcommandlistener.th"
#include "base/objectlock.h"
#include "base/timer.h"
#include "base/utility.h"
/**
* @ingroup compat
*/
-class ExternalCommandListener : public DynamicObject
+class ExternalCommandListener : public ReflectionObjectImpl<ExternalCommandListener>
{
public:
DECLARE_PTR_TYPEDEFS(ExternalCommandListener);
protected:
virtual void Start(void);
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- String m_CommandPath;
-
#ifndef _WIN32
boost::thread m_CommandThread;
void CommandPipeThread(const String& commandPath);
#endif /* _WIN32 */
-
- String GetCommandPath(void) const;
};
}
--- /dev/null
+#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"; }}}
+ };
+};
+
+}
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)
{
Service::Ptr service;
Dictionary::Ptr comments = owner->GetComments();
- if (!comments)
- return;
-
Host::Ptr host = owner->GetHost();
if (!host)
Dictionary::Ptr downtimes = owner->GetDowntimes();
- if (!downtimes)
- return;
-
ObjectLock olock(downtimes);
String id;
<< "\t" << "active_checks_enabled" << "\t" << (service->GetEnableActiveChecks() ? 1 : 0) << "\n"
<< "\t" << "passive_checks_enabled" << "\t" << (service->GetEnablePassiveChecks() ? 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" << "notification_options" << "\t" << "u,w,c,r" << "\n"
<< "\t" << "notification_interval" << "\t" << notification_interval / 60.0 << "\n"
statusfp << "programstatus {" << "\n"
<< "\t" << "icinga_pid=" << Utility::GetPid() << "\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" << "passive_service_checks_enabled=1" << "\n"
<< "\t" << "active_host_checks_enabled=1" << "\n"
}
}
-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");
- }
-}
#ifndef STATUSDATAWRITER_H
#define STATUSDATAWRITER_H
+#include "compat/statusdatawriter.th"
#include "icinga/host.h"
#include "icinga/service.h"
#include "icinga/command.h"
#include "icinga/compatutility.h"
-#include "base/dynamicobject.h"
#include "base/objectlock.h"
#include "base/timer.h"
#include "base/utility.h"
/**
* @ingroup compat
*/
-class StatusDataWriter : public DynamicObject
+class StatusDataWriter : public ReflectionObjectImpl<StatusDataWriter>
{
public:
DECLARE_PTR_TYPEDEFS(StatusDataWriter);
protected:
virtual void Start(void);
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- String m_StatusPath;
- String m_ObjectsPath;
-
Timer::Ptr m_StatusTimer;
- String GetStatusPath(void) const;
- String GetObjectsPath(void) const;
-
void DumpCommand(std::ostream& fp, const Command::Ptr& command);
void DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& tp);
void DumpDowntimes(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type);
--- /dev/null
+#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"; }}}
+ };
+};
+
+}
pkglib_LTLIBRARIES = \
libdb_ido_mysql.la
+BUILT_SOURCES = \
+ idomysqlconnection.th
+
CLEANFILES = \
db_ido_mysql-type.cpp
.conf.cpp: $(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 = \
db_ido_mysql-type.conf \
idomysqlconnection.cpp \
- idomysqlconnection.h
+ idomysqlconnection.h \
+ idomysqlconnection.ti
libdb_ido_mysql_la_CPPFLAGS = \
$(LTDLINCL) \
#include "base/convert.h"
#include "base/utility.h"
#include "base/application.h"
+#include "base/dynamictype.h"
#include "db_ido/dbtype.h"
#include "db_ido/dbvalue.h"
#include "db_ido_mysql/idomysqlconnection.h"
REGISTER_TYPE(IdoMysqlConnection);
+#define SCHEMA_VERSION "1.10.0"
+
void IdoMysqlConnection::Start(void)
{
DbConnection::Start();
m_Connected = false;
- m_RequiredSchemaVersion = "1.10.0";
m_TxTimer = boost::make_shared<Timer>();
m_TxTimer->SetInterval(5);
const char *host, *user , *passwd, *db;
long port;
- ihost = m_Host;
- iuser = m_User;
- ipasswd = m_Password;
- idb = m_Database;
+ ihost = GetHost();
+ iuser = GetUser();
+ ipasswd = GetPassword();
+ idb = GetDatabase();
host = (!ihost.IsEmpty()) ? ihost.CStr() : NULL;
- port = m_Port;
+ port = GetPort();
user = (!iuser.IsEmpty()) ? iuser.CStr() : NULL;
passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : NULL;
db = (!idb.IsEmpty()) ? idb.CStr() : NULL;
Dictionary::Ptr version_row = version_rows->Get(0);
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 '" +
- m_RequiredSchemaVersion + "'! Please check the upgrade documentation."));
+ SCHEMA_VERSION + "'! Please check the upgrade documentation."));
}
- String instanceName = "default";
-
- if (!m_InstanceName.IsEmpty())
- instanceName = m_InstanceName;
+ String instanceName = GetInstanceName();
Array::Ptr rows = Query("SELECT instance_id FROM " + GetTablePrefix() + "instances WHERE instance_name = '" + Escape(instanceName) + "'");
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();
} else {
Dictionary::Ptr row = rows->Get(0);
"<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");
- }
-}
#ifndef IDOMYSQLCONNECTION_H
#define IDOMYSQLCONNECTION_H
+#include "db_ido_mysql/idomysqlconnection.th"
#include "base/array.h"
-#include "base/dynamictype.h"
#include "base/timer.h"
-#include "db_ido/dbconnection.h"
#include <mysql/mysql.h>
namespace icinga
*
* @ingroup ido
*/
-class IdoMysqlConnection : public DbConnection
+class IdoMysqlConnection : public ReflectionObjectImpl<IdoMysqlConnection>
{
public:
DECLARE_PTR_TYPEDEFS(IdoMysqlConnection);
virtual void CleanUpExecuteQuery(const String& table, const String& time_key, double time_value);
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_LastNotificationID;
bool m_Connected;
MYSQL m_Connection;
- String m_RequiredSchemaVersion;
-
Timer::Ptr m_ReconnectTimer;
Timer::Ptr m_TxTimer;
--- /dev/null
+#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;
+};
+
+}
pkglib_LTLIBRARIES = \
libdemo.la
+BUILT_SOURCES = \
+ demo.th
+
CLEANFILES = \
demo-type.cpp
.conf.cpp: $(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 = \
demo.cpp \
demo.h \
+ demo.ti \
demo-type.conf
libdemo_la_CPPFLAGS = \
#ifndef DEMO_H
#define DEMO_H
-#include "base/dynamicobject.h"
+#include "demo/demo.th"
#include "base/timer.h"
namespace icinga
/**
* @ingroup demo
*/
-class Demo : public DynamicObject
+class Demo : public ReflectionObjectImpl<Demo>
{
public:
DECLARE_PTR_TYPEDEFS(Demo);
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class Demo : DynamicObject
+{
+};
+
+}
pkglib_LTLIBRARIES = \
liblivestatus.la
+BUILT_SOURCES = \
+ listener.th
+
CLEANFILES = \
livestatus-type.cpp
.conf.cpp: $(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 = \
aggregator.cpp \
aggregator.h \
invsumaggregator.h \
listener.cpp \
listener.h \
+ listener.ti \
livestatus-type.conf \
logtable.cpp \
logtable.h \
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
Dictionary::Ptr comments = service->GetComments();
- if (!comments)
- continue;
-
ObjectLock olock(comments);
String id;
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
Dictionary::Ptr downtimes = service->GetDowntimes();
- if (!downtimes)
- continue;
-
ObjectLock olock(downtimes);
String id;
if (!hc)
return Empty;
- return hc->GetCurrentCheckAttempt();
+ return hc->GetCheckAttempt();
}
Value HostsTable::LastNotificationAccessor(const Value& row)
notification_interval = notification->GetNotificationInterval();
}
- if (notification_interval == 0 && !hc->IsVolatile())
+ if (notification_interval == 0 && !hc->GetVolatile())
return 1;
return 0;
Dictionary::Ptr downtimes = hc->GetDowntimes();
- if (!downtimes)
- return Empty;
-
Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(downtimes);
Dictionary::Ptr downtimes = hc->GetDowntimes();
- if (!downtimes)
- return Empty;
-
Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(downtimes);
Dictionary::Ptr comments = hc->GetComments();
- if (!comments)
- return Empty;
-
Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(comments);
Dictionary::Ptr comments = hc->GetComments();
- if (!comments)
- return Empty;
-
Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(comments);
Dictionary::Ptr comments = hc->GetComments();
- if (!comments)
- return Empty;
-
Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(comments);
}
}
-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)
{
boost::mutex::scoped_lock lock(l_ComponentMutex);
}
}
-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");
- }
-}
#ifndef LIVESTATUSLISTENER_H
#define LIVESTATUSLISTENER_H
+#include "livestatus/listener.th"
#include "livestatus/query.h"
-#include "base/dynamicobject.h"
#include "base/socket.h"
#include <boost/thread/thread.hpp>
/**
* @ingroup livestatus
*/
-class LivestatusListener : public DynamicObject
+class LivestatusListener : public ReflectionObjectImpl<LivestatusListener>
{
public:
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 GetConnections(void);
protected:
virtual void Start(void);
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- String m_SocketType;
- String m_SocketPath;
- String m_BindHost;
- String m_BindPort;
-
void ServerThreadProc(const Socket::Ptr& server);
void ClientThreadProc(const Socket::Ptr& client);
};
--- /dev/null
+#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"; }}}
+ };
+};
+
+}
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)
notification_interval = notification->GetNotificationInterval();
}
- if (notification_interval == 0 && !service->IsVolatile())
+ if (notification_interval == 0 && !service->GetVolatile())
return 1;
return 0;
{
Dictionary::Ptr downtimes = static_cast<Service::Ptr>(row)->GetDowntimes();
- if (!downtimes)
- return Empty;
-
Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(downtimes);
{
Dictionary::Ptr downtimes = static_cast<Service::Ptr>(row)->GetDowntimes();
- if (!downtimes)
- return Empty;
-
Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(downtimes);
{
Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments();
- if (!comments)
- return Empty;
-
Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(comments);
{
Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments();
- if (!comments)
- return Empty;
-
Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(comments);
{
Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments();
- if (!comments)
- return Empty;
-
Array::Ptr ids = boost::make_shared<Array>();
ObjectLock olock(comments);
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::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::ProgramStartAccessor(const Value& row)
{
- return static_cast<int>(IcingaApplication::GetInstance()->GetStartTime());
+ return Application::GetStartTime();
}
Value StatusTable::NumHostsAccessor(const Value& row)
pkglib_LTLIBRARIES = \
libnotification.la
+BUILT_SOURCES = \
+ notificationcomponent.th
+
CLEANFILES = \
notification-type.cpp
.conf.cpp: $(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 = \
notificationcomponent.cpp \
notificationcomponent.h \
+ notificationcomponent.ti \
notification-type.conf
libnotification_la_CPPFLAGS = \
#ifndef NOTIFICATIONCOMPONENT_H
#define NOTIFICATIONCOMPONENT_H
+#include "notification/notificationcomponent.th"
#include "icinga/service.h"
#include "base/dynamicobject.h"
#include "base/timer.h"
/**
* @ingroup notification
*/
-class NotificationComponent : public DynamicObject
+class NotificationComponent : public ReflectionObjectImpl<NotificationComponent>
{
public:
DECLARE_PTR_TYPEDEFS(NotificationComponent);
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class NotificationComponent : DynamicObject
+{
+};
+
+}
pkglib_LTLIBRARIES = \
libperfdata.la
+BUILT_SOURCES = \
+ graphitewriter.th \
+ perfdatawriter.th
+
CLEANFILES = \
perfdata-type.cpp
.conf.cpp: $(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 = \
graphitewriter.cpp \
graphitewriter.h \
+ graphitewriter.ti \
perfdatawriter.cpp \
perfdatawriter.h \
+ perfdatawriter.th \
perfdata-type.conf
libperfdata_la_CPPFLAGS = \
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)
{
try {
Value metricValue;
/* 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, "state_type", service->GetStateType());
AddServiceMetric(metrics, service, "state", service->GetState());
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");
- }
-}
#ifndef GRAPHITEWRITER_H
#define GRAPHITEWRITER_H
+#include "perfdata/graphitewriter.th"
#include "icinga/service.h"
#include "base/dynamicobject.h"
#include "base/tcpsocket.h"
*
* @ingroup perfdata
*/
-class GraphiteWriter : public DynamicObject
+class GraphiteWriter : public ReflectionObjectImpl<GraphiteWriter>
{
public:
DECLARE_PTR_TYPEDEFS(GraphiteWriter);
DECLARE_TYPENAME(GraphiteWriter);
- String GetHost(void) const;
- String GetPort(void) const;
-
protected:
virtual void Start(void);
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- String m_Host;
- String m_Port;
Stream::Ptr m_Stream;
Timer::Ptr m_ReconnectTimer;
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class GraphiteWriter : DynamicObject
+{
+ [config] String host {
+ default {{{ return "127.0.0.1"; }}}
+ };
+ [config] String port {
+ default {{{ return "2003"; }}}
+ };
+};
+
+}
REGISTER_TYPE(PerfdataWriter);
-PerfdataWriter::PerfdataWriter(void)
- : m_RotationInterval(30)
-{ }
-
void PerfdataWriter::Start(void)
{
DynamicObject::Start();
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)
{
if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !service->GetEnablePerfdata())
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");
- }
-}
#ifndef PERFDATAWRITER_H
#define PERFDATAWRITER_H
-#include "icinga/i2-icinga.h"
+#include "perfdata/perfdatawriter.th"
#include "icinga/service.h"
#include "base/dynamicobject.h"
#include "base/timer.h"
*
* @ingroup icinga
*/
-class PerfdataWriter : public DynamicObject
+class PerfdataWriter : public ReflectionObjectImpl<PerfdataWriter>
{
public:
DECLARE_PTR_TYPEDEFS(PerfdataWriter);
DECLARE_TYPENAME(PerfdataWriter);
- PerfdataWriter(void);
-
- String GetPerfdataPath(void) const;
- String GetFormatTemplate(void) const;
- double GetRotationInterval(void) const;
-
protected:
virtual void Start(void);
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- String m_PerfdataPath;
- String m_FormatTemplate;
- double m_RotationInterval;
-
void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr);
Timer::Ptr m_RotationTimer;
--- /dev/null
+#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; }}}
+ };
+};
+
+}
tools/Makefile
tools/migration/Makefile
tools/icinga2-enable-feature
+tools/mkclass/Makefile
tools/mkembedconfig/Makefile
])
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\_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\_passive\_checks|**Optional.** Whether passive checks are enabled. Defaults to true.
enable\_event\_handler|**Optional.** Enables event handlers for this service. Defaults to true.
*/
int main(int argc, char **argv)
{
+ Application::SetStartTime(Utility::GetTime());
+
#ifndef _WIN32
LTDL_SET_PRELOADED_SYMBOLS();
#endif /* _WIN32 */
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo", "components\demo\demo.vcxproj", "{2E6C1133-730F-4875-A72C-B455B1DD4C5C}"
ProjectSection(ProjectDependencies) = postProject
{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}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "notification", "components\notification\notification.vcxproj", "{EBEA7D10-66FB-4760-8AA8-81CD500D899E}"
ProjectSection(ProjectDependencies) = postProject
+ {950E8743-BB34-4F8A-99EC-C87E8FC0EB3F} = {950E8743-BB34-4F8A-99EC-C87E8FC0EB3F}
{D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "checker", "components\checker\checker.vcxproj", "{38CE81CC-2660-4EF0-A936-4A337591DA3E}"
ProjectSection(ProjectDependencies) = postProject
{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}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "compat", "components\compat\compat.vcxproj", "{2BD1C70C-43DB-4F44-B66B-67CF5C7044AA}"
ProjectSection(ProjectDependencies) = postProject
{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}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
ProjectSection(ProjectDependencies) = postProject
{19CBCE06-3F5C-479A-BD75-E2AB6215D345} = {19CBCE06-3F5C-479A-BD75-E2AB6215D345}
{66BED474-C33F-48F9-90BA-BBCFEDC006B8} = {66BED474-C33F-48F9-90BA-BBCFEDC006B8}
+ {CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "config", "lib\config\config.vcxproj", "{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icinga", "lib\icinga\icinga.vcxproj", "{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}"
ProjectSection(ProjectDependencies) = postProject
{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}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
EndProjectSection
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "livestatus", "components\livestatus\livestatus.vcxproj", "{950E8743-BB34-4F8A-99EC-C87E8FC0EB3F}"
ProjectSection(ProjectDependencies) = postProject
{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}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cluster", "components\cluster\cluster.vcxproj", "{8732E0CD-E3D0-41F2-A538-94884543890F}"
ProjectSection(ProjectDependencies) = postProject
{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}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "db_ido", "lib\db_ido\db_ido.vcxproj", "{87BBCE4C-36F5-4C04-90FB-9B74618AF988}"
ProjectSection(ProjectDependencies) = postProject
{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}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "perfdata", "components\perfdata\perfdata.vcxproj", "{E08A9B69-97E2-4203-B4D7-501DFF020CCF}"
ProjectSection(ProjectDependencies) = postProject
+ {950E8743-BB34-4F8A-99EC-C87E8FC0EB3F} = {950E8743-BB34-4F8A-99EC-C87E8FC0EB3F}
{D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
EndProjectSection
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mkclass", "tools\mkclass\mkclass.vcxproj", "{CBC9DD83-BAEB-4995-8D0B-F711898908E7}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|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.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
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
pkglib_LTLIBRARIES = \
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 = \
application.cpp \
application.h \
+ application.ti \
array.cpp \
array.h \
bufferedstream.cpp \
bufferedstream.h \
consolelogger.cpp \
consolelogger.h \
+ consolelogger.ti \
convert.cpp \
convert.h \
debug.h \
dictionary.h \
dynamicobject.cpp \
dynamicobject.h \
+ dynamicobject.ti \
dynamictype.cpp \
dynamictype.h \
exception.cpp \
fifo.h \
filelogger.cpp \
filelogger.h \
+ filelogger.ti \
i2-base.h \
initialize.h \
logger.cpp \
logger.h \
+ logger.ti \
logger_fwd.h \
netstring.cpp \
netstring.h \
process.h \
qstring.cpp \
qstring.h \
+ reflectionobject.cpp \
+ reflectionobject.h \
registry.h \
ringbuffer.cpp \
ringbuffer.h \
script.cpp \
script.h \
+ script.ti \
scriptfunction.cpp \
scriptfunction.h \
scriptfunctionwrapper.cpp \
stream_bio.h \
streamlogger.cpp \
streamlogger.h \
+ streamlogger.ti \
sysloglogger.cpp \
sysloglogger.h \
+ sysloglogger.ti \
tcpsocket.cpp \
tcpsocket.h \
threadpool.cpp \
bool Application::m_Debugging = false;
int Application::m_ArgC;
char **Application::m_ArgV;
+double Application::m_StartTime;
/**
* Constructor for the Application class.
return "unspecified version";
#endif /* _WIN32 */
}
+
+double Application::GetStartTime(void)
+{
+ return m_StartTime;
+}
+
+void Application::SetStartTime(double ts)
+{
+ m_StartTime = ts;
+}
#define APPLICATION_H
#include "base/i2-base.h"
+#include "base/application.th"
#include "base/threadpool.h"
#include "base/dynamicobject.h"
*
* @ingroup base
*/
-class I2_BASE_API Application : public DynamicObject {
+class I2_BASE_API Application : public ReflectionObjectImpl<Application> {
public:
DECLARE_PTR_TYPEDEFS(Application);
static String GetVersion(void);
+ static double GetStartTime(void);
+ static void SetStartTime(double ts);
+
protected:
virtual void OnConfigLoaded(void);
virtual void Stop(void);
static char **m_ArgV; /**< Command-line arguments. */
FILE *m_PidFile; /**< The PID file */
static bool m_Debugging; /**< Whether debugging is enabled. */
+ static double m_StartTime;
#ifndef _WIN32
static void SigIntHandler(int signum);
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class Application : DynamicObject
+{
+};
+
+}
<ClCompile Include="dynamictype.cpp" />
<ClCompile Include="filelogger.cpp" />
<ClCompile Include="networkstream.cpp" />
+ <ClCompile Include="reflectionobject.cpp" />
<ClCompile Include="script.cpp" />
<ClCompile Include="scriptinterpreter.cpp" />
<ClCompile Include="scriptlanguage.cpp" />
<ClInclude Include="filelogger.h" />
<ClInclude Include="initialize.h" />
<ClInclude Include="networkstream.h" />
+ <ClInclude Include="reflectionobject.h" />
<ClInclude Include="script.h" />
<ClInclude Include="scriptinterpreter.h" />
<ClInclude Include="scriptlanguage.h" />
<ClInclude Include="zlibstream.h" />
</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)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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" />
+ <CustomBuild Include="script.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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>
<PropertyGroup Label="Globals">
<ProjectGuid>{9C92DA90-FD53-43A9-A244-90F2E8AF9677}</ProjectGuid>
<ClCompile Include="zlibstream.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
+ <ClCompile Include="reflectionobject.cpp">
+ <Filter>Quelldateien</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="application.h">
<ClInclude Include="zlibstream.h">
<Filter>Headerdateien</Filter>
</ClInclude>
+ <ClInclude Include="reflectionobject.h">
+ <Filter>Headerdateien</Filter>
+ </ClInclude>
+ <ClInclude Include="dynamicobject.th">
+ <Filter>Headerdateien</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Quelldateien">
</ItemGroup>
<ItemGroup>
<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>
</Project>
\ No newline at end of file
#define CONSOLELOGGER_H
#include "base/i2-base.h"
-#include "base/streamlogger.h"
+#include "base/consolelogger.th"
namespace icinga
{
*
* @ingroup base
*/
-class I2_BASE_API ConsoleLogger : public StreamLogger
+class I2_BASE_API ConsoleLogger : public ReflectionObjectImpl<ConsoleLogger>
{
public:
DECLARE_PTR_TYPEDEFS(ConsoleLogger);
--- /dev/null
+#include "base/streamlogger.h"
+
+namespace icinga
+{
+
+class ConsoleLogger : StreamLogger
+{
+};
+
+}
\ No newline at end of file
#include "i2-base.h"
-#ifdef NDEBUG
+#ifndef _DEBUG
# define ASSERT(expr) ((void)0)
-#else /* NDEBUG */
+#else /* _DEBUG */
# 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__))
+#ifdef _MSC_VER
+# define NORETURNPRE __declspec(noreturn)
+#else /* _MSC_VER */
+# define NORETURNPRE
+#endif /* _MSC_VER */
+
#ifdef __GNUC__
-# define NORETURN __attribute__((noreturn))
+# define NORETURNPOST __attribute__((noreturn))
#else /* __GNUC__ */
-# define NORETURN
+# define NORETURNPOST
#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)
{
fprintf(stderr, "%s:%d: assertion failed: %s\n", file, line, expr);
abort();
-#ifndef __GNUC__
+#if !defined(__GNUC__) && !defined(_MSC_VER)
return 0;
-#endif /* __GNUC__ */
+#endif /* !defined(__GNUC__) && !defined(_MSC_VER) */
}
+#ifdef _MSC_VER
+# pragma warning( pop )
+#endif /* _MSC_VER */
+
#endif /* DEBUG_H */
boost::signals2::signal<void (const DynamicObject::Ptr&, const String&, bool)> DynamicObject::OnAuthorityChanged;
DynamicObject::DynamicObject(void)
- : m_Active(false)
-{ }
-
-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;
+ SetActive(false);
}
-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");
-}
+DynamicObject::~DynamicObject(void)
+{ }
DynamicType::Ptr DynamicObject::GetType(void) const
{
- return DynamicType::GetByName(m_Type);
-}
-
-String DynamicObject::GetName(void) const
-{
- return m_Name;
+ return DynamicType::GetByName(GetTypeName());
}
bool DynamicObject::IsActive(void) const
{
- return m_Active;
-}
-
-Array::Ptr DynamicObject::GetAuthorities(void) const
-{
- return m_Authorities;
+ return GetActive();
}
void DynamicObject::SetAuthority(const String& type, bool value)
{
ObjectLock olock(this);
- if (!m_Authority)
- m_Authority = boost::make_shared<Dictionary>();
-
bool old_value = HasAuthority(type);
if (old_value == value)
return;
- m_Authority->Set(type, value);
+ GetAuthorityInfo()->Set(type, value);
}
OnAuthorityChanged(GetSelf(), type, value);
bool DynamicObject::HasAuthority(const String& type) const
{
- if (!m_Authority)
- return true;
-
- return m_Authority->Get(type);
-}
-
-Array::Ptr DynamicObject::GetDomains(void) const
-{
- return m_Domains;
+ return GetAuthorityInfo()->Get(type);
}
void DynamicObject::SetPrivileges(const String& instance, int privs)
void DynamicObject::SetExtension(const String& key, const Object::Ptr& object)
{
- Dictionary::Ptr extensions = m_Extensions;
+ Dictionary::Ptr extensions = GetExtensions();
if (!extensions) {
extensions = boost::make_shared<Dictionary>();
- m_Extensions = extensions;
+ SetExtensions(extensions);
}
extensions->Set(key, object);
Object::Ptr DynamicObject::GetExtension(const String& key)
{
- Dictionary::Ptr extensions = m_Extensions;
+ Dictionary::Ptr extensions = GetExtensions();
if (!extensions)
return Object::Ptr();
void DynamicObject::ClearExtension(const String& key)
{
- Dictionary::Ptr extensions = m_Extensions;
+ Dictionary::Ptr extensions = GetExtensions();
if (!extensions)
return;
{
ASSERT(!OwnsLock());
- ASSERT(!m_Active);
- m_Active = true;
+ ASSERT(!IsActive());
+ SetActive(true);
OnStarted(GetSelf());
}
{
ASSERT(!OwnsLock());
- ASSERT(m_Active);
- m_Active = false;
+ ASSERT(IsActive());
+ SetActive(false);
OnStopped(GetSelf());
}
{
Dictionary::Ptr methods;
- methods = m_Methods;
+ methods = GetMethods();
if (!methods)
BOOST_THROW_EXCEPTION(std::invalid_argument("Method '" + method + "' does not exist."));
DynamicType::Ptr dtype = DynamicType::GetByName(type);
return dtype->GetObject(name);
}
-
-Dictionary::Ptr DynamicObject::GetCustom(void) const
-{
- return m_Custom;
-}
#define DYNAMICOBJECT_H
#include "base/i2-base.h"
+#include "base/dynamicobject.th"
#include "base/object.h"
#include "base/dictionary.h"
#include "base/array.h"
*/
enum AttributeType
{
- Attribute_State = 1,
- Attribute_Config = 2,
+ Attribute_State = FAState,
+ Attribute_Config = FAConfig
};
enum DomainPriv
*
* @ingroup base
*/
-class I2_BASE_API DynamicObject : public Object
+class I2_BASE_API DynamicObject : public ReflectionObjectImpl<DynamicObject>
{
public:
DECLARE_PTR_TYPEDEFS(DynamicObject);
~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&)> OnStopped;
static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStateChanged;
Value InvokeMethod(const String& method, const std::vector<Value>& arguments);
shared_ptr<DynamicType> GetType(void) const;
- String GetName(void) const;
bool IsActive(void) const;
- Array::Ptr GetAuthorities(void) const;
-
void SetAuthority(const String& type, bool value);
bool HasAuthority(const String& type) const;
- Array::Ptr GetDomains(void) const;
-
void SetPrivileges(const String& instance, int privs);
bool HasPrivileges(const String& instance, int privs) const;
static void RestoreObjects(const String& filename, int attributeTypes = Attribute_State);
static void StopObjects(void);
- Dictionary::Ptr GetCustom(void) const;
-
protected:
explicit DynamicObject(void);
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
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;
- bool m_Active;
- Dictionary::Ptr m_Authority;
-
static DynamicObject::Ptr GetObject(const String& type, const String& name);
};
--- /dev/null
+#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;
+};
+
+}
std::ofstream *stream = new std::ofstream();
- String path = m_Path;
+ String path = GetPath();
try {
stream->open(path.CStr(), std::fstream::out | std::fstream::trunc);
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");
-}
#define FILELOGGER_H
#include "base/i2-base.h"
-#include "base/streamlogger.h"
+#include "base/filelogger.th"
namespace icinga
{
*
* @ingroup base
*/
-class I2_BASE_API FileLogger : public StreamLogger
+class I2_BASE_API FileLogger : public ReflectionObjectImpl<FileLogger>
{
public:
DECLARE_PTR_TYPEDEFS(FileLogger);
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;
};
}
--- /dev/null
+#include "base/streamlogger.h"
+
+namespace icinga
+{
+
+class FileLogger : StreamLogger
+{
+ [config] String path;
+};
+
+}
\ No newline at end of file
*/
LogSeverity Logger::GetMinSeverity(void) const
{
- String severity = m_Severity;
+ String severity = GetSeverity();
if (severity.IsEmpty())
return LogInformation;
else
else
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");
-}
#define LOGGER_H
#include "base/i2-base.h"
+#include "base/logger.th"
#include "base/dynamicobject.h"
#include "base/logger_fwd.h"
#include <set>
*
* @ingroup base
*/
-class I2_BASE_API Logger : public DynamicObject
+class I2_BASE_API Logger : public ReflectionObjectImpl<Logger>
{
public:
DECLARE_PTR_TYPEDEFS(Logger);
virtual void Start(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:
- String m_Severity;
-
static boost::mutex m_Mutex;
static std::set<Logger::Ptr> m_Loggers;
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class Logger : DynamicObject
+{
+ [config] String severity;
+};
+
+}
\ No newline at end of file
(void) close(fds[0]);
(void) close(fds[1]);
- if (execvpe(argv[0], argv, envp) < 0) {
+ if (icinga2_execvpe(argv[0], argv, envp) < 0) {
perror("execvpe() failed.");
_exit(128);
}
--- /dev/null
+/******************************************************************************
+ * 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));
+ }
+}
--- /dev/null
+/******************************************************************************
+ * 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 */
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)
{
Log(LogInformation, "base", "Reloading script '" + GetName() + "'");
ScriptLanguage::Ptr language = ScriptLanguage::GetByName(GetLanguage());
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");
- }
-}
#define SCRIPT_H
#include "base/i2-base.h"
-#include "base/dynamicobject.h"
+#include "base/script.th"
namespace icinga
{
*
* @ingroup base
*/
-class I2_BASE_API Script : public DynamicObject
+class I2_BASE_API Script : public ReflectionObjectImpl<Script>
{
public:
DECLARE_PTR_TYPEDEFS(Script);
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:
- String m_Language;
- String m_Code;
-
shared_ptr<ScriptInterpreter> m_Interpreter;
void SpawnInterpreter(void);
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class Script : DynamicObject
+{
+ [config] String language;
+ [config] String "code";
+};
+
+}
#define STREAMLOGGER_H
#include "base/i2-base.h"
-#include "base/logger.h"
+#include "base/streamlogger.th"
#include "base/timer.h"
#include <ostream>
*
* @ingroup base
*/
-class I2_BASE_API StreamLogger : public Logger
+class I2_BASE_API StreamLogger : public ReflectionObjectImpl<StreamLogger>
{
public:
DECLARE_PTR_TYPEDEFS(StreamLogger);
static boost::mutex m_Mutex;
std::ostream *m_Stream;
bool m_OwnsStream;
- bool m_Tty;
+ bool m_Tty;
- Timer::Ptr m_FlushLogTimer;
+ Timer::Ptr m_FlushLogTimer;
- void FlushLogTimerHandler(void);
+ void FlushLogTimerHandler(void);
};
}
--- /dev/null
+#include "base/logger.h"
+
+namespace icinga
+{
+
+class StreamLogger : Logger
+{
+};
+
+}
\ No newline at end of file
#define SYSLOGLOGGER_H
#include "base/i2-base.h"
-#include "base/logger.h"
+#include "base/sysloglogger.th"
#ifndef _WIN32
namespace icinga
*
* @ingroup base
*/
-class I2_BASE_API SyslogLogger : public Logger
+class I2_BASE_API SyslogLogger : public ReflectionObjectImpl<SyslogLogger>
{
public:
DECLARE_PTR_TYPEDEFS(SyslogLogger);
--- /dev/null
+#include "base/logger.h"
+
+namespace icinga
+{
+
+class SyslogLogger : Logger
+{
+};
+
+}
\ No newline at end of file
pkglib_LTLIBRARIES = \
libdb_ido.la
+BUILT_SOURCES = \
+ dbconnection.th
+
CLEANFILES = \
db_ido-type.cpp
.conf.cpp: $(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 = \
commanddbobject.cpp \
commanddbobject.h \
dbconnection.cpp \
dbconnection.h \
+ dbconnection.ti \
dbobject.cpp \
dbobject.h \
dbquery.cpp \
</CustomBuild>
</ItemGroup>
<ItemGroup>
+ <CustomBuild Include="dbconnection.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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" />
</ItemGroup>
<PropertyGroup Label="Globals">
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
+ <None Include="dbconnection.th">
+ <Filter>Headerdateien</Filter>
+ </None>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="db_ido-type.conf">
<Filter>Quelldateien</Filter>
</CustomBuild>
+ <CustomBuild Include="dbconnection.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
</ItemGroup>
</Project>
\ No newline at end of file
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)
{
DbQuery query;
query2.Fields = boost::make_shared<Dictionary>();
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("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("process_id", Utility::GetPid());
query2.Fields->Set("daemon_mode", 1);
{
long now = static_cast<long>(Utility::GetTime());
- if (GetCleanUpAcknowledgementsAge() > 0) {
- CleanUpExecuteQuery("acknowledgements", "entry_time", now - GetCleanUpAcknowledgementsAge());
- Log(LogDebug, "db_ido", "GetCleanUpAcknowledgementsAge: " + Convert::ToString(GetCleanUpAcknowledgementsAge()) +
+ if (GetCleanupAcknowledgementsAge() > 0) {
+ CleanUpExecuteQuery("acknowledgements", "entry_time", now - GetCleanupAcknowledgementsAge());
+ Log(LogDebug, "db_ido", "GetCleanupAcknowledgementsAge: " + Convert::ToString(GetCleanupAcknowledgementsAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpAcknowledgementsAge()));
+ " old: " + Convert::ToString(now - GetCleanupAcknowledgementsAge()));
}
- if (GetCleanUpCommentHistoryAge() > 0) {
- CleanUpExecuteQuery("commenthistory", "entry_time", now - GetCleanUpCommentHistoryAge());
- Log(LogDebug, "db_ido", "GetCleanUpCommentHistoryAge: " + Convert::ToString(GetCleanUpCommentHistoryAge()) +
+ if (GetCleanupCommentHistoryAge() > 0) {
+ CleanUpExecuteQuery("commenthistory", "entry_time", now - GetCleanupCommentHistoryAge());
+ Log(LogDebug, "db_ido", "GetCleanupCommentHistoryAge: " + Convert::ToString(GetCleanupCommentHistoryAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpCommentHistoryAge()));
+ " old: " + Convert::ToString(now - GetCleanupCommentHistoryAge()));
}
- if (GetCleanUpContactNotificationsAge() > 0) {
- CleanUpExecuteQuery("contactnotifications", "start_time", now - GetCleanUpContactNotificationsAge());
- Log(LogDebug, "db_ido", "GetCleanUpContactNotificationsAge: " + Convert::ToString(GetCleanUpContactNotificationsAge()) +
+ if (GetCleanupContactNotificationsAge() > 0) {
+ CleanUpExecuteQuery("contactnotifications", "start_time", now - GetCleanupContactNotificationsAge());
+ Log(LogDebug, "db_ido", "GetCleanupContactNotificationsAge: " + Convert::ToString(GetCleanupContactNotificationsAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpContactNotificationsAge()));
+ " old: " + Convert::ToString(now - GetCleanupContactNotificationsAge()));
}
- if (GetCleanUpContactNotificationMethodsAge() > 0) {
- CleanUpExecuteQuery("contactnotificationmethods", "start_time", now - GetCleanUpContactNotificationMethodsAge());
- Log(LogDebug, "db_ido", "GetCleanUpContactNotificationMethodsAge: " + Convert::ToString(GetCleanUpContactNotificationMethodsAge()) +
+ if (GetCleanupContactNotificationMethodsAge() > 0) {
+ CleanUpExecuteQuery("contactnotificationmethods", "start_time", now - GetCleanupContactNotificationMethodsAge());
+ Log(LogDebug, "db_ido", "GetCleanupContactNotificationMethodsAge: " + Convert::ToString(GetCleanupContactNotificationMethodsAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpContactNotificationMethodsAge()));
+ " old: " + Convert::ToString(now - GetCleanupContactNotificationMethodsAge()));
}
- if (GetCleanUpDowntimeHistoryAge() > 0) {
- CleanUpExecuteQuery("downtimehistory", "entry_time", now - GetCleanUpDowntimeHistoryAge());
- Log(LogDebug, "db_ido", "CleanUpDowntimeHistoryAge: " + Convert::ToString(GetCleanUpDowntimeHistoryAge()) +
+ if (GetCleanupDowntimeHistoryAge() > 0) {
+ CleanUpExecuteQuery("downtimehistory", "entry_time", now - GetCleanupDowntimeHistoryAge());
+ Log(LogDebug, "db_ido", "CleanUpDowntimeHistoryAge: " + Convert::ToString(GetCleanupDowntimeHistoryAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpDowntimeHistoryAge()));
+ " old: " + Convert::ToString(now - GetCleanupDowntimeHistoryAge()));
}
- if (GetCleanUpEventHandlersAge() > 0) {
- CleanUpExecuteQuery("eventhandlers", "start_time", now - GetCleanUpEventHandlersAge());
- Log(LogDebug, "db_ido", "GetCleanUpEventHandlersAge: " + Convert::ToString(GetCleanUpEventHandlersAge()) +
+ if (GetCleanupEventHandlersAge() > 0) {
+ CleanUpExecuteQuery("eventhandlers", "start_time", now - GetCleanupEventHandlersAge());
+ Log(LogDebug, "db_ido", "GetCleanupEventHandlersAge: " + Convert::ToString(GetCleanupEventHandlersAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpEventHandlersAge()));
+ " old: " + Convert::ToString(now - GetCleanupEventHandlersAge()));
}
- if (GetCleanUpExternalCommandsAge() > 0) {
- CleanUpExecuteQuery("externalcommands", "entry_time", now - GetCleanUpExternalCommandsAge());
- Log(LogDebug, "db_ido", "GetCleanUpExternalCommandsAge: " + Convert::ToString(GetCleanUpExternalCommandsAge()) +
+ if (GetCleanupExternalCommandsAge() > 0) {
+ CleanUpExecuteQuery("externalcommands", "entry_time", now - GetCleanupExternalCommandsAge());
+ Log(LogDebug, "db_ido", "GetCleanupExternalCommandsAge: " + Convert::ToString(GetCleanupExternalCommandsAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpExternalCommandsAge()));
+ " old: " + Convert::ToString(now - GetCleanupExternalCommandsAge()));
}
- if (GetCleanUpFlappingHistoryAge() > 0) {
- CleanUpExecuteQuery("flappinghistory", "event_time", now - GetCleanUpFlappingHistoryAge());
- Log(LogDebug, "db_ido", "GetCleanUpFlappingHistoryAge: " + Convert::ToString(GetCleanUpFlappingHistoryAge()) +
+ if (GetCleanupFlappingHistoryAge() > 0) {
+ CleanUpExecuteQuery("flappinghistory", "event_time", now - GetCleanupFlappingHistoryAge());
+ Log(LogDebug, "db_ido", "GetCleanupFlappingHistoryAge: " + Convert::ToString(GetCleanupFlappingHistoryAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpFlappingHistoryAge()));
+ " old: " + Convert::ToString(now - GetCleanupFlappingHistoryAge()));
}
- if (GetCleanUpHostChecksAge() > 0) {
- CleanUpExecuteQuery("hostchecks", "start_time", now - GetCleanUpHostChecksAge());
- Log(LogDebug, "db_ido", "GetCleanUpHostChecksAge: " + Convert::ToString(GetCleanUpHostChecksAge()) +
+ if (GetCleanupHostChecksAge() > 0) {
+ CleanUpExecuteQuery("hostchecks", "start_time", now - GetCleanupHostChecksAge());
+ Log(LogDebug, "db_ido", "GetCleanupHostChecksAge: " + Convert::ToString(GetCleanupHostChecksAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpHostChecksAge()));
+ " old: " + Convert::ToString(now - GetCleanupHostChecksAge()));
}
- if (GetCleanUpLogEntriesAge() > 0) {
- CleanUpExecuteQuery("logentries", "logentry_time", now - GetCleanUpLogEntriesAge());
- Log(LogDebug, "db_ido", "GetCleanUpLogEntriesAge: " + Convert::ToString(GetCleanUpLogEntriesAge()) +
+ if (GetCleanupLogEntriesAge() > 0) {
+ CleanUpExecuteQuery("logentries", "logentry_time", now - GetCleanupLogEntriesAge());
+ Log(LogDebug, "db_ido", "GetCleanupLogEntriesAge: " + Convert::ToString(GetCleanupLogEntriesAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpLogEntriesAge()));
+ " old: " + Convert::ToString(now - GetCleanupLogEntriesAge()));
}
- if (GetCleanUpNotificationsAge() > 0) {
- CleanUpExecuteQuery("notifications", "start_time", now - GetCleanUpNotificationsAge());
- Log(LogDebug, "db_ido", "GetCleanUpNotificationsAge: " + Convert::ToString(GetCleanUpNotificationsAge()) +
+ if (GetCleanupNotificationsAge() > 0) {
+ CleanUpExecuteQuery("notifications", "start_time", now - GetCleanupNotificationsAge());
+ Log(LogDebug, "db_ido", "GetCleanupNotificationsAge: " + Convert::ToString(GetCleanupNotificationsAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpNotificationsAge()));
+ " old: " + Convert::ToString(now - GetCleanupNotificationsAge()));
}
- if (GetCleanUpProcessEventsAge() > 0) {
- CleanUpExecuteQuery("processevents", "event_time", now - GetCleanUpProcessEventsAge());
- Log(LogDebug, "db_ido", "GetCleanUpProcessEventsAge: " + Convert::ToString(GetCleanUpProcessEventsAge()) +
+ if (GetCleanupProcessEventsAge() > 0) {
+ CleanUpExecuteQuery("processevents", "event_time", now - GetCleanupProcessEventsAge());
+ Log(LogDebug, "db_ido", "GetCleanupProcessEventsAge: " + Convert::ToString(GetCleanupProcessEventsAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpProcessEventsAge()));
+ " old: " + Convert::ToString(now - GetCleanupProcessEventsAge()));
}
- if (GetCleanUpStateHistoryAge() > 0) {
- CleanUpExecuteQuery("statehistory", "state_time", now - GetCleanUpStateHistoryAge());
- Log(LogDebug, "db_ido", "GetCleanUpStateHistoryAge: " + Convert::ToString(GetCleanUpStateHistoryAge()) +
+ if (GetCleanupStateHistoryAge() > 0) {
+ CleanUpExecuteQuery("statehistory", "state_time", now - GetCleanupStateHistoryAge());
+ Log(LogDebug, "db_ido", "GetCleanupStateHistoryAge: " + Convert::ToString(GetCleanupStateHistoryAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpStateHistoryAge()));
+ " old: " + Convert::ToString(now - GetCleanupStateHistoryAge()));
}
- if (GetCleanUpServiceChecksAge() > 0) {
- CleanUpExecuteQuery("servicechecks", "start_time", now - GetCleanUpServiceChecksAge());
- Log(LogDebug, "db_ido", "GetCleanUpServiceChecksAge: " + Convert::ToString(GetCleanUpServiceChecksAge()) +
+ if (GetCleanupServiceChecksAge() > 0) {
+ CleanUpExecuteQuery("servicechecks", "start_time", now - GetCleanupServiceChecksAge());
+ Log(LogDebug, "db_ido", "GetCleanupServiceChecksAge: " + Convert::ToString(GetCleanupServiceChecksAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpServiceChecksAge()));
+ " old: " + Convert::ToString(now - GetCleanupServiceChecksAge()));
}
- if (GetCleanUpSystemCommandsAge() > 0) {
- CleanUpExecuteQuery("systemcommands", "start_time", now - GetCleanUpSystemCommandsAge());
- Log(LogDebug, "db_ido", "GetCleanUpSystemCommandsAge: " + Convert::ToString(GetCleanUpSystemCommandsAge()) +
+ if (GetCleanupSystemCommandsAge() > 0) {
+ CleanUpExecuteQuery("systemcommands", "start_time", now - GetCleanupSystemCommandsAge());
+ Log(LogDebug, "db_ido", "GetCleanupSystemCommandsAge: " + Convert::ToString(GetCleanupSystemCommandsAge()) +
" now: " + Convert::ToString(now) +
- " old: " + Convert::ToString(now - GetCleanUpSystemCommandsAge()));
+ " old: " + Convert::ToString(now - GetCleanupSystemCommandsAge()));
}
}
/* Default handler does nothing. */
}
-Dictionary::Ptr DbConnection::GetCleanUp(void) const
+double DbConnection::GetCleanupAcknowledgementsAge(void) const
{
- if (!m_CleanUp)
- return Empty;
- else
- return m_CleanUp;
+ return GetCleanup()->Get("acknowledgement_age");
}
-Value DbConnection::GetCleanUpAcknowledgementsAge(void) const
+double DbConnection::GetCleanupCommentHistoryAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- if (!cleanup || cleanup->Get("acknowledgement_age").IsEmpty())
- return CleanUpAgeNone;
- else
- return cleanup->Get("acknowledgement_age");
+ return GetCleanup()->Get("commenthistory_age");
}
-Value DbConnection::GetCleanUpCommentHistoryAge(void) const
+double DbConnection::GetCleanupContactNotificationsAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- if (!cleanup || cleanup->Get("commenthistory_age").IsEmpty())
- return CleanUpAgeNone;
- else
- return cleanup->Get("commenthistory_age");
+ return GetCleanup()->Get("contactnotifications_age");
}
-Value DbConnection::GetCleanUpContactNotificationsAge(void) const
+double DbConnection::GetCleanupContactNotificationMethodsAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- if (!cleanup || cleanup->Get("contactnotifications_age").IsEmpty())
- return CleanUpAgeNone;
- else
- return cleanup->Get("contactnotifications_age");
+ return GetCleanup()->Get("contactnotificationmethods_age");
}
-Value DbConnection::GetCleanUpContactNotificationMethodsAge(void) const
+double DbConnection::GetCleanupDowntimeHistoryAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- if (!cleanup || cleanup->Get("contactnotificationmethods_age").IsEmpty())
- return CleanUpAgeNone;
- else
- return cleanup->Get("contactnotificationmethods_age");
+ return GetCleanup()->Get("downtimehistory_age");
}
-Value DbConnection::GetCleanUpDowntimeHistoryAge(void) const
+double DbConnection::GetCleanupEventHandlersAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- if (!cleanup || cleanup->Get("downtimehistory_age").IsEmpty())
- return CleanUpAgeNone;
- else
- return cleanup->Get("downtimehistory_age");
+ return GetCleanup()->Get("eventhandlers_age");
}
-Value DbConnection::GetCleanUpEventHandlersAge(void) const
+double DbConnection::GetCleanupExternalCommandsAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- if (!cleanup || cleanup->Get("eventhandlers_age").IsEmpty())
- return CleanUpAgeNone;
- else
- return cleanup->Get("eventhandlers_age");
+ return GetCleanup()->Get("externalcommands_age");
}
-Value DbConnection::GetCleanUpExternalCommandsAge(void) const
+double DbConnection::GetCleanupFlappingHistoryAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- if (!cleanup || cleanup->Get("externalcommands_age").IsEmpty())
- return CleanUpAgeNone;
- else
- return cleanup->Get("externalcommands_age");
+ return GetCleanup()->Get("flappinghistory_age");
}
-Value DbConnection::GetCleanUpFlappingHistoryAge(void) const
+double DbConnection::GetCleanupHostChecksAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- if (!cleanup || cleanup->Get("flappinghistory_age").IsEmpty())
- return CleanUpAgeNone;
- else
- return cleanup->Get("flappinghistory_age");
+ return GetCleanup()->Get("hostchecks_age");
}
-Value DbConnection::GetCleanUpHostChecksAge(void) const
+double DbConnection::GetCleanupLogEntriesAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- if (!cleanup || cleanup->Get("hostchecks_age").IsEmpty())
- return CleanUpAgeNone;
- else
- return cleanup->Get("hostchecks_age");
+ return GetCleanup()->Get("logentries_age");
}
-Value DbConnection::GetCleanUpLogEntriesAge(void) const
+double DbConnection::GetCleanupNotificationsAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- if (!cleanup || cleanup->Get("logentries_age").IsEmpty())
- return CleanUpAgeNone;
- else
- return cleanup->Get("logentries_age");
+ return GetCleanup()->Get("notifications_age");
}
-Value DbConnection::GetCleanUpNotificationsAge(void) const
+double DbConnection::GetCleanupProcessEventsAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- if (!cleanup || cleanup->Get("notifications_age").IsEmpty())
- return CleanUpAgeNone;
- else
- return cleanup->Get("notifications_age");
+ return GetCleanup()->Get("processevents_age");
}
-Value DbConnection::GetCleanUpProcessEventsAge(void) const
+double DbConnection::GetCleanupStateHistoryAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- if (!cleanup || cleanup->Get("processevents_age").IsEmpty())
- return CleanUpAgeNone;
- else
- return cleanup->Get("processevents_age");
+ return GetCleanup()->Get("statehistory_age");
}
-Value DbConnection::GetCleanUpStateHistoryAge(void) const
+double DbConnection::GetCleanupServiceChecksAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- if (!cleanup || cleanup->Get("statehistory_age").IsEmpty())
- return CleanUpAgeNone;
- else
- return cleanup->Get("statehistory_age");
+ return GetCleanup()->Get("servicechecks_age");
}
-Value DbConnection::GetCleanUpServiceChecksAge(void) const
+double DbConnection::GetCleanupSystemCommandsAge(void) const
{
- Dictionary::Ptr cleanup = GetCleanUp();
-
- 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");
+ return GetCleanup()->Get("systemcommands_age");
}
void DbConnection::SetObjectID(const DbObject::Ptr& dbobj, const DbReference& dbref)
}
}
}
-
-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");
- }
-}
\ No newline at end of file
#ifndef DBCONNECTION_H
#define DBCONNECTION_H
-#include "base/dynamicobject.h"
-#include "base/timer.h"
+#include "db_ido/dbconnection.th"
#include "db_ido/dbobject.h"
#include "db_ido/dbquery.h"
+#include "base/timer.h"
namespace icinga
{
-enum CleanUpAge
-{
- CleanUpAgeNone = 0,
- CleanUpAgeOneMonth = 44640,
- CleanUpAgeOneMeek = 10080,
- CleanUpAgeOneDay = 1440,
-};
-
/**
* A database connection.
*
* @ingroup db_ido
*/
-class DbConnection : public DynamicObject
+class DbConnection : public ReflectionObjectImpl<DbConnection>
{
public:
DECLARE_PTR_TYPEDEFS(DbConnection);
void SetStatusUpdate(const DbObject::Ptr& dbobj, bool hasupdate);
bool GetStatusUpdate(const DbObject::Ptr& dbobj) const;
- String GetTablePrefix(void) const;
- Dictionary::Ptr GetCleanUp(void) const;
- Value GetCleanUpAcknowledgementsAge(void) const;
- Value GetCleanUpCommentHistoryAge(void) const;
- Value GetCleanUpContactNotificationsAge(void) const;
- Value GetCleanUpContactNotificationMethodsAge(void) const;
- Value GetCleanUpDowntimeHistoryAge(void) const;
- Value GetCleanUpEventHandlersAge(void) const;
- Value GetCleanUpExternalCommandsAge(void) const;
- Value GetCleanUpFlappingHistoryAge(void) const;
- Value GetCleanUpHostChecksAge(void) const;
- Value GetCleanUpLogEntriesAge(void) const;
- Value GetCleanUpNotificationsAge(void) const;
- Value GetCleanUpProcessEventsAge(void) const;
- Value GetCleanUpStateHistoryAge(void) const;
- Value GetCleanUpServiceChecksAge(void) const;
- Value GetCleanUpSystemCommandsAge(void) const;
+ double GetCleanupAcknowledgementsAge(void) const;
+ double GetCleanupCommentHistoryAge(void) const;
+ double GetCleanupContactNotificationsAge(void) const;
+ double GetCleanupContactNotificationMethodsAge(void) const;
+ double GetCleanupDowntimeHistoryAge(void) const;
+ double GetCleanupEventHandlersAge(void) const;
+ double GetCleanupExternalCommandsAge(void) const;
+ double GetCleanupFlappingHistoryAge(void) const;
+ double GetCleanupHostChecksAge(void) const;
+ double GetCleanupLogEntriesAge(void) const;
+ double GetCleanupNotificationsAge(void) const;
+ double GetCleanupProcessEventsAge(void) const;
+ double GetCleanupStateHistoryAge(void) const;
+ double GetCleanupServiceChecksAge(void) const;
+ double GetCleanupSystemCommandsAge(void) const;
protected:
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 ActivateObject(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);
private:
- String m_TablePrefix;
- Dictionary::Ptr m_CleanUp;
-
std::map<DbObject::Ptr, DbReference> m_ObjectIDs;
std::map<DbObject::Ptr, DbReference> m_InsertIDs;
std::set<DbObject::Ptr> m_ConfigUpdates;
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;
--- /dev/null
+#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>(); }}}
+ };
+};
+
+}
\ No newline at end of file
/* dump all comments */
Dictionary::Ptr comments = service->GetComments();
- if (!comments)
- return;
-
ObjectLock olock(comments);
String comment_id;
/* dump all downtimes */
Dictionary::Ptr downtimes = service->GetDowntimes();
- if (!downtimes)
- return;
-
ObjectLock olock(downtimes);
String downtime_id;
fields1->Set("state_change", 1); /* service */
fields1->Set("state", service->GetState());
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("last_state", service->GetLastState());
fields1->Set("last_hard_state", service->GetLastHardState());
pkglib_LTLIBRARIES = \
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 = \
icinga-type.cpp
.conf.cpp: $(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 = \
api.cpp \
api.h \
checkcommand.cpp \
checkcommand.h \
+ checkcommand.ti \
cib.cpp \
cib.h \
command.cpp \
command.h \
+ command.ti \
compatutility.cpp \
compatutility.h \
domain.cpp \
domain.h \
+ domain.ti \
eventcommand.cpp \
eventcommand.h \
+ eventcommand.ti \
externalcommandprocessor.cpp \
externalcommandprocessor.h \
host.cpp \
+ host.h \
+ host.ti \
hostgroup.cpp \
hostgroup.h \
- host.h \
+ hostgroup.ti \
i2-icinga.h \
icinga-type.conf \
icingaapplication.cpp \
icingaapplication.h \
+ icingaapplication.ti \
legacytimeperiod.cpp \
legacytimeperiod.h \
macroprocessor.cpp \
macroresolver.h \
notification.cpp \
notification.h \
+ notification.ti \
notificationcommand.cpp \
notificationcommand.h \
+ notificationcommand.ti \
nullchecktask.cpp \
nullchecktask.h \
nulleventtask.cpp \
randomchecktask.cpp \
randomchecktask.h \
service.cpp \
+ service.h \
+ service.ti \
service-check.cpp \
service-comment.cpp \
service-downtime.cpp \
service-event.cpp \
service-flapping.cpp \
service-notification.cpp \
- service.h \
servicegroup.cpp \
servicegroup.h \
+ servicegroup.ti \
timeperiod.cpp \
timeperiod.h \
+ timeperiod.ti \
user.cpp \
user.h \
+ user.ti \
usergroup.cpp \
- usergroup.h
+ usergroup.h \
+ usergroup.ti
libicinga_la_CPPFLAGS = \
-DI2_ICINGA_BUILD \
#ifndef CHECKCOMMAND_H
#define CHECKCOMMAND_H
-#include "icinga/command.h"
+#include "icinga/checkcommand.th"
#include "icinga/service.h"
namespace icinga
*
* @ingroup icinga
*/
-class I2_ICINGA_API CheckCommand : public Command
+class I2_ICINGA_API CheckCommand : public ReflectionObjectImpl<CheckCommand>
{
public:
DECLARE_PTR_TYPEDEFS(CheckCommand);
--- /dev/null
+#include "icinga/command.h"
+
+namespace icinga
+{
+
+class CheckCommand : Command
+{
+};
+
+}
\ No newline at end of file
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
{
Dictionary::Ptr macros = GetMacros();
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");
- }
-}
#ifndef COMMAND_H
#define COMMAND_H
+#include "icinga/command.th"
#include "icinga/macroresolver.h"
#include "base/i2-base.h"
#include "base/array.h"
-#include "base/dynamicobject.h"
#include "base/logger_fwd.h"
#include <set>
*
* @ingroup icinga
*/
-class I2_ICINGA_API Command : public DynamicObject, public MacroResolver
+class I2_ICINGA_API Command : public ReflectionObjectImpl<Command>, public MacroResolver
{
public:
DECLARE_PTR_TYPEDEFS(Command);
//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;
-
-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;
};
}
--- /dev/null
+#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;
+};
+
+}
\ No newline at end of file
attr->Set("check_type", (service->GetEnableActiveChecks() ? 0 : 1));
attr->Set("last_check", schedule_end);
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("last_state_change", service->GetLastStateChange());
attr->Set("last_hard_state_change", service->GetLastHardStateChange());
attr->Set("high_flap_threshold", service->GetFlappingThreshold());
attr->Set("notifications_enabled", (service->GetEnableNotifications() ? 1 : 0));
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("notification_options", boost::algorithm::join(notification_options, ","));
attr->Set("notification_interval", notification_interval / 60.0);
REGISTER_TYPE(Domain);
-Dictionary::Ptr Domain::GetAcl(void) const
-{
- return m_Acl;
-}
-
int Domain::GetPrivileges(const String& instance) const
{
- return m_Acl->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");
- }
+ return GetAcl()->Get(instance);
}
#define DOMAIN_H
#include "icinga/i2-icinga.h"
-#include "base/dynamicobject.h"
+#include "icinga/domain.th"
#include "base/dictionary.h"
namespace icinga
*
* @ingroup icinga
*/
-class I2_ICINGA_API Domain : public DynamicObject
+class I2_ICINGA_API Domain : public ReflectionObjectImpl<Domain>
{
public:
DECLARE_PTR_TYPEDEFS(Domain);
DECLARE_TYPENAME(Domain);
- Dictionary::Ptr GetAcl(void) 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;
};
}
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class Domain : DynamicObject
+{
+ [config] Dictionary::Ptr acl;
+};
+
+}
\ No newline at end of file
#ifndef EVENTCOMMAND_H
#define EVENTCOMMAND_H
-#include "icinga/command.h"
+#include "icinga/eventcommand.th"
#include "icinga/service.h"
namespace icinga
*
* @ingroup icinga
*/
-class I2_ICINGA_API EventCommand : public Command
+class I2_ICINGA_API EventCommand : public ReflectionObjectImpl<EventCommand>
{
public:
DECLARE_PTR_TYPEDEFS(EventCommand);
--- /dev/null
+#include "icinga/command.h"
+
+namespace icinga
+{
+
+class EventCommand : Command
+{
+};
+
+}
\ No newline at end of file
// TODO: unregister slave services/notifications?
}
-String Host::GetDisplayName(void) const
-{
- if (!m_DisplayName.IsEmpty())
- return m_DisplayName;
- else
- return GetName();
-}
-
-Array::Ptr Host::GetGroups(void) const
-{
- return m_Groups;
-}
-
-Dictionary::Ptr Host::GetMacros(void) const
-{
- return m_Macros;
-}
-
-Array::Ptr Host::GetHostDependencies(void) const
-{
- return m_HostDependencies;;
-}
-
-Array::Ptr Host::GetServiceDependencies(void) const
-{
- return m_ServiceDependencies;
-}
-
-String Host::GetCheck(void) const
-{
- return m_Check;
-}
-
-Dictionary::Ptr Host::GetNotificationDescriptions(void) const
-{
- return m_NotificationDescriptions;
-}
-
bool Host::IsReachable(void) const
{
ASSERT(!OwnsLock());
if (!item)
return;
- if (!m_ServiceDescriptions)
+ Dictionary::Ptr service_descriptions = GetServiceDescriptions();
+
+ if (!service_descriptions)
return;
- ObjectLock olock(m_ServiceDescriptions);
+ ObjectLock olock(service_descriptions);
String svcname;
Value svcdesc;
- BOOST_FOREACH(boost::tie(svcname, svcdesc), m_ServiceDescriptions) {
+ BOOST_FOREACH(boost::tie(svcname, svcdesc), service_descriptions) {
if (svcdesc.IsScalar())
svcname = svcdesc;
std::set<Host::Ptr> Host::GetChildHosts(void) const
{
- std::set<Host::Ptr> childs;
+ std::set<Host::Ptr> children;
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
Array::Ptr dependencies = host->GetHostDependencies();
BOOST_FOREACH(const Value& value, dependencies) {
if (value == GetName())
- childs.insert(host);
+ children.insert(host);
}
}
}
- return childs;
-
+ return children;
}
Service::Ptr Host::GetCheckService(void) const
Service::Ptr hc = GetCheckService();
if (!hc)
- return IcingaApplication::GetInstance()->GetStartTime();
+ return Application::GetStartTime();
return hc->GetLastStateChange();
}
Service::Ptr hc = GetCheckService();
if (!hc)
- return IcingaApplication::GetInstance()->GetStartTime();
+ return Application::GetStartTime();
return hc->GetLastHardStateChange();
}
*result = Service::StateTypeToString(hc->GetStateType());
return true;
} else if (macro == "HOSTATTEMPT") {
- *result = Convert::ToString(hc->GetCurrentCheckAttempt());
+ *result = Convert::ToString(hc->GetCheckAttempt());
return true;
} else if (macro == "MAXHOSTATTEMPT") {
*result = Convert::ToString(hc->GetMaxCheckAttempts());
return false;
}
-
-void Host::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
-{
- DynamicObject::InternalSerialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config) {
- bag->Set("display_name", m_DisplayName);
- bag->Set("groups", m_Groups);
- bag->Set("macros", m_Macros);
- bag->Set("host_dependencies", m_HostDependencies);
- bag->Set("service_dependencies", m_ServiceDependencies);
- bag->Set("check", m_Check);
- bag->Set("services", m_ServiceDescriptions);
- bag->Set("notifications", m_NotificationDescriptions);
- }
-}
-
-void Host::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
-{
- DynamicObject::InternalDeserialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config) {
- m_DisplayName = bag->Get("display_name");
- m_Groups = bag->Get("groups");
- m_Macros = bag->Get("macros");
- m_HostDependencies = bag->Get("host_dependencies");
- m_ServiceDependencies = bag->Get("service_dependencies");
- m_Check = bag->Get("check");
- m_ServiceDescriptions = bag->Get("services");
- m_NotificationDescriptions = bag->Get("notifications");
- }
-}
#define HOST_H
#include "icinga/i2-icinga.h"
+#include "icinga/host.th"
#include "icinga/macroresolver.h"
#include "base/array.h"
-#include "base/dynamicobject.h"
#include "base/dictionary.h"
namespace icinga
HostUnreachable = 2
};
-/**
- * The state of a service.
- *
- * @ingroup icinga
- */
-enum ServiceState
-{
- StateOK = 0,
- StateWarning = 1,
- StateCritical = 2,
- StateUnknown = 3
-};
-
-/**
- * The state type of a host or service.
- *
- * @ingroup icinga
- */
-enum StateType
-{
- StateTypeSoft = 0,
- StateTypeHard = 1
-};
-
/**
* An Icinga host.
*
* @ingroup icinga
*/
-class I2_ICINGA_API Host : public DynamicObject, public MacroResolver
+class I2_ICINGA_API Host : public ReflectionObjectImpl<Host>, public MacroResolver
{
public:
DECLARE_PTR_TYPEDEFS(Host);
DECLARE_TYPENAME(Host);
- String GetDisplayName(void) const;
- Array::Ptr GetGroups(void) const;
-
- Dictionary::Ptr GetMacros(void) const;
- Array::Ptr GetHostDependencies(void) const;
- Array::Ptr GetServiceDependencies(void) const;
- String GetCheck(void) const;
- //Dictionary::Ptr GetServiceDescriptions(void) const;
- Dictionary::Ptr GetNotificationDescriptions(void) const;
-
shared_ptr<Service> GetCheckService(void) const;
std::set<Host::Ptr> GetParentHosts(void) const;
std::set<Host::Ptr> GetChildHosts(void) const;
virtual void OnConfigLoaded(void);
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- String m_DisplayName;
- Array::Ptr m_Groups;
- Dictionary::Ptr m_Macros;
- Array::Ptr m_HostDependencies;
- Array::Ptr m_ServiceDependencies;
- String m_Check;
- Dictionary::Ptr m_ServiceDescriptions;
- Dictionary::Ptr m_NotificationDescriptions;
-
mutable boost::mutex m_ServicesMutex;
std::map<String, shared_ptr<Service> > m_Services;
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+code {{{
+/**
+ * The state of a service.
+ *
+ * @ingroup icinga
+ */
+enum ServiceState
+{
+ StateOK = 0,
+ StateWarning = 1,
+ StateCritical = 2,
+ StateUnknown = 3
+};
+
+/**
+ * The state type of a host or service.
+ *
+ * @ingroup icinga
+ */
+enum StateType
+{
+ StateTypeSoft = 0,
+ StateTypeHard = 1
+};
+}}}
+
+class Host : DynamicObject
+{
+ [config] String display_name {
+ default {{{ return GetName(); }}}
+ };
+ [config] Array::Ptr groups;
+ [config] Dictionary::Ptr macros;
+ [config] Array::Ptr host_dependencies;
+ [config] Array::Ptr service_dependencies;
+ [config] String check;
+ [config, protected] Dictionary::Ptr services (ServiceDescriptions);
+};
+
+}
\ No newline at end of file
REGISTER_TYPE(HostGroup);
-String HostGroup::GetDisplayName(void) const
-{
- if (!m_DisplayName.IsEmpty())
- return m_DisplayName;
- else
- return GetName();
-}
-
std::set<Host::Ptr> HostGroup::GetMembers(void) const
{
return m_Members;
{
m_Members.erase(host);
}
-
-void HostGroup::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
-{
- DynamicObject::InternalSerialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config)
- bag->Set("display_name", m_DisplayName);
-}
-
-void HostGroup::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
-{
- DynamicObject::InternalDeserialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config)
- m_DisplayName = bag->Get("display_name");
-}
#define HOSTGROUP_H
#include "icinga/i2-icinga.h"
+#include "icinga/hostgroup.th"
#include "icinga/host.h"
-#include "base/dynamicobject.h"
namespace icinga
{
*
* @ingroup icinga
*/
-class I2_ICINGA_API HostGroup : public DynamicObject
+class I2_ICINGA_API HostGroup : public ReflectionObjectImpl<HostGroup>
{
public:
DECLARE_PTR_TYPEDEFS(HostGroup);
DECLARE_TYPENAME(HostGroup);
- String GetDisplayName(void) const;
-
std::set<Host::Ptr> GetMembers(void) const;
void AddMember(const Host::Ptr& host);
void RemoveMember(const Host::Ptr& host);
-protected:
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- String m_DisplayName;
std::set<Host::Ptr> m_Members;
};
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class HostGroup : DynamicObject
+{
+ [config] String display_name {
+ default {{{ return GetName(); }}}
+ };
+};
+
+}
\ No newline at end of file
</CustomBuild>
</ItemGroup>
<ItemGroup>
+ <CustomBuild Include="checkcommand.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="checkcommand.th" />
+ <CustomBuild Include="command.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="command.th" />
+ <CustomBuild Include="eventcommand.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="domain.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="eventcommand.th" />
+ <CustomBuild Include="host.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="host.th" />
+ <CustomBuild Include="hostgroup.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="hostgroup.th" />
+ <CustomBuild Include="icingaapplication.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="icingaapplication.th" />
+ <CustomBuild Include="notificationcommand.ti">
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="notification.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="notification.th" />
+ <None Include="notificationcommand.th" />
<None Include="packages.config" />
+ <CustomBuild Include="timeperiod.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="servicegroup.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="service.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="service.th" />
+ <None Include="servicegroup.th" />
+ <None Include="timeperiod.th" />
+ <CustomBuild Include="usergroup.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="user.ti">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(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="user.th" />
+ <None Include="usergroup.th" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}</ProjectGuid>
<Import Project="..\..\packages\boost_date_time.1.54.0.2\build\native\boost_date_time.targets" Condition="Exists('..\..\packages\boost_date_time.1.54.0.2\build\native\boost_date_time.targets')" />
<Import Project="..\..\packages\boost_chrono.1.54.0.2\build\native\boost_chrono.targets" Condition="Exists('..\..\packages\boost_chrono.1.54.0.2\build\native\boost_chrono.targets')" />
</ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
<ClCompile Include="domain.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
+ <ClCompile Include="randomchecktask.cpp">
+ <Filter>Quelldateien</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="i2-icinga.h">
<ClInclude Include="domain.h">
<Filter>Headerdateien</Filter>
</ClInclude>
+ <ClInclude Include="randomchecktask.h">
+ <Filter>Headerdateien</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Headerdateien">
<CustomBuild Include="icinga-type.conf">
<Filter>Quelldateien</Filter>
</CustomBuild>
+ <CustomBuild Include="checkcommand.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
+ <CustomBuild Include="command.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
+ <CustomBuild Include="eventcommand.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
+ <CustomBuild Include="domain.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
+ <CustomBuild Include="host.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
+ <CustomBuild Include="hostgroup.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
+ <CustomBuild Include="icingaapplication.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
+ <CustomBuild Include="timeperiod.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
+ <CustomBuild Include="usergroup.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
+ <CustomBuild Include="servicegroup.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
+ <CustomBuild Include="notificationcommand.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
+ <CustomBuild Include="notification.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
+ <CustomBuild Include="user.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
+ <CustomBuild Include="service.ti">
+ <Filter>Headerdateien</Filter>
+ </CustomBuild>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
+ <None Include="checkcommand.th">
+ <Filter>Headerdateien</Filter>
+ </None>
+ <None Include="command.th">
+ <Filter>Headerdateien</Filter>
+ </None>
+ <None Include="eventcommand.th">
+ <Filter>Headerdateien</Filter>
+ </None>
+ <None Include="host.th">
+ <Filter>Headerdateien</Filter>
+ </None>
+ <None Include="hostgroup.th">
+ <Filter>Headerdateien</Filter>
+ </None>
+ <None Include="icingaapplication.th">
+ <Filter>Headerdateien</Filter>
+ </None>
+ <None Include="timeperiod.th">
+ <Filter>Headerdateien</Filter>
+ </None>
+ <None Include="usergroup.th">
+ <Filter>Headerdateien</Filter>
+ </None>
+ <None Include="servicegroup.th">
+ <Filter>Headerdateien</Filter>
+ </None>
+ <None Include="notificationcommand.th">
+ <Filter>Headerdateien</Filter>
+ </None>
+ <None Include="notification.th">
+ <Filter>Headerdateien</Filter>
+ </None>
+ <None Include="user.th">
+ <Filter>Headerdateien</Filter>
+ </None>
+ <None Include="service.th">
+ <Filter>Headerdateien</Filter>
+ </None>
</ItemGroup>
</Project>
\ No newline at end of file
{
Log(LogDebug, "icinga", "In IcingaApplication::Main()");
- m_StartTime = Utility::GetTime();
-
/* periodically dump the program state */
l_RetentionTimer = boost::make_shared<Timer>();
l_RetentionTimer->SetInterval(300);
return ScriptVariable::Get("IcingaMacros");
}
-double IcingaApplication::GetStartTime(void) const
-{
- ObjectLock olock(this);
-
- return m_StartTime;
-}
-
bool IcingaApplication::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
{
double now = Utility::GetTime();
bool IcingaApplication::GetEnableNotifications(void) const
{
- if (!m_OverrideEnableNotifications.IsEmpty())
- return m_OverrideEnableNotifications;
+ if (!GetOverrideEnableNotifications().IsEmpty())
+ return GetOverrideEnableNotifications();
else
return ScriptVariable::Get("IcingaEnableNotifications");
}
void IcingaApplication::SetEnableNotifications(bool enabled)
{
- m_OverrideEnableNotifications = enabled;
+ SetOverrideEnableNotifications(enabled);
}
void IcingaApplication::ClearEnableNotifications(void)
{
- m_OverrideEnableNotifications = Empty;
+ SetOverrideEnableNotifications(Empty);
}
bool IcingaApplication::GetEnableEventHandlers(void) const
{
- if (!m_OverrideEnableEventHandlers.IsEmpty())
- return m_OverrideEnableEventHandlers;
+ if (!GetOverrideEnableEventHandlers().IsEmpty())
+ return GetOverrideEnableEventHandlers();
else
return ScriptVariable::Get("IcingaEnableEventHandlers");
}
void IcingaApplication::SetEnableEventHandlers(bool enabled)
{
- m_OverrideEnableEventHandlers = enabled;
+ SetOverrideEnableEventHandlers(enabled);
}
void IcingaApplication::ClearEnableEventHandlers(void)
{
- m_OverrideEnableEventHandlers = Empty;
+ SetOverrideEnableEventHandlers(Empty);
}
bool IcingaApplication::GetEnableFlapping(void) const
{
- if (!m_OverrideEnableFlapping.IsEmpty())
- return m_OverrideEnableFlapping;
+ if (!GetOverrideEnableFlapping().IsEmpty())
+ return GetOverrideEnableFlapping();
else
return ScriptVariable::Get("IcingaEnableFlapping");
}
void IcingaApplication::SetEnableFlapping(bool enabled)
{
- m_OverrideEnableFlapping = enabled;
+ SetOverrideEnableFlapping(enabled);
}
void IcingaApplication::ClearEnableFlapping(void)
{
- m_OverrideEnableFlapping = Empty;
+ SetOverrideEnableFlapping(Empty);
}
bool IcingaApplication::GetEnableChecks(void) const
{
- if (!m_OverrideEnableChecks.IsEmpty())
- return m_OverrideEnableChecks;
+ if (!GetOverrideEnableChecks().IsEmpty())
+ return GetOverrideEnableChecks();
else
return ScriptVariable::Get("IcingaEnableChecks");
}
void IcingaApplication::SetEnableChecks(bool enabled)
{
- m_OverrideEnableChecks = enabled;
+ SetOverrideEnableChecks(enabled);
}
void IcingaApplication::ClearEnableChecks(void)
{
- m_OverrideEnableChecks = Empty;
+ SetOverrideEnableChecks(Empty);
}
bool IcingaApplication::GetEnablePerfdata(void) const
{
- if (!m_OverrideEnablePerfdata.IsEmpty())
- return m_OverrideEnablePerfdata;
+ if (!GetOverrideEnablePerfdata().IsEmpty())
+ return GetOverrideEnablePerfdata();
else
return ScriptVariable::Get("IcingaEnablePerfdata");
}
void IcingaApplication::SetEnablePerfdata(bool enabled)
{
- m_OverrideEnablePerfdata = enabled;
+ SetOverrideEnablePerfdata(enabled);
}
void IcingaApplication::ClearEnablePerfdata(void)
{
- m_OverrideEnablePerfdata = Empty;
-}
-
-void IcingaApplication::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
-{
- DynamicObject::InternalSerialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_State) {
- bag->Set("override_enable_notifications", m_OverrideEnableNotifications);
- bag->Set("override_enable_event_handlers", m_OverrideEnableEventHandlers);
- bag->Set("override_enable_flapping", m_OverrideEnableFlapping);
- bag->Set("override_enable_checks", m_OverrideEnableChecks);
- bag->Set("override_enable_perfdata", m_OverrideEnablePerfdata);
- }
-}
-
-void IcingaApplication::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
-{
- DynamicObject::InternalDeserialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_State) {
- m_OverrideEnableNotifications = bag->Get("override_enable_notifications");
- m_OverrideEnableEventHandlers = bag->Get("override_enable_event_handlers");
- m_OverrideEnableFlapping = bag->Get("override_enable_flapping");
- m_OverrideEnableChecks = bag->Get("override_enable_checks");
- m_OverrideEnablePerfdata = bag->Get("override_enable_perfdata");
- }
+ SetOverrideEnablePerfdata(Empty);
}
#define ICINGAAPPLICATION_H
#include "icinga/i2-icinga.h"
+#include "icinga/icingaapplication.th"
#include "icinga/macroresolver.h"
-#include "base/application.h"
namespace icinga
{
*
* @ingroup icinga
*/
-class I2_ICINGA_API IcingaApplication : public Application, public MacroResolver
+class I2_ICINGA_API IcingaApplication : public ReflectionObjectImpl<IcingaApplication>, public MacroResolver
{
public:
DECLARE_PTR_TYPEDEFS(IcingaApplication);
String GetPidPath(void) const;
Dictionary::Ptr GetMacros(void) const;
- double GetStartTime(void) const;
-
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
bool GetEnableNotifications(void) const;
void SetEnablePerfdata(bool enabled);
void ClearEnablePerfdata(void);
-protected:
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- double m_StartTime;
-
- Value m_OverrideEnableNotifications;
- Value m_OverrideEnableEventHandlers;
- Value m_OverrideEnableFlapping;
- Value m_OverrideEnableChecks;
- Value m_OverrideEnablePerfdata;
-
void DumpProgramState(void);
virtual void OnShutdown(void);
--- /dev/null
+#include "base/application.h"
+
+namespace icinga
+{
+
+class IcingaApplication : Application
+{
+ [state, protected] Value override_enable_notifications;
+ [state, protected] Value override_enable_event_handlers;
+ [state, protected] Value override_enable_flapping;
+ [state, protected] Value override_enable_checks;
+ [state, protected] Value override_enable_perfdata;
+};
+
+}
\ No newline at end of file
Service::Ptr Notification::GetService(void) const
{
- Host::Ptr host = Host::GetByName(m_HostName);
+ Host::Ptr host = Host::GetByName(GetHostRaw());
if (!host)
return Service::Ptr();
- if (m_Service.IsEmpty())
+ if (GetServiceRaw().IsEmpty())
return host->GetCheckService();
else
- return host->GetServiceByShortName(m_Service);
+ return host->GetServiceByShortName(GetServiceRaw());
}
NotificationCommand::Ptr Notification::GetNotificationCommand(void) const
{
- return NotificationCommand::GetByName(m_NotificationCommand);
-}
-
-Dictionary::Ptr Notification::GetMacros(void) const
-{
- return m_Macros;
-}
-
-Array::Ptr Notification::GetExportMacros(void) const
-{
- return m_ExportMacros;
+ return NotificationCommand::GetByName(GetNotificationCommandRaw());
}
std::set<User::Ptr> Notification::GetUsers(void) const
{
std::set<User::Ptr> result;
- Array::Ptr users = m_Users;
+ Array::Ptr users = GetUsersRaw();
if (users) {
ObjectLock olock(users);
{
std::set<UserGroup::Ptr> result;
- Array::Ptr groups = m_UserGroups;
+ Array::Ptr groups = GetUserGroupsRaw();
if (groups) {
ObjectLock olock(groups);
return result;
}
-Dictionary::Ptr Notification::GetTimes(void) const
-{
- return m_Times;
-}
-
-unsigned long Notification::GetNotificationTypeFilter(void) const
-{
- if (m_NotificationTypeFilter.IsEmpty())
- return ~(unsigned long)0; /* All types. */
- else
- return m_NotificationTypeFilter;
-}
-
-unsigned long Notification::GetNotificationStateFilter(void) const
-{
- if (m_NotificationStateFilter.IsEmpty())
- return ~(unsigned long)0; /* All states. */
- else
- return m_NotificationStateFilter;
-}
-
-double Notification::GetNotificationInterval(void) const
-{
- if (m_NotificationInterval.IsEmpty())
- return 300;
- else
- return m_NotificationInterval;
-}
-
TimePeriod::Ptr Notification::GetNotificationPeriod(void) const
{
- return TimePeriod::GetByName(m_NotificationPeriod);
-}
-
-double Notification::GetLastNotification(void) const
-{
- if (m_LastNotification.IsEmpty())
- return 0;
- else
- return m_LastNotification;
-}
-
-/**
- * Sets the timestamp when the last notification was sent.
- */
-void Notification::SetLastNotification(double time)
-{
- m_LastNotification = time;
+ return TimePeriod::GetByName(GetNotificationPeriodRaw());
}
double Notification::GetNextNotification(void) const
{
- if (m_NextNotification.IsEmpty())
- return 0;
- else
- return m_NextNotification;
+ return GetNextNotificationRaw();
}
/**
*/
void Notification::SetNextNotification(double time, const String& authority)
{
- m_NextNotification = time;
+ SetNextNotificationRaw(time);
Utility::QueueAsyncCallback(boost::bind(boost::ref(OnNextNotificationChanged), GetSelf(), time, authority));
}
-long Notification::GetNotificationNumber(void) const
-{
- if (m_NotificationNumber.IsEmpty())
- return 0;
- else
- return m_NotificationNumber;
-}
-
void Notification::UpdateNotificationNumber(void)
{
- m_NotificationNumber = m_NotificationNumber + 1;
+ SetNotificationNumber(GetNotificationNumber() + 1);
}
void Notification::ResetNotificationNumber(void)
{
- m_NotificationNumber = 0;
+ SetNotificationNumber(0);
}
String Notification::NotificationTypeToString(NotificationType type)
return false;
}
-
-void Notification::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
-{
- DynamicObject::InternalSerialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config) {
- bag->Set("notification_command", m_NotificationCommand);
- bag->Set("notification_interval", m_NotificationInterval);
- bag->Set("notification_period", m_NotificationPeriod);
- bag->Set("macros", m_Macros);
- bag->Set("users", m_Users);
- bag->Set("user_groups", m_UserGroups);
- bag->Set("times", m_Times);
- bag->Set("notification_type_filter", m_NotificationTypeFilter);
- bag->Set("notification_state_filter", m_NotificationStateFilter);
- bag->Set("host", m_HostName);
- bag->Set("export_macros", m_ExportMacros);
- bag->Set("service", m_Service);
- }
-
- if (attributeTypes & Attribute_State) {
- bag->Set("last_notification", m_LastNotification);
- bag->Set("next_notification", m_NextNotification);
- bag->Set("notification_number", m_NotificationNumber);
- }
-}
-
-void Notification::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
-{
- DynamicObject::InternalDeserialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config) {
- m_NotificationCommand = bag->Get("notification_command");
- m_NotificationInterval = bag->Get("notification_interval");
- m_NotificationPeriod = bag->Get("notification_period");
- m_Macros = bag->Get("macros");
- m_Users = bag->Get("users");
- m_UserGroups = bag->Get("user_groups");
- m_Times = bag->Get("times");
- m_NotificationTypeFilter = bag->Get("notification_type_filter");
- m_NotificationStateFilter = bag->Get("notification_state_filter");
- m_HostName = bag->Get("host");
- m_ExportMacros = bag->Get("export_macros");
- m_Service = bag->Get("service");
- }
-
- if (attributeTypes & Attribute_State) {
- m_LastNotification = bag->Get("last_notification");
- m_NextNotification = bag->Get("next_notification");
- m_NotificationNumber = bag->Get("notification_number");
- }
-}
#define NOTIFICATION_H
#include "icinga/i2-icinga.h"
+#include "icinga/notification.th"
#include "icinga/user.h"
#include "icinga/usergroup.h"
#include "icinga/timeperiod.h"
*
* @ingroup icinga
*/
-class I2_ICINGA_API Notification : public DynamicObject, public MacroResolver
+class I2_ICINGA_API Notification : public ReflectionObjectImpl<Notification>, public MacroResolver
{
public:
DECLARE_PTR_TYPEDEFS(Notification);
shared_ptr<Service> GetService(void) const;
shared_ptr<NotificationCommand> GetNotificationCommand(void) const;
- double GetNotificationInterval(void) const;
TimePeriod::Ptr GetNotificationPeriod(void) const;
- Dictionary::Ptr GetMacros(void) const;
- Array::Ptr GetExportMacros(void) const;
std::set<User::Ptr> GetUsers(void) const;
std::set<UserGroup::Ptr> GetUserGroups(void) const;
- Dictionary::Ptr GetTimes(void) const;
- unsigned long GetNotificationTypeFilter(void) const;
- unsigned long GetNotificationStateFilter(void) const;
-
- double GetLastNotification(void) const;
- void SetLastNotification(double time);
double GetNextNotification(void) const;
void SetNextNotification(double time, const String& authority = String());
- long GetNotificationNumber(void) const;
void UpdateNotificationNumber(void);
void ResetNotificationNumber(void);
virtual void Start(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:
- String m_NotificationCommand;
- Value m_NotificationInterval;
- String m_NotificationPeriod;
- Value m_LastNotification;
- Value m_NextNotification;
- Value m_NotificationNumber;
- Dictionary::Ptr m_Macros;
- Array::Ptr m_ExportMacros;
- Array::Ptr m_Users;
- Array::Ptr m_UserGroups;
- Dictionary::Ptr m_Times;
- Value m_NotificationTypeFilter;
- Value m_NotificationStateFilter;
- String m_HostName;
- String m_Service;
-
void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force, const String& author = "", const String& text = "");
};
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class Notification : DynamicObject
+{
+ [config, protected] String notification_command (NotificationCommandRaw);
+ [config] double notification_interval {
+ default {{{ return 300; }}}
+ };
+ [config] String notification_period (NotificationPeriodRaw);
+ [config] Dictionary::Ptr macros;
+ [config, protected] Array::Ptr users (UsersRaw);
+ [config, protected] Array::Ptr user_groups (UserGroupsRaw);
+ [config] Dictionary::Ptr times;
+ [config] int notification_type_filter {
+ default {{{ return ~(int)0; }}}
+ };
+ [config] int notification_state_filter {
+ default {{{ return ~(int)0; }}}
+ };
+ [config, protected] String host (HostRaw);
+ [config, protected] String service (ServiceRaw);
+
+ [state] double last_notification;
+ [state, set_protected] double next_notification (NextNotificationRaw);
+ [state, set_protected] Value notification_number;
+};
+
+}
\ No newline at end of file
#ifndef NOTIFICATIONCOMMAND_H
#define NOTIFICATIONCOMMAND_H
-#include "icinga/command.h"
+#include "icinga/notificationcommand.th"
#include "icinga/notification.h"
namespace icinga
*
* @ingroup icinga
*/
-class I2_ICINGA_API NotificationCommand : public Command
+class I2_ICINGA_API NotificationCommand : public ReflectionObjectImpl<NotificationCommand>
{
public:
DECLARE_PTR_TYPEDEFS(NotificationCommand);
--- /dev/null
+#include "icinga/command.h"
+
+namespace icinga
+{
+
+class NotificationCommand : Command
+{
+};
+
+}
\ No newline at end of file
Dictionary::Ptr envMacros = boost::make_shared<Dictionary>();
- Array::Ptr export_macros = notification->GetExportMacros();
+ Array::Ptr export_macros = commandObj->GetExportMacros();
if (export_macros) {
BOOST_FOREACH(const String& macro, export_macros) {
using namespace icinga;
-const int Service::DefaultMaxCheckAttempts = 3;
-const double Service::DefaultCheckInterval = 5 * 60;
-const double Service::CheckIntervalDivisor = 5.0;
-
boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> Service::OnNewCheckResult;
boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, StateType, const String&)> Service::OnStateChange;
boost::signals2::signal<void (const Service::Ptr&, NotificationType, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationsRequested;
CheckCommand::Ptr Service::GetCheckCommand(void) const
{
- return CheckCommand::GetByName(m_CheckCommand);
-}
-
-long Service::GetMaxCheckAttempts(void) const
-{
- if (m_MaxCheckAttempts.IsEmpty())
- return DefaultMaxCheckAttempts;
-
- return m_MaxCheckAttempts;
+ return CheckCommand::GetByName(GetCheckCommandRaw());
}
TimePeriod::Ptr Service::GetCheckPeriod(void) const
{
- return TimePeriod::GetByName(m_CheckPeriod);
+ return TimePeriod::GetByName(GetCheckPeriodRaw());
}
double Service::GetCheckInterval(void) const
{
- if (!m_OverrideCheckInterval.IsEmpty())
- return m_OverrideCheckInterval;
- else if (!m_CheckInterval.IsEmpty())
- return m_CheckInterval;
+ if (!GetOverrideCheckInterval().IsEmpty())
+ return GetOverrideCheckInterval();
else
- return DefaultCheckInterval;
+ return GetCheckIntervalRaw();
}
void Service::SetCheckInterval(double interval)
{
- m_OverrideCheckInterval = interval;
+ SetOverrideCheckInterval(interval);
}
-
double Service::GetRetryInterval(void) const
{
- if (!m_OverrideRetryInterval.IsEmpty())
- return m_OverrideRetryInterval;
- if (!m_RetryInterval.IsEmpty())
- return m_RetryInterval;
+ if (!GetOverrideRetryInterval().IsEmpty())
+ return GetOverrideRetryInterval();
else
- return GetCheckInterval() / CheckIntervalDivisor;
+ return GetRetryIntervalRaw();
}
void Service::SetRetryInterval(double interval)
{
- m_OverrideRetryInterval = interval;
+ SetOverrideRetryInterval(interval);
}
void Service::SetSchedulingOffset(long offset)
void Service::SetNextCheck(double nextCheck, const String& authority)
{
- m_NextCheck = nextCheck;
+ SetNextCheckRaw(nextCheck);
Utility::QueueAsyncCallback(boost::bind(boost::ref(Service::OnNextCheckChanged), GetSelf(), nextCheck, authority));
}
double Service::GetNextCheck(void)
{
- return m_NextCheck;
+ return GetNextCheckRaw();
}
void Service::UpdateNextCheck(void)
SetNextCheck(now - adj + interval);
}
-void Service::SetCurrentChecker(const String& checker)
-{
- m_CurrentChecker = checker;
-}
-
-String Service::GetCurrentChecker(void) const
-{
- return m_CurrentChecker;
-}
-
-void Service::SetCurrentCheckAttempt(long attempt)
-{
- m_CheckAttempt = attempt;
-}
-
-long Service::GetCurrentCheckAttempt(void) const
-{
- if (m_CheckAttempt.IsEmpty())
- return 1;
-
- return m_CheckAttempt;
-}
-
-void Service::SetState(ServiceState state)
-{
- m_State = static_cast<long>(state);
-}
-
-ServiceState Service::GetState(void) const
-{
- if (m_State.IsEmpty())
- return StateUnknown;
-
- int ivalue = static_cast<int>(m_State);
- return static_cast<ServiceState>(ivalue);
-}
-
-void Service::SetLastState(ServiceState state)
-{
- m_LastState = static_cast<long>(state);
-}
-
-ServiceState Service::GetLastState(void) const
-{
- if (m_LastState.IsEmpty())
- return StateUnknown;
-
- int ivalue = static_cast<int>(m_LastState);
- return static_cast<ServiceState>(ivalue);
-}
-
-void Service::SetLastHardState(ServiceState state)
-{
- m_LastHardState = static_cast<long>(state);
-}
-
-ServiceState Service::GetLastHardState(void) const
-{
- if (m_LastHardState.IsEmpty())
- return StateUnknown;
-
- int ivalue = static_cast<int>(m_LastHardState);
- return static_cast<ServiceState>(ivalue);
-}
-
-void Service::SetStateType(StateType type)
-{
- m_StateType = static_cast<long>(type);
-}
-
-StateType Service::GetStateType(void) const
-{
- if (m_StateType.IsEmpty())
- return StateTypeSoft;
-
- int ivalue = static_cast<int>(m_StateType);
- return static_cast<StateType>(ivalue);
-}
-
-void Service::SetLastStateType(StateType type)
-{
- m_LastStateType = static_cast<long>(type);
-}
-
-StateType Service::GetLastStateType(void) const
-{
- if (m_LastStateType.IsEmpty())
- return StateTypeSoft;
-
- int ivalue = static_cast<int>(m_LastStateType);
- return static_cast<StateType>(ivalue);
-}
-
-void Service::SetLastStateOK(double ts)
-{
- m_LastStateOK = ts;
-}
-
-double Service::GetLastStateOK(void) const
-{
- if (m_LastStateOK.IsEmpty())
- return 0;
-
- return m_LastStateOK;
-}
-
-void Service::SetLastStateWarning(double ts)
-{
- m_LastStateWarning = ts;
-}
-
-double Service::GetLastStateWarning(void) const
-{
- if (m_LastStateWarning.IsEmpty())
- return 0;
-
- return m_LastStateWarning;
-}
-
-void Service::SetLastStateCritical(double ts)
-{
- m_LastStateCritical = ts;
-}
-
-double Service::GetLastStateCritical(void) const
-{
- if (m_LastStateCritical.IsEmpty())
- return 0;
-
- return m_LastStateCritical;
-}
-
-void Service::SetLastStateUnknown(double ts)
-{
- m_LastStateUnknown = ts;
-}
-
-double Service::GetLastStateUnknown(void) const
-{
- if (m_LastStateUnknown.IsEmpty())
- return 0;
-
- return m_LastStateUnknown;
-}
-
-void Service::SetLastStateUnreachable(double ts)
-{
- m_LastStateUnreachable = ts;
-}
-
-double Service::GetLastStateUnreachable(void) const
-{
- if (m_LastStateUnreachable.IsEmpty())
- return 0;
-
- return m_LastStateUnreachable;
-}
-
-void Service::SetLastReachable(bool reachable)
-{
- m_LastReachable = reachable;
-}
-
-bool Service::GetLastReachable(void) const
-{
- if (m_LastReachable.IsEmpty())
- return true;
-
- return m_LastReachable;
-}
-
-void Service::SetLastCheckResult(const Dictionary::Ptr& result)
-{
- m_LastResult = result;
-}
-
-Dictionary::Ptr Service::GetLastCheckResult(void) const
-{
- return m_LastResult;
-}
-
bool Service::HasBeenChecked(void) const
{
return GetLastCheckResult();
Dictionary::Ptr cr = GetLastCheckResult();
double schedule_end = -1;
- if (cr) {
+ if (cr)
schedule_end = cr->Get("schedule_end");
- }
return schedule_end;
}
return perfdata;
}
-void Service::SetLastStateChange(double ts)
-{
- m_LastStateChange = ts;
-}
-
-double Service::GetLastStateChange(void) const
-{
- if (m_LastStateChange.IsEmpty())
- return IcingaApplication::GetInstance()->GetStartTime();
-
- return m_LastStateChange;
-}
-
-void Service::SetLastHardStateChange(double ts)
-{
- m_LastHardStateChange = ts;
-}
-
-double Service::GetLastHardStateChange(void) const
-{
- if (m_LastHardStateChange.IsEmpty())
- return IcingaApplication::GetInstance()->GetStartTime();
-
- return m_LastHardStateChange;
-}
-
bool Service::GetEnableActiveChecks(void) const
{
- if (!m_OverrideEnableActiveChecks.IsEmpty())
- return m_OverrideEnableActiveChecks;
- else if (!m_EnableActiveChecks.IsEmpty())
- return m_EnableActiveChecks;
+ if (!GetOverrideEnableActiveChecks().IsEmpty())
+ return GetOverrideEnableActiveChecks();
else
- return true;
+ return GetEnableActiveChecksRaw();
}
void Service::SetEnableActiveChecks(bool enabled, const String& authority)
{
- m_OverrideEnableActiveChecks = enabled ? 1 : 0;
+ SetOverrideEnableActiveChecks(enabled);
Utility::QueueAsyncCallback(boost::bind(boost::ref(OnEnableActiveChecksChanged), GetSelf(), enabled, authority));
}
bool Service::GetEnablePassiveChecks(void) const
{
- if (!m_OverrideEnablePassiveChecks.IsEmpty())
- return m_OverrideEnablePassiveChecks;
- if (!m_EnablePassiveChecks.IsEmpty())
- return m_EnablePassiveChecks;
+ if (!GetOverrideEnablePassiveChecks().IsEmpty())
+ return GetOverrideEnablePassiveChecks();
else
- return true;
+ return GetEnablePassiveChecksRaw();
}
void Service::SetEnablePassiveChecks(bool enabled, const String& authority)
{
- m_OverrideEnablePassiveChecks = enabled ? 1 : 0;
+ SetOverrideEnablePassiveChecks(enabled);
Utility::QueueAsyncCallback(boost::bind(boost::ref(OnEnablePassiveChecksChanged), GetSelf(), enabled, authority));
}
bool Service::GetForceNextCheck(void) const
{
- if (m_ForceNextCheck.IsEmpty())
- return false;
-
- return static_cast<bool>(m_ForceNextCheck);
+ return GetForceNextCheckRaw();
}
void Service::SetForceNextCheck(bool forced, const String& authority)
{
- m_ForceNextCheck = forced ? 1 : 0;
+ SetForceNextCheckRaw(forced);
Utility::QueueAsyncCallback(boost::bind(boost::ref(OnForceNextCheckChanged), GetSelf(), forced, authority));
}
Dictionary::Ptr old_cr = GetLastCheckResult();
ServiceState old_state = GetState();
StateType old_stateType = GetStateType();
- long old_attempt = GetCurrentCheckAttempt();
+ long old_attempt = GetCheckAttempt();
bool recovery;
if (old_cr && cr->Get("execution_start") < old_cr->Get("execution_start"))
if (!reachable)
SetLastStateUnreachable(Utility::GetTime());
- SetCurrentCheckAttempt(attempt);
+ SetCheckAttempt(attempt);
int state = cr->Get("state");
SetState(static_cast<ServiceState>(state));
if (old_state != GetState() && old_stateType == StateTypeHard && GetStateType() == StateTypeHard)
hardChange = true;
- if (IsVolatile())
+ if (GetVolatile())
hardChange = true;
if (hardChange) {
if (old_state == StateOK && old_stateType == StateTypeSoft)
send_notification = false; /* Don't send notifications for SOFT-OK -> HARD-OK. */
- bool send_downtime_notification = m_LastInDowntime != in_downtime;
- m_LastInDowntime = in_downtime;
+ bool send_downtime_notification = (GetLastInDowntime() != in_downtime);
+ SetLastInDowntime(in_downtime);
olock.Unlock();
Dictionary::Ptr vars_after = boost::make_shared<Dictionary>();
vars_after->Set("state", GetState());
vars_after->Set("state_type", GetStateType());
- vars_after->Set("attempt", GetCurrentCheckAttempt());
+ vars_after->Set("attempt", GetCheckAttempt());
vars_after->Set("reachable", reachable);
vars_after->Set("host_reachable", host_reachable);
return l_NextCommentID;
}
-Dictionary::Ptr Service::GetComments(void) const
-{
- return m_Comments;
-}
-
String Service::AddComment(CommentType entryType, const String& author,
const String& text, double expireTime, const String& id, const String& authority)
{
comment->Set("legacy_id", legacy_id);
- Dictionary::Ptr comments;
-
- {
- ObjectLock olock(this);
-
- comments = GetComments();
-
- if (!comments)
- comments = boost::make_shared<Dictionary>();
-
- m_Comments = comments;
- }
-
- {
- ObjectLock olock(this);
-
- comments->Set(uid, comment);
- }
+ GetComments()->Set(uid, comment);
{
boost::mutex::scoped_lock lock(l_CommentMutex);
void Service::RemoveAllComments(void)
{
std::vector<String> ids;
- Dictionary::Ptr comments = m_Comments;
-
- if (!comments)
- return;
+ Dictionary::Ptr comments = GetComments();
ObjectLock olock(comments);
String id;
Dictionary::Ptr comments = owner->GetComments();
- if (!comments)
- return;
-
ObjectLock olock(owner);
Dictionary::Ptr comment = comments->Get(id);
Dictionary::Ptr comments = GetComments();
- if (!comments)
- return;
-
ObjectLock olock(comments);
boost::mutex::scoped_lock lock(l_CommentMutex);
{
Dictionary::Ptr comments = GetComments();
- if (!comments)
- return;
-
std::vector<String> removedComments;
{
{
Dictionary::Ptr comments = GetComments();
- if (!comments)
- return;
-
std::vector<String> expiredComments;
{
return l_NextDowntimeID;
}
-Dictionary::Ptr Service::GetDowntimes(void) const
-{
- return m_Downtimes;
-}
-
String Service::AddDowntime(const String& comment_id,
double startTime, double endTime, bool fixed,
const String& triggeredBy, double duration, const String& id, const String& authority)
if (!triggeredBy.IsEmpty()) {
Service::Ptr otherOwner = GetOwnerByDowntimeID(triggeredBy);
- Dictionary::Ptr otherDowntimes = otherOwner->m_Downtimes;
+ Dictionary::Ptr otherDowntimes = otherOwner->GetDowntimes();
Dictionary::Ptr otherDowntime = otherDowntimes->Get(triggeredBy);
Dictionary::Ptr triggers = otherDowntime->Get("triggers");
}
}
- Dictionary::Ptr downtimes;
-
- {
- ObjectLock olock(this);
-
- downtimes = m_Downtimes;
-
- if (!downtimes)
- downtimes = boost::make_shared<Dictionary>();
-
- m_Downtimes = downtimes;
- }
-
- downtimes->Set(uid, downtime);
+ GetDowntimes()->Set(uid, downtime);
{
boost::mutex::scoped_lock lock(l_DowntimeMutex);
Dictionary::Ptr downtimes = owner->GetDowntimes();
- if (!downtimes)
- return;
-
Dictionary::Ptr downtime = downtimes->Get(id);
if (!downtime)
{
Dictionary::Ptr downtimes = GetDowntimes();
- if (!downtimes)
- return;
-
std::vector<String> ids;
{
Dictionary::Ptr downtimes = GetDowntimes();
- if (!downtimes)
- return;
-
boost::mutex::scoped_lock lock(l_DowntimeMutex);
ObjectLock olock(downtimes);
{
Dictionary::Ptr downtimes = GetDowntimes();
- if (!downtimes)
- return;
-
std::vector<String> expiredDowntimes;
{
{
Dictionary::Ptr downtimes = GetDowntimes();
- if (!downtimes)
- return false;
-
ObjectLock olock(downtimes);
Dictionary::Ptr downtime;
int downtime_depth = 0;
Dictionary::Ptr downtimes = GetDowntimes();
- if (!downtimes)
- return 0;
-
ObjectLock olock(downtimes);
Dictionary::Ptr downtime;
bool Service::GetEnableEventHandler(void) const
{
- if (!m_OverrideEnableEventHandler.IsEmpty())
- return m_EnableEventHandler;
- else if (!m_EnableEventHandler.IsEmpty())
- return m_EnableEventHandler;
+ if (!GetOverrideEnableEventHandler().IsEmpty())
+ return GetOverrideEnableEventHandler();
else
- return true;
+ return GetEnableEventHandlerRaw();
}
void Service::SetEnableEventHandler(bool enabled)
{
- m_OverrideEnableEventHandler = enabled;
+ SetOverrideEnableEventHandler(enabled);
}
EventCommand::Ptr Service::GetEventCommand(void) const
{
- return EventCommand::GetByName(m_EventCommand);
+ return EventCommand::GetByName(GetEventCommandRaw());
}
void Service::ExecuteEventHandler(void)
double Service::GetFlappingCurrent(void) const
{
- if (m_FlappingPositive + m_FlappingNegative <= 0)
+ if (GetFlappingPositive() + GetFlappingNegative() <= 0)
return 0;
- return 100 * m_FlappingPositive / (m_FlappingPositive + m_FlappingNegative);
-}
-
-double Service::GetFlappingThreshold(void) const
-{
- if (m_FlappingThreshold.IsEmpty())
- return 30;
- else
- return m_FlappingThreshold;
+ return 100 * GetFlappingPositive() / (GetFlappingPositive() + GetFlappingNegative());
}
bool Service::GetEnableFlapping(void) const
{
- if (m_EnableFlapping.IsEmpty())
- return true;
- else
- return m_EnableFlapping;
-
+ return GetEnableFlappingRaw();
}
void Service::SetEnableFlapping(bool enabled, const String& authority)
{
- m_EnableFlapping = enabled;
+ SetEnableFlappingRaw(enabled);
OnFlappingChanged(GetSelf(), enabled ? FlappingEnabled : FlappingDisabled);
Utility::QueueAsyncCallback(boost::bind(boost::ref(OnEnableFlappingChanged), GetSelf(), enabled, authority));
now = Utility::GetTime();
- if (m_FlappingLastChange.IsEmpty()) {
- ts = now;
- positive = 0;
- negative = 0;
- } else {
- ts = m_FlappingLastChange;
- positive = m_FlappingPositive;
- negative = m_FlappingNegative;
- }
+ ts = GetFlappingLastChange();
+ positive = GetFlappingPositive();
+ negative = GetFlappingNegative();
double diff = now - ts;
// Log(LogDebug, "icinga", "Flapping counter for '" + GetName() + "' is positive=" + Convert::ToString(positive) + ", negative=" + Convert::ToString(negative));
- m_FlappingPositive = positive;
- m_FlappingNegative = negative;
- m_FlappingLastChange = now;
+ SetFlappingLastChange(now);
+ SetFlappingPositive(positive);
+ SetFlappingNegative(negative);
}
bool Service::IsFlapping(void) const
boost::signals2::signal<void (const Service::Ptr&, const std::set<User::Ptr>&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationSentToAllUsers;
boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationSentToUser;
-Dictionary::Ptr Service::GetNotificationDescriptions(void) const
-{
- return m_NotificationDescriptions;
-}
-
void Service::ResetNotificationNumbers(void)
{
BOOST_FOREACH(const Notification::Ptr& notification, GetNotifications()) {
bool Service::GetEnableNotifications(void) const
{
- if (m_EnableNotifications.IsEmpty())
- return true;
- else
- return m_EnableNotifications;
+ return GetEnableNotificationsRaw();
}
void Service::SetEnableNotifications(bool enabled, const String& authority)
{
- m_EnableNotifications = enabled;
+ SetEnableNotificationsRaw(enabled);
Utility::QueueAsyncCallback(boost::bind(boost::ref(OnEnableNotificationsChanged), GetSelf(), enabled, authority));
}
bool Service::GetForceNextNotification(void) const
{
- if (m_ForceNextNotification.IsEmpty())
- return false;
-
- return static_cast<bool>(m_ForceNextNotification);
+ return GetForceNextNotificationRaw();
}
void Service::SetForceNextNotification(bool forced, const String& authority)
{
- m_ForceNextNotification = forced ? 1 : 0;
+ SetForceNextNotificationRaw(forced);
Utility::QueueAsyncCallback(boost::bind(boost::ref(OnForceNextNotificationChanged), GetSelf(), forced, authority));
}
UpdateSlaveNotifications();
}
-String Service::GetDisplayName(void) const
-{
- if (m_DisplayName.IsEmpty())
- return GetShortName();
- else
- return m_DisplayName;
-}
-
Service::Ptr Service::GetByNamePair(const String& hostName, const String& serviceName)
{
if (!hostName.IsEmpty()) {
Host::Ptr Service::GetHost(void) const
{
- return Host::GetByName(m_HostName);
-}
-
-Dictionary::Ptr Service::GetMacros(void) const
-{
- return m_Macros;
-}
-
-Array::Ptr Service::GetHostDependencies(void) const
-{
- return m_HostDependencies;
-}
-
-Array::Ptr Service::GetServiceDependencies(void) const
-{
- return m_ServiceDependencies;
-}
-
-Array::Ptr Service::GetGroups(void) const
-{
- return m_Groups;
-}
-
-String Service::GetHostName(void) const
-{
- return m_HostName;
-}
-
-String Service::GetShortName(void) const
-{
- if (m_ShortName.IsEmpty())
- return GetName();
- else
- return m_ShortName;
+ return Host::GetByName(GetHostRaw());
}
bool Service::IsHostCheck(void) const
return true;
}
-bool Service::IsVolatile(void) const
-{
- if (m_Volatile.IsEmpty())
- return false;
-
- return m_Volatile;
-}
-
AcknowledgementType Service::GetAcknowledgement(void)
{
ASSERT(OwnsLock());
- if (m_Acknowledgement.IsEmpty())
- return AcknowledgementNone;
-
- int ivalue = static_cast<int>(m_Acknowledgement);
- AcknowledgementType avalue = static_cast<AcknowledgementType>(ivalue);
+ AcknowledgementType avalue = static_cast<AcknowledgementType>(GetAcknowledgementRaw());
if (avalue != AcknowledgementNone) {
double expiry = GetAcknowledgementExpiry();
return GetAcknowledgement() != AcknowledgementNone;
}
-double Service::GetAcknowledgementExpiry(void) const
-{
- if (m_AcknowledgementExpiry.IsEmpty())
- return 0;
-
- return static_cast<double>(m_AcknowledgementExpiry);
-}
-
void Service::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority)
{
{
ObjectLock olock(this);
- m_Acknowledgement = type;
- m_AcknowledgementExpiry = expiry;
+ SetAcknowledgementRaw(type);
+ SetAcknowledgementExpiry(expiry);
}
OnNotificationsRequested(GetSelf(), NotificationAcknowledgement, GetLastCheckResult(), author, comment);
{
ASSERT(OwnsLock());
- m_Acknowledgement = AcknowledgementNone;
- m_AcknowledgementExpiry = 0;
+ SetAcknowledgementRaw(AcknowledgementNone);
+ SetAcknowledgementExpiry(0);
Utility::QueueAsyncCallback(boost::bind(boost::ref(OnAcknowledgementCleared), GetSelf(), authority));
}
return parents;
}
-bool Service::GetEnablePerfdata(void) const
-{
- if (!m_EnablePerfdata.IsEmpty())
- return m_EnablePerfdata;
- else
- return true;
-}
-
int Service::GetModifiedAttributes(void) const
{
int attrs = 0;
- if (!m_OverrideEnableActiveChecks.IsEmpty())
+ if (!GetOverrideEnableActiveChecks().IsEmpty())
attrs |= ModAttrActiveChecksEnabled;
- if (!m_OverrideEnablePassiveChecks.IsEmpty())
+ if (!GetOverrideEnablePassiveChecks().IsEmpty())
attrs |= ModAttrPassiveChecksEnabled;
- if (!m_OverrideEnableEventHandler.IsEmpty())
+ if (!GetOverrideEnableEventHandler().IsEmpty())
attrs |= ModAttrEventHandlerEnabled;
- if (!m_OverrideCheckInterval.IsEmpty())
+ if (!GetOverrideCheckInterval().IsEmpty())
attrs |= ModAttrNormalCheckInterval;
- if (!m_OverrideRetryInterval.IsEmpty())
+ if (!GetOverrideRetryInterval().IsEmpty())
attrs |= ModAttrRetryCheckInterval;
// TODO: finish
void Service::SetModifiedAttributes(int flags)
{
if ((flags & ModAttrActiveChecksEnabled) == 0)
- m_OverrideEnableActiveChecks = Empty;
+ SetOverrideEnableActiveChecks(Empty);
if ((flags & ModAttrPassiveChecksEnabled) == 0)
- m_OverrideEnablePassiveChecks = Empty;
+ SetOverrideEnablePassiveChecks(Empty);
if ((flags & ModAttrEventHandlerEnabled) == 0)
- m_OverrideEnableEventHandler = Empty;
+ SetOverrideEnableEventHandler(Empty);
if ((flags & ModAttrNormalCheckInterval) == 0)
- m_OverrideCheckInterval = Empty;
+ SetOverrideCheckInterval(Empty);
if ((flags & ModAttrRetryCheckInterval) == 0)
- m_OverrideRetryInterval = Empty;
+ SetOverrideRetryInterval(Empty);
}
bool Service::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
*result = StateTypeToString(GetStateType());
return true;
} else if (macro == "SERVICEATTEMPT") {
- *result = Convert::ToString(GetCurrentCheckAttempt());
+ *result = Convert::ToString(GetCheckAttempt());
return true;
} else if (macro == "MAXSERVICEATTEMPT") {
*result = Convert::ToString(GetMaxCheckAttempts());
return false;
}
-
-void Service::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
-{
- DynamicObject::InternalSerialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config) {
- bag->Set("display_name", m_DisplayName);
- bag->Set("macros", m_Macros);
- bag->Set("host_dependencies", m_HostDependencies);
- bag->Set("service_dependencies", m_ServiceDependencies);
- bag->Set("groups", m_Groups);
- bag->Set("check_command", m_CheckCommand);
- bag->Set("max_check_attempts", m_MaxCheckAttempts);
- bag->Set("check_period", m_CheckPeriod);
- bag->Set("check_interval", m_CheckInterval);
- bag->Set("retry_interval", m_RetryInterval);
- bag->Set("event_command", m_EventCommand);
- bag->Set("volatile", m_Volatile);
- bag->Set("short_name", m_ShortName);
- bag->Set("host", m_HostName);
- bag->Set("flapping_threshold", m_FlappingThreshold);
- bag->Set("notifications", m_NotificationDescriptions);
- bag->Set("enable_active_checks", m_EnableActiveChecks);
- bag->Set("enable_passive_checks", m_EnablePassiveChecks);
- bag->Set("enable_event_handler", m_EnableEventHandler);
- }
-
- if (attributeTypes & Attribute_State) {
- bag->Set("next_check", m_NextCheck);
- bag->Set("current_checker", m_CurrentChecker);
- bag->Set("check_attempt", m_CheckAttempt);
- bag->Set("state", m_State);
- bag->Set("state_type", m_StateType);
- bag->Set("last_state", m_LastState);
- bag->Set("last_hard_state", m_LastHardState);
- bag->Set("last_state_type", m_LastStateType);
- bag->Set("last_reachable", m_LastReachable);
- bag->Set("last_result", m_LastResult);
- bag->Set("last_state_change", m_LastStateChange);
- bag->Set("last_hard_state_change", m_LastHardStateChange);
- bag->Set("last_state_ok", m_LastStateOK);
- bag->Set("last_state_warning", m_LastStateWarning);
- bag->Set("last_state_critical", m_LastStateCritical);
- bag->Set("last_state_unknown", m_LastStateUnknown);
- bag->Set("last_state_unreachable", m_LastStateUnreachable);
- bag->Set("last_in_downtime", m_LastInDowntime);
- bag->Set("enable_active_checks", m_EnableActiveChecks);
- bag->Set("enable_passive_checks", m_EnablePassiveChecks);
- bag->Set("force_next_check", m_ForceNextCheck);
- bag->Set("acknowledgement", m_Acknowledgement);
- bag->Set("acknowledgement_expiry", m_AcknowledgementExpiry);
- bag->Set("comments", m_Comments);
- bag->Set("downtimes", m_Downtimes);
- bag->Set("enable_notifications", m_EnableNotifications);
- bag->Set("force_next_notification", m_ForceNextNotification);
- bag->Set("flapping_positive", m_FlappingPositive);
- bag->Set("flapping_negative", m_FlappingNegative);
- bag->Set("flapping_lastchange", m_FlappingLastChange);
- bag->Set("enable_flapping", m_EnableFlapping);
- bag->Set("enable_perfdata", m_EnablePerfdata);
- bag->Set("override_enable_active_checks", m_OverrideEnableActiveChecks);
- bag->Set("override_enable_passive_checks", m_OverrideEnablePassiveChecks);
- bag->Set("override_check_interval", m_OverrideCheckInterval);
- bag->Set("override_retry_interval", m_OverrideRetryInterval);
- bag->Set("override_enable_event_handler", m_OverrideEnableEventHandler);
- }
-}
-
-void Service::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
-{
- DynamicObject::InternalDeserialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config) {
- m_DisplayName = bag->Get("display_name");
- m_Macros = bag->Get("macros");
- m_HostDependencies = bag->Get("host_dependencies");
- m_ServiceDependencies = bag->Get("service_dependencies");
- m_Groups = bag->Get("groups");
- m_CheckCommand = bag->Get("check_command");
- m_MaxCheckAttempts = bag->Get("max_check_attempts");
- m_CheckPeriod = bag->Get("check_period");
- m_CheckInterval = bag->Get("check_interval");
- m_RetryInterval = bag->Get("retry_interval");
- m_EventCommand = bag->Get("event_command");
- m_Volatile = bag->Get("volatile");
- m_ShortName = bag->Get("short_name");
- m_HostName = bag->Get("host");
- m_FlappingThreshold = bag->Get("flapping_threshold");
- m_NotificationDescriptions = bag->Get("notifications");
- m_EnableActiveChecks = bag->Get("enable_active_checks");
- m_EnablePassiveChecks = bag->Get("enable_passive_checks");
- m_EnableEventHandler = bag->Get("enable_event_handler");
- }
-
- if (attributeTypes & Attribute_State) {
- m_NextCheck = bag->Get("next_check");
- m_CurrentChecker = bag->Get("current_checker");
- m_CheckAttempt = bag->Get("check_attempt");
- m_State = bag->Get("state");
- m_StateType = bag->Get("state_type");
- m_LastState = bag->Get("last_state");
- m_LastHardState = bag->Get("last_hard_state");
- m_LastStateType = bag->Get("last_state_type");
- m_LastReachable = bag->Get("last_reachable");
- m_LastResult = bag->Get("last_result");
- m_LastStateChange = bag->Get("last_state_change");
- m_LastHardStateChange = bag->Get("last_hard_state_change");
- m_LastStateOK = bag->Get("last_state_ok");
- m_LastStateWarning = bag->Get("last_state_warning");
- m_LastStateCritical = bag->Get("last_state_critical");
- m_LastStateUnknown = bag->Get("last_state_unknown");
- m_LastStateUnreachable = bag->Get("last_state_unreachable");
- m_LastInDowntime = bag->Get("last_in_downtime");
- m_ForceNextCheck = bag->Get("force_next_check");
- m_Acknowledgement = bag->Get("acknowledgement");
- m_AcknowledgementExpiry = bag->Get("acknowledgement_expiry");
- m_Comments = bag->Get("comments");
- m_Downtimes = bag->Get("downtimes");
- m_EnableNotifications = bag->Get("enable_notifications");
- m_ForceNextNotification = bag->Get("force_next_notification");
- m_FlappingPositive = bag->Get("flapping_positive");
- m_FlappingNegative = bag->Get("flapping_negative");
- m_FlappingLastChange = bag->Get("flapping_lastchange");
- m_EnableFlapping = bag->Get("enable_flapping");
- m_EnablePerfdata = bag->Get("enable_perfdata");
- m_OverrideEnableActiveChecks = bag->Get("override_enable_active_checks");
- m_OverrideEnablePassiveChecks = bag->Get("override_enable_passive_checks");
- m_OverrideCheckInterval = bag->Get("override_check_interval");
- m_OverrideRetryInterval = bag->Get("override_retry_interval");
- m_OverrideEnableEventHandler = bag->Get("override_enable_event_handler");
- }
-}
#define SERVICE_H
#include "icinga/i2-icinga.h"
+#include "icinga/service.th"
#include "icinga/macroresolver.h"
#include "icinga/host.h"
#include "icinga/timeperiod.h"
#include "icinga/notification.h"
#include "base/i2-base.h"
-#include "base/dynamicobject.h"
#include "base/array.h"
#include <boost/signals2.hpp>
#include <boost/thread/once.hpp>
namespace icinga
{
-/**
- * The acknowledgement type of a service.
- *
- * @ingroup icinga
- */
-enum AcknowledgementType
-{
- AcknowledgementNone = 0,
- AcknowledgementNormal = 1,
- AcknowledgementSticky = 2
-};
-
/**
* The type of a service comment.
*
*
* @ingroup icinga
*/
-class I2_ICINGA_API Service : public DynamicObject, public MacroResolver
+class I2_ICINGA_API Service : public ReflectionObjectImpl<Service>, public MacroResolver
{
public:
DECLARE_PTR_TYPEDEFS(Service);
static Service::Ptr GetByNamePair(const String& hostName, const String& serviceName);
- static const int DefaultMaxCheckAttempts;
- static const double DefaultCheckInterval;
- static const double CheckIntervalDivisor;
-
- String GetDisplayName(void) const;
Host::Ptr GetHost(void) const;
- Dictionary::Ptr GetMacros(void) const;
- Array::Ptr GetHostDependencies(void) const;
- Array::Ptr GetServiceDependencies(void) const;
- Array::Ptr GetGroups(void) const;
- String GetHostName(void) const;
- String GetShortName(void) const;
std::set<Host::Ptr> GetParentHosts(void) const;
std::set<Service::Ptr> GetParentServices(void) const;
bool IsHostCheck(void) const;
- bool IsVolatile(void) const;
-
bool IsReachable(void) const;
AcknowledgementType GetAcknowledgement(void);
- double GetAcknowledgementExpiry(void) const;
void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry = 0, const String& authority = String());
void ClearAcknowledgement(const String& authority = String());
/* Checks */
shared_ptr<CheckCommand> GetCheckCommand(void) const;
- long GetMaxCheckAttempts(void) const;
TimePeriod::Ptr GetCheckPeriod(void) const;
double GetCheckInterval(void) const;
double GetNextCheck(void);
void UpdateNextCheck(void);
- void SetCurrentChecker(const String& checker);
- String GetCurrentChecker(void) const;
-
- void SetCurrentCheckAttempt(long attempt);
- long GetCurrentCheckAttempt(void) const;
-
- void SetState(ServiceState state);
- ServiceState GetState(void) const;
-
- void SetStateType(StateType type);
- StateType GetStateType(void) const;
-
- void SetLastState(ServiceState state);
- ServiceState GetLastState(void) const;
-
- void SetLastHardState(ServiceState state);
- ServiceState GetLastHardState(void) const;
-
- void SetLastStateType(StateType type);
- StateType GetLastStateType(void) const;
-
- void SetLastCheckResult(const Dictionary::Ptr& result);
- Dictionary::Ptr GetLastCheckResult(void) const;
bool HasBeenChecked(void) const;
double GetLastCheck(void) const;
String GetLastCheckLongOutput(void) const;
String GetLastCheckPerfData(void) const;
- void SetLastStateChange(double ts);
- double GetLastStateChange(void) const;
-
- void SetLastHardStateChange(double ts);
- double GetLastHardStateChange(void) const;
-
- void SetLastStateOK(double ts);
- double GetLastStateOK(void) const;
- void SetLastStateWarning(double ts);
- double GetLastStateWarning(void) const;
- void SetLastStateCritical(double ts);
- double GetLastStateCritical(void) const;
- void SetLastStateUnknown(double ts);
- double GetLastStateUnknown(void) const;
- void SetLastStateUnreachable(double ts);
- double GetLastStateUnreachable(void) const;
-
- void SetLastReachable(bool reachable);
- bool GetLastReachable(void) const;
-
bool GetEnableActiveChecks(void) const;
void SetEnableActiveChecks(bool enabled, const String& authority = String());
bool GetEnablePassiveChecks(void) const;
void SetEnablePassiveChecks(bool enabled, const String& authority = String());
- bool GetEnablePerfdata(void) const;
-
bool GetForceNextCheck(void) const;
void SetForceNextCheck(bool forced, const String& authority = String());
/* Downtimes */
static int GetNextDowntimeID(void);
- Dictionary::Ptr GetDowntimes(void) const;
int GetDowntimeDepth(void) const;
String AddDowntime(const String& comment_id,
/* Comments */
static int GetNextCommentID(void);
- Dictionary::Ptr GetComments(void) const;
-
String AddComment(CommentType entryType, const String& author,
const String& text, double expireTime, const String& id = String(), const String& authority = String());
static bool IsCommentExpired(const Dictionary::Ptr& comment);
/* Notifications */
- Dictionary::Ptr GetNotificationDescriptions(void) const;
-
bool GetEnableNotifications(void) const;
void SetEnableNotifications(bool enabled, const String& authority = String());
void SetEnableEventHandler(bool enabled);
/* Flapping Detection */
+ double GetFlappingCurrent(void) const;
+
bool GetEnableFlapping(void) const;
void SetEnableFlapping(bool enabled, const String& authority = String());
- double GetFlappingCurrent(void) const;
- double GetFlappingThreshold(void) const;
-
bool IsFlapping(void) const;
void UpdateFlappingStatus(bool stateChange);
virtual void OnConfigLoaded(void);
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- String m_DisplayName;
- Dictionary::Ptr m_Macros;
- Array::Ptr m_HostDependencies;
- Array::Ptr m_ServiceDependencies;
- Array::Ptr m_Groups;
- String m_ShortName;
- Value m_Acknowledgement;
- Value m_AcknowledgementExpiry;
- String m_HostName;
- Value m_Volatile;
- Value m_EnablePerfdata;
-
- /* Checks */
- String m_CheckCommand;
- Value m_MaxCheckAttempts;
- String m_CheckPeriod;
- Value m_CheckInterval;
- Value m_OverrideCheckInterval;
- Value m_RetryInterval;
- Value m_OverrideRetryInterval;
- double m_NextCheck;
- String m_CurrentChecker;
- Value m_CheckAttempt;
- Value m_State;
- Value m_StateType;
- Value m_LastState;
- Value m_LastHardState;
- Value m_LastStateType;
- Value m_LastReachable;
- Dictionary::Ptr m_LastResult;
- Value m_LastStateChange;
- Value m_LastHardStateChange;
- Value m_LastStateOK;
- Value m_LastStateWarning;
- Value m_LastStateCritical;
- Value m_LastStateUnknown;
- Value m_LastStateUnreachable;
- bool m_LastInDowntime;
- Value m_EnableActiveChecks;
- Value m_OverrideEnableActiveChecks;
- Value m_EnablePassiveChecks;
- Value m_OverrideEnablePassiveChecks;
- Value m_ForceNextCheck;
-
bool m_CheckRunning;
long m_SchedulingOffset;
/* Downtimes */
- Dictionary::Ptr m_Downtimes;
-
static void DowntimesExpireTimerHandler(void);
-
void RemoveExpiredDowntimes(void);
-
void AddDowntimesToCache(void);
/* Comments */
- Dictionary::Ptr m_Comments;
-
static void CommentsExpireTimerHandler(void);
-
void RemoveExpiredComments(void);
-
void AddCommentsToCache(void);
/* Notifications */
- Dictionary::Ptr m_NotificationDescriptions;
-
- Value m_EnableNotifications;
- Value m_ForceNextNotification;
-
std::set<Notification::Ptr> m_Notifications;
-
- /* Event Handler */
- Value m_EnableEventHandler;
- Value m_OverrideEnableEventHandler;
- String m_EventCommand;
-
- /* Flapping */
- Value m_EnableFlapping;
- long m_FlappingPositive;
- long m_FlappingNegative;
- Value m_FlappingLastChange;
- Value m_FlappingThreshold;
};
}
--- /dev/null
+#include "icinga/host.h"
+#include "icinga/icingaapplication.h"
+#include "base/dynamicobject.h"
+#include <boost/smart_ptr/make_shared.hpp>
+
+namespace icinga
+{
+
+code {{{
+/**
+ * The acknowledgement type of a service.
+ *
+ * @ingroup icinga
+ */
+enum AcknowledgementType
+{
+ AcknowledgementNone = 0,
+ AcknowledgementNormal = 1,
+ AcknowledgementSticky = 2
+};
+}}}
+
+class Service : DynamicObject
+{
+ [config] String display_name {
+ get {{{
+ if (m_DisplayName.IsEmpty())
+ return GetShortName();
+ else
+ return m_DisplayName;
+ }}}
+ };
+ [config] Dictionary::Ptr macros;
+ [config] Array::Ptr host_dependencies;
+ [config] Array::Ptr service_dependencies;
+ [config] Array::Ptr groups;
+ [config, protected] String check_command (CheckCommandRaw);
+ [config] int max_check_attempts {
+ default {{{ return 3; }}}
+ };
+ [config, protected] String check_period (CheckPeriodRaw);
+ [config] double check_interval (CheckIntervalRaw) {
+ default {{{ return 5 * 60; }}}
+ };
+ [config] double retry_interval (RetryIntervalRaw) {
+ default {{{ return 60; }}}
+ };
+ [config] String event_command (EventCommandRaw);
+ [config] bool volatile;
+ [config] String short_name {
+ default {{{ return GetName(); }}}
+ };
+ [config] String host (HostRaw);
+ [config] double flapping_threshold {
+ default {{{ return 30; }}}
+ };
+ [config] Dictionary::Ptr notifications (NotificationDescriptions);
+ [config] bool enable_active_checks (EnableActiveChecksRaw) {
+ default {{{ return true; }}}
+ };
+ [config] bool enable_passive_checks (EnablePassiveChecksRaw) {
+ default {{{ return true; }}}
+ };
+ [config] bool enable_event_handler (EnableEventHandlerRaw) {
+ default {{{ return true; }}}
+ };
+
+ [state] double next_check (NextCheckRaw);
+ [state] int check_attempt {
+ default {{{ return 1; }}}
+ };
+ [state, enum] ServiceState "state" {
+ default {{{ return StateUnknown; }}}
+ };
+ [state, enum] StateType state_type {
+ default {{{ return StateTypeSoft; }}}
+ };
+ [state, enum] ServiceState last_state {
+ default {{{ return StateUnknown; }}}
+ };
+ [state, enum] ServiceState last_hard_state {
+ default {{{ return StateUnknown; }}}
+ };
+ [state, enum] StateType last_state_type {
+ default {{{ return StateTypeSoft; }}}
+ };
+ [state] bool last_reachable {
+ default {{{ return true; }}}
+ };
+ [state] Dictionary::Ptr last_check_result;
+ [state] double last_state_change {
+ default {{{ return Application::GetStartTime(); }}}
+ };
+ [state] double last_hard_state_change {
+ default {{{ return Application::GetStartTime(); }}}
+ };
+ [state] double last_state_ok (LastStateOK);
+ [state] double last_state_warning;
+ [state] double last_state_critical;
+ [state] double last_state_unknown;
+ [state] double last_state_unreachable;
+ [state] bool last_in_downtime;
+ [state] bool force_next_check (ForceNextCheckRaw);
+ [state] int acknowledgement (AcknowledgementRaw) {
+ default {{{ return AcknowledgementNone; }}}
+ };
+ [state] double acknowledgement_expiry;
+ [state] Dictionary::Ptr comments {
+ default {{{ return boost::make_shared<Dictionary>(); }}}
+ };
+ [state] Dictionary::Ptr downtimes {
+ default {{{ return boost::make_shared<Dictionary>(); }}}
+ };
+ [state] bool enable_notifications (EnableNotificationsRaw) {
+ default {{{ return true; }}}
+ };
+ [state] bool force_next_notification (ForceNextNotificationRaw);
+ [state] int flapping_positive;
+ [state] int flapping_negative;
+ [state] double flapping_last_change;
+ [state] bool enable_flapping (EnableFlappingRaw) {
+ default {{{ return true; }}}
+ };
+ [state] bool enable_perfdata {
+ default {{{ return true; }}}
+ };
+ [state] Value override_enable_active_checks;
+ [state] Value override_enable_passive_checks;
+ [state] Value override_check_interval;
+ [state] Value override_retry_interval;
+ [state] Value override_enable_event_handler;
+};
+
+}
REGISTER_TYPE(ServiceGroup);
-String ServiceGroup::GetDisplayName(void) const
-{
- if (!m_DisplayName.IsEmpty())
- return m_DisplayName;
- else
- return GetName();
-}
-
std::set<Service::Ptr> ServiceGroup::GetMembers(void) const
{
return m_Members;
{
m_Members.erase(service);
}
-
-void ServiceGroup::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
-{
- DynamicObject::InternalSerialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config)
- bag->Set("display_name", m_DisplayName);
-}
-
-void ServiceGroup::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
-{
- DynamicObject::InternalDeserialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config)
- m_DisplayName = bag->Get("display_name");
-}
#define SERVICEGROUP_H
#include "icinga/i2-icinga.h"
+#include "icinga/servicegroup.th"
#include "icinga/service.h"
-#include "base/dynamictype.h"
namespace icinga
{
*
* @ingroup icinga
*/
-class I2_ICINGA_API ServiceGroup : public DynamicObject
+class I2_ICINGA_API ServiceGroup : public ReflectionObjectImpl<ServiceGroup>
{
public:
DECLARE_PTR_TYPEDEFS(ServiceGroup);
DECLARE_TYPENAME(ServiceGroup);
- String GetDisplayName(void) const;
-
std::set<Service::Ptr> GetMembers(void) const;
void AddMember(const Service::Ptr& service);
void RemoveMember(const Service::Ptr& service);
-protected:
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- String m_DisplayName;
std::set<Service::Ptr> m_Members;
};
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class ServiceGroup : DynamicObject
+{
+ [config] String display_name {
+ default {{{ return GetName(); }}}
+ };
+};
+
+}
\ No newline at end of file
Dump();
}
-String TimePeriod::GetDisplayName(void) const
-{
- if (!m_DisplayName.IsEmpty())
- return m_DisplayName;
- else
- return GetName();
-}
-
-Dictionary::Ptr TimePeriod::GetRanges(void) const
-{
- return m_Ranges;
-}
-
void TimePeriod::AddSegment(double begin, double end)
{
ASSERT(OwnsLock());
Log(LogDebug, "icinga", "Adding segment '" + Utility::FormatDateTime("%c", begin) + "' <-> '" + Utility::FormatDateTime("%c", end) + "' to TimePeriod '" + GetName() + "'");
- if (m_ValidBegin.IsEmpty() || begin < m_ValidBegin)
- m_ValidBegin = begin;
+ if (GetValidBegin().IsEmpty() || begin < GetValidBegin())
+ SetValidBegin(begin);
- if (m_ValidEnd.IsEmpty() || end > m_ValidEnd)
- m_ValidEnd = end;
+ if (GetValidEnd().IsEmpty() || end > GetValidEnd())
+ SetValidEnd(end);
- Array::Ptr segments = m_Segments;
+ Array::Ptr segments = GetSegments();
if (segments) {
/* Try to merge the new segment into an existing segment. */
if (!segments) {
segments = boost::make_shared<Array>();
- m_Segments = segments;
+ SetSegments(segments);
}
segments->Add(segment);
Log(LogDebug, "icinga", "Removing segment '" + Utility::FormatDateTime("%c", begin) + "' <-> '" + Utility::FormatDateTime("%c", end) + "' from TimePeriod '" + GetName() + "'");
- if (m_ValidBegin.IsEmpty() || begin < m_ValidBegin)
- m_ValidBegin = begin;
+ if (GetValidBegin().IsEmpty() || begin < GetValidBegin())
+ SetValidBegin(begin);
- if (m_ValidEnd.IsEmpty() || end > m_ValidEnd)
- m_ValidEnd = end;
+ if (GetValidEnd().IsEmpty() || end > GetValidEnd())
+ SetValidEnd(end);
- Array::Ptr segments = m_Segments;
+ Array::Ptr segments = GetSegments();
if (!segments)
return;
newSegments->Add(segment);
}
- m_Segments = newSegments;
+ SetSegments(newSegments);
Dump();
}
Log(LogDebug, "icinga", "Purging segments older than '" + Utility::FormatDateTime("%c", end) + "' from TimePeriod '" + GetName() + "'");
- if (m_ValidBegin.IsEmpty() || end < m_ValidBegin)
+ if (GetValidBegin().IsEmpty() || end < GetValidBegin())
return;
- m_ValidBegin = end;
+ SetValidBegin(end);
- Array::Ptr segments = m_Segments;
+ Array::Ptr segments = GetSegments();
if (!segments)
return;
newSegments->Add(segment);
}
- m_Segments = newSegments;
+ SetSegments(newSegments);
}
void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting)
{
if (!clearExisting) {
- if (begin < m_ValidEnd)
- begin = m_ValidEnd;
+ if (begin < GetValidEnd())
+ begin = GetValidEnd();
- if (end < m_ValidEnd)
+ if (end < GetValidEnd())
return;
}
{
ObjectLock olock(this);
- if (m_ValidBegin.IsEmpty() || ts < m_ValidBegin || m_ValidEnd.IsEmpty() || ts > m_ValidEnd)
+ if (GetValidBegin().IsEmpty() || ts < GetValidBegin() || GetValidEnd().IsEmpty() || ts > GetValidEnd())
return true; /* Assume that all invalid regions are "inside". */
- Array::Ptr segments = m_Segments;
+ Array::Ptr segments = GetSegments();
if (segments) {
ObjectLock dlock(segments);
{
ObjectLock olock(this);
- Array::Ptr segments = m_Segments;
+ Array::Ptr segments = GetSegments();
double closestTransition = -1;
ObjectLock olock(tp);
tp->PurgeSegments(now - 3600);
- valid_end = tp->m_ValidEnd;
+ valid_end = tp->GetValidEnd();
}
tp->UpdateRegion(valid_end, now + 24 * 3600, false);
void TimePeriod::Dump(void)
{
- Array::Ptr segments = m_Segments;
+ Array::Ptr segments = GetSegments();
Log(LogDebug, "icinga", "Dumping TimePeriod '" + GetName() + "'");
- Log(LogDebug, "icinga", "Valid from '" + Utility::FormatDateTime("%c", m_ValidBegin) + "' until '" + Utility::FormatDateTime("%c", m_ValidEnd));
+ Log(LogDebug, "icinga", "Valid from '" + Utility::FormatDateTime("%c", GetValidBegin()) + "' until '" + Utility::FormatDateTime("%c", GetValidEnd()));
if (segments) {
ObjectLock dlock(segments);
Log(LogDebug, "icinga", "---");
}
-
-void TimePeriod::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
-{
- DynamicObject::InternalSerialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config) {
- bag->Set("display_name", m_DisplayName);
- bag->Set("ranges", m_Ranges);
- }
-
- if (attributeTypes & Attribute_State) {
- bag->Set("valid_begin", m_ValidBegin);
- bag->Set("valid_end", m_ValidEnd);
- bag->Set("segments", m_Segments);
- }
-}
-
-void TimePeriod::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
-{
- DynamicObject::InternalDeserialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config) {
- m_DisplayName = bag->Get("display_name");
- m_Ranges = bag->Get("ranges");
- }
-
- if (attributeTypes & Attribute_State) {
- m_ValidBegin = bag->Get("valid_begin");
- m_ValidEnd = bag->Get("valid_end");
- m_Segments = bag->Get("segments");
- }
-}
#define TIMEPERIOD_H
#include "icinga/i2-icinga.h"
-#include "base/dynamicobject.h"
+#include "icinga/timeperiod.th"
#include "base/array.h"
namespace icinga
*
* @ingroup icinga
*/
-class I2_ICINGA_API TimePeriod : public DynamicObject
+class I2_ICINGA_API TimePeriod : public ReflectionObjectImpl<TimePeriod>
{
public:
DECLARE_PTR_TYPEDEFS(TimePeriod);
DECLARE_TYPENAME(TimePeriod);
- String GetDisplayName(void) const;
- Dictionary::Ptr GetRanges(void) const;
-
virtual void Start(void);
void UpdateRegion(double begin, double end, bool clearExisting);
static Array::Ptr EmptyTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
static Array::Ptr EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
-protected:
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- String m_DisplayName;
- Dictionary::Ptr m_Ranges;
- Value m_ValidBegin;
- Value m_ValidEnd;
- Array::Ptr m_Segments;
-
void AddSegment(double s, double end);
void AddSegment(const Dictionary::Ptr& segment);
void RemoveSegment(double begin, double end);
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class TimePeriod : DynamicObject
+{
+ [config] String display_name {
+ default {{{ return GetName(); }}}
+ };
+ [config] Dictionary::Ptr ranges;
+ [state] Value valid_begin;
+ [state] Value valid_end;
+ [state] Array::Ptr segments;
+};
+
+}
\ No newline at end of file
}
}
-String User::GetDisplayName(void) const
-{
- if (!m_DisplayName.IsEmpty())
- return m_DisplayName;
- else
- return GetName();
-}
-
-Array::Ptr User::GetGroups(void) const
-{
- return m_Groups;
-}
-
-Dictionary::Ptr User::GetMacros(void) const
-{
- return m_Macros;
-}
-
-bool User::GetEnableNotifications(void) const
-{
- if (m_EnableNotifications.IsEmpty())
- return true;
- else
- return m_EnableNotifications;
-}
-
-void User::SetEnableNotifications(bool enabled)
-{
- m_EnableNotifications = enabled;
-}
-
TimePeriod::Ptr User::GetNotificationPeriod(void) const
{
- return TimePeriod::GetByName(m_NotificationPeriod);
-}
-
-unsigned long User::GetNotificationTypeFilter(void) const
-{
- if (m_NotificationTypeFilter.IsEmpty())
- return ~(unsigned long)0; /* All types. */
- else
- return m_NotificationTypeFilter;
-}
-
-unsigned long User::GetNotificationStateFilter(void) const
-{
- if (m_NotificationStateFilter.IsEmpty())
- return ~(unsigned long)0; /* All states. */
- else
- return m_NotificationStateFilter;
-}
-
-void User::SetLastNotification(double ts)
-{
- m_LastNotification = ts;
-}
-
-double User::GetLastNotification(void) const
-{
- return m_LastNotification;
+ return TimePeriod::GetByName(GetNotificationPeriodRaw());
}
bool User::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
return false;
}
}
-
-void User::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
-{
- DynamicObject::InternalSerialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config) {
- bag->Set("display_name", m_DisplayName);
- bag->Set("macros", m_Macros);
- bag->Set("groups", m_Groups);
- bag->Set("notification_period", m_NotificationPeriod);
- bag->Set("notification_type_filter", m_NotificationTypeFilter);
- bag->Set("notification_state_filter", m_NotificationStateFilter);
- }
-
- if (attributeTypes & Attribute_State) {
- bag->Set("enable_notifications", m_EnableNotifications);
- bag->Set("last_notification", m_LastNotification);
- }
-}
-
-void User::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
-{
- DynamicObject::InternalDeserialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config) {
- m_DisplayName = bag->Get("display_name");
- m_Macros = bag->Get("macros");
- m_Groups = bag->Get("groups");
- m_NotificationPeriod = bag->Get("notification_period");
- m_NotificationTypeFilter = bag->Get("notification_type_filter");
- m_NotificationStateFilter = bag->Get("notification_state_filter");
- }
-
- if (attributeTypes & Attribute_State) {
- m_EnableNotifications = bag->Get("enable_notifications");
- m_LastNotification = bag->Get("last_notification");
- }
-}
#define USER_H
#include "icinga/i2-icinga.h"
+#include "icinga/user.th"
#include "icinga/macroresolver.h"
#include "icinga/timeperiod.h"
-#include "base/dynamicobject.h"
#include "base/array.h"
namespace icinga
*
* @ingroup icinga
*/
-class I2_ICINGA_API User : public DynamicObject, public MacroResolver
+class I2_ICINGA_API User : public ReflectionObjectImpl<User>, public MacroResolver
{
public:
DECLARE_PTR_TYPEDEFS(User);
DECLARE_TYPENAME(User);
- String GetDisplayName(void) const;
- Array::Ptr GetGroups(void) const;
-
/* Notifications */
- bool GetEnableNotifications(void) const;
- void SetEnableNotifications(bool enabled);
TimePeriod::Ptr GetNotificationPeriod(void) const;
- unsigned long GetNotificationTypeFilter(void) const;
- unsigned long GetNotificationStateFilter(void) const;
- void SetLastNotification(double ts);
- double GetLastNotification(void) const;
-
- Dictionary::Ptr GetMacros(void) const;
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
virtual void Stop(void);
virtual void OnConfigLoaded(void);
-
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
-private:
- String m_DisplayName;
- Dictionary::Ptr m_Macros;
- Array::Ptr m_Groups;
- Value m_EnableNotifications;
- String m_NotificationPeriod;
- Value m_NotificationTypeFilter;
- Value m_NotificationStateFilter;
- double m_LastNotification;
};
}
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class User : DynamicObject
+{
+ [config] String display_name {
+ default {{{ return GetName(); }}}
+ };
+ [config] Dictionary::Ptr macros;
+ [config] Array::Ptr groups;
+ [config] String notification_period (NotificationPeriodRaw);
+ [config] int notification_type_filter {
+ default {{{ return ~(int)0; }}}
+ };
+ [config] int notification_state_filter {
+ default {{{ return ~(int)0; }}}
+ };
+ [state] bool enable_notifications;
+ [state] double last_notification;
+};
+
+}
\ No newline at end of file
REGISTER_TYPE(UserGroup);
-String UserGroup::GetDisplayName(void) const
-{
- if (!m_DisplayName.IsEmpty())
- return m_DisplayName;
- else
- return GetName();
-}
-
std::set<User::Ptr> UserGroup::GetMembers(void) const
{
return m_Members;
{
m_Members.erase(user);
}
-
-void UserGroup::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
-{
- DynamicObject::InternalSerialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config)
- bag->Set("display_name", m_DisplayName);
-}
-
-void UserGroup::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
-{
- DynamicObject::InternalDeserialize(bag, attributeTypes);
-
- if (attributeTypes & Attribute_Config)
- m_DisplayName = bag->Get("display_name");
-}
#define USERGROUP_H
#include "icinga/i2-icinga.h"
+#include "icinga/usergroup.th"
#include "icinga/user.h"
-#include "base/dynamicobject.h"
namespace icinga
{
*
* @ingroup icinga
*/
-class I2_ICINGA_API UserGroup : public DynamicObject
+class I2_ICINGA_API UserGroup : public ReflectionObjectImpl<UserGroup>
{
public:
DECLARE_PTR_TYPEDEFS(UserGroup);
DECLARE_TYPENAME(UserGroup);
- String GetDisplayName(void) const;
-
std::set<User::Ptr> GetMembers(void) const;
void AddMember(const User::Ptr& user);
void RemoveMember(const User::Ptr& user);
-protected:
- virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
- virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
-
private:
- String m_DisplayName;
std::set<User::Ptr> m_Members;
};
--- /dev/null
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+class UserGroup : DynamicObject
+{
+ [config] String display_name {
+ default {{{ return GetName(); }}}
+ };
+};
+
+}
\ No newline at end of file
/* Execute FILE, searching in the `PATH' environment variable if it contains
no slashes, with arguments ARGV and environment from ENVP. */
int
-execvpe (file, argv, envp)
+icinga2_execvpe (file, argv, envp)
const char *file;
char *const argv[];
char *const envp[];
#ifndef EXECVPE_H
#define EXECVPE_H
-#include "config.h"
-
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
-#if !defined(_MSC_VER) && !defined(HAVE_EXECVPE)
-int execvpe(const char *file, char *const argv[], char *const envp[]);
-#endif /* !defined(_MSC_VER) && !defined(HAVE_EXECVPE) */
+#ifndef _MSC_VER
+int icinga2_execvpe(const char *file, char *const argv[], char *const envp[]);
+#endif /* _MSC_VER */
#ifdef __cplusplus
}
SUBDIRS = \
migration \
+ mkclass \
mkembedconfig
sbin_SCRIPTS = icinga2-enable-feature
--- /dev/null
+mkclass
+class_lexer.cc
+class_parser.cc
+class_parser.h
+class_parser.hh
\ No newline at end of file
--- /dev/null
+## Process this file with automake to produce Makefile.in
+
+noinst_PROGRAMS = \
+ mkclass
+
+EXTRA_DIST = \
+ class_lexer.cc \
+ class_parser.cc \
+ class_parser.h
+
+AM_YFLAGS = -d
+
+.hh.h:
+ if [ -e $(srcdir)/$< ]; then cp $(srcdir)/$< $(srcdir)/$@; fi
+
+class_lexer.cc: class_parser.h
+
+mkclass_SOURCES = \
+ classcompiler.cpp \
+ classcompiler.h \
+ class_lexer.ll \
+ class_parser.yy \
+ mkclass.cpp
--- /dev/null
+#include "base/dynamicobject.h"
+
+
+
+#include "base/logger.h"
+
+class Logger : DynamicObject
+{
+ [config] String severity;
+};
+
+class StreamLogger : Logger { };
+
+class FileLogger : StreamLogger
+{
+ [config] String path;
+};
+
+class ConsoleLogger : StreamLogger { };
+
+class SyslogLogger : Logger { };
+
+class Script : DynamicObject
+{
+ [config] String language;
+ [config] String code;
+};
--- /dev/null
+%{
+/******************************************************************************
+ * 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 "classcompiler.h"
+ #include "class_parser.h"
+
+using namespace icinga;
+
+#define YY_EXTRA_TYPE ClassCompiler *
+#define YY_USER_ACTION \
+do { \
+ yylloc->path = yyextra->GetPath(); \
+ yylloc->first_line = yylineno; \
+ yylloc->first_column = yycolumn; \
+ yylloc->last_line = yylineno; \
+ yylloc->last_column = yycolumn + yyleng - 1;\
+ yycolumn += yyleng; \
+} while (0);
+
+#define YY_INPUT(buf, result, max_size) \
+do { \
+ result = yyextra->ReadInput(buf, max_size); \
+} while (0)
+
+struct lex_buf {
+ char *buf;
+ size_t size;
+};
+
+static void lb_init(lex_buf *lb)
+{
+ lb->buf = NULL;
+ lb->size = 0;
+}
+
+static void lb_cleanup(lex_buf *lb)
+{
+ free(lb->buf);
+}
+
+static void lb_append_char(lex_buf *lb, char new_char)
+{
+ const size_t block_size = 64;
+
+ size_t old_blocks = (lb->size + (block_size - 1)) / block_size;
+ size_t new_blocks = ((lb->size + 1) + (block_size - 1)) / block_size;
+
+ if (old_blocks != new_blocks) {
+ char *new_buf = (char *)realloc(lb->buf, new_blocks * block_size);
+
+ if (new_buf == NULL && new_blocks > 0)
+ throw std::bad_alloc();
+
+ lb->buf = new_buf;
+ }
+
+ lb->size++;
+ lb->buf[lb->size - 1] = new_char;
+}
+
+static char *lb_steal(lex_buf *lb)
+{
+ lb_append_char(lb, '\0');
+
+ char *buf = lb->buf;
+ lb->buf = NULL;
+ lb->size = 0;
+ return buf;
+}
+%}
+
+%option reentrant noyywrap yylineno
+%option bison-bridge bison-locations
+%option never-interactive nounistd
+
+%x HEREDOC
+
+%%
+ lex_buf string_buf;
+
+\{\{\{ { lb_init(&string_buf); BEGIN(HEREDOC); }
+
+<HEREDOC>\}\}\} {
+ BEGIN(INITIAL);
+
+ lb_append_char(&string_buf, '\0');
+
+ yylval->text = lb_steal(&string_buf);
+
+ return T_STRING;
+ }
+
+<HEREDOC>(.|\n) { lb_append_char(&string_buf, yytext[0]); }
+
+[ \t\r\n] /* ignore whitespace */
+
+#include { return T_INCLUDE; }
+class { return T_CLASS; }
+namespace { return T_NAMESPACE; }
+code { return T_CODE; }
+config { yylval->num = FAConfig; return T_FIELD_ATTRIBUTE; }
+state { yylval->num = FAState; return T_FIELD_ATTRIBUTE; }
+enum { yylval->num = FAEnum; return T_FIELD_ATTRIBUTE; }
+get_protected { yylval->num = FAGetProtected; return T_FIELD_ATTRIBUTE; }
+set_protected { yylval->num = FASetProtected; return T_FIELD_ATTRIBUTE; }
+protected { yylval->num = FAGetProtected | FASetProtected; return T_FIELD_ATTRIBUTE; }
+default { yylval->num = FTDefault; return T_FIELD_ACCESSOR_TYPE; }
+get { yylval->num = FTGet; return T_FIELD_ACCESSOR_TYPE; }
+set { yylval->num = FTSet; return T_FIELD_ACCESSOR_TYPE; }
+\"[^\"]+\" { yylval->text = strdup(yytext + 1); yylval->text[strlen(yylval->text) - 1] = '\0'; return T_STRING; }
+\<[^>]+\> { yylval->text = strdup(yytext + 1); yylval->text[strlen(yylval->text) - 1] = '\0'; return T_ANGLE_STRING; }
+[a-zA-Z_][:a-zA-Z0-9\-_]* { yylval->text = strdup(yytext); return T_IDENTIFIER; }
+
+. return yytext[0];
+
+%%
+
+void ClassCompiler::InitializeScanner(void)
+{
+ yylex_init(&m_Scanner);
+ yyset_extra(this, m_Scanner);
+}
+
+void ClassCompiler::DestroyScanner(void)
+{
+ yylex_destroy(m_Scanner);
+}
--- /dev/null
+%code requires {
+/******************************************************************************
+ * 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 "classcompiler.h"
+ #include <iostream>
+ #include <vector>
+
+using namespace icinga;
+
+#define YYLTYPE icinga::ClassDebugInfo
+
+}
+
+%pure-parser
+
+%locations
+%defines
+%error-verbose
+
+%parse-param { ClassCompiler *context }
+%lex-param { void *scanner }
+
+%union {
+ char *text;
+ int num;
+ Field *field;
+ std::vector<Field> *fields;
+ Klass *klass;
+ FieldAccessor *fieldaccessor;
+ std::vector<FieldAccessor> *fieldaccessors;
+}
+
+%token T_INCLUDE "include (T_INCLUDE)"
+%token T_CLASS "class (T_CLASS)"
+%token T_CODE "code (T_CODE)"
+%token T_NAMESPACE "namespace (T_NAMESPACE)"
+%token T_STRING "string (T_STRING)"
+%token T_ANGLE_STRING "angle_string (T_ANGLE_STRING)"
+%token T_FIELD_ATTRIBUTE "field_attribute (T_FIELD_ATTRIBUTE)"
+%token T_IDENTIFIER "identifier (T_IDENTIFIER)"
+%token T_GET "get (T_GET)"
+%token T_SET "set (T_SET)"
+%token T_DEFAULT "default (T_DEFAULT)"
+%token T_FIELD_ACCESSOR_TYPE "field_accessor_type (T_FIELD_ACCESSOR_TYPE)"
+%type <text> T_IDENTIFIER
+%type <text> T_STRING
+%type <text> T_ANGLE_STRING
+%type <text> identifier
+%type <text> alternative_name_specifier
+%type <text> inherits_specifier
+%type <text> include
+%type <text> angle_include
+%type <text> code
+%type <num> T_FIELD_ATTRIBUTE
+%type <num> field_attributes
+%type <num> field_attribute_list
+%type <num> T_FIELD_ACCESSOR_TYPE
+%type <field> class_field
+%type <fields> class_fields
+%type <klass> class
+%type <fieldaccessors> field_accessor_list
+%type <fieldaccessors> field_accessors
+%type <fieldaccessor> field_accessor
+
+%{
+
+int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
+
+void yyerror(YYLTYPE *locp, ClassCompiler *, const char *err)
+{
+ std::cerr << "in " << locp->path << " at " << locp->first_line << ":" << locp->first_column << "-" << locp->last_line << ":" << locp->last_column << ": "
+ << err
+ << std::endl;
+}
+
+int yyparse(ClassCompiler *context);
+
+void ClassCompiler::Compile(void)
+{
+ try {
+ yyparse(this);
+ } catch (const std::exception& ex) {
+ std::cerr << "Exception: " << ex.what();
+ }
+}
+
+#define scanner (context->GetScanner())
+
+%}
+
+%%
+
+statements: /* empty */
+ | statements statement
+ ;
+
+statement: include
+ {
+ context->HandleInclude($1, yylloc);
+ free($1);
+ }
+ | angle_include
+ {
+ context->HandleAngleInclude($1, yylloc);
+ free($1);
+ }
+ | class
+ {
+ context->HandleClass(*$1, yylloc);
+ delete $1;
+ }
+ | namespace
+ | code
+ {
+ context->HandleCode($1, yylloc);
+ free($1);
+ }
+ ;
+
+include: T_INCLUDE T_STRING
+ {
+ $$ = $2;
+ }
+ ;
+
+angle_include: T_INCLUDE T_ANGLE_STRING
+ {
+ $$ = $2;
+ }
+ ;
+
+namespace: T_NAMESPACE identifier '{'
+ {
+ context->HandleNamespaceBegin($2, yylloc);
+ free($2);
+ }
+ statements '}'
+ {
+ context->HandleNamespaceEnd(yylloc);
+ }
+ ;
+
+code: T_CODE T_STRING
+ {
+ $$ = $2;
+ }
+ ;
+
+class: T_CLASS T_IDENTIFIER inherits_specifier '{' class_fields '}' ';'
+ {
+ $$ = new Klass();
+
+ $$->Name = $2;
+ free($2);
+
+ if ($3) {
+ $$->Parent = $3;
+ free($3);
+ }
+
+ $$->Fields = *$5;
+ delete $5;
+ }
+ ;
+
+inherits_specifier: /* empty */
+ {
+ $$ = NULL;
+ }
+ | ':' identifier
+ {
+ $$ = $2;
+ }
+ ;
+
+class_fields: /* empty */
+ {
+ $$ = new std::vector<Field>();
+ }
+ | class_fields class_field
+ {
+ $$->push_back(*$2);
+ delete $2;
+ }
+ ;
+
+class_field: field_attribute_list identifier identifier alternative_name_specifier field_accessor_list ';'
+ {
+ Field *field = new Field();
+
+ field->Attributes = $1;
+
+ field->Type = $2;
+ free($2);
+
+ field->Name = $3;
+ free($3);
+
+ if ($4) {
+ field->AlternativeName = $4;
+ free($4);
+ }
+
+ std::vector<FieldAccessor>::const_iterator it;
+ for (it = $5->begin(); it != $5->end(); it++) {
+ switch (it->Type) {
+ case FTGet:
+ field->GetAccessor = it->Accessor;
+ break;
+ case FTSet:
+ field->SetAccessor = it->Accessor;
+ break;
+ case FTDefault:
+ field->DefaultAccessor = it->Accessor;
+ break;
+ }
+ }
+
+ delete $5;
+
+ $$ = field;
+ }
+ ;
+
+alternative_name_specifier: /* empty */
+ {
+ $$ = NULL;
+ }
+ | '(' identifier ')'
+ {
+ $$ = $2;
+ }
+ ;
+
+field_attribute_list: /* empty */
+ {
+ $$ = 0;
+ }
+ | '[' field_attributes ']'
+ {
+ $$ = $2;
+ }
+ ;
+
+field_attributes: /* empty */
+ {
+ $$ = 0;
+ }
+ | field_attributes ',' T_FIELD_ATTRIBUTE
+ {
+ $$ = $1 | $3;
+ }
+ | T_FIELD_ATTRIBUTE
+ {
+ $$ = $1;
+ }
+ ;
+
+field_accessor_list: /* empty */
+ {
+ $$ = new std::vector<FieldAccessor>();
+ }
+ | '{' field_accessors '}'
+ {
+ $$ = $2;
+ }
+ ;
+
+field_accessors: /* empty */
+ {
+ $$ = new std::vector<FieldAccessor>();
+ }
+ | field_accessors field_accessor
+ {
+ $$ = $1;
+ $$->push_back(*$2);
+ delete $2;
+ }
+ ;
+
+field_accessor: T_FIELD_ACCESSOR_TYPE T_STRING
+ {
+ $$ = new FieldAccessor(static_cast<FieldAccessorType>($1), $2);
+ free($2);
+ }
+ ;
+
+identifier: T_IDENTIFIER
+ | T_STRING
+ {
+ $$ = $1;
+ }
+ ;
--- /dev/null
+/******************************************************************************
+ * 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 "classcompiler.h"
+#include <iostream>
+#include <fstream>
+#include <stdexcept>
+
+using namespace icinga;
+
+ClassCompiler::ClassCompiler(const std::string& path, std::istream *input)
+ : m_Path(path), m_Input(input)
+{
+ InitializeScanner();
+}
+
+ClassCompiler::~ClassCompiler(void)
+{
+ DestroyScanner();
+}
+
+std::string ClassCompiler::GetPath(void) const
+{
+ return m_Path;
+}
+
+void *ClassCompiler::GetScanner(void)
+{
+ return m_Scanner;
+}
+
+size_t ClassCompiler::ReadInput(char *buffer, size_t max_size)
+{
+ m_Input->read(buffer, max_size);
+ return static_cast<size_t>(m_Input->gcount());
+}
+
+void ClassCompiler::HandleInclude(const std::string& path, const ClassDebugInfo& locp)
+{
+ std::cout << "#include \"" << path << "\"" << std::endl << std::endl;
+}
+
+void ClassCompiler::HandleAngleInclude(const std::string& path, const ClassDebugInfo& locp)
+{
+ std::cout << "#include <" << path << ">" << std::endl << std::endl;
+}
+
+void ClassCompiler::HandleNamespaceBegin(const std::string& name, const ClassDebugInfo& locp)
+{
+ std::cout << "namespace " << name << std::endl
+ << "{" << std::endl << std::endl;
+}
+
+void ClassCompiler::HandleNamespaceEnd(const ClassDebugInfo& locp)
+{
+ std::cout << "}" << std::endl;
+}
+
+void ClassCompiler::HandleCode(const std::string& code, const ClassDebugInfo& locp)
+{
+ std::cout << code << std::endl;
+}
+
+void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo& locp)
+{
+ std::vector<Field>::const_iterator it;
+
+ if (klass.Name.find_first_of(':') == std::string::npos)
+ std::cout << "class " << klass.Name << ";" << std::endl << std::endl;
+
+ std::cout << "template<>" << std::endl
+ << "class ReflectionObjectImpl<" << klass.Name << ">"
+ << " : public " << (klass.Parent.empty() ? "ReflectionObject" : klass.Parent) << std::endl
+ << "{" << std::endl
+ << "public:" << std::endl
+ << "\t" << "DECLARE_PTR_TYPEDEFS(ReflectionObjectImpl<" << klass.Name << ">);" << std::endl;
+
+ if (!klass.Fields.empty()) {
+ /* constructor */
+ std::cout << "public:" << std::endl
+ << "\t" << "ReflectionObjectImpl<" << klass.Name << ">(void)" << std::endl
+ << "\t" << "{" << std::endl;
+
+ for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
+ std::cout << "\t\t" << "Set" << it->GetFriendlyName() << "(" << "GetDefault" << it->GetFriendlyName() << "());" << std::endl;
+ }
+
+ std::cout << "\t" << "}" << std::endl << std::endl;
+
+ /* GetFieldId */
+ std::cout << "public:" << std::endl
+ << "\t" << "virtual int GetFieldId(const String& name) const" << std::endl
+ << "\t" << "{" << std::endl
+ << "\t\t" << "int offset = ";
+
+ if (!klass.Parent.empty())
+ std::cout << klass.Parent << "::GetFieldCount()";
+ else
+ std::cout << "0";
+
+ std::cout << ";" << std::endl << std::endl;
+
+ int num = 0;
+ for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
+ std::cout << "\t\t" << "if (name == \"" << it->Name << "\")" << std::endl
+ << "\t\t\t" << "return offset + " << num << ";" << std::endl;
+ num++;
+ }
+
+ std::cout << std::endl
+ << "\t\t" << "return ";
+
+ if (!klass.Parent.empty())
+ std::cout << klass.Parent << "::GetFieldId(name)";
+ else
+ std::cout << "-1";
+
+ std::cout << ";" << std::endl
+ << "\t" << "}" << std::endl << std::endl;
+
+ /* GetFieldInfo */
+ std::cout << "public:" << std::endl
+ << "\t" << "virtual ReflectionField GetFieldInfo(int id) const" << std::endl
+ << "\t" << "{" << std::endl;
+
+ if (!klass.Parent.empty())
+ std::cout << "\t\t" << "int real_id = id - " << klass.Parent << "::GetFieldCount();" << std::endl
+ << "\t\t" << "if (real_id < 0) { return " << klass.Parent << "::GetFieldInfo(id); }" << std::endl;
+
+ std::cout << "\t\t" << "switch (";
+
+ if (!klass.Parent.empty())
+ std::cout << "real_id";
+ else
+ std::cout << "id";
+
+ std::cout << ") {" << std::endl;
+
+ num = 0;
+ for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
+ std::cout << "\t\t\t" << "case " << num << ":" << std::endl
+ << "\t\t\t\t" << "return ReflectionField(" << num << ", \"" << it->Name << "\", " << it->Attributes << ", " << "GetDefault" << it->GetFriendlyName() << "());" << std::endl;
+ num++;
+ }
+
+ std::cout << "\t\t\t" << "default:" << std::endl
+ << "\t\t\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl
+ << "\t\t" << "}" << std::endl;
+
+ std::cout << "\t" << "}" << std::endl << std::endl;
+
+ /* GetFieldCount */
+ std::cout << "public:" << std::endl
+ << "\t" << "virtual int GetFieldCount(void) const" << std::endl
+ << "\t" << "{" << std::endl
+ << "\t\t" << "return " << klass.Fields.size();
+
+ if (!klass.Parent.empty())
+ std::cout << " + " << klass.Parent + "::GetFieldCount()";
+
+ std::cout << ";" << std::endl
+ << "\t" << "}" << std::endl << std::endl;
+
+ /* SetField */
+ std::cout << "protected:" << std::endl
+ << "\t" << "virtual void SetField(int id, const Value& value)" << std::endl
+ << "\t" << "{" << std::endl;
+
+ if (!klass.Parent.empty())
+ std::cout << "\t\t" << "int real_id = id - " << klass.Parent << "::GetFieldCount();" << std::endl
+ << "\t\t" << "if (real_id < 0) { " << klass.Parent << "::SetField(id, value); return; }" << std::endl;
+
+ std::cout << "\t\t" << "switch (";
+
+ if (!klass.Parent.empty())
+ std::cout << "real_id";
+ else
+ std::cout << "id";
+
+ std::cout << ") {" << std::endl;
+
+ num = 0;
+ for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
+ std::cout << "\t\t\t" << "case " << num << ":" << std::endl
+ << "\t\t\t\t" << "Set" << it->GetFriendlyName() << "(";
+
+ if (it->Attributes & FAEnum)
+ std::cout << "static_cast<" << it->Type << ">(static_cast<int>(";
+
+ std::cout << "value";
+
+ if (it->Attributes & FAEnum)
+ std::cout << "))";
+
+ std::cout << ");" << std::endl
+ << "\t\t\t\t" << "break;" << std::endl;
+ num++;
+ }
+
+ std::cout << "\t\t\t" << "default:" << std::endl
+ << "\t\t\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl
+ << "\t\t" << "}" << std::endl;
+
+ std::cout << "\t" << "}" << std::endl << std::endl;
+
+ /* GetField */
+ std::cout << "protected:" << std::endl
+ << "\t" << "virtual Value GetField(int id) const" << std::endl
+ << "\t" << "{" << std::endl;
+
+ if (!klass.Parent.empty())
+ std::cout << "\t\t" << "int real_id = id - " << klass.Parent << "::GetFieldCount();" << std::endl
+ << "\t\t" << "if (real_id < 0) { return " << klass.Parent << "::GetField(id); }" << std::endl;
+
+ std::cout << "\t\t" << "switch (";
+
+ if (!klass.Parent.empty())
+ std::cout << "real_id";
+ else
+ std::cout << "id";
+
+ std::cout << ") {" << std::endl;
+
+ num = 0;
+ for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
+ std::cout << "\t\t\t" << "case " << num << ":" << std::endl
+ << "\t\t\t\t" << "return Get" << it->GetFriendlyName() << "();" << std::endl;
+ num++;
+ }
+
+ std::cout << "\t\t\t" << "default:" << std::endl
+ << "\t\t\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl
+ << "\t\t" << "}" << std::endl;
+
+ std::cout << "\t" << "}" << std::endl << std::endl;
+
+ /* getters */
+ for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
+ std::string prot;
+
+ if (it->Attributes & FAGetProtected)
+ prot = "protected";
+ else
+ prot = "public";
+
+ std::cout << prot << ":" << std::endl
+ << "\t" << it->Type << " Get" << it->GetFriendlyName() << "(void) const" << std::endl
+ << "\t" << "{" << std::endl;
+
+ if (it->GetAccessor.empty())
+ std::cout << "\t\t" << "return m_" << it->GetFriendlyName() << ";" << std::endl;
+ else
+ std::cout << it->GetAccessor << std::endl;
+
+ std::cout << "\t" << "}" << std::endl << std::endl;
+ }
+
+ /* setters */
+ for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
+ std::string prot;
+
+ if (it->Attributes & FASetProtected)
+ prot = "protected";
+ else if (it->Attributes & FAConfig)
+ prot = "private";
+ else
+ prot = "public";
+
+ std::cout << prot << ":" << std::endl
+ << "\t" << "void Set" << it->GetFriendlyName() << "(const " << it->Type << "& value)" << std::endl
+ << "\t" << "{" << std::endl;
+
+ if (it->SetAccessor.empty())
+ std::cout << "\t\t" << "m_" << it->GetFriendlyName() << " = value;" << std::endl;
+ else
+ std::cout << it->SetAccessor << std::endl;
+
+ std::cout << "\t" << "}" << std::endl << std::endl;
+ }
+
+ /* default */
+ for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
+ std::string prot;
+
+ std::cout << "private:" << std::endl
+ << "\t" << it->Type << " GetDefault" << it->GetFriendlyName() << "(void) const" << std::endl
+ << "\t" << "{" << std::endl;
+
+ if (it->DefaultAccessor.empty())
+ std::cout << "\t\t" << "return Empty;" << std::endl;
+ else
+ std::cout << it->DefaultAccessor << std::endl;
+
+ std::cout << "\t" << "}" << std::endl;
+ }
+
+ /* instance variables */
+ std::cout << "private:" << std::endl;
+
+ for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
+ std::cout << "\t" << it->Type << " m_" << it->GetFriendlyName() << ";" << std::endl;
+ }
+ }
+
+ std::cout << "};" << std::endl << std::endl;
+}
+
+void ClassCompiler::CompileFile(const std::string& path)
+{
+ std::ifstream stream;
+ stream.open(path.c_str(), std::ifstream::in);
+
+ if (!stream)
+ throw std::invalid_argument("Could not open config file: " + path);
+
+ std::cerr << "Compiling class file: " + path << std::endl;
+
+ return CompileStream(path, &stream);
+}
+
+void ClassCompiler::CompileStream(const std::string& path, std::istream *stream)
+{
+ stream->exceptions(std::istream::badbit);
+
+ std::cout << "#include \"base/reflectionobject.h\"" << std::endl
+ << "#include \"base/debug.h\"" << std::endl
+ << "#include \"base/value.h\"" << std::endl
+ << "#include \"base/array.h\"" << std::endl
+ << "#include \"base/dictionary.h\"" << std::endl << std::endl
+ << "#ifdef _MSC_VER" << std::endl
+ << "#pragma warning( push )" << std::endl
+ << "#pragma warning( disable : 4244 )" << std::endl
+ << "#pragma warning( disable : 4800 )" << std::endl
+ << "#endif /* _MSC_VER */" << std::endl << std::endl;
+
+ ClassCompiler ctx(path, stream);
+ ctx.Compile();
+
+ std::cout << "#ifdef _MSC_VER" << std::endl
+ << "#pragma warning ( pop )" << std::endl
+ << "#endif /* _MSC_VER */" << std::endl;
+}
--- /dev/null
+/******************************************************************************
+ * 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 CLASSCOMPILER_H
+#define CLASSCOMPILER_H
+
+#include <string>
+#include <istream>
+#include <vector>
+#include <algorithm>
+
+struct YYLTYPE;
+
+namespace icinga
+{
+
+struct ClassDebugInfo
+{
+ std::string path;
+ int first_line;
+ int first_column;
+ int last_line;
+ int last_column;
+};
+
+enum FieldAccessorType
+{
+ FTGet,
+ FTSet,
+ FTDefault
+};
+
+struct FieldAccessor
+{
+ FieldAccessorType Type;
+ std::string Accessor;
+
+ FieldAccessor(FieldAccessorType type, const std::string& accessor)
+ : Type(type), Accessor(accessor)
+ { }
+};
+
+enum FieldAttribute
+{
+ FAConfig = 1,
+ FAState = 2,
+ FAEnum = 4,
+ FAGetProtected = 8,
+ FASetProtected = 16
+};
+
+struct Field
+{
+ int Attributes;
+ std::string Type;
+ std::string Name;
+ std::string AlternativeName;
+ std::string GetAccessor;
+ std::string SetAccessor;
+ std::string DefaultAccessor;
+
+ std::string GetFriendlyName(void) const
+ {
+ if (!AlternativeName.empty())
+ return AlternativeName;
+
+ bool cap = true;
+ std::string name = Name;
+
+ for (size_t i = 0; i < name.size(); i++) {
+ if (name[i] == '_') {
+ cap = true;
+ continue;
+ }
+
+ if (cap) {
+ name[i] = toupper(name[i]);
+ cap = false;
+ }
+ }
+
+ name.erase(
+ std::remove(name.begin(), name.end(), '_'),
+ name.end()
+ );
+
+ /* TODO: figure out name */
+ return name;
+ }
+};
+
+struct Klass
+{
+ std::string Name;
+ std::string Parent;
+ std::vector<Field> Fields;
+};
+
+class ClassCompiler
+{
+public:
+ ClassCompiler(const std::string& path, std::istream *input);
+ ~ClassCompiler(void);
+
+ void Compile(void);
+
+ std::string GetPath(void) const;
+
+ void InitializeScanner(void);
+ void DestroyScanner(void);
+
+ void *GetScanner(void);
+
+ size_t ReadInput(char *buffer, size_t max_size);
+
+ void HandleInclude(const std::string& path, const ClassDebugInfo& locp);
+ void HandleAngleInclude(const std::string& path, const ClassDebugInfo& locp);
+ void HandleClass(const Klass& klass, const ClassDebugInfo& locp);
+ void HandleNamespaceBegin(const std::string& name, const ClassDebugInfo& locp);
+ void HandleNamespaceEnd(const ClassDebugInfo& locp);
+ void HandleCode(const std::string& code, const ClassDebugInfo& locp);
+
+ static void CompileFile(const std::string& path);
+ static void CompileStream(const std::string& path, std::istream *stream);
+
+private:
+ std::string m_Path;
+ std::istream *m_Input;
+ void *m_Scanner;
+};
+
+}
+
+#endif /* CLASSCOMPILER_H */
\ No newline at end of file
--- /dev/null
+/******************************************************************************
+ * 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 "classcompiler.h"
+#include <iostream>
+
+using namespace icinga;
+
+int main(int argc, char **argv)
+{
+ if (argc < 1) {
+ std::cerr << "Syntax: " << argv[0] << " <file>" << std::endl;
+ return 1;
+ }
+
+ ClassCompiler::CompileFile(argv[1]);
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Quelldateien">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ <Filter Include="Headerdateien">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+ </Filter>
+ <Filter Include="Ressourcendateien">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="mkembedconfig.c">
+ <Filter>Quelldateien</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+</Project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="..\..\packages\openssl.1.0.1.24\build\native\openssl.props" Condition="Exists('..\..\packages\openssl.1.0.1.24\build\native\openssl.props')" />
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{CBC9DD83-BAEB-4995-8D0B-F711898908E7}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>mkclass</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>MultiByte</CharacterSet>
+ <PlatformToolset>v110</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>MultiByte</CharacterSet>
+ <PlatformToolset>v110</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ <PlatformToolset>v110</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ <PlatformToolset>v110</PlatformToolset>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LinkIncremental>true</LinkIncremental>
+ <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <LinkIncremental>true</LinkIncremental>
+ <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <LinkIncremental>false</LinkIncremental>
+ <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="classcompiler.cpp" />
+ <ClCompile Include="class_lexer.cc" />
+ <ClCompile Include="class_parser.cc" />
+ <ClCompile Include="mkclass.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <CustomBuild Include="class_parser.yy">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">win_bison -d "%(FullPath)"
+del class_parser.cc
+ren class_parser.tab.cc class_parser.cc
+del class_parser.h
+ren class_parser.tab.hh class_parser.h</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">win_bison -d "%(FullPath)"
+del class_parser.cc
+ren class_parser.tab.cc class_parser.cc
+del class_parser.h
+ren class_parser.tab.hh class_parser.h</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">win_bison -d "%(FullPath)"
+del class_parser.cc
+ren class_parser.tab.cc class_parser.cc
+del class_parser.h
+ren class_parser.tab.hh class_parser.h</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">win_bison -d "%(FullPath)"
+del class_parser.cc
+ren class_parser.tab.cc class_parser.cc
+del class_parser.h
+ren class_parser.tab.hh class_parser.h</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">class_parser.cc;class_parser.h</Outputs>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">class_parser.cc;class_parser.h</Outputs>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">class_parser.cc;class_parser.h</Outputs>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">class_parser.cc;class_parser.h</Outputs>
+ </CustomBuild>
+ <CustomBuild Include="class_lexer.ll">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">win_flex "%(FullPath)"
+del class_lexer.cc
+ren lex.yy.c class_lexer.cc</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">class_lexer.cc</Outputs>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">win_flex "%(FullPath)"
+del class_lexer.cc
+ren lex.yy.c class_lexer.cc</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">class_lexer.cc</Outputs>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">win_flex "%(FullPath)"
+del class_lexer.cc
+ren lex.yy.c class_lexer.cc</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">class_lexer.cc</Outputs>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">win_flex "%(FullPath)"
+del class_lexer.cc
+ren lex.yy.c class_lexer.cc</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">class_lexer.cc</Outputs>
+ </CustomBuild>
+ <None Include="base.int" />
+ <None Include="icinga.int" />
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="classcompiler.h" />
+ <ClInclude Include="class_parser.h" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ <Import Project="..\..\packages\boost.1.54.0.1\build\native\boost.targets" Condition="Exists('..\..\packages\boost.1.54.0.1\build\native\boost.targets')" />
+ <Import Project="..\..\packages\boost_thread.1.54.0.2\build\native\boost_thread.targets" Condition="Exists('..\..\packages\boost_thread.1.54.0.2\build\native\boost_thread.targets')" />
+ <Import Project="..\..\packages\boost_system.1.54.0.2\build\native\boost_system.targets" Condition="Exists('..\..\packages\boost_system.1.54.0.2\build\native\boost_system.targets')" />
+ <Import Project="..\..\packages\boost_exception.1.54.0.2\build\native\boost_exception.targets" Condition="Exists('..\..\packages\boost_exception.1.54.0.2\build\native\boost_exception.targets')" />
+ <Import Project="..\..\packages\boost_program_options.1.54.0.2\build\native\boost_program_options.targets" Condition="Exists('..\..\packages\boost_program_options.1.54.0.2\build\native\boost_program_options.targets')" />
+ <Import Project="..\..\packages\boost_unit_test_framework.1.54.0.2\build\native\boost_unit_test_framework.targets" Condition="Exists('..\..\packages\boost_unit_test_framework.1.54.0.2\build\native\boost_unit_test_framework.targets')" />
+ <Import Project="..\..\packages\zlib.redist.1.2.8.6\build\native\zlib.redist.targets" Condition="Exists('..\..\packages\zlib.redist.1.2.8.6\build\native\zlib.redist.targets')" />
+ <Import Project="..\..\packages\zlib.1.2.8.6\build\native\zlib.targets" Condition="Exists('..\..\packages\zlib.1.2.8.6\build\native\zlib.targets')" />
+ <Import Project="..\..\packages\openssl.redist.1.0.1.24\build\native\openssl.redist.targets" Condition="Exists('..\..\packages\openssl.redist.1.0.1.24\build\native\openssl.redist.targets')" />
+ <Import Project="..\..\packages\openssl.1.0.1.24\build\native\openssl.targets" Condition="Exists('..\..\packages\openssl.1.0.1.24\build\native\openssl.targets')" />
+ <Import Project="..\..\packages\boost_date_time.1.54.0.2\build\native\boost_date_time.targets" Condition="Exists('..\..\packages\boost_date_time.1.54.0.2\build\native\boost_date_time.targets')" />
+ <Import Project="..\..\packages\boost_chrono.1.54.0.2\build\native\boost_chrono.targets" Condition="Exists('..\..\packages\boost_chrono.1.54.0.2\build\native\boost_chrono.targets')" />
+ </ImportGroup>
+</Project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="boost" version="1.54.0.1" targetFramework="Native" />
+ <package id="boost_chrono" version="1.54.0.2" targetFramework="Native" />
+ <package id="boost_date_time" version="1.54.0.2" targetFramework="Native" />
+ <package id="boost_exception" version="1.54.0.2" targetFramework="Native" />
+ <package id="boost_program_options" version="1.54.0.2" targetFramework="Native" />
+ <package id="boost_system" version="1.54.0.2" targetFramework="Native" />
+ <package id="boost_thread" version="1.54.0.2" targetFramework="Native" />
+ <package id="boost_unit_test_framework" version="1.54.0.2" targetFramework="Native" />
+ <package id="openssl" version="1.0.1.24" targetFramework="Native" />
+ <package id="openssl.redist" version="1.0.1.24" targetFramework="Native" />
+ <package id="zlib" version="1.2.8.6" targetFramework="Native" />
+ <package id="zlib.redist" version="1.2.8.6" targetFramework="Native" />
+</packages>
\ No newline at end of file