- Added component locks
[public/netxms.git] / src / server / core / nms_events.h
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** $module: nms_events.h
20 **
21 **/
22
23 #ifndef _nms_events_h_
24 #define _nms_events_h_
25
26
27 //
28 // Constants
29 //
30
31 #define FIRST_USER_EVENT_ID 100000
32
33 #define EVENT_SEVERITY_INFO 0
34 #define EVENT_SEVERITY_MINOR 1
35 #define EVENT_SEVERITY_WARNING 2
36 #define EVENT_SEVERITY_MAJOR 3
37 #define EVENT_SEVERITY_CRITICAL 4
38
39
40 //
41 // Event flags
42 //
43
44 #define EF_LOG 0x0001
45
46
47 //
48 // System-defined events
49 //
50
51 #define EVENT_NODE_ADDED 1
52 #define EVENT_SUBNET_ADDED 2
53 #define EVENT_INTERFACE_ADDED 3
54 #define EVENT_INTERFACE_UP 4
55 #define EVENT_INTERFACE_DOWN 5
56 #define EVENT_NODE_NORMAL 6
57 #define EVENT_NODE_MINOR 7
58 #define EVENT_NODE_WARNING 8
59 #define EVENT_NODE_MAJOR 9
60 #define EVENT_NODE_CRITICAL 10
61 #define EVENT_NODE_UNKNOWN 11
62 #define EVENT_NODE_UNMANAGED 12
63 #define EVENT_NODE_FLAGS_CHANGED 13
64 #define EVENT_SNMP_FAIL 14
65 #define EVENT_AGENT_FAIL 15
66 #define EVENT_INTERFACE_DELETED 16
67 #define EVENT_THREAD_HANGS 1001
68
69
70 //
71 // Event template
72 //
73
74 struct EVENT_TEMPLATE
75 {
76 DWORD dwId;
77 DWORD dwSeverity;
78 DWORD dwFlags;
79 char *szMessageTemplate;
80 char *szDescription;
81 };
82
83
84 //
85 // Event
86 //
87
88 class Event
89 {
90 private:
91 DWORD m_dwId;
92 DWORD m_dwSeverity;
93 DWORD m_dwFlags;
94 DWORD m_dwSource;
95 char *m_szMessageText;
96 DWORD m_dwNumParameters;
97 char **m_pszParameters;
98 time_t m_tTimeStamp;
99
100 void ExpandMessageText(char *szMessageTemplate);
101
102 public:
103 Event();
104 Event(EVENT_TEMPLATE *pTemplate, DWORD dwSourceId, char *szFormat, va_list args);
105 ~Event();
106
107 DWORD Id(void) { return m_dwId; }
108 DWORD Severity(void) { return m_dwSeverity; }
109 DWORD Flags(void) { return m_dwFlags; }
110 DWORD SourceId(void) { return m_dwSource; }
111 const char *Message(void) { return m_szMessageText; }
112 time_t TimeStamp(void) { return m_tTimeStamp; }
113
114 void PrepareMessage(NXC_EVENT *pEventData);
115 };
116
117
118 //
119 // Event policy rule flags
120 //
121
122 #define RF_STOP_PROCESSING 0x01
123 #define RF_NEGATED_SOURCE 0x02
124 #define RF_NEGATED_EVENTS 0x04
125
126
127 //
128 // Event source structure
129 //
130
131 typedef struct
132 {
133 int iType;
134 DWORD dwObjectId;
135 } EVENT_SOURCE;
136
137
138 //
139 // Event policy rule
140 //
141
142 class EPRule
143 {
144 private:
145 DWORD m_dwId;
146 DWORD m_dwFlags;
147 DWORD m_dwNumSources;
148 EVENT_SOURCE *m_pSourceList;
149 DWORD m_dwNumEvents;
150 DWORD *m_pdwEventList;
151 DWORD m_dwNumActions;
152 DWORD *m_pdwActionList;
153 char *m_pszComment;
154
155 public:
156 EPRule(DWORD dwId, char *szComment, DWORD dwFlags);
157 ~EPRule();
158
159 DWORD Id(void) { return m_dwId; }
160
161 BOOL LoadFromDB(void);
162 };
163
164
165 //
166 // Event policy
167 //
168
169 class EventPolicy
170 {
171 private:
172 DWORD m_dwNumRules;
173 EPRule **m_ppRuleList;
174
175 public:
176 EventPolicy();
177 ~EventPolicy();
178
179 BOOL LoadFromDB(void);
180 };
181
182
183 //
184 // Functions
185 //
186
187 BOOL InitEventSubsystem(void);
188 BOOL PostEvent(DWORD dwEventId, DWORD dwSourceId, char *szFormat, ...);
189
190
191 //
192 // Global variables
193 //
194
195 extern Queue *g_pEventQueue;
196 extern EventPolicy *g_pEventPolicy;
197
198 #endif /* _nms_events_h_ */