2 ** NetXMS - Network Management System
4 ** Copyright (C) 2003-2010 Victor Kirhenshtein
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published by
8 ** the Free Software Foundation; either version 3 of the License, or
9 ** (at your option) any later version.
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 // Fill event template structure from NXCP message
31 static void EventTemplateFromMsg(CSCPMessage
*pMsg
, NXC_EVENT_TEMPLATE
*pEventTemplate
)
33 pEventTemplate
->dwCode
= pMsg
->GetVariableLong(VID_EVENT_CODE
);
34 pEventTemplate
->dwSeverity
= pMsg
->GetVariableLong(VID_SEVERITY
);
35 pEventTemplate
->dwFlags
= pMsg
->GetVariableLong(VID_FLAGS
);
36 pMsg
->GetVariableStr(VID_NAME
, pEventTemplate
->szName
, MAX_EVENT_NAME
);
37 pEventTemplate
->pszMessage
= pMsg
->GetVariableStr(VID_MESSAGE
, NULL
, 0);
38 pEventTemplate
->pszDescription
= pMsg
->GetVariableStr(VID_DESCRIPTION
, NULL
, 0);
43 // Process CMD_EVENT_DB_UPDATE message
46 void ProcessEventDBUpdate(NXCL_Session
*pSession
, CSCPMessage
*pMsg
)
48 NXC_EVENT_TEMPLATE et
;
51 dwCode
= pMsg
->GetVariableShort(VID_NOTIFICATION_CODE
);
52 et
.dwCode
= pMsg
->GetVariableLong(VID_EVENT_CODE
);
53 if (dwCode
!= NX_NOTIFY_ETMPL_DELETED
)
54 EventTemplateFromMsg(pMsg
, &et
);
55 pSession
->callEventHandler(NXC_EVENT_NOTIFICATION
, dwCode
, &et
);
60 // Duplicate event template
63 NXC_EVENT_TEMPLATE
*DuplicateEventTemplate(NXC_EVENT_TEMPLATE
*pSrc
)
65 NXC_EVENT_TEMPLATE
*pDst
;
67 pDst
= (NXC_EVENT_TEMPLATE
*)nx_memdup(pSrc
, sizeof(NXC_EVENT_TEMPLATE
));
68 pDst
->pszDescription
= _tcsdup(pSrc
->pszDescription
);
69 pDst
->pszMessage
= _tcsdup(pSrc
->pszMessage
);
75 // Add template to list
78 void LIBNXCL_EXPORTABLE
NXCAddEventTemplate(NXC_SESSION hSession
, NXC_EVENT_TEMPLATE
*pEventTemplate
)
80 ((NXCL_Session
*)hSession
)->AddEventTemplate(pEventTemplate
, TRUE
);
85 // Delete record from list
88 void LIBNXCL_EXPORTABLE
NXCDeleteEDBRecord(NXC_SESSION hSession
, DWORD dwEventCode
)
90 ((NXCL_Session
*)hSession
)->DeleteEDBRecord(dwEventCode
);
95 // Process record from network
98 void ProcessEventDBRecord(NXCL_Session
*pSession
, CSCPMessage
*pMsg
)
100 NXC_EVENT_TEMPLATE
*pEventTemplate
;
103 if (pMsg
->GetCode() == CMD_EVENT_DB_RECORD
)
105 dwEventCode
= pMsg
->GetVariableLong(VID_EVENT_CODE
);
106 if (!pMsg
->IsEndOfSequence() && (dwEventCode
!= 0))
108 // Allocate new event template structure and fill it with values from message
109 pEventTemplate
= (NXC_EVENT_TEMPLATE
*)malloc(sizeof(NXC_EVENT_TEMPLATE
));
110 EventTemplateFromMsg(pMsg
, pEventTemplate
);
111 pSession
->AddEventTemplate(pEventTemplate
, FALSE
);
115 pSession
->CompleteSync(SYNC_EVENT_DB
, RCC_SUCCESS
);
122 // Load event configuration database
125 DWORD LIBNXCL_EXPORTABLE
NXCLoadEventDB(NXC_SESSION hSession
)
127 return ((NXCL_Session
*)hSession
)->LoadEventDB();
132 // Set event information
135 DWORD LIBNXCL_EXPORTABLE
NXCModifyEventTemplate(NXC_SESSION hSession
, NXC_EVENT_TEMPLATE
*pArg
)
140 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
143 msg
.SetCode(CMD_SET_EVENT_INFO
);
145 msg
.SetVariable(VID_EVENT_CODE
, pArg
->dwCode
);
146 msg
.SetVariable(VID_SEVERITY
, pArg
->dwSeverity
);
147 msg
.SetVariable(VID_FLAGS
, pArg
->dwFlags
);
148 msg
.SetVariable(VID_NAME
, pArg
->szName
);
149 msg
.SetVariable(VID_MESSAGE
, pArg
->pszMessage
);
150 msg
.SetVariable(VID_DESCRIPTION
, pArg
->pszDescription
);
151 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
154 return ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
159 // Delete event template
162 DWORD LIBNXCL_EXPORTABLE
NXCDeleteEventTemplate(NXC_SESSION hSession
, DWORD dwEventCode
)
167 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
170 msg
.SetCode(CMD_DELETE_EVENT_TEMPLATE
);
172 msg
.SetVariable(VID_EVENT_CODE
, dwEventCode
);
173 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
176 return ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
181 // Generate ID for new event
184 DWORD LIBNXCL_EXPORTABLE
NXCGenerateEventCode(NXC_SESSION hSession
, DWORD
*pdwEventCode
)
186 CSCPMessage msg
, *pResponse
;
187 DWORD dwRqId
, dwRetCode
;
189 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
192 msg
.SetCode(CMD_GENERATE_EVENT_CODE
);
194 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
197 pResponse
= ((NXCL_Session
*)hSession
)->WaitForMessage(CMD_REQUEST_COMPLETED
, dwRqId
);
198 if (pResponse
!= NULL
)
200 dwRetCode
= pResponse
->GetVariableLong(VID_RCC
);
201 if (dwRetCode
== RCC_SUCCESS
)
202 *pdwEventCode
= pResponse
->GetVariableLong(VID_EVENT_CODE
);
206 dwRetCode
= RCC_TIMEOUT
;
213 // Get pointer to event templates list
216 BOOL LIBNXCL_EXPORTABLE
NXCGetEventDB(NXC_SESSION hSession
,
217 NXC_EVENT_TEMPLATE
***pppTemplateList
,
218 DWORD
*pdwNumRecords
)
220 return ((NXCL_Session
*)hSession
)->GetEventDB(pppTemplateList
, pdwNumRecords
);
225 // Resolve event id to name
228 const TCHAR LIBNXCL_EXPORTABLE
*NXCGetEventName(NXC_SESSION hSession
, DWORD dwId
)
230 return ((NXCL_Session
*)hSession
)->GetEventName(dwId
);
235 // Resolve event id to name using application-provided buffer
238 BOOL LIBNXCL_EXPORTABLE
NXCGetEventNameEx(NXC_SESSION hSession
, DWORD dwId
,
239 TCHAR
*pszBuffer
, DWORD dwBufSize
)
241 return ((NXCL_Session
*)hSession
)->GetEventNameEx(dwId
, pszBuffer
, dwBufSize
);
246 // Get severity for given event id. Will return -1 for unknown id.
249 int LIBNXCL_EXPORTABLE
NXCGetEventSeverity(NXC_SESSION hSession
, DWORD dwId
)
251 return ((NXCL_Session
*)hSession
)->GetEventSeverity(dwId
);
256 // Get text of event template with given ID.
257 // If there are no template with such ID, empty string will be returned.
260 BOOL LIBNXCL_EXPORTABLE
NXCGetEventText(NXC_SESSION hSession
, DWORD dwId
, TCHAR
*pszBuffer
, DWORD dwBufSize
)
262 return ((NXCL_Session
*)hSession
)->GetEventText(dwId
, pszBuffer
, dwBufSize
);