1 /*
2  * Copyright (C) Tildeslash Ltd. All rights reserved.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License version 3.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU Affero General Public License
13  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
14  *
15  * In addition, as a special exception, the copyright holders give
16  * permission to link the code of portions of this program with the
17  * OpenSSL library under certain conditions as described in each
18  * individual source file, and distribute linked combinations
19  * including the two.
20  *
21  * You must obey the GNU Affero General Public License in all respects
22  * for all of the code used other than OpenSSL.
23  */
24 
25 #ifndef MONIT_EVENT_H
26 #define MONIT_EVENT_H
27 
28 #include "monit.h"
29 
30 
31 typedef enum {
32         Event_Null       = 0x0,
33         Event_Checksum   = 0x1,
34         Event_Resource   = 0x2, //FIXME: split to more specific events (cpu, totalcpu, mem, totalmem, loadaverage, space, inode, ...)
35         Event_Timeout    = 0x4,
36         Event_Timestamp  = 0x8, //FIXME: split to more specific events (atime, mtime, ctime)
37         Event_Size       = 0x10,
38         Event_Connection = 0x20,
39         Event_Permission = 0x40,
40         Event_Uid        = 0x80,
41         Event_Gid        = 0x100,
42         Event_NonExist   = 0x200,
43         Event_Invalid    = 0x400,
44         Event_Data       = 0x800,
45         Event_Exec       = 0x1000,
46         Event_FsFlag     = 0x2000,
47         Event_Icmp       = 0x4000,
48         Event_Content    = 0x8000,
49         Event_Instance   = 0x10000,
50         Event_Action     = 0x20000,
51         Event_Pid        = 0x40000,
52         Event_PPid       = 0x80000,
53         Event_Heartbeat  = 0x100000,
54         Event_Status     = 0x200000,
55         Event_Uptime     = 0x400000,
56         Event_Link       = 0x800000, //FIXME: split to more specific events (link status, link errors)
57         Event_Speed      = 0x1000000,
58         Event_Saturation = 0x2000000,
59         Event_ByteIn     = 0x4000000,
60         Event_ByteOut    = 0x8000000,
61         Event_PacketIn   = 0x10000000,
62         Event_PacketOut  = 0x20000000,
63         Event_Exist      = 0x40000000,
64         Event_All        = 0x7FFFFFFF
65 } Event_Type;
66 
67 
68 #define IS_EVENT_SET(value, mask) ((value & mask) != 0)
69 
70 typedef struct myeventtable {
71         int id;
72         const char *description_failed;
73         const char *description_succeeded;
74         const char *description_changed;
75         const char *description_changednot;
76         State_Type saveState; // Bitmap of the event states that should trigger state file update
77 } EventTable_T;
78 
79 
80 extern EventTable_T Event_Table[];
81 
82 
83 /**
84  * This class implements the <b>event</b> processing machinery used by
85  * monit. In monit an event is an object containing a Service_T
86  * reference indicating the object where the event originated, an id
87  * specifying the event type, a value representing up or down state
88  * and an optional message describing why the event was fired.
89  *
90  * Clients may use the function Event_post() to post events to the
91  * event handler for processing.
92  *
93  * @file
94  */
95 
96 
97 /**
98  * Post a new Event
99  * @param service The Service the event belongs to
100  * @param id The event identification
101  * @param state The event state
102  * @param action Description of the event action
103  * @param s Optional message describing the event
104  */
105 void Event_post(Service_T service, long id, State_Type state, EventAction_T action, const char *s, ...) __attribute__((format (printf, 5, 6)));
106 
107 
108 /**
109  * Get a textual description of actual event type. For instance if the
110  * event type is positive Event_Timestamp, the textual description is
111  * "Timestamp error". Likewise if the event type is negative Event_Checksum
112  * the textual description is "Checksum recovery" and so on.
113  * @param E An event object
114  * @return A string describing the event type in clear text. If the
115  * event type is not found NULL is returned.
116  */
117 const char *Event_get_description(Event_T E);
118 
119 
120 /**
121  * Get an event action id.
122  * @param E An event object
123  * @return An action id
124  */
125 Action_Type Event_get_action(Event_T E);
126 
127 
128 /**
129  * Get a textual description of actual event action. For instance if the
130  * event type is positive Event_NonExist, the textual description of
131  * failed state related action is "restart". Likewise if the event type is
132  * negative Event_Checksum the textual description of recovery related action
133  * is "alert" and so on.
134  * @param E An event object
135  * @return A string describing the event type in clear text. If the
136  * event type is not found NULL is returned.
137  */
138 const char *Event_get_action_description(Event_T E);
139 
140 
141 /**
142  * Reprocess the partially handled event queue
143  */
144 void Event_queue_process(void);
145 
146 
147 #endif
148