2 ** NetXMS - Network Management System
4 ** Copyright (C) 2004, 2005, 2006, 2007, 2008 Victor Kirhenshtein
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 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 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 // Get list of configuration variables
31 DWORD LIBNXCL_EXPORTABLE
NXCGetServerVariables(NXC_SESSION hSession
,
32 NXC_SERVER_VARIABLE
**ppVarList
,
35 CSCPMessage msg
, *pResponse
;
36 DWORD i
, dwId
, dwRqId
, dwRetCode
;
38 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
43 // Build request message
44 msg
.SetCode(CMD_GET_CONFIG_VARLIST
);
48 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
51 pResponse
= ((NXCL_Session
*)hSession
)->WaitForMessage(CMD_REQUEST_COMPLETED
, dwRqId
, 30000);
52 if (pResponse
!= NULL
)
54 dwRetCode
= pResponse
->GetVariableLong(VID_RCC
);
55 if (dwRetCode
== RCC_SUCCESS
)
57 *pdwNumVars
= pResponse
->GetVariableLong(VID_NUM_VARIABLES
);
58 *ppVarList
= (NXC_SERVER_VARIABLE
*)malloc(sizeof(NXC_SERVER_VARIABLE
) * (*pdwNumVars
));
60 for(i
= 0, dwId
= VID_VARLIST_BASE
; i
< *pdwNumVars
; i
++)
62 pResponse
->GetVariableStr(dwId
++, (*ppVarList
)[i
].szName
, MAX_OBJECT_NAME
);
63 pResponse
->GetVariableStr(dwId
++, (*ppVarList
)[i
].szValue
, MAX_DB_STRING
);
64 (*ppVarList
)[i
].bNeedRestart
= pResponse
->GetVariableShort(dwId
++) ? TRUE
: FALSE
;
71 dwRetCode
= RCC_TIMEOUT
;
79 // Set value of server's variable
82 DWORD LIBNXCL_EXPORTABLE
NXCSetServerVariable(NXC_SESSION hSession
, const TCHAR
*pszVarName
,
83 const TCHAR
*pszValue
)
88 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
90 msg
.SetCode(CMD_SET_CONFIG_VARIABLE
);
92 msg
.SetVariable(VID_NAME
, pszVarName
);
93 msg
.SetVariable(VID_VALUE
, pszValue
);
94 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
96 return ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
101 // Delete server's variable
104 DWORD LIBNXCL_EXPORTABLE
NXCDeleteServerVariable(NXC_SESSION hSession
, const TCHAR
*pszVarName
)
109 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
111 msg
.SetCode(CMD_DELETE_CONFIG_VARIABLE
);
113 msg
.SetVariable(VID_NAME
, pszVarName
);
114 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
116 return ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
121 // Get server statistics
124 DWORD LIBNXCL_EXPORTABLE
NXCGetServerStats(NXC_SESSION hSession
, NXC_SERVER_STATS
*pStats
)
126 CSCPMessage msg
, *pResponse
;
127 DWORD dwRqId
, dwRetCode
;
129 memset(pStats
, 0, sizeof(NXC_SERVER_STATS
));
130 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
132 msg
.SetCode(CMD_GET_SERVER_STATS
);
134 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
136 pResponse
= ((NXCL_Session
*)hSession
)->WaitForMessage(CMD_REQUEST_COMPLETED
, dwRqId
);
137 if (pResponse
!= NULL
)
139 dwRetCode
= pResponse
->GetVariableLong(VID_RCC
);
140 if (dwRetCode
== RCC_SUCCESS
)
142 pStats
->dwNumAlarms
= pResponse
->GetVariableLong(VID_NUM_ALARMS
);
143 pResponse
->GetVariableInt32Array(VID_ALARMS_BY_SEVERITY
, 5, pStats
->dwAlarmsBySeverity
);
144 pStats
->dwNumClientSessions
= pResponse
->GetVariableLong(VID_NUM_SESSIONS
);
145 pStats
->dwNumDCI
= pResponse
->GetVariableLong(VID_NUM_ITEMS
);
146 pStats
->dwNumNodes
= pResponse
->GetVariableLong(VID_NUM_NODES
);
147 pStats
->dwNumObjects
= pResponse
->GetVariableLong(VID_NUM_OBJECTS
);
148 pStats
->dwServerProcessVMSize
= pResponse
->GetVariableLong(VID_NETXMSD_PROCESS_VMSIZE
);
149 pStats
->dwServerProcessWorkSet
= pResponse
->GetVariableLong(VID_NETXMSD_PROCESS_WKSET
);
150 pStats
->dwServerUptime
= pResponse
->GetVariableLong(VID_SERVER_UPTIME
);
151 pResponse
->GetVariableStr(VID_SERVER_VERSION
, pStats
->szServerVersion
, MAX_DB_STRING
);
152 pStats
->dwQSizeConditionPoller
= pResponse
->GetVariableLong(VID_QSIZE_CONDITION_POLLER
);
153 pStats
->dwQSizeConfPoller
= pResponse
->GetVariableLong(VID_QSIZE_CONF_POLLER
);
154 pStats
->dwQSizeDBWriter
= pResponse
->GetVariableLong(VID_QSIZE_DBWRITER
);
155 pStats
->dwQSizeDCIPoller
= pResponse
->GetVariableLong(VID_QSIZE_DCI_POLLER
);
156 pStats
->dwQSizeDiscovery
= pResponse
->GetVariableLong(VID_QSIZE_DISCOVERY
);
157 pStats
->dwQSizeEvents
= pResponse
->GetVariableLong(VID_QSIZE_EVENT
);
158 pStats
->dwQSizeNodePoller
= pResponse
->GetVariableLong(VID_QSIZE_NODE_POLLER
);
159 pStats
->dwQSizeRoutePoller
= pResponse
->GetVariableLong(VID_QSIZE_ROUTE_POLLER
);
160 pStats
->dwQSizeStatusPoller
= pResponse
->GetVariableLong(VID_QSIZE_STATUS_POLLER
);
166 dwRetCode
= RCC_TIMEOUT
;
176 DWORD LIBNXCL_EXPORTABLE
NXCGetAddrList(NXC_SESSION hSession
, DWORD dwListType
,
177 DWORD
*pdwAddrCount
, NXC_ADDR_ENTRY
**ppAddrList
)
179 DWORD i
, dwRetCode
, dwRqId
, dwId
;
180 CSCPMessage msg
, *pResponse
;
182 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
184 msg
.SetCode(CMD_GET_ADDR_LIST
);
186 msg
.SetVariable(VID_ADDR_LIST_TYPE
, dwListType
);
187 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
189 pResponse
= ((NXCL_Session
*)hSession
)->WaitForMessage(CMD_REQUEST_COMPLETED
, dwRqId
);
190 if (pResponse
!= NULL
)
192 dwRetCode
= pResponse
->GetVariableLong(VID_RCC
);
193 if (dwRetCode
== RCC_SUCCESS
)
195 *pdwAddrCount
= pResponse
->GetVariableLong(VID_NUM_RECORDS
);
196 *ppAddrList
= (NXC_ADDR_ENTRY
*)malloc(sizeof(NXC_ADDR_ENTRY
) * (*pdwAddrCount
));
197 for(i
= 0, dwId
= VID_ADDR_LIST_BASE
; i
< *pdwAddrCount
; i
++, dwId
+= 7)
199 (*ppAddrList
)[i
].dwType
= pResponse
->GetVariableLong(dwId
++);
200 (*ppAddrList
)[i
].dwAddr1
= pResponse
->GetVariableLong(dwId
++);
201 (*ppAddrList
)[i
].dwAddr2
= pResponse
->GetVariableLong(dwId
++);
208 dwRetCode
= RCC_TIMEOUT
;
218 DWORD LIBNXCL_EXPORTABLE
NXCSetAddrList(NXC_SESSION hSession
, DWORD dwListType
,
219 DWORD dwAddrCount
, NXC_ADDR_ENTRY
*pAddrList
)
221 DWORD i
, dwRqId
, dwId
;
224 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
226 msg
.SetCode(CMD_SET_ADDR_LIST
);
228 msg
.SetVariable(VID_ADDR_LIST_TYPE
, dwListType
);
229 msg
.SetVariable(VID_NUM_RECORDS
, dwAddrCount
);
230 for(i
= 0, dwId
= VID_ADDR_LIST_BASE
; i
< dwAddrCount
; i
++, dwId
+= 7)
232 msg
.SetVariable(dwId
++, pAddrList
[i
].dwType
);
233 msg
.SetVariable(dwId
++, pAddrList
[i
].dwAddr1
);
234 msg
.SetVariable(dwId
++, pAddrList
[i
].dwAddr2
);
236 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
238 return ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
243 // Reset server's component
246 DWORD LIBNXCL_EXPORTABLE
NXCResetServerComponent(NXC_SESSION hSession
, DWORD dwComponent
)
251 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
253 msg
.SetCode(CMD_RESET_COMPONENT
);
255 msg
.SetVariable(VID_COMPONENT_ID
, dwComponent
);
256 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
258 return ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
263 // Get value of CLOB config variable
266 DWORD LIBNXCL_EXPORTABLE
NXCGetServerConfigCLOB(NXC_SESSION hSession
, const TCHAR
*name
, TCHAR
**value
)
268 CSCPMessage msg
, *pResponse
;
269 DWORD dwRqId
, dwRetCode
;
271 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
274 // Build request message
275 msg
.SetCode(CMD_CONFIG_GET_CLOB
);
277 msg
.SetVariable(VID_NAME
, name
);
280 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
283 pResponse
= ((NXCL_Session
*)hSession
)->WaitForMessage(CMD_REQUEST_COMPLETED
, dwRqId
);
284 if (pResponse
!= NULL
)
286 dwRetCode
= pResponse
->GetVariableLong(VID_RCC
);
287 if (dwRetCode
== RCC_SUCCESS
)
289 *value
= pResponse
->GetVariableStr(VID_VALUE
);
295 dwRetCode
= RCC_TIMEOUT
;
303 // Set value of CLOB config variable
306 DWORD LIBNXCL_EXPORTABLE
NXCSetServerConfigCLOB(NXC_SESSION hSession
, const TCHAR
*name
, const TCHAR
*value
)
311 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
313 // Build request message
314 msg
.SetCode(CMD_CONFIG_SET_CLOB
);
316 msg
.SetVariable(VID_NAME
, name
);
317 msg
.SetVariable(VID_VALUE
, value
);
320 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
322 return ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);