icinga2/lib/icingadb/icingadb.hpp

132 lines
5.2 KiB
C++
Raw Normal View History

2019-11-02 14:00:06 +01:00
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2017-09-25 14:41:43 +02:00
2019-11-02 17:24:34 +01:00
#ifndef ICINGADB_H
#define ICINGADB_H
2017-09-25 14:41:43 +02:00
2019-10-29 18:36:16 +01:00
#include "icingadb/icingadb-ti.hpp"
2019-11-02 18:01:31 +01:00
#include "icingadb/redisconnection.hpp"
2017-09-25 14:41:43 +02:00
#include "base/timer.hpp"
#include "base/workqueue.hpp"
2019-11-02 18:01:31 +01:00
#include "icinga/customvarobject.hpp"
2018-11-15 17:04:03 +01:00
#include "icinga/checkable.hpp"
2018-12-07 16:33:10 +01:00
#include "icinga/service.hpp"
2018-11-30 09:28:20 +01:00
#include "icinga/downtime.hpp"
2019-11-02 18:01:31 +01:00
#include "remote/messageorigin.hpp"
2018-10-30 12:51:55 +01:00
#include <memory>
2017-09-25 14:41:43 +02:00
namespace icinga
{
/**
2019-10-29 18:36:16 +01:00
* @ingroup icingadb
2017-09-25 14:41:43 +02:00
*/
class IcingaDB : public ObjectImpl<IcingaDB>
2017-09-25 14:41:43 +02:00
{
public:
DECLARE_OBJECT(IcingaDB);
DECLARE_OBJECTNAME(IcingaDB);
2017-09-25 14:41:43 +02:00
IcingaDB();
2017-09-25 14:41:43 +02:00
2018-05-15 14:43:01 +02:00
static void ConfigStaticInitialize();
2017-09-25 14:41:43 +02:00
virtual void Start(bool runtimeCreated) override;
virtual void Stop(bool runtimeRemoved) override;
private:
2018-05-15 14:43:01 +02:00
void ReconnectTimerHandler();
void TryToReconnect();
void HandleEvents();
2017-10-16 12:03:49 +02:00
void SendEvent(const Dictionary::Ptr& event);
2017-09-25 14:41:43 +02:00
2018-05-15 14:43:01 +02:00
void PublishStatsTimerHandler();
void PublishStats();
2017-09-25 14:41:43 +02:00
/* config & status dump */
2018-05-15 14:43:01 +02:00
void UpdateAllConfigObjects();
std::vector<std::vector<intrusive_ptr<ConfigObject>>> ChunkObjects(std::vector<intrusive_ptr<ConfigObject>> objects, size_t chunkSize);
void DeleteKeys(const std::vector<String>& keys, RedisConnection::QueryPriority priority);
2019-06-14 11:52:34 +02:00
std::vector<String> GetTypeObjectKeys(const String& type);
void InsertObjectDependencies(const ConfigObject::Ptr& object, const String typeName, std::map<String, std::vector<String>>& hMSets,
std::map<String, std::vector<String>>& publishes, bool runtimeUpdate);
2018-11-15 17:04:03 +01:00
void UpdateState(const Checkable::Ptr& checkable);
void SendConfigUpdate(const ConfigObject::Ptr& object, bool runtimeUpdate);
void CreateConfigUpdate(const ConfigObject::Ptr& object, const String type, std::map<String, std::vector<String>>& hMSets,
std::map<String, std::vector<String>>& publishes, bool runtimeUpdate);
void SendConfigDelete(const ConfigObject::Ptr& object);
void SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type);
void SendSentNotification(
const Notification::Ptr& notification, const Checkable::Ptr& checkable, const std::set<User::Ptr>& users,
NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text
);
void SendStartedDowntime(const Downtime::Ptr& downtime);
void SendRemovedDowntime(const Downtime::Ptr& downtime);
void SendAddedComment(const Comment::Ptr& comment);
void SendRemovedComment(const Comment::Ptr& comment);
void SendFlappingChanged(const Checkable::Ptr& checkable, const Value& value);
2019-11-27 13:13:58 +01:00
void SendNextUpdate(const Checkable::Ptr& checkable);
void SendAcknowledgementSet(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double expiry);
void SendAcknowledgementCleared(const Checkable::Ptr& checkable, const String& removedBy);
2018-11-12 17:45:32 +01:00
std::vector<String> UpdateObjectAttrs(const ConfigObject::Ptr& object, int fieldType, const String& typeNameOverride);
2018-11-15 17:04:03 +01:00
Dictionary::Ptr SerializeState(const Checkable::Ptr& checkable);
2017-09-25 14:41:43 +02:00
2018-06-08 11:38:36 +02:00
/* Stats */
Dictionary::Ptr GetStats();
2017-09-25 14:41:43 +02:00
/* utilities */
static String FormatCheckSumBinary(const String& str);
2018-12-03 15:47:05 +01:00
static String FormatCommandLine(const Value& commandLine);
static long long TimestampToMilliseconds(double timestamp);
2017-09-25 14:41:43 +02:00
static String GetObjectIdentifier(const ConfigObject::Ptr& object);
static String GetEnvironment();
static Dictionary::Ptr SerializeVars(const CustomVarObject::Ptr& object);
2017-09-25 14:41:43 +02:00
2017-10-02 10:05:56 +02:00
static String HashValue(const Value& value);
static String HashValue(const Value& value, const std::set<String>& propertiesBlacklist, bool propertiesWhitelist = false);
2017-09-25 14:41:43 +02:00
2018-10-29 13:48:15 +01:00
static String GetLowerCaseTypeNameDB(const ConfigObject::Ptr& obj);
2018-11-30 17:01:42 +01:00
static bool PrepareObject(const ConfigObject::Ptr& object, Dictionary::Ptr& attributes, Dictionary::Ptr& checkSums);
2018-10-29 13:48:15 +01:00
2018-11-28 11:30:56 +01:00
static void StateChangeHandler(const ConfigObject::Ptr& object);
static void StateChangeHandler(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type);
2017-09-25 14:41:43 +02:00
static void VersionChangedHandler(const ConfigObject::Ptr& object);
static void DowntimeStartedHandler(const Downtime::Ptr& downtime);
static void DowntimeRemovedHandler(const Downtime::Ptr& downtime);
2017-09-25 14:41:43 +02:00
static void NotificationSentToAllUsersHandler(
const Notification::Ptr& notification, const Checkable::Ptr& checkable, const std::set<User::Ptr>& users,
NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text
);
static void CommentAddedHandler(const Comment::Ptr& comment);
static void CommentRemovedHandler(const Comment::Ptr& comment);
static void FlappingChangedHandler(const Checkable::Ptr& checkable, const Value& value);
2019-11-27 13:13:58 +01:00
static void NewCheckResultHandler(const Checkable::Ptr& checkable);
static void AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double expiry);
static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy);
2018-05-15 14:43:01 +02:00
void AssertOnWorkQueue();
2017-09-25 14:41:43 +02:00
void ExceptionHandler(boost::exception_ptr exp);
Timer::Ptr m_StatsTimer;
Timer::Ptr m_ReconnectTimer;
WorkQueue m_WorkQueue;
String m_PrefixConfigObject;
String m_PrefixConfigCheckSum;
2018-11-15 17:04:03 +01:00
String m_PrefixStateObject;
2017-09-25 14:41:43 +02:00
bool m_ConfigDumpInProgress;
bool m_ConfigDumpDone;
2017-09-25 14:41:43 +02:00
RedisConnection::Ptr m_Rcon;
};
2017-09-25 14:41:43 +02:00
}
2019-11-02 17:24:34 +01:00
#endif /* ICINGADB_H */