2013-07-05 09:37:04 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2016-01-12 08:29:59 +01:00
|
|
|
* Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) *
|
2013-07-05 09:37:04 +02:00
|
|
|
* *
|
|
|
|
* 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 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
|
|
|
|
*/
|
2013-11-03 13:45:26 +01:00
|
|
|
class I2_DB_IDO_API 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
|
|
|
|
2013-08-01 11:14:33 +02:00
|
|
|
static void StaticInitialize(void);
|
|
|
|
|
2015-08-15 20:28:05 +02:00
|
|
|
void SetObject(const ConfigObject::Ptr& object);
|
|
|
|
ConfigObject::Ptr GetObject(void) const;
|
2013-07-05 09:37:04 +02:00
|
|
|
|
|
|
|
String GetName1(void) const;
|
|
|
|
String GetName2(void) const;
|
2014-11-08 21:17:16 +01:00
|
|
|
intrusive_ptr<DbType> GetType(void) const;
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2013-07-22 12:08:49 +02:00
|
|
|
virtual Dictionary::Ptr GetConfigFields(void) const = 0;
|
|
|
|
virtual Dictionary::Ptr GetStatusFields(void) 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);
|
|
|
|
void SendConfigUpdateLight(void);
|
2014-03-20 15:41:45 +01:00
|
|
|
void SendStatusUpdate(void);
|
2016-08-14 22:24:51 +02:00
|
|
|
void SendVarsConfigUpdateHeavy(void);
|
2014-04-15 17:33:56 +02:00
|
|
|
void SendVarsStatusUpdate(void);
|
2013-07-17 11:29:51 +02:00
|
|
|
|
2013-07-24 10:55:04 +02:00
|
|
|
double GetLastConfigUpdate(void) const;
|
|
|
|
double GetLastStatusUpdate(void) const;
|
|
|
|
|
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:
|
2014-11-08 21:17:16 +01:00
|
|
|
DbObject(const intrusive_ptr<DbType>& type, const String& name1, const String& name2);
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
virtual void OnConfigUpdateHeavy(void);
|
|
|
|
virtual void OnConfigUpdateLight(void);
|
2013-07-25 08:30:02 +02:00
|
|
|
virtual void OnStatusUpdate(void);
|
|
|
|
|
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);
|
|
|
|
|
2015-03-02 16:20:22 +01:00
|
|
|
static boost::mutex& GetStaticMutex(void);
|
2013-07-05 09:37:04 +02:00
|
|
|
|
|
|
|
friend class DbType;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DBOBJECT_H */
|