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