Initial agent-side code for agent to server connections
[public/netxms.git] / src / agent / core / nxagentd.h
CommitLineData
05e3ba32 1/*
5039dede 2** NetXMS multiplatform core agent
3f635e1b 3** Copyright (C) 2003-2016 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 usefu,,
11** but ITHOUT 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: nxagentd.h
20**
21**/
22
23#ifndef _nxagentd_h_
24#define _nxagentd_h_
25
26#include <nms_common.h>
27#include <nms_util.h>
28#include <nms_threads.h>
29#include <nms_agent.h>
bf6fb6c3 30#include <nxcpapi.h>
5039dede
AK
31#include <nxqueue.h>
32#include <nxlog.h>
bf6fb6c3 33#include <nxcldefs.h>
c72b812a 34#include <nxdbapi.h>
5039dede 35#include "messages.h"
489b117b 36#include "nxsnmp.h"
7f6ecb6d 37#include "localdb.h"
5039dede 38
5039dede
AK
39#ifdef _NETWARE
40#undef SEVERITY_CRITICAL
41#endif
42
a2a24e9d
VK
43#ifdef _WIN32
44#include <aclapi.h>
a2a24e9d
VK
45#endif
46
5039dede 47
489b117b 48/**
49 * Version
50 */
5039dede
AK
51
52#ifdef _DEBUG
bf3b7f79 53#define DEBUG_SUFFIX _T("-debug")
5039dede 54#else
bf3b7f79 55#define DEBUG_SUFFIX _T("")
5039dede
AK
56#endif
57#define AGENT_VERSION_STRING NETXMS_VERSION_STRING DEBUG_SUFFIX
58
1a93e64a
VK
59/**
60 * Default files
61 */
5039dede 62#if defined(_WIN32)
1039d7ee
VK
63#define AGENT_DEFAULT_CONFIG _T("{search}")
64#define AGENT_DEFAULT_CONFIG_D _T("{search}")
bf3b7f79
VK
65#define AGENT_DEFAULT_LOG _T("C:\\nxagentd.log")
66#define AGENT_DEFAULT_FILE_STORE _T("C:\\")
1039d7ee 67#define AGENT_DEFAULT_DATA_DIR _T("{default}")
5039dede
AK
68#elif defined(_NETWARE)
69#define AGENT_DEFAULT_CONFIG "SYS:ETC/nxagentd.conf"
abf35d58 70#define AGENT_DEFAULT_CONFIG_D "SYS:ETC/nxagentd.conf.d"
5039dede
AK
71#define AGENT_DEFAULT_LOG "SYS:ETC/nxagentd.log"
72#define AGENT_DEFAULT_FILE_STORE "SYS:\\"
203e9d8a 73#define AGENT_DEFAULT_DATA_DIR "SYS:ETC"
5039dede 74#elif defined(_IPSO)
f3387429
VK
75#define AGENT_DEFAULT_CONFIG _T("/opt/netxms/etc/nxagentd.conf")
76#define AGENT_DEFAULT_CONFIG_D _T("/opt/netxms/etc/nxagentd.conf.d")
77#define AGENT_DEFAULT_LOG _T("/opt/netxms/log/nxagentd.log")
78#define AGENT_DEFAULT_FILE_STORE _T("/opt/netxms/store")
79#define AGENT_DEFAULT_DATA_DIR _T("/opt/netxms/data")
5039dede 80#else
f3387429
VK
81#define AGENT_DEFAULT_CONFIG _T("{search}")
82#define AGENT_DEFAULT_CONFIG_D _T("{search}")
83#define AGENT_DEFAULT_LOG _T("/var/log/nxagentd")
84#define AGENT_DEFAULT_FILE_STORE _T("/tmp")
f31c22b3 85#define AGENT_DEFAULT_DATA_DIR _T("{default}")
5039dede
AK
86#endif
87
88
489b117b 89/**
90 * Constants
91 */
5039dede 92#ifdef _WIN32
9f96fc88
VK
93#define DEFAULT_AGENT_SERVICE_NAME _T("NetXMSAgentdW32")
94#define DEFAULT_AGENT_EVENT_SOURCE _T("NetXMS Win32 Agent")
95#define NXAGENTD_SYSLOG_NAME g_windowsEventSourceName
5039dede 96#else
9f96fc88 97#define NXAGENTD_SYSLOG_NAME _T("nxagentd")
5039dede
AK
98#endif
99
100#define MAX_PSUFFIX_LENGTH 32
101#define MAX_SERVERS 32
e464b7dc 102#define MAX_ESA_USER_NAME 64
842378a4
VK
103#define MAX_AGENT_MSG_SIZE 4194304
104
5039dede 105
9fcdfda7
VK
106#define AF_DAEMON 0x00000001
107#define AF_USE_SYSLOG 0x00000002
0df58041 108#define AF_SUBAGENT_LOADER 0x00000004
9fcdfda7
VK
109#define AF_REQUIRE_AUTH 0x00000008
110#define AF_LOG_UNRESOLVED_SYMBOLS 0x00000010
111#define AF_ENABLE_ACTIONS 0x00000020
112#define AF_REQUIRE_ENCRYPTION 0x00000040
113#define AF_HIDE_WINDOW 0x00000080
114#define AF_ENABLE_AUTOLOAD 0x00000100
115#define AF_ENABLE_PROXY 0x00000200
116#define AF_CENTRAL_CONFIG 0x00000400
175bd003 117#define AF_ENABLE_SNMP_PROXY 0x00000800
9fcdfda7 118#define AF_SHUTDOWN 0x00001000
175bd003 119#define AF_INTERACTIVE_SERVICE 0x00002000
9fcdfda7
VK
120#define AF_REGISTER 0x00004000
121#define AF_ENABLE_WATCHDOG 0x00008000
122#define AF_CATCH_EXCEPTIONS 0x00010000
cbc777ee 123#define AF_WRITE_FULL_DUMP 0x00020000
c90749f1 124#define AF_ENABLE_CONTROL_CONNECTOR 0x00040000
6239e6a4
VK
125#define AF_DISABLE_IPV4 0x00080000
126#define AF_DISABLE_IPV6 0x00100000
489b117b 127#define AF_ENABLE_SNMP_TRAP_PROXY 0x00200000
4e0e77e6 128#define AF_BACKGROUND_LOG_WRITER 0x00400000
685508a7 129#define AF_ENABLE_SYSLOG_PROXY 0x00800000
5039dede 130
c5459490 131// Flags for component failures
b123ecb3 132#define FAIL_OPEN_LOG 0x00000001
133#define FAIL_OPEN_DATABASE 0x00000002
c5459490 134#define FAIL_UPGRADE_DATABASE 0x00000004
5039dede
AK
135
136#ifdef _WIN32
137
489b117b 138/**
139 * Request types for H_MemoryInfo
140 */
5039dede
AK
141#define MEMINFO_PHYSICAL_FREE 1
142#define MEMINFO_PHYSICAL_FREE_PCT 2
143#define MEMINFO_PHYSICAL_TOTAL 3
144#define MEMINFO_PHYSICAL_USED 4
145#define MEMINFO_PHYSICAL_USED_PCT 5
146#define MEMINFO_VIRTUAL_FREE 6
147#define MEMINFO_VIRTUAL_FREE_PCT 7
148#define MEMINFO_VIRTUAL_TOTAL 8
149#define MEMINFO_VIRTUAL_USED 9
150#define MEMINFO_VIRTUAL_USED_PCT 10
151
152
489b117b 153/**
154 * Request types for H_DiskInfo
155 */
5039dede
AK
156#define DISKINFO_FREE_BYTES 1
157#define DISKINFO_USED_BYTES 2
158#define DISKINFO_TOTAL_BYTES 3
159#define DISKINFO_FREE_SPACE_PCT 4
160#define DISKINFO_USED_SPACE_PCT 5
161
162#endif /* _WIN32 */
163
374afd7b
VK
164/**
165 * Thread pool stats
166 */
167enum ThreadPoolStat
168{
169 THREAD_POOL_CURR_SIZE,
170 THREAD_POOL_MIN_SIZE,
171 THREAD_POOL_MAX_SIZE,
172 THREAD_POOL_REQUESTS,
173 THREAD_POOL_LOAD,
174 THREAD_POOL_USAGE,
175 THREAD_POOL_LOADAVG_1,
176 THREAD_POOL_LOADAVG_5,
177 THREAD_POOL_LOADAVG_15
178};
5039dede 179
489b117b 180/**
181 * Request types for H_DirInfo
182 */
5039dede
AK
183#define DIRINFO_FILE_COUNT 1
184#define DIRINFO_FILE_SIZE 2
5ad4ed06 185#define DIRINFO_FOLDER_COUNT 3
5039dede 186
489b117b 187/**
188 * Request types for H_FileTime
189 */
5039dede
AK
190#define FILETIME_ATIME 1
191#define FILETIME_MTIME 2
192#define FILETIME_CTIME 3
193
489b117b 194/**
195 * Action types
196 */
5039dede
AK
197#define AGENT_ACTION_EXEC 1
198#define AGENT_ACTION_SUBAGENT 2
84d1bd22
VK
199#define AGENT_ACTION_SHELLEXEC 3
200
8e334368
VK
201/**
202 * Action definition structure
203 */
5039dede
AK
204typedef struct
205{
206 TCHAR szName[MAX_PARAM_NAME];
207 int iType;
208 union
209 {
05e3ba32 210 TCHAR *pszCmdLine; // to TCHAR
5039dede
AK
211 struct __subagentAction
212 {
060c5a11 213 LONG (*fpHandler)(const TCHAR *, StringList *, const TCHAR *, AbstractCommSession *);
5039dede
AK
214 const TCHAR *pArg;
215 TCHAR szSubagentName[MAX_PATH];
216 } sa;
217 } handler;
218 TCHAR szDescription[MAX_DB_STRING];
219} ACTION;
220
8e334368
VK
221/**
222 * Loaded subagent information
223 */
5039dede
AK
224struct SUBAGENT
225{
226 HMODULE hModule; // Subagent's module handle
227 NETXMS_SUBAGENT_INFO *pInfo; // Information provided by subagent
bf3b7f79 228 TCHAR szName[MAX_PATH]; // Name of the module // to TCHAR by LWX
5039dede
AK
229#ifdef _NETWARE
230 char szEntryPoint[256]; // Name of agent's entry point
231#endif
232};
233
0f506caa
VK
234/**
235 * External subagent information
236 */
204ace22
VK
237class ExternalSubagent
238{
239private:
240 TCHAR m_name[MAX_SUBAGENT_NAME];
e464b7dc 241 TCHAR m_user[MAX_ESA_USER_NAME];
84d1bd22 242 HPIPE m_pipe;
204ace22 243 bool m_connected;
0df58041 244 MsgWaitQueue *m_msgQueue;
967893bb 245 UINT32 m_requestId;
0df58041
VK
246 MUTEX m_mutexPipeWrite;
247
b368969c
VK
248 bool sendMessage(NXCPMessage *msg);
249 NXCPMessage *waitForMessage(WORD code, UINT32 id);
967893bb
VK
250 UINT32 waitForRCC(UINT32 id);
251 NETXMS_SUBAGENT_PARAM *getSupportedParameters(UINT32 *count);
252 NETXMS_SUBAGENT_LIST *getSupportedLists(UINT32 *count);
253 NETXMS_SUBAGENT_TABLE *getSupportedTables(UINT32 *count);
204ace22
VK
254
255public:
e464b7dc 256 ExternalSubagent(const TCHAR *name, const TCHAR *user);
204ace22
VK
257 ~ExternalSubagent();
258
84d1bd22 259 void connect(HPIPE hPipe);
204ace22
VK
260
261 bool isConnected() { return m_connected; }
262 const TCHAR *getName() { return m_name; }
e464b7dc 263 const TCHAR *getUserName() { return m_user; }
0df58041 264
967893bb
VK
265 UINT32 getParameter(const TCHAR *name, TCHAR *buffer);
266 UINT32 getTable(const TCHAR *name, Table *value);
267 UINT32 getList(const TCHAR *name, StringList *value);
b368969c 268 void listParameters(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
0df58041 269 void listParameters(StringList *list);
b368969c 270 void listLists(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
0f506caa 271 void listLists(StringList *list);
b368969c 272 void listTables(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
0f506caa 273 void listTables(StringList *list);
f918b160 274 void shutdown();
204ace22
VK
275};
276
0f506caa
VK
277/**
278 * Server information
279 */
9319c166 280class ServerInfo
5039dede 281{
9319c166
VK
282private:
283 char *m_name;
8c75ad41 284 InetAddress m_address;
9319c166
VK
285 bool m_control;
286 bool m_master;
287 time_t m_lastResolveTime;
288 bool m_redoResolve;
289 MUTEX m_mutex;
290
291 void resolve();
292
293public:
294 ServerInfo(const TCHAR *name, bool control, bool master);
295 ~ServerInfo();
296
8c75ad41 297 bool match(const InetAddress &addr);
9319c166
VK
298
299 bool isMaster() { return m_master; }
300 bool isControl() { return m_control; }
5039dede
AK
301};
302
6fbaa926
VK
303/**
304 * Pending request information
305 */
306struct PendingRequest
307{
308 UINT32 id;
309 INT64 expirationTime;
310 bool completed;
311
312 PendingRequest(NXCPMessage *msg, UINT32 timeout)
313 {
314 id = msg->getId();
315 expirationTime = GetCurrentTimeMs() + (INT64)timeout;
316 completed = false;
317 }
318};
319
0f506caa
VK
320/**
321 * Communication session
322 */
7cf549ad 323class CommSession : public AbstractCommSession
5039dede
AK
324{
325private:
326 SOCKET m_hSocket;
6fbaa926
VK
327 Queue *m_sendQueue;
328 Queue *m_processingQueue;
5039dede
AK
329 THREAD m_hWriteThread;
330 THREAD m_hProcessingThread;
331 THREAD m_hProxyReadThread;
e9902466 332 UINT64 m_serverId;
8c75ad41 333 InetAddress m_serverAddr; // IP address of connected host
967893bb 334 UINT32 m_dwIndex;
9319c166
VK
335 bool m_authenticated;
336 bool m_masterServer;
337 bool m_controlServer;
338 bool m_proxyConnection;
d1dfba1a 339 bool m_acceptData;
9319c166 340 bool m_acceptTraps;
e13420c1 341 bool m_acceptFileUpdates;
ea3993c8 342 bool m_ipv6Aware;
1a5ddd2a 343 bool m_bulkReconciliationSupported;
5039dede 344 int m_hCurrFile;
503da871
VK
345 UINT32 m_fileRqId;
346 StreamCompressor *m_compressor;
98abc9f1 347 NXCPEncryptionContext *m_pCtx;
e4a64da2 348 time_t m_ts; // Last activity timestamp
5039dede 349 SOCKET m_hProxySocket; // Socket for proxy connection
7b8b337e 350 MUTEX m_socketWriteMutex;
6fbaa926
VK
351 VolatileCounter m_requestId;
352 MsgWaitQueue *m_responseQueue;
5039dede 353
b368969c
VK
354 BOOL sendRawMessage(NXCP_MESSAGE *pMsg, NXCPEncryptionContext *pCtx);
355 void authenticate(NXCPMessage *pRequest, NXCPMessage *pMsg);
356 void getConfig(NXCPMessage *pMsg);
357 void updateConfig(NXCPMessage *pRequest, NXCPMessage *pMsg);
358 void getParameter(NXCPMessage *pRequest, NXCPMessage *pMsg);
359 void getList(NXCPMessage *pRequest, NXCPMessage *pMsg);
360 void getTable(NXCPMessage *pRequest, NXCPMessage *pMsg);
361 void action(NXCPMessage *pRequest, NXCPMessage *pMsg);
362 void recvFile(NXCPMessage *pRequest, NXCPMessage *pMsg);
363 void getLocalFile(NXCPMessage *pRequest, NXCPMessage *pMsg);
364 void cancelFileMonitoring(NXCPMessage *pRequest, NXCPMessage *pMsg);
365 UINT32 upgrade(NXCPMessage *pRequest);
366 UINT32 setupProxyConnection(NXCPMessage *pRequest);
e4a64da2 367
4685a2ad
VK
368 void readThread();
369 void writeThread();
370 void processingThread();
371 void proxyReadThread();
83191808 372 void proxySnmpRequest(NXCPMessage *request);
e4a64da2
VK
373
374 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
375 static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
376 static THREAD_RESULT THREAD_CALL processingThreadStarter(void *);
377 static THREAD_RESULT THREAD_CALL proxyReadThreadStarter(void *);
5039dede
AK
378
379public:
8c75ad41 380 CommSession(SOCKET hSocket, const InetAddress &serverAddr, bool masterServer, bool controlServer);
6fbaa926 381 virtual ~CommSession();
5039dede 382
4685a2ad
VK
383 void run();
384 void disconnect();
5039dede 385
19dbc8ef
VK
386 virtual void sendMessage(NXCPMessage *msg) { m_sendQueue->put(msg->createMessage()); }
387 virtual void sendRawMessage(NXCP_MESSAGE *msg) { m_sendQueue->put(nx_memdup(msg, ntohl(msg->size))); }
9319c166 388 virtual bool sendFile(UINT32 requestId, const TCHAR *file, long offset);
63ff3c9d 389 virtual UINT32 doRequest(NXCPMessage *msg, UINT32 timeout);
a1273b42 390 virtual NXCPMessage *doRequestEx(NXCPMessage *msg, UINT32 timeout);
6fbaa926 391 virtual UINT32 generateRequestId();
5039dede 392
e9902466 393 virtual UINT64 getServerId() { return m_serverId; }
8c75ad41 394 virtual const InetAddress& getServerAddress() { return m_serverAddr; }
203e9d8a 395
ea3993c8
VK
396 virtual bool isIPv6Aware() { return m_ipv6Aware; }
397
967893bb
VK
398 UINT32 getIndex() { return m_dwIndex; }
399 void setIndex(UINT32 dwIndex) { if (m_dwIndex == INVALID_INDEX) m_dwIndex = dwIndex; }
5039dede 400
4685a2ad
VK
401 time_t getTimeStamp() { return m_ts; }
402 void updateTimeStamp() { m_ts = time(NULL); }
5039dede 403
d1dfba1a 404 bool canAcceptData() { return m_acceptData; }
9319c166 405 bool canAcceptTraps() { return m_acceptTraps; }
e13420c1 406 bool canAcceptFileUpdates() { return m_acceptFileUpdates; }
1a5ddd2a 407 bool isBulkReconciliationSupported() { return m_bulkReconciliationSupported; }
489b117b 408
9319c166
VK
409 virtual bool isMasterServer() { return m_masterServer; }
410 virtual bool isControlServer() { return m_controlServer; }
489b117b 411
9319c166 412 virtual UINT32 openFile(TCHAR* nameOfFile, UINT32 requestId);
5039dede
AK
413};
414
9c786c0f
VK
415/**
416 * Session agent connector
417 */
418class SessionAgentConnector : public RefCountObject
419{
420private:
421 UINT32 m_id;
422 SOCKET m_socket;
423 MUTEX m_mutex;
b368969c 424 NXCP_BUFFER m_msgBuffer;
9c786c0f
VK
425 MsgWaitQueue m_msgQueue;
426 UINT32 m_sessionId;
427 TCHAR *m_sessionName;
74540dab
VK
428 INT16 m_sessionState;
429 TCHAR *m_userName;
9c786c0f
VK
430 VolatileCounter m_requestId;
431
432 void readThread();
b368969c 433 bool sendMessage(NXCPMessage *msg);
9c786c0f
VK
434 UINT32 nextRequestId() { return InterlockedIncrement(&m_requestId); }
435
436 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
437
438public:
439 SessionAgentConnector(UINT32 id, SOCKET s);
5e254c4e 440 virtual ~SessionAgentConnector();
9c786c0f
VK
441
442 void run();
443 void disconnect();
444
445 UINT32 getId() { return m_id; }
446 UINT32 getSessionId() { return m_sessionId; }
74540dab 447 INT16 getSessionState() { return m_sessionState; }
9c786c0f 448 const TCHAR *getSessionName() { return CHECK_NULL(m_sessionName); }
74540dab 449 const TCHAR *getUserName() { return CHECK_NULL(m_userName); }
9c786c0f
VK
450
451 bool testConnection();
b368969c 452 void takeScreenshot(NXCPMessage *msg);
9c786c0f
VK
453};
454
489b117b 455/**
456 * Class to reciever traps
457 */
458class SNMP_TrapProxyTransport : public SNMP_UDPTransport
459{
460public:
461 SNMP_TrapProxyTransport(SOCKET hSocket);
e58d58bd
VK
462
463 int readRawMessage(BYTE **rawData, UINT32 timeout, struct sockaddr *sender, socklen_t *addrSize);
489b117b 464};
465
296ae03d
VK
466/**
467 * SNMP target
468 */
c1bc623e 469class SNMPTarget : public RefCountObject
296ae03d
VK
470{
471private:
de4af576 472 uuid m_guid;
296ae03d
VK
473 UINT64 m_serverId;
474 InetAddress m_ipAddress;
475 UINT16 m_port;
476 BYTE m_snmpVersion;
477 BYTE m_authType;
478 BYTE m_encType;
479 char *m_authName;
480 char *m_authPassword;
481 char *m_encPassword;
482 SNMP_Transport *m_transport;
483
484public:
485 SNMPTarget(UINT64 serverId, NXCPMessage *msg, UINT32 baseId);
486 SNMPTarget(DB_RESULT hResult, int row);
5e254c4e 487 virtual ~SNMPTarget();
296ae03d 488
de4af576 489 const uuid& getGuid() const { return m_guid; }
296ae03d
VK
490 SNMP_Transport *getTransport(UINT16 port);
491
492 bool saveToDatabase();
493};
494
0f506caa
VK
495/**
496 * Functions
497 */
203e9d8a
VK
498BOOL Initialize();
499void Shutdown();
500void Main();
640b6719
VK
501
502void ConsolePrintf(const TCHAR *pszFormat, ...)
6e383343 503#if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
640b6719
VK
504 __attribute__ ((format(printf, 1, 2)))
505#endif
506;
507
508void DebugPrintf(UINT32 dwSessionId, int level, const TCHAR *pszFormat, ...)
6e383343 509#if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
640b6719
VK
510 __attribute__ ((format(printf, 3, 4)))
511#endif
512;
513
5039dede
AK
514void BuildFullPath(TCHAR *pszFileName, TCHAR *pszFullPath);
515
516BOOL DownloadConfig(TCHAR *pszServer);
517
203e9d8a 518BOOL InitParameterList();
bf3b7f79 519
060c5a11 520void AddParameter(const TCHAR *szName, LONG (* fpHandler)(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *), const TCHAR *pArg,
bf3b7f79 521 int iDataType, const TCHAR *pszDescription);
f480bdd4 522void AddPushParameter(const TCHAR *name, int dataType, const TCHAR *description);
060c5a11 523void AddList(const TCHAR *name, LONG (* handler)(const TCHAR *, const TCHAR *, StringList *, AbstractCommSession *), const TCHAR *arg);
e13420c1 524void AddTable(const TCHAR *name, LONG (* handler)(const TCHAR *, const TCHAR *, Table *, AbstractCommSession *),
cb97f4dd
VK
525 const TCHAR *arg, const TCHAR *instanceColumns, const TCHAR *description,
526 int numColumns, NETXMS_SUBAGENT_TABLE_COLUMN *columns);
b5ded63e 527BOOL AddExternalParameter(TCHAR *pszCfgLine, BOOL bShellExec, BOOL bIsList);
87fff547
VK
528UINT32 GetParameterValue(UINT32 sessionId, const TCHAR *param, TCHAR *value, AbstractCommSession *session);
529UINT32 GetListValue(UINT32 sessionId, const TCHAR *param, StringList *value, AbstractCommSession *session);
530UINT32 GetTableValue(UINT32 sessionId, const TCHAR *pParam, Table *value, AbstractCommSession *session);
b368969c
VK
531void GetParameterList(NXCPMessage *pMsg);
532void GetEnumList(NXCPMessage *pMsg);
533void GetTableList(NXCPMessage *pMsg);
bf3b7f79 534BOOL LoadSubAgent(TCHAR *szModuleName);
203e9d8a 535void UnloadAllSubAgents();
c1165d33
VK
536BOOL InitSubAgent(HMODULE hModule, const TCHAR *pszModuleName,
537 BOOL (* SubAgentInit)(NETXMS_SUBAGENT_INFO **, Config *),
538 const TCHAR *pszEntryPoint);
b368969c 539BOOL ProcessCmdBySubAgent(UINT32 dwCommand, NXCPMessage *pRequest, NXCPMessage *pResponse, AbstractCommSession *session);
05e3ba32 540BOOL AddAction(const TCHAR *pszName, int iType, const TCHAR *pArg,
060c5a11 541 LONG (*fpHandler)(const TCHAR *, StringList *, const TCHAR *, AbstractCommSession *session),
bf3b7f79
VK
542 const TCHAR *pszSubAgent, const TCHAR *pszDescription);
543BOOL AddActionFromConfig(TCHAR *pszLine, BOOL bShellExec);
060c5a11 544UINT32 ExecAction(const TCHAR *action, StringList *args, AbstractCommSession *session);
908d71bd 545UINT32 ExecActionWithOutput(CommSession *session, UINT32 requestId, const TCHAR *action, StringList *args);
967893bb
VK
546UINT32 ExecuteCommand(TCHAR *pszCommand, StringList *pArgs, pid_t *pid);
547UINT32 ExecuteShellCommand(TCHAR *pszCommand, StringList *pArgs);
5039dede 548
9795113c
VK
549void StartParamProvidersPoller();
550bool AddParametersProvider(const TCHAR *line);
0df58041 551LONG GetParameterValueFromExtProvider(const TCHAR *name, TCHAR *buffer);
b368969c 552void ListParametersFromExtProviders(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
9795113c
VK
553void ListParametersFromExtProviders(StringList *list);
554
204ace22 555bool AddExternalSubagent(const TCHAR *config);
967893bb
VK
556UINT32 GetParameterValueFromExtSubagent(const TCHAR *name, TCHAR *buffer);
557UINT32 GetTableValueFromExtSubagent(const TCHAR *name, Table *value);
558UINT32 GetListValueFromExtSubagent(const TCHAR *name, StringList *value);
b368969c 559void ListParametersFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
0df58041 560void ListParametersFromExtSubagents(StringList *list);
b368969c 561void ListListsFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
0f506caa 562void ListListsFromExtSubagents(StringList *list);
b368969c 563void ListTablesFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
0f506caa 564void ListTablesFromExtSubagents(StringList *list);
b368969c
VK
565bool SendMessageToPipe(HPIPE hPipe, NXCP_MESSAGE *msg);
566bool SendMessageToMasterAgent(NXCPMessage *msg);
567bool SendRawMessageToMasterAgent(NXCP_MESSAGE *msg);
f918b160 568void ShutdownExtSubagents();
204ace22 569
83b20bab
VK
570void RegisterApplicationAgent(const TCHAR *name);
571UINT32 GetParameterValueFromAppAgent(const TCHAR *name, TCHAR *buffer);
572
5039dede
AK
573BOOL WaitForProcess(const TCHAR *name);
574
967893bb 575UINT32 UpgradeAgent(TCHAR *pszPkgFile);
5039dede 576
967893bb
VK
577void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, int iNumArgs, TCHAR **ppArgList);
578void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, const char *pszFormat, ...);
579void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, const char *pszFormat, va_list args);
b368969c 580void ForwardTrap(NXCPMessage *msg);
5039dede 581
0bd64860 582void StartPushConnector();
b60584cf 583bool PushData(const TCHAR *parameter, const TCHAR *value, UINT32 objectId, time_t timestamp);
0bd64860 584
a2a24e9d
VK
585void StartStorageDiscoveryConnector();
586
f918b160 587void StartControlConnector();
b368969c 588bool SendControlMessage(NXCPMessage *msg);
0bd64860 589
9c786c0f
VK
590void StartSessionAgentConnector();
591SessionAgentConnector *AcquireSessionAgentConnector(const TCHAR *sessionName);
09ecddac
VK
592
593UINT32 GenerateMessageId();
9c786c0f 594
87fff547
VK
595void ConfigureDataCollection(UINT64 serverId, NXCPMessage *msg);
596
34b9a3e7 597bool EnumerateSessions(EnumerationCallbackResult (* callback)(AbstractCommSession *, void* ), void *data);
6fbaa926 598AbstractCommSession *FindServerSession(UINT64 serverId);
a1273b42 599AbstractCommSession *FindServerSession(bool (*comparator)(AbstractCommSession *, void *), void *userData);
34b9a3e7 600
5039dede
AK
601#ifdef _WIN32
602
203e9d8a 603void InitService();
56ea99c3 604void InstallService(TCHAR *execName, TCHAR *confFile, int debugLevel);
203e9d8a
VK
605void RemoveService();
606void StartAgentService();
607void StopAgentService();
0137b9f7 608bool WaitForService(DWORD dwDesiredState);
bf3b7f79 609void InstallEventSource(const TCHAR *path);
203e9d8a 610void RemoveEventSource();
5039dede 611
967893bb 612TCHAR *GetPdhErrorText(UINT32 dwError, TCHAR *pszBuffer, int iBufSize);
5039dede
AK
613
614#endif
615
616
489b117b 617/**
618 * Global variables
619 */
967893bb 620extern UINT32 g_dwFlags;
b123ecb3 621extern UINT32 g_failFlags;
bf3b7f79 622extern TCHAR g_szLogFile[];
05e3ba32 623extern TCHAR g_szSharedSecret[];
624extern TCHAR g_szConfigFile[];
625extern TCHAR g_szFileStore[];
626extern TCHAR g_szConfigServer[];
627extern TCHAR g_szRegistrar[];
628extern TCHAR g_szListenAddress[];
6ca3b41c 629extern TCHAR g_szConfigIncludeDir[];
b123ecb3 630extern TCHAR g_szConfigPolicyDir[];
3df8bccd 631extern TCHAR g_szLogParserDirectory[];
c72b812a 632extern TCHAR g_szDataDirectory[];
0df58041 633extern TCHAR g_masterAgent[];
489b117b 634extern TCHAR g_szSNMPTrapListenAddress[];
9c786c0f 635extern UINT16 g_wListenPort;
9319c166 636extern ObjectArray<ServerInfo> g_serverList;
967893bb 637extern UINT32 g_dwServerCount;
5039dede 638extern time_t g_tmAgentStartTime;
05e3ba32 639extern TCHAR g_szPlatformSuffix[];
967893bb
VK
640extern UINT32 g_dwStartupDelay;
641extern UINT32 g_dwIdleTimeout;
642extern UINT32 g_dwMaxSessions;
643extern UINT32 g_dwExecTimeout;
644extern UINT32 g_dwSNMPTimeout;
489b117b 645extern UINT32 g_dwSNMPTrapPort;
89d79e7b 646extern UINT32 g_longRunningQueryThreshold;
9c786c0f 647extern UINT16 g_sessionAgentPort;
3f635e1b 648extern UINT32 g_zoneId;
685508a7 649extern UINT16 g_syslogListenPort;
5039dede 650
e6c91aac
VK
651extern Config *g_config;
652
967893bb
VK
653extern UINT32 g_dwAcceptErrors;
654extern UINT32 g_dwAcceptedConnections;
655extern UINT32 g_dwRejectedConnections;
5039dede
AK
656
657extern CommSession **g_pSessionList;
658extern MUTEX g_hSessionListAccess;
83191808 659extern ThreadPool *g_snmpProxyThreadPool;
5039dede
AK
660
661#ifdef _WIN32
9f96fc88 662extern TCHAR g_windowsEventSourceName[];
5039dede
AK
663#endif /* _WIN32 */
664
665#endif /* _nxagentd_h_ */