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 // Process event log records coming from server
31 void ProcessEventLogRecords(NXCL_Session
*pSession
, CSCPMessage
*pMsg
)
33 DWORD i
, dwNumRecords
, dwId
;
37 dwNumRecords
= pMsg
->GetVariableLong(VID_NUM_RECORDS
);
38 nOrder
= (int)pMsg
->GetVariableShort(VID_RECORDS_ORDER
);
39 DebugPrintf(_T("ProcessEventLogRecords(): %d records in message, in %s order"),
40 dwNumRecords
, (nOrder
== RECORD_ORDER_NORMAL
) ?
_T("normal") : _T("reversed"));
41 for(i
= 0, dwId
= VID_EVENTLOG_MSG_BASE
; i
< dwNumRecords
; i
++)
43 event
.qwEventId
= pMsg
->GetVariableInt64(dwId
++);
44 event
.dwEventCode
= pMsg
->GetVariableLong(dwId
++);
45 event
.dwTimeStamp
= pMsg
->GetVariableLong(dwId
++);
46 event
.dwSourceId
= pMsg
->GetVariableLong(dwId
++);
47 event
.dwSeverity
= pMsg
->GetVariableShort(dwId
++);
48 pMsg
->GetVariableStr(dwId
++, event
.szMessage
, MAX_EVENT_MSG_LENGTH
);
49 pMsg
->GetVariableStr(dwId
++, event
.szUserTag
, MAX_USERTAG_LENGTH
);
52 DWORD count
= pMsg
->GetVariableLong(dwId
++);
55 // Call client's callback to handle new record
56 pSession
->callEventHandler(NXC_EVENT_NEW_ELOG_RECORD
, nOrder
, &event
);
59 // Notify requestor thread if all messages was received
60 if (pMsg
->IsEndOfSequence())
61 pSession
->CompleteSync(SYNC_EVENTS
, RCC_SUCCESS
);
66 // Synchronize event log
67 // This function is NOT REENTRANT
70 DWORD LIBNXCL_EXPORTABLE
NXCSyncEvents(NXC_SESSION hSession
, DWORD dwMaxRecords
)
73 DWORD dwRetCode
, dwRqId
;
75 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
76 ((NXCL_Session
*)hSession
)->PrepareForSync(SYNC_EVENTS
);
78 msg
.SetCode(CMD_GET_EVENTS
);
80 msg
.SetVariable(VID_MAX_RECORDS
, dwMaxRecords
);
81 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
83 dwRetCode
= ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
84 if (dwRetCode
== RCC_SUCCESS
)
85 dwRetCode
= ((NXCL_Session
*)hSession
)->WaitForSync(SYNC_EVENTS
, INFINITE
);
87 ((NXCL_Session
*)hSession
)->UnlockSyncOp(SYNC_EVENTS
);
94 // Send event to server
97 DWORD LIBNXCL_EXPORTABLE
NXCSendEvent(NXC_SESSION hSession
, DWORD dwEventCode
,
98 DWORD dwObjectId
, int iNumArgs
, TCHAR
**pArgList
,
105 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
107 msg
.SetCode(CMD_TRAP
);
109 msg
.SetVariable(VID_EVENT_CODE
, dwEventCode
);
110 msg
.SetVariable(VID_OBJECT_ID
, dwObjectId
);
111 msg
.SetVariable(VID_USER_TAG
, CHECK_NULL_EX(pszUserTag
));
112 msg
.SetVariable(VID_NUM_ARGS
, (WORD
)iNumArgs
);
113 for(i
= 0; i
< iNumArgs
; i
++)
114 msg
.SetVariable(VID_EVENT_ARG_BASE
+ i
, pArgList
[i
]);
115 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
117 return ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
122 // Process syslog records coming from server
125 void ProcessSyslogRecords(NXCL_Session
*pSession
, CSCPMessage
*pMsg
)
127 DWORD i
, dwNumRecords
, dwId
;
128 NXC_SYSLOG_RECORD rec
;
131 dwNumRecords
= pMsg
->GetVariableLong(VID_NUM_RECORDS
);
132 nOrder
= (int)pMsg
->GetVariableShort(VID_RECORDS_ORDER
);
133 DebugPrintf(_T("ProcessSyslogRecords(): %d records in message, in %s order"),
134 dwNumRecords
, (nOrder
== RECORD_ORDER_NORMAL
) ?
_T("normal") : _T("reversed"));
135 for(i
= 0, dwId
= VID_SYSLOG_MSG_BASE
; i
< dwNumRecords
; i
++)
137 rec
.qwMsgId
= pMsg
->GetVariableInt64(dwId
++);
138 rec
.dwTimeStamp
= pMsg
->GetVariableLong(dwId
++);
139 rec
.wFacility
= pMsg
->GetVariableShort(dwId
++);
140 rec
.wSeverity
= pMsg
->GetVariableShort(dwId
++);
141 rec
.dwSourceObject
= pMsg
->GetVariableLong(dwId
++);
142 pMsg
->GetVariableStr(dwId
++, rec
.szHost
, MAX_SYSLOG_HOSTNAME_LEN
);
143 pMsg
->GetVariableStr(dwId
++, rec
.szTag
, MAX_SYSLOG_TAG_LEN
);
144 rec
.pszText
= pMsg
->GetVariableStr(dwId
++);
146 // Call client's callback to handle new record
147 pSession
->callEventHandler(NXC_EVENT_NEW_SYSLOG_RECORD
, nOrder
, &rec
);
151 // Notify requestor thread if all messages was received
152 if (pMsg
->IsEndOfSequence())
153 pSession
->CompleteSync(SYNC_SYSLOG
, RCC_SUCCESS
);
158 // Synchronize syslog
159 // This function is NOT REENTRANT
162 DWORD LIBNXCL_EXPORTABLE
NXCSyncSyslog(NXC_SESSION hSession
, DWORD dwMaxRecords
)
165 DWORD dwRetCode
, dwRqId
;
167 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
168 ((NXCL_Session
*)hSession
)->PrepareForSync(SYNC_SYSLOG
);
170 msg
.SetCode(CMD_GET_SYSLOG
);
172 msg
.SetVariable(VID_MAX_RECORDS
, dwMaxRecords
);
173 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
175 dwRetCode
= ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
176 if (dwRetCode
== RCC_SUCCESS
)
177 dwRetCode
= ((NXCL_Session
*)hSession
)->WaitForSync(SYNC_SYSLOG
, INFINITE
);
179 ((NXCL_Session
*)hSession
)->UnlockSyncOp(SYNC_SYSLOG
);