Server core implemented as DLL/shared library
[public/netxms.git] / src / server / include / nms_events.h
CommitLineData
c1263934 1/*
da54bd8d 2** NetXMS - Network Management System
c1263934
VK
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
b54b2b11
VK
26#include <nxevent.h>
27
c1263934
VK
28
29//
f9b7e653 30// Constants
c1263934
VK
31//
32
f9b7e653
VK
33#define FIRST_USER_EVENT_ID 100000
34
f9b7e653
VK
35
36//
f9b7e653
VK
37// Event template
38//
39
40struct EVENT_TEMPLATE
c1263934
VK
41{
42 DWORD dwId;
43 DWORD dwSeverity;
f9b7e653
VK
44 DWORD dwFlags;
45 char *szMessageTemplate;
46 char *szDescription;
47};
48
49
50//
51// Event
52//
53
54class Event
55{
56private:
57 DWORD m_dwId;
58 DWORD m_dwSeverity;
59 DWORD m_dwFlags;
60 DWORD m_dwSource;
d2a1dd18 61 char *m_pszMessageText;
f9b7e653 62 DWORD m_dwNumParameters;
d2a1dd18 63 char **m_ppszParameters;
f9b7e653
VK
64 time_t m_tTimeStamp;
65
66 void ExpandMessageText(char *szMessageTemplate);
67
68public:
69 Event();
70 Event(EVENT_TEMPLATE *pTemplate, DWORD dwSourceId, char *szFormat, va_list args);
71 ~Event();
72
73 DWORD Id(void) { return m_dwId; }
74 DWORD Severity(void) { return m_dwSeverity; }
75 DWORD Flags(void) { return m_dwFlags; }
76 DWORD SourceId(void) { return m_dwSource; }
d2a1dd18 77 const char *Message(void) { return m_pszMessageText; }
f9b7e653 78 time_t TimeStamp(void) { return m_tTimeStamp; }
62f5857f
VK
79
80 void PrepareMessage(NXC_EVENT *pEventData);
4d5a05a0
VK
81
82 char *ExpandText(char *szTemplate);
c1263934
VK
83};
84
f9b7e653
VK
85
86//
c7ca9142
VK
87// Event policy rule
88//
89
90class EPRule
91{
92private:
93 DWORD m_dwId;
94 DWORD m_dwFlags;
95 DWORD m_dwNumSources;
d2a1dd18 96 DWORD *m_pdwSourceList;
c7ca9142
VK
97 DWORD m_dwNumEvents;
98 DWORD *m_pdwEventList;
99 DWORD m_dwNumActions;
100 DWORD *m_pdwActionList;
101 char *m_pszComment;
102
06e7be2f
VK
103 char m_szAlarmMessage[MAX_DB_STRING];
104 int m_iAlarmSeverity;
105 char m_szAlarmKey[MAX_DB_STRING];
106 char m_szAlarmAckKey[MAX_DB_STRING];
107
4d5a05a0
VK
108 BOOL MatchSource(DWORD dwObjectId);
109 BOOL MatchEvent(DWORD dwEventId);
110 BOOL MatchSeverity(DWORD dwSeverity);
111
06e7be2f
VK
112 void GenerateAlarm(Event *pEvent);
113
c7ca9142 114public:
06e7be2f
VK
115 EPRule(DWORD dwId);
116 EPRule(DB_RESULT hResult, int iRow);
8f7e2482 117 EPRule(CSCPMessage *pMsg);
c7ca9142
VK
118 ~EPRule();
119
120 DWORD Id(void) { return m_dwId; }
a97797f8 121 void SetId(DWORD dwNewId) { m_dwId = dwNewId; }
c7ca9142 122 BOOL LoadFromDB(void);
043fe1ec 123 void SaveToDB(void);
4d5a05a0 124 BOOL ProcessEvent(Event *pEvent);
06e7be2f 125 void CreateMessage(CSCPMessage *pMsg);
c7ca9142
VK
126};
127
128
129//
130// Event policy
131//
132
133class EventPolicy
134{
135private:
136 DWORD m_dwNumRules;
137 EPRule **m_ppRuleList;
b8191466
VK
138 RWLOCK m_rwlock;
139
8f7e2482
VK
140 void ReadLock(void) { RWLockReadLock(m_rwlock, INFINITE); }
141 void WriteLock(void) { RWLockWriteLock(m_rwlock, INFINITE); }
b8191466 142 void Unlock(void) { RWLockUnlock(m_rwlock); }
8f7e2482 143 void Clear(void);
c7ca9142
VK
144
145public:
146 EventPolicy();
147 ~EventPolicy();
148
06e7be2f 149 DWORD NumRules(void) { return m_dwNumRules; }
c7ca9142 150 BOOL LoadFromDB(void);
043fe1ec 151 void SaveToDB(void);
4d5a05a0 152 void ProcessEvent(Event *pEvent);
06e7be2f 153 void SendToClient(ClientSession *pSession, DWORD dwRqId);
8f7e2482 154 void ReplacePolicy(DWORD dwNumRules, EPRule **ppRuleList);
c7ca9142
VK
155};
156
157
158//
f9b7e653
VK
159// Functions
160//
161
162BOOL InitEventSubsystem(void);
e0d3b217 163void ShutdownEventSubsystem(void);
f9b7e653 164BOOL PostEvent(DWORD dwEventId, DWORD dwSourceId, char *szFormat, ...);
4d5a05a0 165void ReloadEvents(void);
f9b7e653
VK
166
167
168//
169// Global variables
170//
171
172extern Queue *g_pEventQueue;
c7ca9142 173extern EventPolicy *g_pEventPolicy;
4d5a05a0
VK
174extern char *g_szStatusText[];
175extern char *g_szStatusTextSmall[];
f9b7e653 176
c1263934 177#endif /* _nms_events_h_ */