- Added user database loading
[public/netxms.git] / include / nxclapi.h
CommitLineData
80ffed5a
VK
1/*
2** NetXMS - Network Management System
3** Client Library API
4** Copyright (C) 2004 Victor Kirhenshtein
5**
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.
10**
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.
15**
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.
19**
20** $module: nxclapi.h
21**
22**/
23
24#ifndef _nxclapi_h_
25#define _nxclapi_h_
26
27#include <nms_common.h>
5ebea5e0 28#include <nxevent.h>
80ffed5a 29
8aeffdee
VK
30#ifdef _WIN32
31#ifdef LIBNXCL_EXPORTS
32#define LIBNXCL_EXPORTABLE __declspec(dllexport)
33#else
34#define LIBNXCL_EXPORTABLE __declspec(dllimport)
35#endif
36#else /* _WIN32 */
37#define LIBNXCL_EXPORTABLE
38#endif
39
80ffed5a 40
c6576857
VK
41//
42// Custom data types
43//
44
45typedef unsigned long HREQUEST;
46
47
0c8bf759
VK
48//
49// Some constants
50//
51
878c92bc
VK
52#define MAX_OBJECT_NAME 64
53#define MAX_COMMUNITY_LENGTH 32
54#define MAX_OID_LENGTH 1024
55#define MAX_EVENT_MSG_LENGTH 256
56#define MAX_EVENT_NAME 64
57#define INVALID_REQUEST_HANDLE ((HREQUEST)0xFFFFFFFF)
0c8bf759
VK
58
59
71c18491
VK
60//
61// Authentication methods
62//
63
64#define AUTH_NONE 0
65#define AUTH_PLAINTEXT 1
66#define AUTH_MD5_HASH 2
67#define AUTH_SHA1_HASH 3
68
69
70//
71// Object types
72//
73
74#define OBJECT_GENERIC 0
75#define OBJECT_SUBNET 1
76#define OBJECT_NODE 2
77#define OBJECT_INTERFACE 3
78#define OBJECT_NETWORK 4
372b525a
VK
79#define OBJECT_LOCATION 5
80#define OBJECT_ZONE 6
71c18491
VK
81
82
4d597931
VK
83//
84// Node flags
85//
86
87#define NF_IS_SNMP 0x0001
88#define NF_IS_NATIVE_AGENT 0x0002
89#define NF_IS_BRIDGE 0x0004
90#define NF_IS_ROUTER 0x0008
91#define NF_IS_LOCAL_MGMT 0x0010
92
93
5fad5c32
VK
94//
95// Events
96//
97
878c92bc
VK
98#define NXC_EVENT_STATE_CHANGED 1
99#define NXC_EVENT_ERROR 2
100#define NXC_EVENT_LOGIN_RESULT 3
101#define NXC_EVENT_NEW_ELOG_RECORD 4
102#define NXC_EVENT_REQUEST_COMPLETED 5
4d597931 103#define NXC_EVENT_OBJECT_CHANGED 6
71f8d3d7
VK
104
105
106//
107// Errors
108//
109
110#define NXC_ERR_INTERNAL 1
5fad5c32
VK
111
112
54481027
VK
113//
114// States
115//
116
117#define STATE_DISCONNECTED 0
118#define STATE_CONNECTING 1
119#define STATE_IDLE 2
7e986059
VK
120#define STATE_SYNC_OBJECTS 3
121#define STATE_SYNC_EVENTS 4
878c92bc
VK
122#define STATE_LOAD_EVENT_DB 5
123#define STATE_LOAD_EPP 6
7e986059
VK
124
125
126//
127// Operations
128//
129
878c92bc
VK
130#define NXC_OP_SYNC_OBJECTS 1
131#define NXC_OP_SYNC_EVENTS 2
132#define NXC_OP_OPEN_EVENT_DB 3
133#define NXC_OP_CLOSE_EVENT_DB 4
31521248 134#define NXC_OP_SET_EVENT_INFO 5
effb51ab 135#define NXC_OP_MODIFY_OBJECT 6
54481027
VK
136
137
b601b1fa
VK
138//
139// Notification codes
140//
141
878c92bc
VK
142#define NX_NOTIFY_SHUTDOWN 1
143
144
145//
146// Request completion codes
147//
148
149#define RCC_SUCCESS ((DWORD)0)
150#define RCC_COMPONENT_LOCKED ((DWORD)1)
151#define RCC_ACCESS_DENIED ((DWORD)2)
152#define RCC_INVALID_REQUEST ((DWORD)3)
153#define RCC_TIMEOUT ((DWORD)4)
605d2931
VK
154#define RCC_OUT_OF_STATE_REQUEST ((DWORD)5)
155#define RCC_DB_FAILURE ((DWORD)6)
effb51ab 156#define RCC_INVALID_OBJECT_ID ((DWORD)7)
878c92bc
VK
157
158
d9152256
VK
159//
160// Mask bits for NXCModifyEventTemplate()
161//
162
163#define EM_SEVERITY ((DWORD)0x01)
164#define EM_FLAGS ((DWORD)0x02)
165#define EM_NAME ((DWORD)0x04)
166#define EM_MESSAGE ((DWORD)0x08)
167#define EM_DESCRIPTION ((DWORD)0x10)
168#define EM_ALL ((DWORD)0x1F)
169
170
effb51ab
VK
171//
172// Mask bits (flags) for NXCModifyObject()
173//
174
175#define OBJ_UPDATE_NAME ((DWORD)0x01)
176#define OBJ_UPDATE_AGENT_PORT ((DWORD)0x02)
177#define OBJ_UPDATE_AGENT_AUTH ((DWORD)0x04)
178#define OBJ_UPDATE_AGENT_SECRET ((DWORD)0x08)
179#define OBJ_UPDATE_SNMP_VERSION ((DWORD)0x10)
180#define OBJ_UPDATE_SNMP_COMMUNITY ((DWORD)0x20)
181#define OBJ_UPDATE_ACL ((DWORD)0x40)
182#define OBJ_UPDATE_ALL ((DWORD)0x7F)
183
184
878c92bc
VK
185//
186// Custom data types
187//
188
189typedef unsigned long HREQUEST;
b601b1fa
VK
190
191
54481027 192//
0c8bf759 193// Callbacks data types
54481027
VK
194//
195
196typedef void (* NXC_EVENT_HANDLER)(DWORD dwEvent, DWORD dwCode, void *pArg);
5d63b3c1 197typedef void (* NXC_DEBUG_CALLBACK)(char *pMsg);
54481027
VK
198
199
878c92bc
VK
200//
201// Event configuration structure
202//
203
204typedef struct
205{
206 DWORD dwCode;
207 DWORD dwSeverity;
208 DWORD dwFlags;
209 char szName[MAX_EVENT_NAME];
210 char *pszMessage;
211 char *pszDescription;
212} NXC_EVENT_TEMPLATE;
213
214
a1dc75b0
VK
215//
216// Event log record structure
217//
218
219typedef struct
220{
221 DWORD dwTimeStamp;
222 DWORD dwEventId;
223 DWORD dwSourceId;
224 DWORD dwSeverity;
225 char szMessage[MAX_EVENT_MSG_LENGTH];
226} NXC_EVENT;
227
228
effb51ab
VK
229//
230// Entry in object's ACL
231//
232
233typedef struct
234{
235 DWORD dwUserId;
236 DWORD dwAccessRights;
237} NXC_ACL_ENTRY;
238
239
0c8bf759
VK
240//
241// Network object structure
242//
243
244typedef struct
245{
246 DWORD dwId; // Unique object's identifier
247 int iClass; // Object's class
248 int iStatus; // Object's status
249 DWORD dwIpAddr; // IP address
250 char szName[MAX_OBJECT_NAME];
251 DWORD dwNumParents;
252 DWORD *pdwParentList;
253 DWORD dwNumChilds;
254 DWORD *pdwChildList;
4d597931 255 BOOL bIsDeleted; // TRUE for deleted objects
effb51ab
VK
256 BOOL bInheritRights;
257 DWORD dwAclSize;
258 NXC_ACL_ENTRY *pAccessList;
0c8bf759
VK
259 union
260 {
261 struct
262 {
263 DWORD dwIpNetMask; // Ip netmask.
264 DWORD dwIfIndex; // Interface index.
265 DWORD dwIfType; // Interface type
266 } iface;
267 struct
268 {
269 DWORD dwFlags;
270 DWORD dwDiscoveryFlags;
271 char szSharedSecret[MAX_SECRET_LENGTH];
272 char szCommunityString[MAX_COMMUNITY_LENGTH];
273 char szObjectId[MAX_OID_LENGTH];
274 WORD wAgentPort; // Listening TCP port for native agent
275 WORD wAuthMethod; // Native agent's authentication method
276 } node;
277 struct
278 {
279 DWORD dwIpNetMask;
280 } subnet;
281 };
282} NXC_OBJECT;
283
284
effb51ab
VK
285//
286// Structure with data for NXCModifyObject
287//
288
289typedef struct
290{
291 DWORD dwObjectId;
292 DWORD dwFlags;
293 char *pszName;
294 int iAgentPort;
295 int iAuthType;
296 char *pszSecret;
297 int iSnmpVersion;
298 char *pszCommunity;
299 BOOL bInheritRights;
300 DWORD dwAclSize;
301 NXC_ACL_ENTRY *pAccessList;
302} NXC_OBJECT_UPDATE;
303
304
80ffed5a
VK
305//
306// Functions
307//
308
309#ifdef __cplusplus
310extern "C" {
311#endif
312
8aeffdee 313DWORD LIBNXCL_EXPORTABLE NXCGetVersion(void);
effb51ab
VK
314const char LIBNXCL_EXPORTABLE *NXCGetErrorText(DWORD dwError);
315
8aeffdee
VK
316BOOL LIBNXCL_EXPORTABLE NXCInitialize(void);
317BOOL LIBNXCL_EXPORTABLE NXCConnect(char *szServer, char *szLogin, char *szPassword);
318void LIBNXCL_EXPORTABLE NXCDisconnect(void);
319void LIBNXCL_EXPORTABLE NXCSetEventHandler(NXC_EVENT_HANDLER pHandler);
320void LIBNXCL_EXPORTABLE NXCSetDebugCallback(NXC_DEBUG_CALLBACK pFunc);
321HREQUEST LIBNXCL_EXPORTABLE NXCRequest(DWORD dwOperation, ...);
80ffed5a 322
8aeffdee 323NXC_OBJECT LIBNXCL_EXPORTABLE *NXCFindObjectById(DWORD dwId);
a98e6d5f 324NXC_OBJECT LIBNXCL_EXPORTABLE *NXCFindObjectByName(char *pszName);
8aeffdee
VK
325void LIBNXCL_EXPORTABLE NXCEnumerateObjects(BOOL (* pHandler)(NXC_OBJECT *));
326NXC_OBJECT LIBNXCL_EXPORTABLE *NXCGetRootObject(void);
8e80aeb6
VK
327void LIBNXCL_EXPORTABLE *NXCGetObjectIndex(DWORD *pdwNumObjects);
328void LIBNXCL_EXPORTABLE NXCLockObjectIndex(void);
329void LIBNXCL_EXPORTABLE NXCUnlockObjectIndex(void);
8b3d61c1 330
8aeffdee
VK
331BOOL LIBNXCL_EXPORTABLE NXCGetEventDB(NXC_EVENT_TEMPLATE ***pppTemplateList, DWORD *pdwNumRecords);
332void LIBNXCL_EXPORTABLE NXCModifyEventTemplate(NXC_EVENT_TEMPLATE *pEvent, DWORD dwMask,
d9152256
VK
333 DWORD dwSeverity, DWORD dwFlags, const char *pszName,
334 const char *pszMessage, const char *pszDescription);
878c92bc 335
80ffed5a
VK
336#ifdef __cplusplus
337}
338#endif
339
340
7e986059 341//
bc97ab99 342// Inline functions
7e986059
VK
343//
344
bc97ab99
VK
345#ifdef __cplusplus
346
347#ifndef __libnxcl_inline_c__
348inline DWORD NXCSyncObjects(void) { return NXCRequest(NXC_OP_SYNC_OBJECTS); }
349inline DWORD NXCSyncEvents(void) { return NXCRequest(NXC_OP_SYNC_EVENTS); }
350inline DWORD NXCOpenEventDB(void) { return NXCRequest(NXC_OP_OPEN_EVENT_DB); }
351inline DWORD NXCCloseEventDB(BOOL bSaveChanges) { return NXCRequest(NXC_OP_CLOSE_EVENT_DB, bSaveChanges); }
effb51ab 352inline DWORD NXCModifyObject(NXC_OBJECT_UPDATE *pData) { return NXCRequest(NXC_OP_MODIFY_OBJECT, pData); }
bc97ab99
VK
353#endif /* __libnxcl_inline_c__ */
354
355#else /* __cplusplus */
356
8aeffdee
VK
357DWORD LIBNXCL_EXPORTABLE NXCSyncObjects(void);
358DWORD LIBNXCL_EXPORTABLE NXCSyncEvents(void);
359DWORD LIBNXCL_EXPORTABLE NXCOpenEventDB(void);
360DWORD LIBNXCL_EXPORTABLE NXCCloseEventDB(BOOL bSaveChanges);
effb51ab 361DWORD LIBNXCL_EXPORTABLE NXCModifyObject(NXC_OBJECT_UPDATE *pData);
7e986059 362
bc97ab99 363#endif /* __cplusplus */
7e986059 364
80ffed5a 365#endif /* _nxclapi_h_ */