]> granicus.if.org Git - icinga2/blob - lib/db_ido/dbevents.hpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / db_ido / dbevents.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef DBEVENTS_H
4 #define DBEVENTS_H
5
6 #include "db_ido/dbobject.hpp"
7 #include "base/configobject.hpp"
8 #include "icinga/service.hpp"
9
10 namespace icinga
11 {
12
13 enum LogEntryType
14 {
15         LogEntryTypeRuntimeError = 1,
16         LogEntryTypeRuntimeWarning = 2,
17         LogEntryTypeVerificationError = 4,
18         LogEntryTypeVerificationWarning = 8,
19         LogEntryTypeConfigError = 16,
20         LogEntryTypeConfigWarning = 32,
21         LogEntryTypeProcessInfo = 64,
22         LogEntryTypeEventHandler = 128,
23         LogEntryTypeExternalCommand = 512,
24         LogEntryTypeHostUp = 1024,
25         LogEntryTypeHostDown = 2048,
26         LogEntryTypeHostUnreachable = 4096,
27         LogEntryTypeServiceOk = 8192,
28         LogEntryTypeServiceUnknown = 16384,
29         LogEntryTypeServiceWarning = 32768,
30         LogEntryTypeServiceCritical = 65536,
31         LogEntryTypePassiveCheck = 1231072,
32         LogEntryTypeInfoMessage = 262144,
33         LogEntryTypeHostNotification = 524288,
34         LogEntryTypeServiceNotification = 1048576
35 };
36
37 /**
38  * IDO events
39  *
40  * @ingroup ido
41  */
42 class DbEvents
43 {
44 public:
45         static void StaticInitialize();
46
47         static void AddComments(const Checkable::Ptr& checkable);
48
49         static void AddDowntimes(const Checkable::Ptr& checkable);
50         static void RemoveDowntimes(const Checkable::Ptr& checkable);
51
52         static void AddLogHistory(const Checkable::Ptr& checkable, const String& buffer, LogEntryType type);
53
54         /* Status */
55         static void NextCheckUpdatedHandler(const Checkable::Ptr& checkable);
56         static void FlappingChangedHandler(const Checkable::Ptr& checkable);
57         static void LastNotificationChangedHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable);
58
59         static void EnableActiveChecksChangedHandler(const Checkable::Ptr& checkable);
60         static void EnablePassiveChecksChangedHandler(const Checkable::Ptr& checkable);
61         static void EnableNotificationsChangedHandler(const Checkable::Ptr& checkable);
62         static void EnablePerfdataChangedHandler(const Checkable::Ptr& checkable);
63         static void EnableFlappingChangedHandler(const Checkable::Ptr& checkable);
64
65         static void AddComment(const Comment::Ptr& comment);
66         static void RemoveComment(const Comment::Ptr& comment);
67
68         static void AddDowntime(const Downtime::Ptr& downtime);
69         static void RemoveDowntime(const Downtime::Ptr& downtime);
70         static void TriggerDowntime(const Downtime::Ptr& downtime);
71
72         static void AddAcknowledgement(const Checkable::Ptr& checkable, AcknowledgementType type);
73         static void RemoveAcknowledgement(const Checkable::Ptr& checkable);
74         static void AddAcknowledgementInternal(const Checkable::Ptr& checkable, AcknowledgementType type, bool add);
75
76         static void ReachabilityChangedHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, std::set<Checkable::Ptr> children);
77
78         /* comment, downtime, acknowledgement history */
79         static void AddCommentHistory(const Comment::Ptr& comment);
80         static void AddDowntimeHistory(const Downtime::Ptr& downtime);
81         static void AddAcknowledgementHistory(const Checkable::Ptr& checkable, const String& author, const String& comment,
82                 AcknowledgementType type, bool notify, double expiry);
83
84         /* notification & contactnotification history */
85         static void AddNotificationHistory(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
86                 const std::set<User::Ptr>& users, NotificationType type, const CheckResult::Ptr& cr, const String& author,
87                 const String& text);
88
89         /* statehistory */
90         static void AddStateChangeHistory(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
91
92         /* logentries */
93         static void AddCheckResultLogHistory(const Checkable::Ptr& checkable, const CheckResult::Ptr &cr);
94         static void AddTriggerDowntimeLogHistory(const Downtime::Ptr& downtime);
95         static void AddRemoveDowntimeLogHistory(const Downtime::Ptr& downtime);
96         static void AddNotificationSentLogHistory(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
97                 const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr,
98                 const String& author, const String& comment_text);
99
100         static void AddFlappingChangedLogHistory(const Checkable::Ptr& checkable);
101         static void AddEnableFlappingChangedLogHistory(const Checkable::Ptr& checkable);
102
103         /* other history */
104         static void AddFlappingChangedHistory(const Checkable::Ptr& checkable);
105         static void AddEnableFlappingChangedHistory(const Checkable::Ptr& checkable);
106         static void AddCheckableCheckHistory(const Checkable::Ptr& checkable, const CheckResult::Ptr &cr);
107         static void AddEventHandlerHistory(const Checkable::Ptr& checkable);
108         static void AddExternalCommandHistory(double time, const String& command, const std::vector<String>& arguments);
109
110 private:
111         DbEvents();
112
113         static void AddCommentInternal(std::vector<DbQuery>& queries, const Comment::Ptr& comment, bool historical);
114         static void RemoveCommentInternal(std::vector<DbQuery>& queries, const Comment::Ptr& comment);
115         static void AddDowntimeInternal(std::vector<DbQuery>& queries, const Downtime::Ptr& downtime, bool historical);
116         static void RemoveDowntimeInternal(std::vector<DbQuery>& queries, const Downtime::Ptr& downtime);
117         static void EnableChangedHandlerInternal(const Checkable::Ptr& checkable, const String& fieldName, bool enabled);
118
119         static int GetHostState(const Host::Ptr& host);
120         static String GetHostStateString(const Host::Ptr& host);
121         static std::pair<unsigned long, unsigned long> ConvertTimestamp(double time);
122         static int MapNotificationReasonType(NotificationType type);
123         static int MapExternalCommandType(const String& name);
124 };
125
126 }
127
128 #endif /* DBEVENTS_H */