minor changes
[public/netxms.git] / src / server / include / nms_core.h
CommitLineData
5039dede
AK
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>
5039dede
AK
72#include <nxqueue.h>
73#include <nxsnmp.h>
74#include <nxmodule.h>
75#include <nxsl.h>
76
77
78//
79// Console context
80//
81
82struct __console_ctx
83{
84 SOCKET hSocket;
85 CSCPMessage *pMsg;
86};
87
88typedef __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"
5039dede
AK
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"
ab621f39 104#include "nxcore_jobs.h"
5039dede
AK
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
115typedef void * HSNMPSESSION;
116
117#define CHECKPOINT_SNMP_PORT 260
118
119
5039dede
AK
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
6e53f004 129//#define IDG_IMAGE 5
5039dede
AK
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
47912c44 138//#define IDG_LPP 14
5039dede
AK
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
237typedef 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
263typedef 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
280typedef 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
292class AgentConnectionEx : public AgentConnection
293{
294protected:
295 virtual void OnTrap(CSCPMessage *pMsg);
296
297public:
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();
45d84f8a
VK
303
304 DWORD deployPolicy(AgentPolicy *policy);
93599cfd 305 DWORD uninstallPolicy(AgentPolicy *policy);
5039dede
AK
306};
307
308
309//
310// Client session
311//
312
313#define DECLARE_THREAD_STARTER(func) static THREAD_RESULT THREAD_CALL ThreadStarter_##func(void *);
314
a0e3917e 315class NXCORE_EXPORTABLE ClientSession
5039dede
AK
316{
317private:
318 SOCKET m_hSocket;
319 Queue *m_pSendQueue;
320 Queue *m_pMessageQueue;
321 Queue *m_pUpdateQueue;
322 DWORD m_dwIndex;
323 int m_iState;
324 WORD m_wCurrentCmd;
325 DWORD m_dwUserId;
326 DWORD m_dwSystemAccess; // User's system access rights
327 DWORD m_dwFlags; // Session flags
328 CSCP_BUFFER *m_pMsgBuffer;
329 CSCP_ENCRYPTION_CONTEXT *m_pCtx;
330 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
331 THREAD m_hWriteThread;
332 THREAD m_hProcessingThread;
333 THREAD m_hUpdateThread;
334 MUTEX m_mutexSendEvents;
335 MUTEX m_mutexSendSyslog;
336 MUTEX m_mutexSendTrapLog;
337 MUTEX m_mutexSendObjects;
338 MUTEX m_mutexSendAlarms;
339 MUTEX m_mutexSendActions;
340 MUTEX m_mutexSendAuditLog;
341 MUTEX m_mutexSendSituations;
342 MUTEX m_mutexPollerInit;
343 DWORD m_dwHostAddr; // IP address of connected host (network byte order)
344 TCHAR m_szWorkstation[16]; // IP address of conneced host in textual form
345 TCHAR m_szUserName[MAX_SESSION_NAME]; // String in form login_name@host
346 TCHAR m_szClientInfo[96]; // Client app info string
347 DWORD m_dwOpenDCIListSize; // Number of open DCI lists
348 DWORD *m_pOpenDCIList; // List of nodes with DCI lists open
349 DWORD m_dwNumRecordsToUpload; // Number of records to be uploaded
350 DWORD m_dwRecordsUploaded;
351 EPRule **m_ppEPPRuleList; // List of loaded EPP rules
352 int m_hCurrFile;
353 DWORD m_dwFileRqId;
354 DWORD m_dwUploadCommand;
355 DWORD m_dwUploadData;
356 TCHAR m_szCurrFileName[MAX_PATH];
357 DWORD m_dwRefCount;
358 DWORD m_dwEncryptionRqId;
359 DWORD m_dwEncryptionResult;
360 CONDITION m_condEncryptionSetup;
361 DWORD m_dwActiveChannels; // Active data channels
362 DWORD m_dwMapSaveRqId; // ID of currently active map saving request
363 nxMapSrv *m_pActiveMap; // Map currenly being saved
364
365 static THREAD_RESULT THREAD_CALL ReadThreadStarter(void *);
366 static THREAD_RESULT THREAD_CALL WriteThreadStarter(void *);
367 static THREAD_RESULT THREAD_CALL ProcessingThreadStarter(void *);
368 static THREAD_RESULT THREAD_CALL UpdateThreadStarter(void *);
369 static THREAD_RESULT THREAD_CALL PollerThreadStarter(void *);
370
371 DECLARE_THREAD_STARTER(GetCollectedData)
372 DECLARE_THREAD_STARTER(ClearDCIData)
373 DECLARE_THREAD_STARTER(QueryL2Topology)
374 DECLARE_THREAD_STARTER(SendEventLog)
375 DECLARE_THREAD_STARTER(SendSyslog)
376 DECLARE_THREAD_STARTER(CreateObject)
377 DECLARE_THREAD_STARTER(GetServerFile)
378
379 void ReadThread(void);
380 void WriteThread(void);
381 void ProcessingThread(void);
382 void UpdateThread(void);
383 void PollerThread(Node *pNode, int iPollType, DWORD dwRqId);
384
385 BOOL CheckSysAccessRights(DWORD dwRequiredAccess)
386 {
387 return m_dwUserId == 0 ? TRUE :
388 ((dwRequiredAccess & m_dwSystemAccess) ? TRUE : FALSE);
389 }
390
391 void SetupEncryption(DWORD dwRqId);
392 void RespondToKeepalive(DWORD dwRqId);
393 void OnFileUpload(BOOL bSuccess);
394 void DebugPrintf(int level, const TCHAR *format, ...);
395 void SendServerInfo(DWORD dwRqId);
396 void Login(CSCPMessage *pRequest);
397 void SendAllObjects(CSCPMessage *pRequest);
398 void SendEventLog(CSCPMessage *pRequest);
399 void SendAllConfigVars(DWORD dwRqId);
400 void SetConfigVariable(CSCPMessage *pRequest);
401 void DeleteConfigVariable(CSCPMessage *pRequest);
402 void SendUserDB(DWORD dwRqId);
403 void SendAllAlarms(DWORD dwRqId, BOOL bIncludeAck);
404 void CreateUser(CSCPMessage *pRequest);
405 void UpdateUser(CSCPMessage *pRequest);
406 void DeleteUser(CSCPMessage *pRequest);
407 void SetPassword(CSCPMessage *pRequest);
408 void LockUserDB(DWORD dwRqId, BOOL bLock);
409 void SendEventDB(DWORD dwRqId);
410 void LockEventDB(DWORD dwRqId);
411 void UnlockEventDB(DWORD dwRqId);
412 void SetEventInfo(CSCPMessage *pRequest);
413 void DeleteEventTemplate(CSCPMessage *pRequest);
414 void GenerateEventCode(DWORD dwRqId);
415 void ModifyObject(CSCPMessage *pRequest);
416 void ChangeObjectMgmtStatus(CSCPMessage *pRequest);
417 void OpenNodeDCIList(CSCPMessage *pRequest);
418 void CloseNodeDCIList(CSCPMessage *pRequest);
419 void ModifyNodeDCI(CSCPMessage *pRequest);
420 void CopyDCI(CSCPMessage *pRequest);
421 void ApplyTemplate(CSCPMessage *pRequest);
422 void GetCollectedData(CSCPMessage *pRequest);
423 void ClearDCIData(CSCPMessage *pRequest);
424 void ChangeDCIStatus(CSCPMessage *pRequest);
425 void SendLastValues(CSCPMessage *pRequest);
426 void OpenEPP(DWORD dwRqId);
427 void CloseEPP(DWORD dwRqId);
428 void SaveEPP(CSCPMessage *pRequest);
429 void ProcessEPPRecord(CSCPMessage *pRequest);
430 void SendMIBTimestamp(DWORD dwRqId);
431 void SendMIB(DWORD dwRqId);
432 void CreateObject(CSCPMessage *pRequest);
433 void ChangeObjectBinding(CSCPMessage *pRequest, BOOL bBind);
434 void DeleteObject(CSCPMessage *pRequest);
435 void AcknowledgeAlarm(CSCPMessage *pRequest);
436 void TerminateAlarm(CSCPMessage *pRequest);
437 void DeleteAlarm(CSCPMessage *pRequest);
438 void CreateAction(CSCPMessage *pRequest);
439 void UpdateAction(CSCPMessage *pRequest);
440 void DeleteAction(CSCPMessage *pRequest);
441 void LockActionDB(DWORD dwRqId, BOOL bLock);
442 void SendAllActions(DWORD dwRqId);
443 void SendContainerCategories(DWORD dwRqId);
444 void ForcedNodePoll(CSCPMessage *pRequest);
445 void OnTrap(CSCPMessage *pRequest);
446 void OnWakeUpNode(CSCPMessage *pRequest);
447 void QueryParameter(CSCPMessage *pRequest);
448 void EditTrap(int iOperation, CSCPMessage *pRequest);
449 void LockTrapCfg(DWORD dwRqId, BOOL bLock);
450 void SendAllTraps(DWORD dwRqId);
451 void SendAllTraps2(DWORD dwRqId);
452 void LockPackageDB(DWORD dwRqId, BOOL bLock);
453 void SendAllPackages(DWORD dwRqId);
454 void InstallPackage(CSCPMessage *pRequest);
455 void RemovePackage(CSCPMessage *pRequest);
456 void DeployPackage(CSCPMessage *pRequest);
457 void SendParametersList(CSCPMessage *pRequest);
458 void GetUserVariable(CSCPMessage *pRequest);
459 void SetUserVariable(CSCPMessage *pRequest);
460 void CopyUserVariable(CSCPMessage *pRequest);
461 void EnumUserVariables(CSCPMessage *pRequest);
462 void DeleteUserVariable(CSCPMessage *pRequest);
463 void ChangeObjectIP(CSCPMessage *pRequest);
464 void GetAgentConfig(CSCPMessage *pRequest);
465 void UpdateAgentConfig(CSCPMessage *pRequest);
466 void ExecuteAction(CSCPMessage *pRequest);
467 void SendObjectTools(DWORD dwRqId);
468 void SendObjectToolDetails(CSCPMessage *pRequest);
469 void UpdateObjectTool(CSCPMessage *pRequest);
470 void DeleteObjectTool(CSCPMessage *pRequest);
471 void GenerateObjectToolId(DWORD dwRqId);
472 void ExecTableTool(CSCPMessage *pRequest);
473 void LockObjectTools(DWORD dwRqId, BOOL bLock);
474 void ChangeSubscription(CSCPMessage *pRequest);
475 void SendSyslog(CSCPMessage *pRequest);
5039dede
AK
476 void SendServerStats(DWORD dwRqId);
477 void SendScriptList(DWORD dwRqId);
478 void SendScript(CSCPMessage *pRequest);
479 void UpdateScript(CSCPMessage *pRequest);
480 void RenameScript(CSCPMessage *pRequest);
481 void DeleteScript(CSCPMessage *pRequest);
482 void SendSessionList(DWORD dwRqId);
483 void KillSession(CSCPMessage *pRequest);
484 void SendTrapLog(CSCPMessage *pRequest);
485 void StartSnmpWalk(CSCPMessage *pRequest);
486 void SendMapList(DWORD dwRqId);
487 void ResolveMapName(CSCPMessage *pRequest);
488 void SaveMap(CSCPMessage *pRequest);
0b514e86 489 void DeleteMap(CSCPMessage *pRequest);
5039dede
AK
490 void ProcessSubmapData(CSCPMessage *pRequest);
491 void CreateMap(CSCPMessage *pRequest);
492 void RenameMap(CSCPMessage *pRequest);
493 void LoadMap(CSCPMessage *pRequest);
494 void SendSubmapBkImage(CSCPMessage *pRequest);
495 void RecvSubmapBkImage(CSCPMessage *pRequest);
496 void ResolveDCINames(CSCPMessage *pRequest);
497 DWORD ResolveDCIName(DWORD dwNode, DWORD dwItem, TCHAR **ppszName);
498 void SendConfigForAgent(CSCPMessage *pRequest);
499 void SendAgentCfgList(DWORD dwRqId);
500 void OpenAgentConfig(CSCPMessage *pRequest);
501 void SaveAgentConfig(CSCPMessage *pRequest);
502 void DeleteAgentConfig(CSCPMessage *pRequest);
503 void SwapAgentConfigs(CSCPMessage *pRequest);
504 void SendObjectComments(CSCPMessage *pRequest);
505 void UpdateObjectComments(CSCPMessage *pRequest);
506 void PushDCIData(CSCPMessage *pRequest);
507 void GetAddrList(CSCPMessage *pRequest);
508 void SetAddrList(CSCPMessage *pRequest);
509 void ResetComponent(CSCPMessage *pRequest);
510 void SendDCIEventList(CSCPMessage *pRequest);
511 void SendDCIInfo(CSCPMessage *pRequest);
512 void SendSystemDCIList(CSCPMessage *pRequest);
513 void CreateManagementPack(CSCPMessage *pRequest);
514 void InstallManagementPack(CSCPMessage *pRequest);
515 void SendGraphList(DWORD dwRqId);
516 void DefineGraph(CSCPMessage *pRequest);
517 void DeleteGraph(CSCPMessage *pRequest);
518 void AddCACertificate(CSCPMessage *pRequest);
519 void DeleteCertificate(CSCPMessage *pRequest);
520 void UpdateCertificateComments(CSCPMessage *pRequest);
521 void SendCertificateList(DWORD dwRqId);
522 void QueryL2Topology(CSCPMessage *pRequest);
523 void SendSMS(CSCPMessage *pRequest);
524 void SendCommunityList(DWORD dwRqId);
525 void UpdateCommunityList(CSCPMessage *pRequest);
526 void SendSituationList(DWORD dwRqId);
527 void CreateSituation(CSCPMessage *pRequest);
528 void UpdateSituation(CSCPMessage *pRequest);
529 void DeleteSituation(CSCPMessage *pRequest);
530 void DeleteSituationInstance(CSCPMessage *pRequest);
531 void SetConfigCLOB(CSCPMessage *pRequest);
532 void GetConfigCLOB(CSCPMessage *pRequest);
533 void WebMapAdd(CSCPMessage *pRequest);
534 void WebMapUpdateData(CSCPMessage *pRequest);
535 void WebMapUpdateProps(CSCPMessage *pRequest);
536 void WebMapDelete(CSCPMessage *pRequest);
537 void WebMapGetData(CSCPMessage *pRequest);
538 void WebMapGetList(DWORD dwRqId);
539 void RegisterAgent(CSCPMessage *pRequest);
540 void GetServerFile(CSCPMessage *pRequest);
4262c0dc 541 void TestDCITransformation(CSCPMessage *pRequest);
45d84f8a
VK
542 void sendJobList(DWORD dwRqId);
543 void cancelJob(CSCPMessage *pRequest);
93599cfd 544 void deployAgentPolicy(CSCPMessage *pRequest, bool uninstallFlag);
d83dc1f0
VK
545 void getUserCustomAttribute(CSCPMessage *request);
546 void setUserCustomAttribute(CSCPMessage *request);
5039dede
AK
547
548public:
549 ClientSession(SOCKET hSocket, DWORD dwHostAddr);
550 ~ClientSession();
551
552 void IncRefCount(void) { m_dwRefCount++; }
553 void DecRefCount(void) { if (m_dwRefCount > 0) m_dwRefCount--; }
554
555 void Run(void);
556
557 void SendMessage(CSCPMessage *pMsg) { m_pSendQueue->Put(pMsg->CreateMessage()); }
558 void SendPollerMsg(DWORD dwRqId, const TCHAR *pszMsg);
a0e3917e 559 BOOL SendFile(const TCHAR *file, DWORD dwRqId);
5039dede
AK
560
561 DWORD GetIndex(void) { return m_dwIndex; }
562 void SetIndex(DWORD dwIndex) { if (m_dwIndex == INVALID_INDEX) m_dwIndex = dwIndex; }
563 int GetState(void) { return m_iState; }
564 const TCHAR *GetUserName(void) { return m_szUserName; }
565 const TCHAR *GetClientInfo(void) { return m_szClientInfo; }
566 DWORD GetUserId(void) { return m_dwUserId; }
567 BOOL IsAuthenticated(void) { return (m_dwFlags & CSF_AUTHENTICATED) ? TRUE : FALSE; }
568 BOOL IsSubscribed(DWORD dwChannel) { return (m_dwActiveChannels & dwChannel) ? TRUE : FALSE; }
569 WORD GetCurrentCmd(void) { return m_wCurrentCmd; }
570 int GetCipher(void) { return (m_pCtx == NULL) ? -1 : m_pCtx->nCipher; }
571
572 void Kill(void);
573 void Notify(DWORD dwCode, DWORD dwData = 0);
574
575 void QueueUpdate(UPDATE_INFO *pUpdate) { m_pUpdateQueue->Put(pUpdate); }
576 void OnNewEvent(Event *pEvent);
577 void OnSyslogMessage(NX_LOG_RECORD *pRec);
578 void OnNewSNMPTrap(CSCPMessage *pMsg);
579 void OnObjectChange(NetObj *pObject);
a50eaebe 580 void OnUserDBUpdate(int code, DWORD id, UserDatabaseObject *user);
5039dede
AK
581 void OnAlarmUpdate(DWORD dwCode, NXC_ALARM *pAlarm);
582 void OnActionDBUpdate(DWORD dwCode, NXC_ACTION *pAction);
583 void OnSituationChange(CSCPMessage *msg);
584};
585
586
587//
588// Functions
589//
590
591BOOL NXCORE_EXPORTABLE ConfigReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize,
592 const TCHAR *szDefault);
593int NXCORE_EXPORTABLE ConfigReadInt(const TCHAR *szVar, int iDefault);
594DWORD NXCORE_EXPORTABLE ConfigReadULong(const TCHAR *szVar, DWORD dwDefault);
595BOOL NXCORE_EXPORTABLE ConfigReadByteArray(const TCHAR *pszVar, int *pnArray,
596 int nSize, int nDefault);
597BOOL NXCORE_EXPORTABLE ConfigWriteStr(const TCHAR *szVar, const TCHAR *szValue, BOOL bCreate,
598 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
599BOOL NXCORE_EXPORTABLE ConfigWriteInt(const TCHAR *szVar, int iValue, BOOL bCreate,
600 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
601BOOL NXCORE_EXPORTABLE ConfigWriteULong(const TCHAR *szVar, DWORD dwValue, BOOL bCreate,
602 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
603BOOL NXCORE_EXPORTABLE ConfigWriteByteArray(const TCHAR *pszVar, int *pnArray,
604 int nSize, BOOL bCreate,
605 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
606TCHAR NXCORE_EXPORTABLE *ConfigReadCLOB(const TCHAR *var, const TCHAR *defValue);
607BOOL NXCORE_EXPORTABLE ConfigWriteCLOB(const TCHAR *var, const TCHAR *value, BOOL bCreate);
608
28f5b9a4
VK
609BOOL NXCORE_EXPORTABLE MetaDataReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
610
5039dede
AK
611BOOL NXCORE_EXPORTABLE LoadConfig(void);
612
613void NXCORE_EXPORTABLE Shutdown(void);
614void NXCORE_EXPORTABLE FastShutdown(void);
615BOOL NXCORE_EXPORTABLE Initialize(void);
616THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL Main(void *);
617void NXCORE_EXPORTABLE ShutdownDB(void);
618void InitiateShutdown(void);
619
620BOOL NXCORE_EXPORTABLE SleepAndCheckForShutdown(int iSeconds);
621
622void ConsolePrintf(CONSOLE_CTX pCtx, const char *pszFormat, ...);
623int ProcessConsoleCommand(char *pszCmdLine, CONSOLE_CTX pCtx);
624
625void SaveObjects(DB_HANDLE hdb);
626
627void NXCORE_EXPORTABLE QueueSQLRequest(char *szQuery);
628void StartDBWriter(void);
629void StopDBWriter(void);
630
631void DecodeSQLStringAndSetVariable(CSCPMessage *pMsg, DWORD dwVarId, TCHAR *pszStr);
632
633void SnmpInit(void);
634DWORD SnmpNewRequestId(void);
5d2c5741 635DWORD SnmpGet(DWORD dwVersion, SNMP_Transport *pTransport,
5039dede
AK
636 const char *szOidStr, const DWORD *oidBinary, DWORD dwOidLen, void *pValue,
637 DWORD dwBufferSize, BOOL bVerbose, BOOL bStringResult);
5d2c5741
VK
638DWORD SnmpEnumerate(DWORD dwVersion, SNMP_Transport *pTransport, const char *szRootOid,
639 DWORD (* pHandler)(DWORD, SNMP_Variable *, SNMP_Transport *, void *),
5039dede 640 void *pUserArg, BOOL bVerbose);
5d2c5741 641BOOL SnmpCheckCommSettings(SNMP_Transport *pTransport, int *version, char *community);
5039dede
AK
642void StrToMac(char *pszStr, BYTE *pBuffer);
643DWORD OidToType(TCHAR *pszOid, DWORD *pdwFlags);
644
645void InitLocalNetInfo(void);
646
647ARP_CACHE *GetLocalArpCache(void);
5d2c5741 648ARP_CACHE *SnmpGetArpCache(DWORD dwVersion, SNMP_Transport *pTransport);
5039dede
AK
649
650INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwVersion, SNMP_Transport *pTransport,
5d2c5741 651 DWORD dwNodeType, BOOL useIfXTable);
5039dede
AK
652INTERFACE_LIST *GetLocalInterfaceList(void);
653void CleanInterfaceList(INTERFACE_LIST *pIfList);
5d2c5741 654int SnmpGetInterfaceStatus(DWORD dwVersion, SNMP_Transport *pTransport, DWORD dwIfIndex);
5039dede 655
5d2c5741 656ROUTING_TABLE *SnmpGetRoutingTable(DWORD dwVersion, SNMP_Transport *pTransport);
5039dede
AK
657
658void WatchdogInit(void);
659DWORD WatchdogAddThread(const TCHAR *szName, time_t tNotifyInterval);
660void WatchdogNotify(DWORD dwId);
661void WatchdogPrintStatus(CONSOLE_CTX pCtx);
662
663void CheckForMgmtNode(void);
07f6978d
VK
664Node *PollNewNode(DWORD dwIpAddr, DWORD dwNetMask, DWORD dwCreationFlags,
665 TCHAR *pszName, DWORD dwProxyNode, DWORD dwSNMPProxy, Cluster *pCluster);
5039dede
AK
666
667void NXCORE_EXPORTABLE EnumerateClientSessions(void (*pHandler)(ClientSession *, void *), void *pArg);
668void NXCORE_EXPORTABLE NotifyClientSessions(DWORD dwCode, DWORD dwData);
669int GetSessionCount(void);
670
671void GetSysInfoStr(char *pszBuffer, int nMaxSize);
672DWORD GetLocalIpAddr(void);
673
674BOOL ExecCommand(char *pszCommand);
675BOOL SendMagicPacket(DWORD dwIpAddr, BYTE *pbMacAddr, int iNumPackets);
676
677BOOL InitIdTable(void);
678DWORD CreateUniqueId(int iGroup);
679QWORD CreateUniqueEventId(void);
680
5039dede
AK
681void InitMailer(void);
682void ShutdownMailer(void);
683void NXCORE_EXPORTABLE PostMail(char *pszRcpt, char *pszSubject, char *pszText);
684
685void InitSMSSender(void);
686void ShutdownSMSSender(void);
687void NXCORE_EXPORTABLE PostSMS(TCHAR *pszRcpt, TCHAR *pszText);
688
689void GetAccelarVLANIfList(DWORD dwVersion, SNMP_Transport *pTransport,
5d2c5741 690 INTERFACE_LIST *pIfList);
5039dede
AK
691
692void InitTraps(void);
693void SendTrapsToClient(ClientSession *pSession, DWORD dwRqId);
694void CreateTrapCfgMessage(CSCPMessage &msg);
695DWORD CreateNewTrap(DWORD *pdwTrapId);
696DWORD CreateNewTrap(NXC_TRAP_CFG_ENTRY *pTrap);
697DWORD UpdateTrapFromMsg(CSCPMessage *pMsg);
698DWORD DeleteTrap(DWORD dwId);
699void CreateNXMPTrapRecord(String &str, DWORD dwId);
700
701BOOL IsTableTool(DWORD dwToolId);
702BOOL CheckObjectToolAccess(DWORD dwToolId, DWORD dwUserId);
703DWORD ExecuteTableTool(DWORD dwToolId, Node *pNode, DWORD dwRqId, ClientSession *pSession);
704DWORD DeleteObjectToolFromDB(DWORD dwToolId);
705DWORD UpdateObjectToolFromMessage(CSCPMessage *pMsg);
706
5039dede 707void CreateMessageFromSyslogMsg(CSCPMessage *pMsg, NX_LOG_RECORD *pRec);
4262c0dc 708void ReinitializeSyslogParser();
5039dede
AK
709
710void EscapeString(String &str);
711
712void InitAuditLog(void);
713void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *pszSubsys, BOOL bSuccess, DWORD dwUserId,
714 const TCHAR *pszWorkstation, DWORD dwObjectId, const TCHAR *pszFormat, ...);
715
716void AddObjectToIndex(INDEX **ppIndex, DWORD *pdwIndexSize, DWORD dwKey, void *pObject);
717void DeleteObjectFromIndex(INDEX **ppIndex, DWORD *pdwIndexSize, DWORD dwKey);
718DWORD SearchIndex(INDEX *pIndex, DWORD dwIndexSize, DWORD dwKey);
719
720#ifdef _WITH_ENCRYPTION
721X509 *CertificateFromLoginMessage(CSCPMessage *pMsg);
a50eaebe 722BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChallenge,
5039dede 723 BYTE *pSignature, DWORD dwSigLen, int nMappingMethod,
a50eaebe 724 const TCHAR *pszMappingData);
5039dede
AK
725void ReloadCertificates(void);
726#endif
727
728#ifndef _WIN32
729THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL SignalHandler(void *);
730#endif /* not _WIN32 */
731
732void DbgTestMutex(MUTEX hMutex, const TCHAR *szName, CONSOLE_CTX pCtx);
733void DbgTestRWLock(RWLOCK hLock, const TCHAR *szName, CONSOLE_CTX pCtx);
734void DumpSessions(CONSOLE_CTX pCtx);
735void ShowPollerState(CONSOLE_CTX pCtx);
736void SetPollerInfo(int nIdx, const char *pszMsg);
737void ShowServerStats(CONSOLE_CTX pCtx);
738void ShowQueueStats(CONSOLE_CTX pCtx, Queue *pQueue, const char *pszName);
739void DumpProcess(CONSOLE_CTX pCtx);
740
741
742//
743// Global variables
744//
745
746extern TCHAR NXCORE_EXPORTABLE g_szConfigFile[];
747extern TCHAR NXCORE_EXPORTABLE g_szLogFile[];
748extern TCHAR NXCORE_EXPORTABLE g_szDumpDir[];
749extern TCHAR NXCORE_EXPORTABLE g_szListenAddress[];
750#ifndef _WIN32
751extern TCHAR NXCORE_EXPORTABLE g_szPIDFile[];
752#endif
753extern TCHAR g_szDataDir[];
754extern QWORD g_qwServerId;
755extern RSA *g_pServerKey;
756extern DWORD g_dwPingSize;
757extern DWORD g_dwAuditFlags;
758extern time_t g_tServerStartTime;
759extern DWORD g_dwLockTimeout;
760extern DWORD g_dwSNMPTimeout;
761extern DWORD g_dwAgentCommandTimeout;
762extern DWORD g_dwThresholdRepeatInterval;
763extern int g_nRequiredPolls;
764
765extern DB_HANDLE NXCORE_EXPORTABLE g_hCoreDB;
766extern Queue *g_pLazyRequestQueue;
767
28f5b9a4 768extern int NXCORE_EXPORTABLE g_nDBSyntax;
5039dede
AK
769
770#endif /* _nms_core_h_ */