alarm detaild view: intermediate commit
[public/netxms.git] / src / server / include / nms_core.h
CommitLineData
5039dede
AK
1/*
2** NetXMS - Network Management System
6adc4a1a 3** Copyright (C) 2003-2012 Victor Kirhenshtein
5039dede
AK
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** File: nms_core.h
20**
21**/
22
23#ifndef _nms_core_h_
24#define _nms_core_h_
25
26#ifdef _WIN32
27#ifdef NXCORE_EXPORTS
28#define NXCORE_EXPORTABLE __declspec(dllexport)
29#else
30#define NXCORE_EXPORTABLE __declspec(dllimport)
31#endif
32#else /* _WIN32 */
33#define NXCORE_EXPORTABLE
34#endif
35
36#define LIBNXCL_NO_DECLARATIONS 1
37
38#include <nms_common.h>
39
40#ifndef _WIN32
41
42#if HAVE_SYS_TYPES_H
43# include <sys/types.h>
44#endif
45
46#if HAVE_DLFCN_H
47#include <dlfcn.h>
48#endif
49
50#define WSAGetLastError() (errno)
51
52#endif /* _WIN32 */
53
54#include <time.h>
55#include <stdio.h>
56#include <string.h>
57#include <stdarg.h>
58
59#define SHOW_FLAG_VALUE(x) _T(" %-32s = %d\n"), _T(#x), (g_dwFlags & x) ? 1 : 0
60
61
62//
63// Common includes
64//
65
66#include <nms_util.h>
67#include <dbdrv.h>
68#include <nms_cscp.h>
69#include <uuid.h>
70#include <nxsrvapi.h>
5039dede
AK
71#include <nxqueue.h>
72#include <nxsnmp.h>
73#include <nxmodule.h>
74#include <nxsl.h>
9d88cdc9 75#include <nxdbapi.h>
9796ce45 76#include <nddrv.h>
d41edbd3 77#include <nxcore_smclp.h>
5039dede
AK
78
79
80//
81// Console context
82//
83
84struct __console_ctx
85{
86 SOCKET hSocket;
d3a7cf4c 87 MUTEX socketMutex;
5039dede 88 CSCPMessage *pMsg;
200d662d 89 ClientSession *session;
5039dede
AK
90};
91
92typedef __console_ctx * CONSOLE_CTX;
93
94
95//
96// Server includes
97//
98
99#include "nms_dcoll.h"
100#include "nms_users.h"
101#include "nms_objects.h"
5039dede
AK
102#include "nms_locks.h"
103#include "nms_pkg.h"
104#include "nms_topo.h"
105#include "nms_script.h"
5039dede 106#include "nxcore_situations.h"
ab621f39 107#include "nxcore_jobs.h"
e05b1945 108#include "nxcore_logs.h"
5039dede
AK
109
110
111//
112// Common constants and macros
113//
114
73869331
VK
115#define MAX_LINE_SIZE 4096
116#define GROUP_FLAG_BIT ((DWORD)0x80000000)
117#define CHECKPOINT_SNMP_PORT 260
118#define DEFAULT_AFFINITY_MASK 0xFFFFFFFF
5039dede
AK
119
120typedef void * HSNMPSESSION;
121
5039dede 122
df8a4ca2
VK
123//
124// Prefixes for poller messages
125//
126
127#define POLLER_ERROR _T("\x7F") _T("e")
128#define POLLER_WARNING _T("\x7Fw")
129#define POLLER_INFO _T("\x7Fi")
130
131
5039dede
AK
132//
133// Unique identifier group codes
134//
135
136#define IDG_NETWORK_OBJECT 0
137#define IDG_CONTAINER_CAT 1
138#define IDG_EVENT 2
139#define IDG_ITEM 3
140#define IDG_SNMP_TRAP 4
24dc5346 141#define IDG_JOB 5
5039dede
AK
142#define IDG_ACTION 6
143#define IDG_EVENT_GROUP 7
144#define IDG_THRESHOLD 8
145#define IDG_USER 9
146#define IDG_USER_GROUP 10
147#define IDG_ALARM 11
148#define IDG_ALARM_NOTE 12
149#define IDG_PACKAGE 13
636e0c72 150#define IDG_SLM_TICKET 14
5039dede
AK
151#define IDG_OBJECT_TOOL 15
152#define IDG_SCRIPT 16
153#define IDG_AGENT_CONFIG 17
154#define IDG_GRAPH 18
155#define IDG_CERTIFICATE 19
156#define IDG_SITUATION 20
ba89fed2 157#define IDG_DCT_COLUMN 21
5039dede
AK
158
159
160//
161// Exit codes for console commands
162//
163
164#define CMD_EXIT_CONTINUE 0
165#define CMD_EXIT_CLOSE_SESSION 1
166#define CMD_EXIT_SHUTDOWN 2
167
168
169//
170// Network discovery mode
171//
172
173#define DISCOVERY_DISABLED 0
174#define DISCOVERY_PASSIVE_ONLY 1
175#define DISCOVERY_ACTIVE 2
176
177
178//
179// Client session flags
180//
181
5039dede
AK
182#define CSF_EPP_LOCKED ((DWORD)0x0002)
183#define CSF_PACKAGE_DB_LOCKED ((DWORD)0x0004)
184#define CSF_USER_DB_LOCKED ((DWORD)0x0008)
185#define CSF_EPP_UPLOAD ((DWORD)0x0010)
200d662d 186#define CSF_CONSOLE_OPEN ((DWORD)0x0020)
5039dede 187#define CSF_AUTHENTICATED ((DWORD)0x0080)
5039dede
AK
188#define CSF_RECEIVING_MAP_DATA ((DWORD)0x0200)
189#define CSF_SYNC_OBJECT_COMMENTS ((DWORD)0x0400)
190
191
192//
193// Client session states
194//
195
196#define SESSION_STATE_INIT 0
197#define SESSION_STATE_IDLE 1
198#define SESSION_STATE_PROCESSING 2
199
200
201//
202// Information categories for UPDATE_INFO structure
203//
204
205#define INFO_CAT_EVENT 1
206#define INFO_CAT_OBJECT_CHANGE 2
207#define INFO_CAT_ALARM 3
208#define INFO_CAT_ACTION 4
209#define INFO_CAT_SYSLOG_MSG 5
210#define INFO_CAT_SNMP_TRAP 6
211#define INFO_CAT_AUDIT_RECORD 7
212#define INFO_CAT_SITUATION 8
624f1165 213#define INFO_CAT_LIBRARY_IMAGE 9
5039dede
AK
214
215
216//
217// Certificate types
218//
219
220#define CERT_TYPE_TRUSTED_CA 0
221#define CERT_TYPE_USER 1
222
223
224//
225// Audit subsystems
226//
227
228#define AUDIT_SECURITY _T("SECURITY")
229#define AUDIT_OBJECTS _T("OBJECTS")
230#define AUDIT_SYSCFG _T("SYSCFG")
231#define AUDIT_CONSOLE _T("CONSOLE")
232
233
234//
235// Event handling subsystem definitions
236//
237
238#include "nms_events.h"
239#include "nms_actions.h"
240#include "nms_alarm.h"
241
242
243//
244// New node information
245//
246
247typedef struct
248{
249 DWORD dwIpAddr;
250 DWORD dwNetMask;
dc25b21c 251 DWORD zoneId;
5039dede 252 BOOL ignoreFilter;
baa5324c 253 BYTE bMacAddr[MAC_ADDR_LENGTH];
5039dede
AK
254} NEW_NODE;
255
256
257//
258// New node flags
259//
260
261#define NNF_IS_SNMP 0x0001
262#define NNF_IS_AGENT 0x0002
263#define NNF_IS_ROUTER 0x0004
264#define NNF_IS_BRIDGE 0x0008
265#define NNF_IS_PRINTER 0x0010
266#define NNF_IS_CDP 0x0020
267#define NNF_IS_SONMP 0x0040
268#define NNF_IS_LLDP 0x0080
269
270
271//
272// Node information for autodiscovery filter
273//
274
275typedef struct
276{
277 DWORD dwIpAddr;
278 DWORD dwNetMask;
279 DWORD dwSubnetAddr;
280 DWORD dwFlags;
281 int nSNMPVersion;
35f836fe
VK
282 TCHAR szObjectId[MAX_OID_LEN * 4]; // SNMP OID
283 TCHAR szAgentVersion[MAX_AGENT_VERSION_LEN];
284 TCHAR szPlatform[MAX_PLATFORM_NAME_LEN];
5039dede
AK
285} DISCOVERY_FILTER_DATA;
286
287
288//
289// Data update structure for client sessions
290//
291
292typedef struct
293{
294 DWORD dwCategory; // Data category - event, network object, etc.
295 DWORD dwCode; // Data-specific update code
296 void *pData; // Pointer to data block
297} UPDATE_INFO;
298
534e1b83
VK
299/**
300 * Extended agent connection
301 */
5039dede
AK
302class AgentConnectionEx : public AgentConnection
303{
304protected:
f480bdd4
VK
305 virtual void onTrap(CSCPMessage *msg);
306 virtual void onDataPush(CSCPMessage *msg);
5039dede
AK
307
308public:
5039dede
AK
309 AgentConnectionEx(DWORD dwAddr, WORD wPort = AGENT_LISTEN_PORT,
310 int iAuthMethod = AUTH_NONE, TCHAR *pszSecret = NULL) :
311 AgentConnection(dwAddr, wPort, iAuthMethod, pszSecret) { }
312 virtual ~AgentConnectionEx();
45d84f8a
VK
313
314 DWORD deployPolicy(AgentPolicy *policy);
93599cfd 315 DWORD uninstallPolicy(AgentPolicy *policy);
5039dede
AK
316};
317
534e1b83
VK
318/**
319 * Mobile device session
320 */
321class NXCORE_EXPORTABLE MobileDeviceSession
322{
323private:
324 SOCKET m_hSocket;
325 Queue *m_pSendQueue;
326 Queue *m_pMessageQueue;
327 DWORD m_dwIndex;
328 int m_iState;
329 WORD m_wCurrentCmd;
330 DWORD m_dwUserId;
331 DWORD m_deviceObjectId;
332 CSCP_BUFFER *m_pMsgBuffer;
333 NXCPEncryptionContext *m_pCtx;
334 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
335 THREAD m_hWriteThread;
336 THREAD m_hProcessingThread;
337 MUTEX m_mutexSocketWrite;
338 struct sockaddr *m_clientAddr;
339 TCHAR m_szHostName[256]; // IP address of name of conneced host in textual form
340 TCHAR m_szUserName[MAX_SESSION_NAME]; // String in form login_name@host
341 TCHAR m_szClientInfo[96]; // Client app info string
342 DWORD m_dwEncryptionRqId;
343 DWORD m_dwEncryptionResult;
344 CONDITION m_condEncryptionSetup;
345 DWORD m_dwRefCount;
346 bool m_isAuthenticated;
347
348 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
349 static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
350 static THREAD_RESULT THREAD_CALL processingThreadStarter(void *);
5039dede 351
534e1b83
VK
352 void readThread();
353 void writeThread();
354 void processingThread();
355
356 void setupEncryption(CSCPMessage *request);
357 void respondToKeepalive(DWORD dwRqId);
358 void debugPrintf(int level, const TCHAR *format, ...);
359 void sendServerInfo(DWORD dwRqId);
360 void login(CSCPMessage *pRequest);
361 void updateDeviceInfo(CSCPMessage *pRequest);
362 void updateDeviceStatus(CSCPMessage *pRequest);
363
364public:
365 MobileDeviceSession(SOCKET hSocket, struct sockaddr *addr);
366 ~MobileDeviceSession();
367
368 void incRefCount() { m_dwRefCount++; }
369 void decRefCount() { if (m_dwRefCount > 0) m_dwRefCount--; }
370
371 void run();
372
373 void postMessage(CSCPMessage *pMsg) { m_pSendQueue->Put(pMsg->CreateMessage()); }
374 void sendMessage(CSCPMessage *pMsg);
5039dede 375
534e1b83
VK
376 DWORD getIndex() { return m_dwIndex; }
377 void setIndex(DWORD dwIndex) { if (m_dwIndex == INVALID_INDEX) m_dwIndex = dwIndex; }
378 int getState() { return m_iState; }
379 const TCHAR *getUserName() { return m_szUserName; }
380 const TCHAR *getClientInfo() { return m_szClientInfo; }
381 const TCHAR *getHostName() { return m_szHostName; }
382 DWORD getUserId() { return m_dwUserId; }
383 bool isAuthenticated() { return m_isAuthenticated; }
384 WORD getCurrentCmd() { return m_wCurrentCmd; }
385 int getCipher() { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
386};
387
388/**
389 * Client (user) session
390 */
5039dede
AK
391#define DECLARE_THREAD_STARTER(func) static THREAD_RESULT THREAD_CALL ThreadStarter_##func(void *);
392
a0e3917e 393class NXCORE_EXPORTABLE ClientSession
5039dede
AK
394{
395private:
396 SOCKET m_hSocket;
397 Queue *m_pSendQueue;
398 Queue *m_pMessageQueue;
399 Queue *m_pUpdateQueue;
400 DWORD m_dwIndex;
401 int m_iState;
402 WORD m_wCurrentCmd;
403 DWORD m_dwUserId;
404 DWORD m_dwSystemAccess; // User's system access rights
405 DWORD m_dwFlags; // Session flags
f8c6f10f 406 int m_clientType; // Client system type - desktop, web, mobile, etc.
5039dede 407 CSCP_BUFFER *m_pMsgBuffer;
98abc9f1 408 NXCPEncryptionContext *m_pCtx;
5039dede
AK
409 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
410 THREAD m_hWriteThread;
411 THREAD m_hProcessingThread;
412 THREAD m_hUpdateThread;
d3a7cf4c 413 MUTEX m_mutexSocketWrite;
5039dede
AK
414 MUTEX m_mutexSendEvents;
415 MUTEX m_mutexSendSyslog;
416 MUTEX m_mutexSendTrapLog;
417 MUTEX m_mutexSendObjects;
418 MUTEX m_mutexSendAlarms;
419 MUTEX m_mutexSendActions;
420 MUTEX m_mutexSendAuditLog;
421 MUTEX m_mutexSendSituations;
422 MUTEX m_mutexPollerInit;
60557d06
VK
423 struct sockaddr *m_clientAddr;
424 TCHAR m_szWorkstation[256]; // IP address of name of conneced host in textual form
5039dede
AK
425 TCHAR m_szUserName[MAX_SESSION_NAME]; // String in form login_name@host
426 TCHAR m_szClientInfo[96]; // Client app info string
427 DWORD m_dwOpenDCIListSize; // Number of open DCI lists
428 DWORD *m_pOpenDCIList; // List of nodes with DCI lists open
429 DWORD m_dwNumRecordsToUpload; // Number of records to be uploaded
430 DWORD m_dwRecordsUploaded;
431 EPRule **m_ppEPPRuleList; // List of loaded EPP rules
432 int m_hCurrFile;
433 DWORD m_dwFileRqId;
434 DWORD m_dwUploadCommand;
435 DWORD m_dwUploadData;
436 TCHAR m_szCurrFileName[MAX_PATH];
437 DWORD m_dwRefCount;
438 DWORD m_dwEncryptionRqId;
439 DWORD m_dwEncryptionResult;
440 CONDITION m_condEncryptionSetup;
441 DWORD m_dwActiveChannels; // Active data channels
200d662d 442 CONSOLE_CTX m_console; // Server console context
5039dede 443
534e1b83
VK
444 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
445 static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
446 static THREAD_RESULT THREAD_CALL processingThreadStarter(void *);
447 static THREAD_RESULT THREAD_CALL updateThreadStarter(void *);
448 static THREAD_RESULT THREAD_CALL pollerThreadStarter(void *);
5039dede 449
92c51b1d
VK
450 DECLARE_THREAD_STARTER(getCollectedData)
451 DECLARE_THREAD_STARTER(getTableCollectedData)
452 DECLARE_THREAD_STARTER(clearDCIData)
adac28be
VK
453 DECLARE_THREAD_STARTER(queryParameter)
454 DECLARE_THREAD_STARTER(queryAgentTable)
84880c89 455 DECLARE_THREAD_STARTER(queryL2Topology)
5039dede
AK
456 DECLARE_THREAD_STARTER(SendEventLog)
457 DECLARE_THREAD_STARTER(SendSyslog)
1da08bc6
VK
458 DECLARE_THREAD_STARTER(createObject)
459 DECLARE_THREAD_STARTER(getServerFile)
6f16f12d 460 DECLARE_THREAD_STARTER(getAgentFile)
e05b1945
VK
461 DECLARE_THREAD_STARTER(queryServerLog)
462 DECLARE_THREAD_STARTER(getServerLogQueryData)
e31c8e60 463 DECLARE_THREAD_STARTER(executeAction)
630e15d6 464 DECLARE_THREAD_STARTER(findNodeConnection)
06a93345 465 DECLARE_THREAD_STARTER(findMacAddress)
80e0db05 466 DECLARE_THREAD_STARTER(findIpAddress)
200d662d 467 DECLARE_THREAD_STARTER(processConsoleCommand)
b08d31f4 468 DECLARE_THREAD_STARTER(sendMib)
e12e1422 469 DECLARE_THREAD_STARTER(getReportResults)
3932fde6 470 DECLARE_THREAD_STARTER(deleteReportResults)
e12e1422 471 DECLARE_THREAD_STARTER(renderReport)
6d069676 472 DECLARE_THREAD_STARTER(getNetworkPath)
5039dede 473
62768df3
VK
474 void readThread();
475 void writeThread();
476 void processingThread();
477 void updateThread();
478 void pollerThread(Node *pNode, int iPollType, DWORD dwRqId);
5039dede 479
9e9d631e 480 void setupEncryption(CSCPMessage *request);
711e5e9a 481 void respondToKeepalive(DWORD dwRqId);
e05b1945 482 void onFileUpload(BOOL bSuccess);
534e1b83 483 void debugPrintf(int level, const TCHAR *format, ...);
711e5e9a
VK
484 void sendServerInfo(DWORD dwRqId);
485 void login(CSCPMessage *pRequest);
62768df3
VK
486 void sendAllObjects(CSCPMessage *pRequest);
487 void sendSelectedObjects(CSCPMessage *pRequest);
5039dede
AK
488 void SendEventLog(CSCPMessage *pRequest);
489 void SendAllConfigVars(DWORD dwRqId);
490 void SetConfigVariable(CSCPMessage *pRequest);
491 void DeleteConfigVariable(CSCPMessage *pRequest);
492 void SendUserDB(DWORD dwRqId);
1add6d73 493 void sendAllAlarms(DWORD dwRqId);
5039dede
AK
494 void CreateUser(CSCPMessage *pRequest);
495 void UpdateUser(CSCPMessage *pRequest);
496 void DeleteUser(CSCPMessage *pRequest);
497 void SetPassword(CSCPMessage *pRequest);
498 void LockUserDB(DWORD dwRqId, BOOL bLock);
8eb2d92b
VK
499 void sendEventDB(DWORD dwRqId);
500 void modifyEventTemplate(CSCPMessage *pRequest);
501 void deleteEventTemplate(CSCPMessage *pRequest);
502 void generateEventCode(DWORD dwRqId);
92c51b1d 503 void modifyObject(CSCPMessage *pRequest);
1da08bc6 504 void changeObjectMgmtStatus(CSCPMessage *pRequest);
92c51b1d
VK
505 void openNodeDCIList(CSCPMessage *pRequest);
506 void closeNodeDCIList(CSCPMessage *pRequest);
507 void modifyNodeDCI(CSCPMessage *pRequest);
508 void copyDCI(CSCPMessage *pRequest);
509 void applyTemplate(CSCPMessage *pRequest);
510 void getCollectedData(CSCPMessage *pRequest);
511 void getTableCollectedData(CSCPMessage *pRequest);
6fd6de0a 512 bool getCollectedDataFromDB(CSCPMessage *request, CSCPMessage *response, DataCollectionTarget *object, int dciType);
92c51b1d
VK
513 void clearDCIData(CSCPMessage *pRequest);
514 void changeDCIStatus(CSCPMessage *pRequest);
b9a8e081
VK
515 void getLastValues(CSCPMessage *pRequest);
516 void getTableLastValues(CSCPMessage *pRequest);
711e5e9a 517 void getThresholdSummary(CSCPMessage *request);
92c51b1d
VK
518 void openEPP(DWORD dwRqId);
519 void closeEPP(DWORD dwRqId);
520 void saveEPP(CSCPMessage *pRequest);
521 void processEPPRecord(CSCPMessage *pRequest);
522 void sendMIBTimestamp(DWORD dwRqId);
b08d31f4 523 void sendMib(CSCPMessage *request);
1da08bc6
VK
524 void createObject(CSCPMessage *pRequest);
525 void changeObjectBinding(CSCPMessage *pRequest, BOOL bBind);
f5d16551 526 void deleteObject(CSCPMessage *pRequest);
4d00760d 527 void getAlarm(CSCPMessage *pRequest);
1add6d73 528 void acknowledgeAlarm(CSCPMessage *pRequest);
5f6bc78c 529 void resolveAlarm(CSCPMessage *pRequest, bool terminate);
1add6d73 530 void deleteAlarm(CSCPMessage *pRequest);
1b94acbf
VK
531 void getAlarmNotes(CSCPMessage *pRequest);
532 void updateAlarmNote(CSCPMessage *pRequest);
533 void createAction(CSCPMessage *pRequest);
534 void updateAction(CSCPMessage *pRequest);
535 void deleteAction(CSCPMessage *pRequest);
536 void sendAllActions(DWORD dwRqId);
5039dede 537 void SendContainerCategories(DWORD dwRqId);
92c51b1d 538 void forcedNodePoll(CSCPMessage *pRequest);
5039dede
AK
539 void OnTrap(CSCPMessage *pRequest);
540 void OnWakeUpNode(CSCPMessage *pRequest);
adac28be
VK
541 void queryParameter(CSCPMessage *pRequest);
542 void queryAgentTable(CSCPMessage *pRequest);
5039dede
AK
543 void EditTrap(int iOperation, CSCPMessage *pRequest);
544 void LockTrapCfg(DWORD dwRqId, BOOL bLock);
545 void SendAllTraps(DWORD dwRqId);
546 void SendAllTraps2(DWORD dwRqId);
547 void LockPackageDB(DWORD dwRqId, BOOL bLock);
548 void SendAllPackages(DWORD dwRqId);
549 void InstallPackage(CSCPMessage *pRequest);
550 void RemovePackage(CSCPMessage *pRequest);
551 void DeployPackage(CSCPMessage *pRequest);
552 void SendParametersList(CSCPMessage *pRequest);
553 void GetUserVariable(CSCPMessage *pRequest);
554 void SetUserVariable(CSCPMessage *pRequest);
555 void CopyUserVariable(CSCPMessage *pRequest);
556 void EnumUserVariables(CSCPMessage *pRequest);
557 void DeleteUserVariable(CSCPMessage *pRequest);
4c789f9e 558 void changeObjectZone(CSCPMessage *pRequest);
92c51b1d
VK
559 void getAgentConfig(CSCPMessage *pRequest);
560 void updateAgentConfig(CSCPMessage *pRequest);
e31c8e60 561 void executeAction(CSCPMessage *pRequest);
0e950f45
VK
562 void sendObjectTools(DWORD dwRqId);
563 void sendObjectToolDetails(CSCPMessage *pRequest);
564 void updateObjectTool(CSCPMessage *pRequest);
565 void deleteObjectTool(CSCPMessage *pRequest);
566 void generateObjectToolId(DWORD dwRqId);
567 void execTableTool(CSCPMessage *pRequest);
5039dede
AK
568 void ChangeSubscription(CSCPMessage *pRequest);
569 void SendSyslog(CSCPMessage *pRequest);
5039dede 570 void SendServerStats(DWORD dwRqId);
0c7aca90
VK
571 void sendScriptList(DWORD dwRqId);
572 void sendScript(CSCPMessage *pRequest);
573 void updateScript(CSCPMessage *pRequest);
574 void renameScript(CSCPMessage *pRequest);
575 void deleteScript(CSCPMessage *pRequest);
5039dede
AK
576 void SendSessionList(DWORD dwRqId);
577 void KillSession(CSCPMessage *pRequest);
578 void SendTrapLog(CSCPMessage *pRequest);
579 void StartSnmpWalk(CSCPMessage *pRequest);
5039dede
AK
580 void ResolveDCINames(CSCPMessage *pRequest);
581 DWORD ResolveDCIName(DWORD dwNode, DWORD dwItem, TCHAR **ppszName);
582 void SendConfigForAgent(CSCPMessage *pRequest);
583 void SendAgentCfgList(DWORD dwRqId);
584 void OpenAgentConfig(CSCPMessage *pRequest);
585 void SaveAgentConfig(CSCPMessage *pRequest);
586 void DeleteAgentConfig(CSCPMessage *pRequest);
587 void SwapAgentConfigs(CSCPMessage *pRequest);
588 void SendObjectComments(CSCPMessage *pRequest);
6fd6de0a
VK
589 void updateObjectComments(CSCPMessage *pRequest);
590 void pushDCIData(CSCPMessage *pRequest);
591 void getAddrList(CSCPMessage *pRequest);
592 void setAddrList(CSCPMessage *pRequest);
92c51b1d 593 void resetComponent(CSCPMessage *pRequest);
7a46028e 594 void sendDCIEventList(CSCPMessage *request);
5039dede 595 void SendDCIInfo(CSCPMessage *pRequest);
74526d25 596 void sendPerfTabDCIList(CSCPMessage *pRequest);
a7ff20a5
VK
597 void exportConfiguration(CSCPMessage *pRequest);
598 void importConfiguration(CSCPMessage *pRequest);
5039dede
AK
599 void SendGraphList(DWORD dwRqId);
600 void DefineGraph(CSCPMessage *pRequest);
601 void DeleteGraph(CSCPMessage *pRequest);
602 void AddCACertificate(CSCPMessage *pRequest);
603 void DeleteCertificate(CSCPMessage *pRequest);
604 void UpdateCertificateComments(CSCPMessage *pRequest);
605 void SendCertificateList(DWORD dwRqId);
84880c89 606 void queryL2Topology(CSCPMessage *pRequest);
5039dede
AK
607 void SendSMS(CSCPMessage *pRequest);
608 void SendCommunityList(DWORD dwRqId);
609 void UpdateCommunityList(CSCPMessage *pRequest);
610 void SendSituationList(DWORD dwRqId);
611 void CreateSituation(CSCPMessage *pRequest);
612 void UpdateSituation(CSCPMessage *pRequest);
613 void DeleteSituation(CSCPMessage *pRequest);
614 void DeleteSituationInstance(CSCPMessage *pRequest);
1da08bc6
VK
615 void setConfigCLOB(CSCPMessage *pRequest);
616 void getConfigCLOB(CSCPMessage *pRequest);
1da08bc6
VK
617 void registerAgent(CSCPMessage *pRequest);
618 void getServerFile(CSCPMessage *pRequest);
6f16f12d 619 void getAgentFile(CSCPMessage *pRequest);
1da08bc6 620 void testDCITransformation(CSCPMessage *pRequest);
45d84f8a
VK
621 void sendJobList(DWORD dwRqId);
622 void cancelJob(CSCPMessage *pRequest);
8d9f7450
VK
623 void holdJob(CSCPMessage *pRequest);
624 void unholdJob(CSCPMessage *pRequest);
93599cfd 625 void deployAgentPolicy(CSCPMessage *pRequest, bool uninstallFlag);
d83dc1f0
VK
626 void getUserCustomAttribute(CSCPMessage *request);
627 void setUserCustomAttribute(CSCPMessage *request);
e05b1945
VK
628 void openServerLog(CSCPMessage *request);
629 void closeServerLog(CSCPMessage *request);
630 void queryServerLog(CSCPMessage *request);
631 void getServerLogQueryData(CSCPMessage *request);
df8a4ca2
VK
632 void sendUsmCredentials(DWORD dwRqId);
633 void updateUsmCredentials(CSCPMessage *pRequest);
071fd171 634 void sendDCIThresholds(CSCPMessage *request);
1da08bc6 635 void addClusterNode(CSCPMessage *request);
630e15d6 636 void findNodeConnection(CSCPMessage *request);
06a93345 637 void findMacAddress(CSCPMessage *request);
80e0db05 638 void findIpAddress(CSCPMessage *request);
e6b9439a
AK
639 void sendLibraryImage(CSCPMessage *request);
640 void updateLibraryImage(CSCPMessage *request);
641 void listLibraryImages(CSCPMessage *request);
642 void deleteLibraryImage(CSCPMessage *request);
f69c6203 643 void executeServerCommand(CSCPMessage *request);
619e5c9b 644 void uploadFileToAgent(CSCPMessage *request);
1a5e0c22 645 void listServerFileStore(CSCPMessage *request);
200d662d
VK
646 void processConsoleCommand(CSCPMessage *msg);
647 void openConsole(DWORD rqId);
648 void closeConsole(DWORD rqId);
7f632dfe 649 void getVlans(CSCPMessage *msg);
68f898c9
VK
650 void receiveFile(CSCPMessage *request);
651 void deleteFile(CSCPMessage *request);
8c5b6ed3
VK
652 void executeReport(CSCPMessage *msg);
653 void getReportResults(CSCPMessage *msg);
3932fde6 654 void deleteReportResults(CSCPMessage *msg);
e12e1422 655 void renderReport(CSCPMessage *request);
6d069676 656 void getNetworkPath(CSCPMessage *request);
8836184f 657 void getNodeComponents(CSCPMessage *request);
5039dede
AK
658
659public:
60557d06 660 ClientSession(SOCKET hSocket, struct sockaddr *addr);
5039dede
AK
661 ~ClientSession();
662
e05b1945
VK
663 void incRefCount() { m_dwRefCount++; }
664 void decRefCount() { if (m_dwRefCount > 0) m_dwRefCount--; }
665
666 void run();
667
d3a7cf4c
VK
668 void postMessage(CSCPMessage *pMsg) { m_pSendQueue->Put(pMsg->CreateMessage()); }
669 void sendMessage(CSCPMessage *pMsg);
92c51b1d 670 void sendRawMessage(CSCP_MESSAGE *pMsg);
e05b1945
VK
671 void sendPollerMsg(DWORD dwRqId, const TCHAR *pszMsg);
672 BOOL sendFile(const TCHAR *file, DWORD dwRqId);
673
f669df41 674 DWORD getIndex() { return m_dwIndex; }
e05b1945 675 void setIndex(DWORD dwIndex) { if (m_dwIndex == INVALID_INDEX) m_dwIndex = dwIndex; }
f669df41 676 int getState() { return m_iState; }
889d7ff7
VK
677 const TCHAR *getUserName() { return m_szUserName; }
678 const TCHAR *getClientInfo() { return m_szClientInfo; }
679 const TCHAR *getWorkstation() { return m_szWorkstation; }
e05b1945
VK
680 DWORD getUserId() { return m_dwUserId; }
681 DWORD getSystemRights() { return m_dwSystemAccess; }
f669df41
VK
682 bool isAuthenticated() { return (m_dwFlags & CSF_AUTHENTICATED) ? true : false; }
683 bool isConsoleOpen() { return (m_dwFlags & CSF_CONSOLE_OPEN) ? true : false; }
684 bool isSubscribed(DWORD dwChannel) { return (m_dwActiveChannels & dwChannel) ? true : false; }
685 WORD getCurrentCmd() { return m_wCurrentCmd; }
98abc9f1 686 int getCipher() { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
f8c6f10f 687 int getClientType() { return m_clientType; }
e05b1945
VK
688
689 bool checkSysAccessRights(DWORD requiredAccess)
690 {
691 return m_dwUserId == 0 ? true :
692 ((requiredAccess & m_dwSystemAccess) ? true : false);
693 }
694
f669df41 695 void kill();
e05b1945
VK
696 void notify(DWORD dwCode, DWORD dwData = 0);
697
698 void queueUpdate(UPDATE_INFO *pUpdate) { m_pUpdateQueue->Put(pUpdate); }
699 void onNewEvent(Event *pEvent);
e0f99bf0 700 void onSyslogMessage(NX_SYSLOG_RECORD *pRec);
e05b1945
VK
701 void onNewSNMPTrap(CSCPMessage *pMsg);
702 void onObjectChange(NetObj *pObject);
703 void onUserDBUpdate(int code, DWORD id, UserDatabaseObject *user);
704 void onAlarmUpdate(DWORD dwCode, NXC_ALARM *pAlarm);
705 void onActionDBUpdate(DWORD dwCode, NXC_ACTION *pAction);
706 void onSituationChange(CSCPMessage *msg);
624f1165 707 void onLibraryImageChange(uuid_t *guid);
5039dede
AK
708};
709
710
7dad92fb
VK
711//
712// Delayed SQL request
713//
714
715typedef struct
716{
717 TCHAR *query;
718 int bindCount;
719 BYTE *sqlTypes;
720 TCHAR *bindings[1]; /* actual size determined by bindCount field */
721} DELAYED_SQL_REQUEST;
722
723
f68d9eac
VK
724//
725// Delayed request for idata_ INSERT
726//
727
728typedef struct
729{
730 time_t timestamp;
731 DWORD nodeId;
732 DWORD dciId;
733 TCHAR value[MAX_RESULT_LENGTH];
734} DELAYED_IDATA_INSERT;
735
736
5039dede
AK
737//
738// Functions
739//
740
35f836fe
VK
741BOOL NXCORE_EXPORTABLE ConfigReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
742#ifdef UNICODE
743BOOL NXCORE_EXPORTABLE ConfigReadStrA(const WCHAR *szVar, char *szBuffer, int iBufSize, const char *szDefault);
744#else
745#define ConfigReadStrA ConfigReadStr
746#endif
5039dede
AK
747int NXCORE_EXPORTABLE ConfigReadInt(const TCHAR *szVar, int iDefault);
748DWORD NXCORE_EXPORTABLE ConfigReadULong(const TCHAR *szVar, DWORD dwDefault);
749BOOL NXCORE_EXPORTABLE ConfigReadByteArray(const TCHAR *pszVar, int *pnArray,
750 int nSize, int nDefault);
751BOOL NXCORE_EXPORTABLE ConfigWriteStr(const TCHAR *szVar, const TCHAR *szValue, BOOL bCreate,
752 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
753BOOL NXCORE_EXPORTABLE ConfigWriteInt(const TCHAR *szVar, int iValue, BOOL bCreate,
754 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
755BOOL NXCORE_EXPORTABLE ConfigWriteULong(const TCHAR *szVar, DWORD dwValue, BOOL bCreate,
756 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
757BOOL NXCORE_EXPORTABLE ConfigWriteByteArray(const TCHAR *pszVar, int *pnArray,
758 int nSize, BOOL bCreate,
759 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
760TCHAR NXCORE_EXPORTABLE *ConfigReadCLOB(const TCHAR *var, const TCHAR *defValue);
761BOOL NXCORE_EXPORTABLE ConfigWriteCLOB(const TCHAR *var, const TCHAR *value, BOOL bCreate);
762
28f5b9a4
VK
763BOOL NXCORE_EXPORTABLE MetaDataReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
764
35f836fe 765BOOL NXCORE_EXPORTABLE LoadConfig();
5039dede 766
35f836fe
VK
767void NXCORE_EXPORTABLE Shutdown();
768void NXCORE_EXPORTABLE FastShutdown();
769BOOL NXCORE_EXPORTABLE Initialize();
5039dede 770THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL Main(void *);
35f836fe
VK
771void NXCORE_EXPORTABLE ShutdownDB();
772void InitiateShutdown();
5039dede
AK
773
774BOOL NXCORE_EXPORTABLE SleepAndCheckForShutdown(int iSeconds);
775
35f836fe
VK
776void ConsolePrintf(CONSOLE_CTX pCtx, const TCHAR *pszFormat, ...);
777int ProcessConsoleCommand(const TCHAR *pszCmdLine, CONSOLE_CTX pCtx);
5039dede
AK
778
779void SaveObjects(DB_HANDLE hdb);
780
ce7565e7 781void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query);
7dad92fb 782void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query, int bindCount, int *sqlTypes, const TCHAR **values);
f68d9eac 783void QueueIDataInsert(time_t timestamp, DWORD nodeId, DWORD dciId, const TCHAR *value);
ce7565e7
VK
784void StartDBWriter();
785void StopDBWriter();
5039dede 786
8c08411e 787bool NXCORE_EXPORTABLE IsDatabaseRecordExist(DB_HANDLE hdb, const TCHAR *table, const TCHAR *idColumn, DWORD id);
ba89fed2 788
5039dede
AK
789void DecodeSQLStringAndSetVariable(CSCPMessage *pMsg, DWORD dwVarId, TCHAR *pszStr);
790
df8a4ca2 791SNMP_SecurityContext *SnmpCheckCommSettings(SNMP_Transport *pTransport, int *version, SNMP_SecurityContext *originalContext);
35f836fe 792void StrToMac(const TCHAR *pszStr, BYTE *pBuffer);
5039dede 793
f42b8099 794void InitLocalNetInfo();
5039dede 795
f42b8099 796ARP_CACHE *GetLocalArpCache();
5d2c5741 797ARP_CACHE *SnmpGetArpCache(DWORD dwVersion, SNMP_Transport *pTransport);
5039dede 798
98762401 799InterfaceList *GetLocalInterfaceList();
1e6b68a6 800void SnmpGetInterfaceStatus(DWORD dwVersion, SNMP_Transport *pTransport, DWORD dwIfIndex, int *adminState, int *operState);
5039dede 801
5d2c5741 802ROUTING_TABLE *SnmpGetRoutingTable(DWORD dwVersion, SNMP_Transport *pTransport);
5039dede 803
9796ce45 804void LoadNetworkDeviceDrivers();
21254a93 805NetworkDeviceDriver *FindDriverForNode(Node *node, SNMP_Transport *pTransport);
9796ce45 806
5ad2167d 807void WatchdogInit();
5039dede
AK
808DWORD WatchdogAddThread(const TCHAR *szName, time_t tNotifyInterval);
809void WatchdogNotify(DWORD dwId);
810void WatchdogPrintStatus(CONSOLE_CTX pCtx);
811
5ad2167d 812void CheckForMgmtNode();
f1b6417b
VK
813Node *PollNewNode(DWORD dwIpAddr, DWORD dwNetMask, DWORD dwCreationFlags, WORD agentPort,
814 WORD snmpPort, TCHAR *pszName, DWORD dwProxyNode, DWORD dwSNMPProxy, Cluster *pCluster,
a749a70a 815 DWORD zoneId, bool doConfPoll, bool discoveredNode);
5039dede 816
04572884 817void NXCORE_EXPORTABLE EnumerateClientSessions(void (*pHandler)(ClientSession *, void *), void *pArg, ClientSession *current = NULL);
5039dede 818void NXCORE_EXPORTABLE NotifyClientSessions(DWORD dwCode, DWORD dwData);
5ad2167d 819int GetSessionCount();
5039dede 820
35f836fe
VK
821void GetSysInfoStr(TCHAR *pszBuffer, int nMaxSize);
822DWORD GetLocalIpAddr();
f7694811 823TCHAR *GetLocalHostName(TCHAR *buffer, size_t bufSize);
5039dede 824
35f836fe 825BOOL ExecCommand(TCHAR *pszCommand);
5039dede
AK
826BOOL SendMagicPacket(DWORD dwIpAddr, BYTE *pbMacAddr, int iNumPackets);
827
35f836fe 828BOOL InitIdTable();
5039dede 829DWORD CreateUniqueId(int iGroup);
35f836fe 830QWORD CreateUniqueEventId();
5039dede 831
35f836fe
VK
832void InitMailer();
833void ShutdownMailer();
834void NXCORE_EXPORTABLE PostMail(const TCHAR *pszRcpt, const TCHAR *pszSubject, const TCHAR *pszText);
5039dede 835
35f836fe
VK
836void InitSMSSender();
837void ShutdownSMSSender();
838void NXCORE_EXPORTABLE PostSMS(const TCHAR *pszRcpt, const TCHAR *pszText);
5039dede 839
35f836fe 840void InitTraps();
5039dede
AK
841void SendTrapsToClient(ClientSession *pSession, DWORD dwRqId);
842void CreateTrapCfgMessage(CSCPMessage &msg);
843DWORD CreateNewTrap(DWORD *pdwTrapId);
844DWORD CreateNewTrap(NXC_TRAP_CFG_ENTRY *pTrap);
845DWORD UpdateTrapFromMsg(CSCPMessage *pMsg);
846DWORD DeleteTrap(DWORD dwId);
847void CreateNXMPTrapRecord(String &str, DWORD dwId);
848
849BOOL IsTableTool(DWORD dwToolId);
850BOOL CheckObjectToolAccess(DWORD dwToolId, DWORD dwUserId);
851DWORD ExecuteTableTool(DWORD dwToolId, Node *pNode, DWORD dwRqId, ClientSession *pSession);
852DWORD DeleteObjectToolFromDB(DWORD dwToolId);
853DWORD UpdateObjectToolFromMessage(CSCPMessage *pMsg);
854
e0f99bf0 855void CreateMessageFromSyslogMsg(CSCPMessage *pMsg, NX_SYSLOG_RECORD *pRec);
4262c0dc 856void ReinitializeSyslogParser();
5039dede
AK
857
858void EscapeString(String &str);
859
ce7565e7
VK
860void InitAuditLog();
861void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *subsys, BOOL isSuccess, DWORD userId,
862 const TCHAR *workstation, DWORD objectId,
863 const TCHAR *format, ...);
5039dede 864
a65c1819
VK
865bool ValidateConfig(Config *config, DWORD flags, TCHAR *errorText, int errorTextLen);
866DWORD ImportConfig(Config *config, DWORD flags);
5039dede
AK
867
868#ifdef _WITH_ENCRYPTION
869X509 *CertificateFromLoginMessage(CSCPMessage *pMsg);
a50eaebe 870BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChallenge,
5039dede 871 BYTE *pSignature, DWORD dwSigLen, int nMappingMethod,
a50eaebe 872 const TCHAR *pszMappingData);
9796ce45 873void ReloadCertificates();
5039dede
AK
874#endif
875
876#ifndef _WIN32
877THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL SignalHandler(void *);
878#endif /* not _WIN32 */
879
5039dede 880void DbgTestRWLock(RWLOCK hLock, const TCHAR *szName, CONSOLE_CTX pCtx);
534e1b83
VK
881void DumpClientSessions(CONSOLE_CTX pCtx);
882void DumpMobileDeviceSessions(CONSOLE_CTX pCtx);
5039dede 883void ShowPollerState(CONSOLE_CTX pCtx);
35f836fe 884void SetPollerInfo(int nIdx, const TCHAR *pszMsg);
5039dede 885void ShowServerStats(CONSOLE_CTX pCtx);
35f836fe 886void ShowQueueStats(CONSOLE_CTX pCtx, Queue *pQueue, const TCHAR *pszName);
5039dede
AK
887void DumpProcess(CONSOLE_CTX pCtx);
888
534e1b83
VK
889/**
890 * Global variables
891 */
5039dede
AK
892extern TCHAR NXCORE_EXPORTABLE g_szConfigFile[];
893extern TCHAR NXCORE_EXPORTABLE g_szLogFile[];
4f8998ca
VK
894extern DWORD g_dwLogRotationMode;
895extern DWORD g_dwMaxLogSize;
896extern DWORD g_dwLogHistorySize;
897extern TCHAR g_szDailyLogFileSuffix[64];
5039dede
AK
898extern TCHAR NXCORE_EXPORTABLE g_szDumpDir[];
899extern TCHAR NXCORE_EXPORTABLE g_szListenAddress[];
900#ifndef _WIN32
901extern TCHAR NXCORE_EXPORTABLE g_szPIDFile[];
902#endif
903extern TCHAR g_szDataDir[];
9796ce45 904extern TCHAR g_szLibDir[];
712dd47d 905extern TCHAR g_szJavaLibDir[];
73869331 906extern DWORD NXCORE_EXPORTABLE g_processAffinityMask;
5039dede
AK
907extern QWORD g_qwServerId;
908extern RSA *g_pServerKey;
909extern DWORD g_dwPingSize;
910extern DWORD g_dwAuditFlags;
911extern time_t g_tServerStartTime;
912extern DWORD g_dwLockTimeout;
5039dede
AK
913extern DWORD g_dwAgentCommandTimeout;
914extern DWORD g_dwThresholdRepeatInterval;
915extern int g_nRequiredPolls;
52c75f5c 916extern DWORD g_dwSlmPollingInterval;
5039dede 917
b8c1ec69
VK
918extern TCHAR g_szDbDriver[];
919extern TCHAR g_szDbDrvParams[];
920extern TCHAR g_szDbServer[];
921extern TCHAR g_szDbLogin[];
922extern TCHAR g_szDbPassword[];
923extern TCHAR g_szDbName[];
f3c30cf5 924extern TCHAR g_szDbSchema[];
712dd47d 925extern TCHAR NXCORE_EXPORTABLE g_szJavaPath[];
b8c1ec69 926extern DB_DRIVER g_dbDriver;
5039dede
AK
927extern DB_HANDLE NXCORE_EXPORTABLE g_hCoreDB;
928extern Queue *g_pLazyRequestQueue;
c9a9601c 929extern Queue *g_pIDataInsertQueue;
5039dede 930
28f5b9a4 931extern int NXCORE_EXPORTABLE g_nDBSyntax;
5039dede
AK
932
933#endif /* _nms_core_h_ */