2013-07-05 09:37:04 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2018-10-18 09:27:04 +02:00
|
|
|
* Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/) *
|
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
|
|
|
|
*/
|
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 */
|