This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
event.h
208 lines (171 loc) · 5.9 KB
/
event.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* Copyright (C) 2011 Tildeslash Ltd. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3.
*
* 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, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
*
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
#ifndef MONIT_EVENT_H
#define MONIT_EVENT_H
#include "monitor.h"
typedef enum {
Event_Null = 0x0,
Event_Checksum = 0x1,
Event_Resource = 0x2,
Event_Timeout = 0x4,
Event_Timestamp = 0x8,
Event_Size = 0x10,
Event_Connection = 0x20,
Event_Permission = 0x40,
Event_Uid = 0x80,
Event_Gid = 0x100,
Event_Nonexist = 0x200,
Event_Invalid = 0x400,
Event_Data = 0x800,
Event_Exec = 0x1000,
Event_Fsflag = 0x2000,
Event_Icmp = 0x4000,
Event_Content = 0x8000,
Event_Instance = 0x10000,
Event_Action = 0x20000,
Event_Pid = 0x40000,
Event_PPid = 0x80000,
Event_Heartbeat = 0x100000,
Event_All = 0xFFFFFFFF
} Event_Type;
#define IS_EVENT_SET(value, mask) ((value & mask) != 0)
typedef struct myeventtable {
int id;
char *description_failed;
char *description_succeeded;
char *description_changed;
char *description_changednot;
} EventTable_T;
extern EventTable_T Event_Table[];
/**
* This class implements the <b>event</b> processing machinery used by
* monit. In monit an event is an object containing a Service_T
* reference indicating the object where the event orginated, an id
* specifying the event type, a value representing up or down state
* and an optional message describing why the event was fired.
*
* Clients may use the function Event_post() to post events to the
* event handler for processing.
*
* @author Jan-Henrik Haukeland, <[email protected]>
* @author Martin Pala, <[email protected]>
* @file
*/
/**
* Post a new Event
* @param service The Service the event belongs to
* @param id The event identification
* @param state The event state
* @param action Description of the event action
* @param s Optional message describing the event
*/
void Event_post(Service_T service, long id, short state, EventAction_T action, char *s, ...);
/**
* Get the Service where the event orginated
* @param E An event object
* @return The Service where the event orginated
*/
Service_T Event_get_source(Event_T E);
/**
* Get the Service name where the event orginated
* @param E An event object
* @return The Service name where the event orginated
*/
char *Event_get_source_name(Event_T E);
/**
* Get the service type of the service where the event orginated
* @param E An event object
* @return The service type of the service where the event orginated
*/
int Event_get_source_type(Event_T E);
/**
* Get the Event timestamp
* @param E An event object
* @return The Event timestamp
*/
struct timeval *Event_get_collected(Event_T E);
/**
* Get the Event raw state
* @param E An event object
* @return The Event raw state
*/
short Event_get_state(Event_T E);
/**
* Return the actual event state based on event state bitmap
* and event ratio needed to trigger the state change
* @param E An event object
* @param S Actual posted state
* @return The Event raw state
*/
short Event_check_state(Event_T E, short S);
/**
* Get the Event type
* @param E An event object
* @return The Event type
*/
int Event_get_id(Event_T E);
/**
* Get the optionally Event message describing why the event was
* fired.
* @param E An event object
* @return The Event message. May be NULL
*/
const char *Event_get_message(Event_T E);
/**
* Get a textual description of actual event type. For instance if the
* event type is possitive Event_Timestamp, the textual description is
* "Timestamp error". Likewise if the event type is negative Event_Checksum
* the textual description is "Checksum recovery" and so on.
* @param E An event object
* @return A string describing the event type in clear text. If the
* event type is not found NULL is returned.
*/
const char *Event_get_description(Event_T E);
/**
* Get an event action id.
* @param E An event object
* @return An action id
*/
short Event_get_action(Event_T E);
/**
* Get a textual description of actual event action. For instance if the
* event type is possitive Event_Nonexist, the textual description of
* failed state related action is "restart". Likewise if the event type is
* negative Event_Checksum the textual description of recovery related action
* is "alert" and so on.
* @param E An event object
* @return A string describing the event type in clear text. If the
* event type is not found NULL is returned.
*/
const char *Event_get_action_description(Event_T E);
/**
* Reprocess the partialy handled event queue
*/
void Event_queue_process();
#endif