SNMP V3 support added (without authentication and encryption)
[public/netxms.git] / src / server / include / nms_events.h
CommitLineData
5039dede
AK
1/*
2** NetXMS - Network Management System
b4fe4886 3** Copyright (C) 2003-2009 Victor Kirhenshtein
5039dede
AK
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**
b4fe4886 19** File: nms_events.h
5039dede
AK
20**
21**/
22
23#ifndef _nms_events_h_
24#define _nms_events_h_
25
26#include <nxevent.h>
27
28
29//
30// Constants
31//
32
33#define FIRST_USER_EVENT_ID 100000
34
35
36//
37// Event template
38//
39
40struct EVENT_TEMPLATE
41{
42 DWORD dwCode;
43 DWORD dwSeverity;
44 DWORD dwFlags;
45 TCHAR *pszMessageTemplate;
46 TCHAR *pszDescription;
47 TCHAR szName[MAX_EVENT_NAME];
48};
49
50
51//
52// Event
53//
54
55class Event
56{
57private:
58 QWORD m_qwId;
59 QWORD m_qwRootId; // Root event id
60 DWORD m_dwCode;
61 DWORD m_dwSeverity;
62 DWORD m_dwFlags;
63 DWORD m_dwSource;
b4fe4886 64 TCHAR m_szName[MAX_EVENT_NAME];
5039dede
AK
65 TCHAR *m_pszMessageText;
66 TCHAR *m_pszMessageTemplate;
67 DWORD m_dwNumParameters;
68 TCHAR **m_ppszParameters;
69 time_t m_tTimeStamp;
70 TCHAR *m_pszUserTag;
71 TCHAR *m_pszCustomMessage;
72
73public:
74 Event();
75 Event(EVENT_TEMPLATE *pTemplate, DWORD dwSourceId, const TCHAR *pszUserTag, const char *szFormat, va_list args);
76 ~Event();
77
b4fe4886
VK
78 QWORD Id() { return m_qwId; }
79 DWORD Code() { return m_dwCode; }
80 DWORD Severity() { return m_dwSeverity; }
81 DWORD Flags() { return m_dwFlags; }
82 DWORD SourceId() { return m_dwSource; }
83 const TCHAR *Name() { return m_szName; }
84 const TCHAR *Message() { return m_pszMessageText; }
85 const TCHAR *UserTag() { return m_pszUserTag; }
86 time_t TimeStamp() { return m_tTimeStamp; }
5039dede 87
b4fe4886 88 QWORD GetRootId() { return m_qwRootId; }
5039dede
AK
89 void SetRootId(QWORD qwId) { m_qwRootId = qwId; }
90
91 void PrepareMessage(CSCPMessage *pMsg);
92
b4fe4886 93 void ExpandMessageText();
5039dede
AK
94 TCHAR *ExpandText(TCHAR *szTemplate, TCHAR *pszAlarmMsg = NULL);
95
b4fe4886 96 DWORD GetParametersCount() { return m_dwNumParameters; }
5039dede
AK
97 char *GetParameter(DWORD dwIndex) { return (dwIndex < m_dwNumParameters) ? m_ppszParameters[dwIndex] : NULL; }
98 DWORD GetParameterAsULong(DWORD dwIndex) { return (dwIndex < m_dwNumParameters) ? _tcstoul(m_ppszParameters[dwIndex], NULL, 0) : 0; }
99 QWORD GetParameterAsUInt64(DWORD dwIndex) { return (dwIndex < m_dwNumParameters) ? _tcstoull(m_ppszParameters[dwIndex], NULL, 0) : 0; }
100
101 void SetCustomMessage(const TCHAR *pszMessage) { safe_free(m_pszCustomMessage); m_pszCustomMessage = (pszMessage != NULL) ? _tcsdup(pszMessage) : NULL; }
102};
103
104
105//
106// Event policy rule
107//
108
109class EPRule
110{
111private:
112 DWORD m_dwId;
113 DWORD m_dwFlags;
114 DWORD m_dwNumSources;
115 DWORD *m_pdwSourceList;
116 DWORD m_dwNumEvents;
117 DWORD *m_pdwEventList;
118 DWORD m_dwNumActions;
119 DWORD *m_pdwActionList;
120 TCHAR *m_pszComment;
121 TCHAR *m_pszScript;
122 NXSL_Program *m_pScript;
123
124 TCHAR m_szAlarmMessage[MAX_DB_STRING];
125 int m_iAlarmSeverity;
126 TCHAR m_szAlarmKey[MAX_DB_STRING];
127 DWORD m_dwAlarmTimeout;
128 DWORD m_dwAlarmTimeoutEvent;
129
130 DWORD m_dwSituationId;
131 TCHAR m_szSituationInstance[MAX_DB_STRING];
132 StringMap m_situationAttrList;
133
134 BOOL MatchSource(DWORD dwObjectId);
135 BOOL MatchEvent(DWORD dwEventCode);
136 BOOL MatchSeverity(DWORD dwSeverity);
137 BOOL MatchScript(Event *pEvent);
138
139 void GenerateAlarm(Event *pEvent);
140
141public:
142 EPRule(DWORD dwId);
143 EPRule(DB_RESULT hResult, int iRow);
144 EPRule(CSCPMessage *pMsg);
145 ~EPRule();
146
147 DWORD Id(void) { return m_dwId; }
148 void SetId(DWORD dwNewId) { m_dwId = dwNewId; }
149 BOOL LoadFromDB(void);
150 void SaveToDB(void);
151 BOOL ProcessEvent(Event *pEvent);
152 void CreateMessage(CSCPMessage *pMsg);
153
154 BOOL ActionInUse(DWORD dwActionId);
155};
156
157
158//
159// Event policy
160//
161
162class EventPolicy
163{
164private:
165 DWORD m_dwNumRules;
166 EPRule **m_ppRuleList;
167 RWLOCK m_rwlock;
168
169 void ReadLock(void) { RWLockReadLock(m_rwlock, INFINITE); }
170 void WriteLock(void) { RWLockWriteLock(m_rwlock, INFINITE); }
171 void Unlock(void) { RWLockUnlock(m_rwlock); }
172 void Clear(void);
173
174public:
175 EventPolicy();
176 ~EventPolicy();
177
178 DWORD NumRules(void) { return m_dwNumRules; }
179 BOOL LoadFromDB(void);
180 void SaveToDB(void);
181 void ProcessEvent(Event *pEvent);
182 void SendToClient(ClientSession *pSession, DWORD dwRqId);
183 void ReplacePolicy(DWORD dwNumRules, EPRule **ppRuleList);
184
185 BOOL ActionInUse(DWORD dwActionId);
186};
187
188
189//
190// Functions
191//
192
193BOOL InitEventSubsystem(void);
194void ShutdownEventSubsystem(void);
195BOOL PostEvent(DWORD dwEventCode, DWORD dwSourceId, const char *pszFormat, ...);
196BOOL PostEventWithTag(DWORD dwEventCode, DWORD dwSourceId, const TCHAR *pszUserTag, const char *pszFormat, ...);
197BOOL PostEventEx(Queue *pQueue, DWORD dwEventCode, DWORD dwSourceId,
198 const char *pszFormat, ...);
199void ResendEvents(Queue *pQueue);
200void ReloadEvents(void);
201void DeleteEventTemplateFromList(DWORD dwEventCode);
202void CorrelateEvent(Event *pEvent);
203void CreateNXMPEventRecord(String &str, DWORD dwCode);
204BOOL ResolveEventName(DWORD dwCode, TCHAR *pszBuffer);
205EVENT_TEMPLATE *FindEventTemplateByCode(DWORD dwCode);
206EVENT_TEMPLATE *FindEventTemplateByName(const TCHAR *pszName);
207
208
209//
210// Global variables
211//
212
213extern Queue *g_pEventQueue;
214extern EventPolicy *g_pEventPolicy;
215extern const char *g_szStatusText[];
216extern const char *g_szStatusTextSmall[];
217extern INT64 g_totalEventsProcessed;
218
219#endif /* _nms_events_h_ */