outdated object image stuff removed
[public/netxms.git] / src / server / include / nms_core.h
1 /* $Id$ */
2 /*
3 ** NetXMS - Network Management System
4 ** Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 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 ** File: nms_core.h
21 **
22 **/
23
24 #ifndef _nms_core_h_
25 #define _nms_core_h_
26
27 #ifdef _WIN32
28 #ifdef NXCORE_EXPORTS
29 #define NXCORE_EXPORTABLE __declspec(dllexport)
30 #else
31 #define NXCORE_EXPORTABLE __declspec(dllimport)
32 #endif
33 #else /* _WIN32 */
34 #define NXCORE_EXPORTABLE
35 #endif
36
37 #define LIBNXCL_NO_DECLARATIONS 1
38
39 #include <nms_common.h>
40
41 #ifndef _WIN32
42
43 #if HAVE_SYS_TYPES_H
44 # include <sys/types.h>
45 #endif
46
47 #if HAVE_DLFCN_H
48 #include <dlfcn.h>
49 #endif
50
51 #define WSAGetLastError() (errno)
52
53 #endif /* _WIN32 */
54
55 #include <time.h>
56 #include <stdio.h>
57 #include <string.h>
58 #include <stdarg.h>
59
60 #define SHOW_FLAG_VALUE(x) _T(" %-32s = %d\n"), _T(#x), (g_dwFlags & x) ? 1 : 0
61
62
63 //
64 // Common includes
65 //
66
67 #include <nms_util.h>
68 #include <dbdrv.h>
69 #include <nms_cscp.h>
70 #include <uuid.h>
71 #include <nxsrvapi.h>
72 #include <nxqueue.h>
73 #include <nxsnmp.h>
74 #include <nxmodule.h>
75 #include <nxsl.h>
76
77
78 //
79 // Console context
80 //
81
82 struct __console_ctx
83 {
84 SOCKET hSocket;
85 CSCPMessage *pMsg;
86 };
87
88 typedef __console_ctx * CONSOLE_CTX;
89
90
91 //
92 // Server includes
93 //
94
95 #include "nms_dcoll.h"
96 #include "nms_users.h"
97 #include "nms_objects.h"
98 #include "nms_locks.h"
99 #include "nms_pkg.h"
100 #include "nms_topo.h"
101 #include "nms_script.h"
102 #include "nxcore_maps.h"
103 #include "nxcore_situations.h"
104 #include "nxcore_jobs.h"
105
106
107 //
108 // Common constants and macros
109 //
110
111 #define MAX_LINE_SIZE 4096
112
113 #define GROUP_FLAG_BIT ((DWORD)0x80000000)
114
115 typedef void * HSNMPSESSION;
116
117 #define CHECKPOINT_SNMP_PORT 260
118
119
120 //
121 // Unique identifier group codes
122 //
123
124 #define IDG_NETWORK_OBJECT 0
125 #define IDG_CONTAINER_CAT 1
126 #define IDG_EVENT 2
127 #define IDG_ITEM 3
128 #define IDG_SNMP_TRAP 4
129 //#define IDG_IMAGE 5
130 #define IDG_ACTION 6
131 #define IDG_EVENT_GROUP 7
132 #define IDG_THRESHOLD 8
133 #define IDG_USER 9
134 #define IDG_USER_GROUP 10
135 #define IDG_ALARM 11
136 #define IDG_ALARM_NOTE 12
137 #define IDG_PACKAGE 13
138 //#define IDG_LPP 14
139 #define IDG_OBJECT_TOOL 15
140 #define IDG_SCRIPT 16
141 #define IDG_AGENT_CONFIG 17
142 #define IDG_GRAPH 18
143 #define IDG_CERTIFICATE 19
144 #define IDG_SITUATION 20
145 #define IDG_MAP 21
146
147
148 //
149 // Exit codes for console commands
150 //
151
152 #define CMD_EXIT_CONTINUE 0
153 #define CMD_EXIT_CLOSE_SESSION 1
154 #define CMD_EXIT_SHUTDOWN 2
155
156
157 //
158 // Network discovery mode
159 //
160
161 #define DISCOVERY_DISABLED 0
162 #define DISCOVERY_PASSIVE_ONLY 1
163 #define DISCOVERY_ACTIVE 2
164
165
166 //
167 // Client session flags
168 //
169
170 #define CSF_EVENT_DB_LOCKED ((DWORD)0x0001)
171 #define CSF_EPP_LOCKED ((DWORD)0x0002)
172 #define CSF_PACKAGE_DB_LOCKED ((DWORD)0x0004)
173 #define CSF_USER_DB_LOCKED ((DWORD)0x0008)
174 #define CSF_EPP_UPLOAD ((DWORD)0x0010)
175 #define CSF_ACTION_DB_LOCKED ((DWORD)0x0020)
176 #define CSF_TRAP_CFG_LOCKED ((DWORD)0x0040)
177 #define CSF_AUTHENTICATED ((DWORD)0x0080)
178 #define CSF_OBJECT_TOOLS_LOCKED ((DWORD)0x0100)
179 #define CSF_RECEIVING_MAP_DATA ((DWORD)0x0200)
180 #define CSF_SYNC_OBJECT_COMMENTS ((DWORD)0x0400)
181
182
183 //
184 // Client session states
185 //
186
187 #define SESSION_STATE_INIT 0
188 #define SESSION_STATE_IDLE 1
189 #define SESSION_STATE_PROCESSING 2
190
191
192 //
193 // Information categories for UPDATE_INFO structure
194 //
195
196 #define INFO_CAT_EVENT 1
197 #define INFO_CAT_OBJECT_CHANGE 2
198 #define INFO_CAT_ALARM 3
199 #define INFO_CAT_ACTION 4
200 #define INFO_CAT_SYSLOG_MSG 5
201 #define INFO_CAT_SNMP_TRAP 6
202 #define INFO_CAT_AUDIT_RECORD 7
203 #define INFO_CAT_SITUATION 8
204
205
206 //
207 // Certificate types
208 //
209
210 #define CERT_TYPE_TRUSTED_CA 0
211 #define CERT_TYPE_USER 1
212
213
214 //
215 // Audit subsystems
216 //
217
218 #define AUDIT_SECURITY _T("SECURITY")
219 #define AUDIT_OBJECTS _T("OBJECTS")
220 #define AUDIT_SYSCFG _T("SYSCFG")
221 #define AUDIT_CONSOLE _T("CONSOLE")
222
223
224 //
225 // Event handling subsystem definitions
226 //
227
228 #include "nms_events.h"
229 #include "nms_actions.h"
230 #include "nms_alarm.h"
231
232
233 //
234 // New node information
235 //
236
237 typedef struct
238 {
239 DWORD dwIpAddr;
240 DWORD dwNetMask;
241 BOOL ignoreFilter;
242 } NEW_NODE;
243
244
245 //
246 // New node flags
247 //
248
249 #define NNF_IS_SNMP 0x0001
250 #define NNF_IS_AGENT 0x0002
251 #define NNF_IS_ROUTER 0x0004
252 #define NNF_IS_BRIDGE 0x0008
253 #define NNF_IS_PRINTER 0x0010
254 #define NNF_IS_CDP 0x0020
255 #define NNF_IS_SONMP 0x0040
256 #define NNF_IS_LLDP 0x0080
257
258
259 //
260 // Node information for autodiscovery filter
261 //
262
263 typedef struct
264 {
265 DWORD dwIpAddr;
266 DWORD dwNetMask;
267 DWORD dwSubnetAddr;
268 DWORD dwFlags;
269 int nSNMPVersion;
270 char szObjectId[MAX_OID_LEN * 4]; // SNMP OID
271 char szAgentVersion[MAX_AGENT_VERSION_LEN];
272 char szPlatform[MAX_PLATFORM_NAME_LEN];
273 } DISCOVERY_FILTER_DATA;
274
275
276 //
277 // Data update structure for client sessions
278 //
279
280 typedef struct
281 {
282 DWORD dwCategory; // Data category - event, network object, etc.
283 DWORD dwCode; // Data-specific update code
284 void *pData; // Pointer to data block
285 } UPDATE_INFO;
286
287
288 //
289 // Extended agent connection
290 //
291
292 class AgentConnectionEx : public AgentConnection
293 {
294 protected:
295 virtual void OnTrap(CSCPMessage *pMsg);
296
297 public:
298 AgentConnectionEx() : AgentConnection() { }
299 AgentConnectionEx(DWORD dwAddr, WORD wPort = AGENT_LISTEN_PORT,
300 int iAuthMethod = AUTH_NONE, TCHAR *pszSecret = NULL) :
301 AgentConnection(dwAddr, wPort, iAuthMethod, pszSecret) { }
302 virtual ~AgentConnectionEx();
303 };
304
305
306 //
307 // Client session
308 //
309
310 #define DECLARE_THREAD_STARTER(func) static THREAD_RESULT THREAD_CALL ThreadStarter_##func(void *);
311
312 class NXCORE_EXPORTABLE ClientSession
313 {
314 private:
315 SOCKET m_hSocket;
316 Queue *m_pSendQueue;
317 Queue *m_pMessageQueue;
318 Queue *m_pUpdateQueue;
319 DWORD m_dwIndex;
320 int m_iState;
321 WORD m_wCurrentCmd;
322 DWORD m_dwUserId;
323 DWORD m_dwSystemAccess; // User's system access rights
324 DWORD m_dwFlags; // Session flags
325 CSCP_BUFFER *m_pMsgBuffer;
326 CSCP_ENCRYPTION_CONTEXT *m_pCtx;
327 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
328 THREAD m_hWriteThread;
329 THREAD m_hProcessingThread;
330 THREAD m_hUpdateThread;
331 MUTEX m_mutexSendEvents;
332 MUTEX m_mutexSendSyslog;
333 MUTEX m_mutexSendTrapLog;
334 MUTEX m_mutexSendObjects;
335 MUTEX m_mutexSendAlarms;
336 MUTEX m_mutexSendActions;
337 MUTEX m_mutexSendAuditLog;
338 MUTEX m_mutexSendSituations;
339 MUTEX m_mutexPollerInit;
340 DWORD m_dwHostAddr; // IP address of connected host (network byte order)
341 TCHAR m_szWorkstation[16]; // IP address of conneced host in textual form
342 TCHAR m_szUserName[MAX_SESSION_NAME]; // String in form login_name@host
343 TCHAR m_szClientInfo[96]; // Client app info string
344 DWORD m_dwOpenDCIListSize; // Number of open DCI lists
345 DWORD *m_pOpenDCIList; // List of nodes with DCI lists open
346 DWORD m_dwNumRecordsToUpload; // Number of records to be uploaded
347 DWORD m_dwRecordsUploaded;
348 EPRule **m_ppEPPRuleList; // List of loaded EPP rules
349 int m_hCurrFile;
350 DWORD m_dwFileRqId;
351 DWORD m_dwUploadCommand;
352 DWORD m_dwUploadData;
353 TCHAR m_szCurrFileName[MAX_PATH];
354 DWORD m_dwRefCount;
355 DWORD m_dwEncryptionRqId;
356 DWORD m_dwEncryptionResult;
357 CONDITION m_condEncryptionSetup;
358 DWORD m_dwActiveChannels; // Active data channels
359 DWORD m_dwMapSaveRqId; // ID of currently active map saving request
360 nxMapSrv *m_pActiveMap; // Map currenly being saved
361
362 static THREAD_RESULT THREAD_CALL ReadThreadStarter(void *);
363 static THREAD_RESULT THREAD_CALL WriteThreadStarter(void *);
364 static THREAD_RESULT THREAD_CALL ProcessingThreadStarter(void *);
365 static THREAD_RESULT THREAD_CALL UpdateThreadStarter(void *);
366 static THREAD_RESULT THREAD_CALL PollerThreadStarter(void *);
367
368 DECLARE_THREAD_STARTER(GetCollectedData)
369 DECLARE_THREAD_STARTER(ClearDCIData)
370 DECLARE_THREAD_STARTER(QueryL2Topology)
371 DECLARE_THREAD_STARTER(SendEventLog)
372 DECLARE_THREAD_STARTER(SendSyslog)
373 DECLARE_THREAD_STARTER(CreateObject)
374 DECLARE_THREAD_STARTER(GetServerFile)
375
376 void ReadThread(void);
377 void WriteThread(void);
378 void ProcessingThread(void);
379 void UpdateThread(void);
380 void PollerThread(Node *pNode, int iPollType, DWORD dwRqId);
381
382 BOOL CheckSysAccessRights(DWORD dwRequiredAccess)
383 {
384 return m_dwUserId == 0 ? TRUE :
385 ((dwRequiredAccess & m_dwSystemAccess) ? TRUE : FALSE);
386 }
387
388 void SetupEncryption(DWORD dwRqId);
389 void RespondToKeepalive(DWORD dwRqId);
390 void OnFileUpload(BOOL bSuccess);
391 void DebugPrintf(int level, const TCHAR *format, ...);
392 void SendServerInfo(DWORD dwRqId);
393 void Login(CSCPMessage *pRequest);
394 void SendAllObjects(CSCPMessage *pRequest);
395 void SendEventLog(CSCPMessage *pRequest);
396 void SendAllConfigVars(DWORD dwRqId);
397 void SetConfigVariable(CSCPMessage *pRequest);
398 void DeleteConfigVariable(CSCPMessage *pRequest);
399 void SendUserDB(DWORD dwRqId);
400 void SendAllAlarms(DWORD dwRqId, BOOL bIncludeAck);
401 void CreateUser(CSCPMessage *pRequest);
402 void UpdateUser(CSCPMessage *pRequest);
403 void DeleteUser(CSCPMessage *pRequest);
404 void SetPassword(CSCPMessage *pRequest);
405 void LockUserDB(DWORD dwRqId, BOOL bLock);
406 void SendEventDB(DWORD dwRqId);
407 void LockEventDB(DWORD dwRqId);
408 void UnlockEventDB(DWORD dwRqId);
409 void SetEventInfo(CSCPMessage *pRequest);
410 void DeleteEventTemplate(CSCPMessage *pRequest);
411 void GenerateEventCode(DWORD dwRqId);
412 void ModifyObject(CSCPMessage *pRequest);
413 void ChangeObjectMgmtStatus(CSCPMessage *pRequest);
414 void OpenNodeDCIList(CSCPMessage *pRequest);
415 void CloseNodeDCIList(CSCPMessage *pRequest);
416 void ModifyNodeDCI(CSCPMessage *pRequest);
417 void CopyDCI(CSCPMessage *pRequest);
418 void ApplyTemplate(CSCPMessage *pRequest);
419 void GetCollectedData(CSCPMessage *pRequest);
420 void ClearDCIData(CSCPMessage *pRequest);
421 void ChangeDCIStatus(CSCPMessage *pRequest);
422 void SendLastValues(CSCPMessage *pRequest);
423 void OpenEPP(DWORD dwRqId);
424 void CloseEPP(DWORD dwRqId);
425 void SaveEPP(CSCPMessage *pRequest);
426 void ProcessEPPRecord(CSCPMessage *pRequest);
427 void SendMIBTimestamp(DWORD dwRqId);
428 void SendMIB(DWORD dwRqId);
429 void CreateObject(CSCPMessage *pRequest);
430 void ChangeObjectBinding(CSCPMessage *pRequest, BOOL bBind);
431 void DeleteObject(CSCPMessage *pRequest);
432 void AcknowledgeAlarm(CSCPMessage *pRequest);
433 void TerminateAlarm(CSCPMessage *pRequest);
434 void DeleteAlarm(CSCPMessage *pRequest);
435 void CreateAction(CSCPMessage *pRequest);
436 void UpdateAction(CSCPMessage *pRequest);
437 void DeleteAction(CSCPMessage *pRequest);
438 void LockActionDB(DWORD dwRqId, BOOL bLock);
439 void SendAllActions(DWORD dwRqId);
440 void SendContainerCategories(DWORD dwRqId);
441 void ForcedNodePoll(CSCPMessage *pRequest);
442 void OnTrap(CSCPMessage *pRequest);
443 void OnWakeUpNode(CSCPMessage *pRequest);
444 void QueryParameter(CSCPMessage *pRequest);
445 void EditTrap(int iOperation, CSCPMessage *pRequest);
446 void LockTrapCfg(DWORD dwRqId, BOOL bLock);
447 void SendAllTraps(DWORD dwRqId);
448 void SendAllTraps2(DWORD dwRqId);
449 void LockPackageDB(DWORD dwRqId, BOOL bLock);
450 void SendAllPackages(DWORD dwRqId);
451 void InstallPackage(CSCPMessage *pRequest);
452 void RemovePackage(CSCPMessage *pRequest);
453 void DeployPackage(CSCPMessage *pRequest);
454 void SendParametersList(CSCPMessage *pRequest);
455 void GetUserVariable(CSCPMessage *pRequest);
456 void SetUserVariable(CSCPMessage *pRequest);
457 void CopyUserVariable(CSCPMessage *pRequest);
458 void EnumUserVariables(CSCPMessage *pRequest);
459 void DeleteUserVariable(CSCPMessage *pRequest);
460 void ChangeObjectIP(CSCPMessage *pRequest);
461 void GetAgentConfig(CSCPMessage *pRequest);
462 void UpdateAgentConfig(CSCPMessage *pRequest);
463 void ExecuteAction(CSCPMessage *pRequest);
464 void SendObjectTools(DWORD dwRqId);
465 void SendObjectToolDetails(CSCPMessage *pRequest);
466 void UpdateObjectTool(CSCPMessage *pRequest);
467 void DeleteObjectTool(CSCPMessage *pRequest);
468 void GenerateObjectToolId(DWORD dwRqId);
469 void ExecTableTool(CSCPMessage *pRequest);
470 void LockObjectTools(DWORD dwRqId, BOOL bLock);
471 void ChangeSubscription(CSCPMessage *pRequest);
472 void SendSyslog(CSCPMessage *pRequest);
473 void SendServerStats(DWORD dwRqId);
474 void SendScriptList(DWORD dwRqId);
475 void SendScript(CSCPMessage *pRequest);
476 void UpdateScript(CSCPMessage *pRequest);
477 void RenameScript(CSCPMessage *pRequest);
478 void DeleteScript(CSCPMessage *pRequest);
479 void SendSessionList(DWORD dwRqId);
480 void KillSession(CSCPMessage *pRequest);
481 void SendTrapLog(CSCPMessage *pRequest);
482 void StartSnmpWalk(CSCPMessage *pRequest);
483 void SendMapList(DWORD dwRqId);
484 void ResolveMapName(CSCPMessage *pRequest);
485 void SaveMap(CSCPMessage *pRequest);
486 void DeleteMap(CSCPMessage *pRequest);
487 void ProcessSubmapData(CSCPMessage *pRequest);
488 void CreateMap(CSCPMessage *pRequest);
489 void RenameMap(CSCPMessage *pRequest);
490 void LoadMap(CSCPMessage *pRequest);
491 void SendSubmapBkImage(CSCPMessage *pRequest);
492 void RecvSubmapBkImage(CSCPMessage *pRequest);
493 void ResolveDCINames(CSCPMessage *pRequest);
494 DWORD ResolveDCIName(DWORD dwNode, DWORD dwItem, TCHAR **ppszName);
495 void SendConfigForAgent(CSCPMessage *pRequest);
496 void SendAgentCfgList(DWORD dwRqId);
497 void OpenAgentConfig(CSCPMessage *pRequest);
498 void SaveAgentConfig(CSCPMessage *pRequest);
499 void DeleteAgentConfig(CSCPMessage *pRequest);
500 void SwapAgentConfigs(CSCPMessage *pRequest);
501 void SendObjectComments(CSCPMessage *pRequest);
502 void UpdateObjectComments(CSCPMessage *pRequest);
503 void PushDCIData(CSCPMessage *pRequest);
504 void GetAddrList(CSCPMessage *pRequest);
505 void SetAddrList(CSCPMessage *pRequest);
506 void ResetComponent(CSCPMessage *pRequest);
507 void SendDCIEventList(CSCPMessage *pRequest);
508 void SendDCIInfo(CSCPMessage *pRequest);
509 void SendSystemDCIList(CSCPMessage *pRequest);
510 void CreateManagementPack(CSCPMessage *pRequest);
511 void InstallManagementPack(CSCPMessage *pRequest);
512 void SendGraphList(DWORD dwRqId);
513 void DefineGraph(CSCPMessage *pRequest);
514 void DeleteGraph(CSCPMessage *pRequest);
515 void AddCACertificate(CSCPMessage *pRequest);
516 void DeleteCertificate(CSCPMessage *pRequest);
517 void UpdateCertificateComments(CSCPMessage *pRequest);
518 void SendCertificateList(DWORD dwRqId);
519 void QueryL2Topology(CSCPMessage *pRequest);
520 void SendSMS(CSCPMessage *pRequest);
521 void SendCommunityList(DWORD dwRqId);
522 void UpdateCommunityList(CSCPMessage *pRequest);
523 void SendSituationList(DWORD dwRqId);
524 void CreateSituation(CSCPMessage *pRequest);
525 void UpdateSituation(CSCPMessage *pRequest);
526 void DeleteSituation(CSCPMessage *pRequest);
527 void DeleteSituationInstance(CSCPMessage *pRequest);
528 void SetConfigCLOB(CSCPMessage *pRequest);
529 void GetConfigCLOB(CSCPMessage *pRequest);
530 void WebMapAdd(CSCPMessage *pRequest);
531 void WebMapUpdateData(CSCPMessage *pRequest);
532 void WebMapUpdateProps(CSCPMessage *pRequest);
533 void WebMapDelete(CSCPMessage *pRequest);
534 void WebMapGetData(CSCPMessage *pRequest);
535 void WebMapGetList(DWORD dwRqId);
536 void RegisterAgent(CSCPMessage *pRequest);
537 void GetServerFile(CSCPMessage *pRequest);
538 void TestDCITransformation(CSCPMessage *pRequest);
539 void SendJobList(DWORD dwRqId);
540 void CancelJob(CSCPMessage *pRequest);
541
542 public:
543 ClientSession(SOCKET hSocket, DWORD dwHostAddr);
544 ~ClientSession();
545
546 void IncRefCount(void) { m_dwRefCount++; }
547 void DecRefCount(void) { if (m_dwRefCount > 0) m_dwRefCount--; }
548
549 void Run(void);
550
551 void SendMessage(CSCPMessage *pMsg) { m_pSendQueue->Put(pMsg->CreateMessage()); }
552 void SendPollerMsg(DWORD dwRqId, const TCHAR *pszMsg);
553 BOOL SendFile(const TCHAR *file, DWORD dwRqId);
554
555 DWORD GetIndex(void) { return m_dwIndex; }
556 void SetIndex(DWORD dwIndex) { if (m_dwIndex == INVALID_INDEX) m_dwIndex = dwIndex; }
557 int GetState(void) { return m_iState; }
558 const TCHAR *GetUserName(void) { return m_szUserName; }
559 const TCHAR *GetClientInfo(void) { return m_szClientInfo; }
560 DWORD GetUserId(void) { return m_dwUserId; }
561 BOOL IsAuthenticated(void) { return (m_dwFlags & CSF_AUTHENTICATED) ? TRUE : FALSE; }
562 BOOL IsSubscribed(DWORD dwChannel) { return (m_dwActiveChannels & dwChannel) ? TRUE : FALSE; }
563 WORD GetCurrentCmd(void) { return m_wCurrentCmd; }
564 int GetCipher(void) { return (m_pCtx == NULL) ? -1 : m_pCtx->nCipher; }
565
566 void Kill(void);
567 void Notify(DWORD dwCode, DWORD dwData = 0);
568
569 void QueueUpdate(UPDATE_INFO *pUpdate) { m_pUpdateQueue->Put(pUpdate); }
570 void OnNewEvent(Event *pEvent);
571 void OnSyslogMessage(NX_LOG_RECORD *pRec);
572 void OnNewSNMPTrap(CSCPMessage *pMsg);
573 void OnObjectChange(NetObj *pObject);
574 void OnUserDBUpdate(int code, DWORD id, UserDatabaseObject *user);
575 void OnAlarmUpdate(DWORD dwCode, NXC_ALARM *pAlarm);
576 void OnActionDBUpdate(DWORD dwCode, NXC_ACTION *pAction);
577 void OnSituationChange(CSCPMessage *msg);
578 };
579
580
581 //
582 // Functions
583 //
584
585 BOOL NXCORE_EXPORTABLE ConfigReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize,
586 const TCHAR *szDefault);
587 int NXCORE_EXPORTABLE ConfigReadInt(const TCHAR *szVar, int iDefault);
588 DWORD NXCORE_EXPORTABLE ConfigReadULong(const TCHAR *szVar, DWORD dwDefault);
589 BOOL NXCORE_EXPORTABLE ConfigReadByteArray(const TCHAR *pszVar, int *pnArray,
590 int nSize, int nDefault);
591 BOOL NXCORE_EXPORTABLE ConfigWriteStr(const TCHAR *szVar, const TCHAR *szValue, BOOL bCreate,
592 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
593 BOOL NXCORE_EXPORTABLE ConfigWriteInt(const TCHAR *szVar, int iValue, BOOL bCreate,
594 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
595 BOOL NXCORE_EXPORTABLE ConfigWriteULong(const TCHAR *szVar, DWORD dwValue, BOOL bCreate,
596 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
597 BOOL NXCORE_EXPORTABLE ConfigWriteByteArray(const TCHAR *pszVar, int *pnArray,
598 int nSize, BOOL bCreate,
599 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
600 TCHAR NXCORE_EXPORTABLE *ConfigReadCLOB(const TCHAR *var, const TCHAR *defValue);
601 BOOL NXCORE_EXPORTABLE ConfigWriteCLOB(const TCHAR *var, const TCHAR *value, BOOL bCreate);
602
603 BOOL NXCORE_EXPORTABLE MetaDataReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
604
605 BOOL NXCORE_EXPORTABLE LoadConfig(void);
606
607 void NXCORE_EXPORTABLE Shutdown(void);
608 void NXCORE_EXPORTABLE FastShutdown(void);
609 BOOL NXCORE_EXPORTABLE Initialize(void);
610 THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL Main(void *);
611 void NXCORE_EXPORTABLE ShutdownDB(void);
612 void InitiateShutdown(void);
613
614 BOOL NXCORE_EXPORTABLE SleepAndCheckForShutdown(int iSeconds);
615
616 void ConsolePrintf(CONSOLE_CTX pCtx, const char *pszFormat, ...);
617 int ProcessConsoleCommand(char *pszCmdLine, CONSOLE_CTX pCtx);
618
619 void SaveObjects(DB_HANDLE hdb);
620
621 void NXCORE_EXPORTABLE QueueSQLRequest(char *szQuery);
622 void StartDBWriter(void);
623 void StopDBWriter(void);
624
625 void DecodeSQLStringAndSetVariable(CSCPMessage *pMsg, DWORD dwVarId, TCHAR *pszStr);
626
627 void SnmpInit(void);
628 DWORD SnmpNewRequestId(void);
629 DWORD SnmpGet(DWORD dwVersion, SNMP_Transport *pTransport, const char *szCommunity,
630 const char *szOidStr, const DWORD *oidBinary, DWORD dwOidLen, void *pValue,
631 DWORD dwBufferSize, BOOL bVerbose, BOOL bStringResult);
632 DWORD SnmpEnumerate(DWORD dwVersion, SNMP_Transport *pTransport, const char *szCommunity,
633 const char *szRootOid,
634 DWORD (* pHandler)(DWORD, const char *, SNMP_Variable *, SNMP_Transport *, void *),
635 void *pUserArg, BOOL bVerbose);
636 BOOL SnmpCheckCommSettings(SNMP_Transport *pTransport, const char *currCommunity,
637 int *version, char *community);
638 void StrToMac(char *pszStr, BYTE *pBuffer);
639 DWORD OidToType(TCHAR *pszOid, DWORD *pdwFlags);
640
641 void InitLocalNetInfo(void);
642
643 ARP_CACHE *GetLocalArpCache(void);
644 ARP_CACHE *SnmpGetArpCache(DWORD dwVersion, SNMP_Transport *pTransport, const char *szCommunity);
645
646 INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwVersion, SNMP_Transport *pTransport,
647 const char *szCommunity, DWORD dwNodeType,
648 BOOL useIfXTable);
649 INTERFACE_LIST *GetLocalInterfaceList(void);
650 void CleanInterfaceList(INTERFACE_LIST *pIfList);
651 int SnmpGetInterfaceStatus(DWORD dwVersion, SNMP_Transport *pTransport, char *pszCommunity, DWORD dwIfIndex);
652
653 ROUTING_TABLE *SnmpGetRoutingTable(DWORD dwVersion, SNMP_Transport *pTransport, const char *szCommunity);
654
655 void WatchdogInit(void);
656 DWORD WatchdogAddThread(const TCHAR *szName, time_t tNotifyInterval);
657 void WatchdogNotify(DWORD dwId);
658 void WatchdogPrintStatus(CONSOLE_CTX pCtx);
659
660 void CheckForMgmtNode(void);
661 NetObj *PollNewNode(DWORD dwIpAddr, DWORD dwNetMask, DWORD dwCreationFlags,
662 TCHAR *pszName, DWORD dwProxyNode, DWORD dwSNMPProxy, Cluster *pCluster);
663
664 void NXCORE_EXPORTABLE EnumerateClientSessions(void (*pHandler)(ClientSession *, void *), void *pArg);
665 void NXCORE_EXPORTABLE NotifyClientSessions(DWORD dwCode, DWORD dwData);
666 int GetSessionCount(void);
667
668 void GetSysInfoStr(char *pszBuffer, int nMaxSize);
669 DWORD GetLocalIpAddr(void);
670
671 BOOL ExecCommand(char *pszCommand);
672 BOOL SendMagicPacket(DWORD dwIpAddr, BYTE *pbMacAddr, int iNumPackets);
673
674 BOOL InitIdTable(void);
675 DWORD CreateUniqueId(int iGroup);
676 QWORD CreateUniqueEventId(void);
677
678 void InitMailer(void);
679 void ShutdownMailer(void);
680 void NXCORE_EXPORTABLE PostMail(char *pszRcpt, char *pszSubject, char *pszText);
681
682 void InitSMSSender(void);
683 void ShutdownSMSSender(void);
684 void NXCORE_EXPORTABLE PostSMS(TCHAR *pszRcpt, TCHAR *pszText);
685
686 void GetAccelarVLANIfList(DWORD dwVersion, SNMP_Transport *pTransport,
687 const TCHAR *pszCommunity, INTERFACE_LIST *pIfList);
688
689 void InitTraps(void);
690 void SendTrapsToClient(ClientSession *pSession, DWORD dwRqId);
691 void CreateTrapCfgMessage(CSCPMessage &msg);
692 DWORD CreateNewTrap(DWORD *pdwTrapId);
693 DWORD CreateNewTrap(NXC_TRAP_CFG_ENTRY *pTrap);
694 DWORD UpdateTrapFromMsg(CSCPMessage *pMsg);
695 DWORD DeleteTrap(DWORD dwId);
696 void CreateNXMPTrapRecord(String &str, DWORD dwId);
697
698 BOOL IsTableTool(DWORD dwToolId);
699 BOOL CheckObjectToolAccess(DWORD dwToolId, DWORD dwUserId);
700 DWORD ExecuteTableTool(DWORD dwToolId, Node *pNode, DWORD dwRqId, ClientSession *pSession);
701 DWORD DeleteObjectToolFromDB(DWORD dwToolId);
702 DWORD UpdateObjectToolFromMessage(CSCPMessage *pMsg);
703
704 void CreateMessageFromSyslogMsg(CSCPMessage *pMsg, NX_LOG_RECORD *pRec);
705 void ReinitializeSyslogParser();
706
707 void EscapeString(String &str);
708
709 void InitAuditLog(void);
710 void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *pszSubsys, BOOL bSuccess, DWORD dwUserId,
711 const TCHAR *pszWorkstation, DWORD dwObjectId, const TCHAR *pszFormat, ...);
712
713 void AddObjectToIndex(INDEX **ppIndex, DWORD *pdwIndexSize, DWORD dwKey, void *pObject);
714 void DeleteObjectFromIndex(INDEX **ppIndex, DWORD *pdwIndexSize, DWORD dwKey);
715 DWORD SearchIndex(INDEX *pIndex, DWORD dwIndexSize, DWORD dwKey);
716
717 #ifdef _WITH_ENCRYPTION
718 X509 *CertificateFromLoginMessage(CSCPMessage *pMsg);
719 BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChallenge,
720 BYTE *pSignature, DWORD dwSigLen, int nMappingMethod,
721 const TCHAR *pszMappingData);
722 void ReloadCertificates(void);
723 #endif
724
725 #ifndef _WIN32
726 THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL SignalHandler(void *);
727 #endif /* not _WIN32 */
728
729 void DbgTestMutex(MUTEX hMutex, const TCHAR *szName, CONSOLE_CTX pCtx);
730 void DbgTestRWLock(RWLOCK hLock, const TCHAR *szName, CONSOLE_CTX pCtx);
731 void DumpSessions(CONSOLE_CTX pCtx);
732 void ShowPollerState(CONSOLE_CTX pCtx);
733 void SetPollerInfo(int nIdx, const char *pszMsg);
734 void ShowServerStats(CONSOLE_CTX pCtx);
735 void ShowQueueStats(CONSOLE_CTX pCtx, Queue *pQueue, const char *pszName);
736 void DumpProcess(CONSOLE_CTX pCtx);
737
738
739 //
740 // Global variables
741 //
742
743 extern TCHAR NXCORE_EXPORTABLE g_szConfigFile[];
744 extern TCHAR NXCORE_EXPORTABLE g_szLogFile[];
745 extern TCHAR NXCORE_EXPORTABLE g_szDumpDir[];
746 extern TCHAR NXCORE_EXPORTABLE g_szListenAddress[];
747 #ifndef _WIN32
748 extern TCHAR NXCORE_EXPORTABLE g_szPIDFile[];
749 #endif
750 extern TCHAR g_szDataDir[];
751 extern QWORD g_qwServerId;
752 extern RSA *g_pServerKey;
753 extern DWORD g_dwPingSize;
754 extern DWORD g_dwAuditFlags;
755 extern time_t g_tServerStartTime;
756 extern DWORD g_dwLockTimeout;
757 extern DWORD g_dwSNMPTimeout;
758 extern DWORD g_dwAgentCommandTimeout;
759 extern DWORD g_dwThresholdRepeatInterval;
760 extern int g_nRequiredPolls;
761
762 extern DB_HANDLE NXCORE_EXPORTABLE g_hCoreDB;
763 extern Queue *g_pLazyRequestQueue;
764
765 extern int NXCORE_EXPORTABLE g_nDBSyntax;
766
767 #endif /* _nms_core_h_ */