2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-07-05 09:37:04 +02:00
|
|
|
|
|
|
|
#ifndef DBOBJECT_H
|
|
|
|
#define DBOBJECT_H
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "db_ido/i2-db_ido.hpp"
|
|
|
|
#include "db_ido/dbreference.hpp"
|
|
|
|
#include "db_ido/dbquery.hpp"
|
|
|
|
#include "db_ido/dbtype.hpp"
|
|
|
|
#include "icinga/customvarobject.hpp"
|
2015-08-15 20:28:05 +02:00
|
|
|
#include "base/configobject.hpp"
|
2013-07-05 09:37:04 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2013-07-22 12:08:49 +02:00
|
|
|
enum DbObjectUpdateType
|
2013-07-05 09:37:04 +02:00
|
|
|
{
|
|
|
|
DbObjectCreated,
|
|
|
|
DbObjectRemoved
|
|
|
|
};
|
|
|
|
|
2013-08-02 17:12:07 +02:00
|
|
|
enum DbObjectType
|
|
|
|
{
|
|
|
|
DbObjectTypeHost = 1,
|
|
|
|
DbObjectTypeService = 2,
|
|
|
|
DbObjectTypeHostGroup = 3,
|
|
|
|
DbObjectTypeServiceGroup = 4,
|
|
|
|
DbObjectTypeHostEscalation = 5,
|
|
|
|
DbObjectTypeServiceEscalation = 6,
|
|
|
|
DbObjectTypeHostDependency = 7,
|
|
|
|
DbObjectTypeServiceDependency = 8,
|
|
|
|
DbObjectTypeTimePeriod = 9,
|
|
|
|
DbObjectTypeContact = 10,
|
|
|
|
DbObjectTypeContactGroup = 11,
|
|
|
|
DbObjectTypeCommand = 12,
|
2014-02-21 14:12:34 +01:00
|
|
|
DbObjectTypeEndpoint = 13,
|
2015-06-17 15:45:45 +02:00
|
|
|
DbObjectTypeZone = 14,
|
2013-08-02 17:12:07 +02:00
|
|
|
};
|
|
|
|
|
2013-07-05 09:37:04 +02:00
|
|
|
/**
|
|
|
|
* A database object.
|
|
|
|
*
|
|
|
|
* @ingroup ido
|
|
|
|
*/
|
2017-12-31 07:22:16 +01:00
|
|
|
class DbObject : public Object
|
2013-07-05 09:37:04 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-11-07 18:37:07 +01:00
|
|
|
DECLARE_PTR_TYPEDEFS(DbObject);
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
static void StaticInitialize();
|
2013-08-01 11:14:33 +02:00
|
|
|
|
2015-08-15 20:28:05 +02:00
|
|
|
void SetObject(const ConfigObject::Ptr& object);
|
2018-01-04 04:25:35 +01:00
|
|
|
ConfigObject::Ptr GetObject() const;
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
String GetName1() const;
|
|
|
|
String GetName2() const;
|
|
|
|
intrusive_ptr<DbType> GetType() const;
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
virtual Dictionary::Ptr GetConfigFields() const = 0;
|
|
|
|
virtual Dictionary::Ptr GetStatusFields() const = 0;
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2015-08-15 20:28:05 +02:00
|
|
|
static DbObject::Ptr GetOrCreateByObject(const ConfigObject::Ptr& object);
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2013-07-22 12:08:49 +02:00
|
|
|
static boost::signals2::signal<void (const DbQuery&)> OnQuery;
|
2015-12-14 11:36:03 +01:00
|
|
|
static boost::signals2::signal<void (const std::vector<DbQuery>&)> OnMultipleQueries;
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
void SendConfigUpdateHeavy(const Dictionary::Ptr& configFields);
|
2018-01-04 04:25:35 +01:00
|
|
|
void SendConfigUpdateLight();
|
|
|
|
void SendStatusUpdate();
|
|
|
|
void SendVarsConfigUpdateHeavy();
|
|
|
|
void SendVarsStatusUpdate();
|
2013-07-17 11:29:51 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
double GetLastConfigUpdate() const;
|
|
|
|
double GetLastStatusUpdate() const;
|
2013-07-24 10:55:04 +02:00
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
virtual String CalculateConfigHash(const Dictionary::Ptr& configFields) const;
|
|
|
|
|
2013-07-05 09:37:04 +02:00
|
|
|
protected:
|
2018-01-04 08:54:18 +01:00
|
|
|
DbObject(intrusive_ptr<DbType> type, String name1, String name2);
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
virtual void OnConfigUpdateHeavy();
|
|
|
|
virtual void OnConfigUpdateLight();
|
|
|
|
virtual void OnStatusUpdate();
|
2013-07-25 08:30:02 +02:00
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
static String HashValue(const Value& value);
|
|
|
|
|
2013-07-05 09:37:04 +02:00
|
|
|
private:
|
|
|
|
String m_Name1;
|
|
|
|
String m_Name2;
|
2014-11-08 21:17:16 +01:00
|
|
|
intrusive_ptr<DbType> m_Type;
|
2015-08-15 20:28:05 +02:00
|
|
|
ConfigObject::Ptr m_Object;
|
2013-07-24 10:55:04 +02:00
|
|
|
double m_LastConfigUpdate;
|
|
|
|
double m_LastStatusUpdate;
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2015-08-15 20:28:05 +02:00
|
|
|
static void StateChangedHandler(const ConfigObject::Ptr& object);
|
2014-05-12 16:45:25 +02:00
|
|
|
static void VarsChangedHandler(const CustomVarObject::Ptr& object);
|
2015-09-15 11:59:09 +02:00
|
|
|
static void VersionChangedHandler(const ConfigObject::Ptr& object);
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
static boost::mutex& GetStaticMutex();
|
2013-07-05 09:37:04 +02:00
|
|
|
|
|
|
|
friend class DbType;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DBOBJECT_H */
|