Added new agnet parameter: File.LineCount(*). Fixes #NX-1347
[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 #define DIRINFO_FILE_LINE_COUNT 4
173
174 /**
175 * Request types for H_FileTime
176 */
177 #define FILETIME_ATIME 1
178 #define FILETIME_MTIME 2
179 #define FILETIME_CTIME 3
180
181 /**
182 * Action types
183 */
184 #define AGENT_ACTION_EXEC 1
185 #define AGENT_ACTION_SUBAGENT 2
186 #define AGENT_ACTION_SHELLEXEC 3
187
188 /**
189 * Action definition structure
190 */
191 typedef struct
192 {
193 TCHAR szName[MAX_PARAM_NAME];
194 int iType;
195 union
196 {
197 TCHAR *pszCmdLine; // to TCHAR
198 struct __subagentAction
199 {
200 LONG (*fpHandler)(const TCHAR *, StringList *, const TCHAR *, AbstractCommSession *);
201 const TCHAR *pArg;
202 TCHAR szSubagentName[MAX_PATH];
203 } sa;
204 } handler;
205 TCHAR szDescription[MAX_DB_STRING];
206 } ACTION;
207
208 /**
209 * Loaded subagent information
210 */
211 struct SUBAGENT
212 {
213 HMODULE hModule; // Subagent's module handle
214 NETXMS_SUBAGENT_INFO *pInfo; // Information provided by subagent
215 TCHAR szName[MAX_PATH]; // Name of the module // to TCHAR by LWX
216 #ifdef _NETWARE
217 char szEntryPoint[256]; // Name of agent's entry point
218 #endif
219 };
220
221 /**
222 * External subagent information
223 */
224 class ExternalSubagent
225 {
226 private:
227 TCHAR m_name[MAX_SUBAGENT_NAME];
228 TCHAR m_user[MAX_ESA_USER_NAME];
229 NamedPipeListener *m_listener;
230 NamedPipe *m_pipe;
231 bool m_connected;
232 MsgWaitQueue *m_msgQueue;
233 UINT32 m_requestId;
234
235 bool sendMessage(NXCPMessage *msg);
236 NXCPMessage *waitForMessage(WORD code, UINT32 id);
237 UINT32 waitForRCC(UINT32 id);
238 NETXMS_SUBAGENT_PARAM *getSupportedParameters(UINT32 *count);
239 NETXMS_SUBAGENT_LIST *getSupportedLists(UINT32 *count);
240 NETXMS_SUBAGENT_TABLE *getSupportedTables(UINT32 *count);
241
242 public:
243 ExternalSubagent(const TCHAR *name, const TCHAR *user);
244 ~ExternalSubagent();
245
246 void startListener();
247 void connect(NamedPipe *pipe);
248
249 bool isConnected() { return m_connected; }
250 const TCHAR *getName() { return m_name; }
251 const TCHAR *getUserName() { return m_user; }
252
253 UINT32 getParameter(const TCHAR *name, TCHAR *buffer);
254 UINT32 getTable(const TCHAR *name, Table *value);
255 UINT32 getList(const TCHAR *name, StringList *value);
256 void listParameters(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
257 void listParameters(StringList *list);
258 void listLists(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
259 void listLists(StringList *list);
260 void listTables(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
261 void listTables(StringList *list);
262 void shutdown();
263 void restart();
264 };
265
266 /**
267 * Server information
268 */
269 class ServerInfo
270 {
271 private:
272 char *m_name;
273 InetAddress m_address;
274 bool m_control;
275 bool m_master;
276 time_t m_lastResolveTime;
277 bool m_redoResolve;
278 MUTEX m_mutex;
279
280 void resolve();
281
282 public:
283 ServerInfo(const TCHAR *name, bool control, bool master);
284 ~ServerInfo();
285
286 bool match(const InetAddress &addr);
287
288 bool isMaster() { return m_master; }
289 bool isControl() { return m_control; }
290 };
291
292 /**
293 * Pending request information
294 */
295 struct PendingRequest
296 {
297 UINT32 id;
298 INT64 expirationTime;
299 bool completed;
300
301 PendingRequest(NXCPMessage *msg, UINT32 timeout)
302 {
303 id = msg->getId();
304 expirationTime = GetCurrentTimeMs() + (INT64)timeout;
305 completed = false;
306 }
307 };
308
309 /**
310 * Communication session
311 */
312 class CommSession : public AbstractCommSession
313 {
314 private:
315 UINT32 m_id;
316 UINT32 m_index;
317 AbstractCommChannel *m_channel;
318 Queue *m_sendQueue;
319 Queue *m_processingQueue;
320 THREAD m_hWriteThread;
321 THREAD m_hProcessingThread;
322 THREAD m_hProxyReadThread;
323 UINT64 m_serverId;
324 InetAddress m_serverAddr; // IP address of connected host
325 bool m_disconnected;
326 bool m_authenticated;
327 bool m_masterServer;
328 bool m_controlServer;
329 bool m_proxyConnection;
330 bool m_acceptData;
331 bool m_acceptTraps;
332 bool m_acceptFileUpdates;
333 bool m_ipv6Aware;
334 bool m_bulkReconciliationSupported;
335 HashMap<UINT32, DownloadFileInfo> m_downloadFileMap;
336 bool m_allowCompression; // allow compression for structured messages
337 NXCPEncryptionContext *m_pCtx;
338 time_t m_ts; // Last activity timestamp
339 SOCKET m_hProxySocket; // Socket for proxy connection
340 MUTEX m_socketWriteMutex;
341 VolatileCounter m_requestId;
342 MsgWaitQueue *m_responseQueue;
343
344 bool sendRawMessage(NXCP_MESSAGE *msg, NXCPEncryptionContext *ctx);
345 void authenticate(NXCPMessage *pRequest, NXCPMessage *pMsg);
346 void getConfig(NXCPMessage *pMsg);
347 void updateConfig(NXCPMessage *pRequest, NXCPMessage *pMsg);
348 void getParameter(NXCPMessage *pRequest, NXCPMessage *pMsg);
349 void getList(NXCPMessage *pRequest, NXCPMessage *pMsg);
350 void getTable(NXCPMessage *pRequest, NXCPMessage *pMsg);
351 void action(NXCPMessage *pRequest, NXCPMessage *pMsg);
352 void recvFile(NXCPMessage *pRequest, NXCPMessage *pMsg);
353 void getLocalFile(NXCPMessage *pRequest, NXCPMessage *pMsg);
354 void cancelFileMonitoring(NXCPMessage *pRequest, NXCPMessage *pMsg);
355 UINT32 upgrade(NXCPMessage *request);
356 UINT32 setupProxyConnection(NXCPMessage *pRequest);
357
358 void readThread();
359 void writeThread();
360 void processingThread();
361 void proxyReadThread();
362 void proxySnmpRequest(NXCPMessage *request);
363
364 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
365 static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
366 static THREAD_RESULT THREAD_CALL processingThreadStarter(void *);
367 static THREAD_RESULT THREAD_CALL proxyReadThreadStarter(void *);
368
369 public:
370 CommSession(AbstractCommChannel *channel, const InetAddress &serverAddr, bool masterServer, bool controlServer);
371 virtual ~CommSession();
372
373 void run();
374 void disconnect();
375
376 virtual bool sendMessage(NXCPMessage *msg);
377 virtual void postMessage(NXCPMessage *msg) { if (!m_disconnected) m_sendQueue->put(msg->serialize(m_allowCompression)); }
378 virtual bool sendRawMessage(NXCP_MESSAGE *msg);
379 virtual void postRawMessage(NXCP_MESSAGE *msg) { if (!m_disconnected) m_sendQueue->put(nx_memdup(msg, ntohl(msg->size))); }
380 virtual bool sendFile(UINT32 requestId, const TCHAR *file, long offset, bool allowCompression, VolatileCounter *cancelationFlag);
381 virtual UINT32 doRequest(NXCPMessage *msg, UINT32 timeout);
382 virtual NXCPMessage *doRequestEx(NXCPMessage *msg, UINT32 timeout);
383 virtual UINT32 generateRequestId();
384
385 virtual UINT32 getId() { return m_id; };
386
387 virtual UINT64 getServerId() { return m_serverId; }
388 virtual const InetAddress& getServerAddress() { return m_serverAddr; }
389
390 virtual bool isMasterServer() { return m_masterServer; }
391 virtual bool isControlServer() { return m_controlServer; }
392 virtual bool canAcceptData() { return m_acceptData; }
393 virtual bool canAcceptTraps() { return m_acceptTraps; }
394 virtual bool canAcceptFileUpdates() { return m_acceptFileUpdates; }
395 virtual bool isBulkReconciliationSupported() { return m_bulkReconciliationSupported; }
396 virtual bool isIPv6Aware() { return m_ipv6Aware; }
397
398 virtual UINT32 openFile(TCHAR *nameOfFile, UINT32 requestId, time_t fileModTime = 0);
399
400 virtual void debugPrintf(int level, const TCHAR *format, ...);
401
402 UINT32 getIndex() { return m_index; }
403 void setIndex(UINT32 index) { if (m_index == INVALID_INDEX) m_index = index; }
404
405 time_t getTimeStamp() { return m_ts; }
406 void updateTimeStamp() { m_ts = time(NULL); }
407 };
408
409 /**
410 * Pseudo-session for cached data collection
411 */
412 class VirtualSession : public AbstractCommSession
413 {
414 private:
415 UINT32 m_id;
416 UINT64 m_serverId;
417
418 public:
419 VirtualSession(UINT64 serverId);
420
421 virtual UINT32 getId() { return m_id; }
422
423 virtual UINT64 getServerId() { return m_serverId; };
424 virtual const InetAddress& getServerAddress() { return InetAddress::LOOPBACK; }
425
426 virtual bool isMasterServer() { return false; }
427 virtual bool isControlServer() { return false; }
428 virtual bool canAcceptData() { return true; }
429 virtual bool canAcceptTraps() { return true; }
430 virtual bool canAcceptFileUpdates() { return false; }
431 virtual bool isBulkReconciliationSupported() { return false; }
432 virtual bool isIPv6Aware() { return true; }
433
434 virtual bool sendMessage(NXCPMessage *pMsg) { return false; }
435 virtual void postMessage(NXCPMessage *pMsg) { }
436 virtual bool sendRawMessage(NXCP_MESSAGE *pMsg) { return false; }
437 virtual void postRawMessage(NXCP_MESSAGE *pMsg) { }
438 virtual bool sendFile(UINT32 requestId, const TCHAR *file, long offset, bool allowCompression, VolatileCounter *cancelationFlag) { return false; }
439 virtual UINT32 doRequest(NXCPMessage *msg, UINT32 timeout) { return RCC_NOT_IMPLEMENTED; }
440 virtual NXCPMessage *doRequestEx(NXCPMessage *msg, UINT32 timeout) { return NULL; }
441 virtual UINT32 generateRequestId() { return 0; }
442 virtual UINT32 openFile(TCHAR *fileName, UINT32 requestId, time_t fileModTime = 0) { return ERR_INTERNAL_ERROR; }
443 virtual void debugPrintf(int level, const TCHAR *format, ...);
444 };
445
446 /**
447 * Session agent connector
448 */
449 class SessionAgentConnector : public RefCountObject
450 {
451 private:
452 UINT32 m_id;
453 SOCKET m_socket;
454 MUTEX m_mutex;
455 NXCP_BUFFER m_msgBuffer;
456 MsgWaitQueue m_msgQueue;
457 UINT32 m_sessionId;
458 TCHAR *m_sessionName;
459 INT16 m_sessionState;
460 TCHAR *m_userName;
461 VolatileCounter m_requestId;
462
463 void readThread();
464 bool sendMessage(NXCPMessage *msg);
465 UINT32 nextRequestId() { return InterlockedIncrement(&m_requestId); }
466
467 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
468
469 public:
470 SessionAgentConnector(UINT32 id, SOCKET s);
471 virtual ~SessionAgentConnector();
472
473 void run();
474 void disconnect();
475
476 UINT32 getId() { return m_id; }
477 UINT32 getSessionId() { return m_sessionId; }
478 INT16 getSessionState() { return m_sessionState; }
479 const TCHAR *getSessionName() { return CHECK_NULL(m_sessionName); }
480 const TCHAR *getUserName() { return CHECK_NULL(m_userName); }
481
482 bool testConnection();
483 void takeScreenshot(NXCPMessage *msg);
484 };
485
486 /**
487 * Class to reciever traps
488 */
489 class SNMP_TrapProxyTransport : public SNMP_UDPTransport
490 {
491 public:
492 SNMP_TrapProxyTransport(SOCKET hSocket);
493
494 int readRawMessage(BYTE **rawData, UINT32 timeout, struct sockaddr *sender, socklen_t *addrSize);
495 };
496
497 /**
498 * SNMP target
499 */
500 class SNMPTarget : public RefCountObject
501 {
502 private:
503 uuid m_guid;
504 UINT64 m_serverId;
505 InetAddress m_ipAddress;
506 UINT16 m_port;
507 BYTE m_snmpVersion;
508 BYTE m_authType;
509 BYTE m_encType;
510 char *m_authName;
511 char *m_authPassword;
512 char *m_encPassword;
513 SNMP_Transport *m_transport;
514
515 public:
516 SNMPTarget(UINT64 serverId, NXCPMessage *msg, UINT32 baseId);
517 SNMPTarget(DB_RESULT hResult, int row);
518 virtual ~SNMPTarget();
519
520 const uuid& getGuid() const { return m_guid; }
521 SNMP_Transport *getTransport(UINT16 port);
522
523 bool saveToDatabase();
524 };
525
526 /**
527 * Functions
528 */
529 BOOL Initialize();
530 void Shutdown();
531 void Main();
532
533 void ConsolePrintf(const TCHAR *format, ...)
534 #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
535 __attribute__ ((format(printf, 1, 2)))
536 #endif
537 ;
538
539 void DebugPrintf(int level, const TCHAR *format, ...)
540 #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
541 __attribute__ ((format(printf, 2, 3)))
542 #endif
543 ;
544
545 void BuildFullPath(TCHAR *pszFileName, TCHAR *pszFullPath);
546
547 BOOL DownloadConfig(TCHAR *pszServer);
548
549 BOOL InitParameterList();
550
551 void AddParameter(const TCHAR *szName, LONG (* fpHandler)(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *), const TCHAR *pArg,
552 int iDataType, const TCHAR *pszDescription);
553 void AddPushParameter(const TCHAR *name, int dataType, const TCHAR *description);
554 void AddList(const TCHAR *name, LONG (* handler)(const TCHAR *, const TCHAR *, StringList *, AbstractCommSession *), const TCHAR *arg);
555 void AddTable(const TCHAR *name, LONG (* handler)(const TCHAR *, const TCHAR *, Table *, AbstractCommSession *),
556 const TCHAR *arg, const TCHAR *instanceColumns, const TCHAR *description,
557 int numColumns, NETXMS_SUBAGENT_TABLE_COLUMN *columns);
558 bool AddExternalParameter(TCHAR *config, bool shellExec, bool isList);
559 bool AddExternalTable(TCHAR *config, bool shellExec);
560 UINT32 GetParameterValue(const TCHAR *param, TCHAR *value, AbstractCommSession *session);
561 UINT32 GetListValue(const TCHAR *param, StringList *value, AbstractCommSession *session);
562 UINT32 GetTableValue(const TCHAR *param, Table *value, AbstractCommSession *session);
563 void GetParameterList(NXCPMessage *pMsg);
564 void GetEnumList(NXCPMessage *pMsg);
565 void GetTableList(NXCPMessage *pMsg);
566 BOOL LoadSubAgent(TCHAR *szModuleName);
567 void UnloadAllSubAgents();
568 BOOL InitSubAgent(HMODULE hModule, const TCHAR *pszModuleName,
569 BOOL (* SubAgentInit)(NETXMS_SUBAGENT_INFO **, Config *),
570 const TCHAR *pszEntryPoint);
571 BOOL ProcessCmdBySubAgent(UINT32 dwCommand, NXCPMessage *pRequest, NXCPMessage *pResponse, AbstractCommSession *session);
572 BOOL AddAction(const TCHAR *pszName, int iType, const TCHAR *pArg,
573 LONG (*fpHandler)(const TCHAR *, StringList *, const TCHAR *, AbstractCommSession *session),
574 const TCHAR *pszSubAgent, const TCHAR *pszDescription);
575 BOOL AddActionFromConfig(TCHAR *pszLine, BOOL bShellExec);
576 UINT32 ExecAction(const TCHAR *action, StringList *args, AbstractCommSession *session);
577 UINT32 ExecActionWithOutput(CommSession *session, UINT32 requestId, const TCHAR *action, StringList *args);
578 UINT32 ExecuteCommand(TCHAR *pszCommand, StringList *pArgs, pid_t *pid);
579 UINT32 ExecuteShellCommand(TCHAR *pszCommand, StringList *pArgs);
580
581 void StartParamProvidersPoller();
582 bool AddParametersProvider(const TCHAR *line);
583 LONG GetParameterValueFromExtProvider(const TCHAR *name, TCHAR *buffer);
584 void ListParametersFromExtProviders(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
585 void ListParametersFromExtProviders(StringList *list);
586
587 bool AddExternalSubagent(const TCHAR *config);
588 UINT32 GetParameterValueFromExtSubagent(const TCHAR *name, TCHAR *buffer);
589 UINT32 GetTableValueFromExtSubagent(const TCHAR *name, Table *value);
590 UINT32 GetListValueFromExtSubagent(const TCHAR *name, StringList *value);
591 void ListParametersFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
592 void ListParametersFromExtSubagents(StringList *list);
593 void ListListsFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
594 void ListListsFromExtSubagents(StringList *list);
595 void ListTablesFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
596 void ListTablesFromExtSubagents(StringList *list);
597 bool SendMessageToMasterAgent(NXCPMessage *msg);
598 bool SendRawMessageToMasterAgent(NXCP_MESSAGE *msg);
599 void ShutdownExtSubagents();
600 void RestartExtSubagents();
601
602 void RegisterApplicationAgent(const TCHAR *name);
603 UINT32 GetParameterValueFromAppAgent(const TCHAR *name, TCHAR *buffer);
604
605 bool WaitForProcess(const TCHAR *name);
606
607 UINT32 UpgradeAgent(TCHAR *pszPkgFile);
608
609 void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, int iNumArgs, TCHAR **ppArgList);
610 void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, const char *pszFormat, ...);
611 void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, const char *pszFormat, va_list args);
612 void ForwardTrap(NXCPMessage *msg);
613
614 void StartPushConnector();
615 bool PushData(const TCHAR *parameter, const TCHAR *value, UINT32 objectId, time_t timestamp);
616
617 void StartControlConnector();
618 bool SendControlMessage(NXCPMessage *msg);
619
620 void StartSessionAgentConnector();
621 SessionAgentConnector *AcquireSessionAgentConnector(const TCHAR *sessionName);
622
623 UINT32 GenerateMessageId();
624
625 void ConfigureDataCollection(UINT64 serverId, NXCPMessage *msg);
626
627 bool EnumerateSessions(EnumerationCallbackResult (* callback)(AbstractCommSession *, void* ), void *data);
628 AbstractCommSession *FindServerSession(UINT64 serverId);
629 AbstractCommSession *FindServerSession(bool (*comparator)(AbstractCommSession *, void *), void *userData);
630
631 #ifdef WITH_SYSTEMD
632 bool RestartService(UINT32 pid);
633 #endif
634
635 void KillProcess(UINT32 pid);
636
637 #ifdef _WIN32
638
639 void InitService();
640 void InstallService(TCHAR *execName, TCHAR *confFile, int debugLevel);
641 void RemoveService();
642 void StartAgentService();
643 void StopAgentService();
644 bool WaitForService(DWORD dwDesiredState);
645 void InstallEventSource(const TCHAR *path);
646 void RemoveEventSource();
647
648 TCHAR *GetPdhErrorText(UINT32 dwError, TCHAR *pszBuffer, int iBufSize);
649
650 #endif
651
652
653 /**
654 * Global variables
655 */
656 extern UINT32 g_dwFlags;
657 extern UINT32 g_failFlags;
658 extern TCHAR g_szLogFile[];
659 extern TCHAR g_szSharedSecret[];
660 extern TCHAR g_szConfigFile[];
661 extern TCHAR g_szFileStore[];
662 extern TCHAR g_szConfigServer[];
663 extern TCHAR g_szRegistrar[];
664 extern TCHAR g_szListenAddress[];
665 extern TCHAR g_szConfigIncludeDir[];
666 extern TCHAR g_szConfigPolicyDir[];
667 extern TCHAR g_szLogParserDirectory[];
668 extern TCHAR g_certificateDirectory[];
669 extern TCHAR g_szDataDirectory[];
670 extern TCHAR g_masterAgent[];
671 extern TCHAR g_szSNMPTrapListenAddress[];
672 extern UINT16 g_wListenPort;
673 extern TCHAR g_systemName[];
674 extern ObjectArray<ServerInfo> g_serverList;
675 extern time_t g_tmAgentStartTime;
676 extern TCHAR g_szPlatformSuffix[];
677 extern UINT32 g_dwStartupDelay;
678 extern UINT32 g_dwIdleTimeout;
679 extern UINT32 g_dwMaxSessions;
680 extern UINT32 g_execTimeout;
681 extern UINT32 g_eppTimeout;
682 extern UINT32 g_snmpTimeout;
683 extern UINT16 g_snmpTrapPort;
684 extern UINT32 g_longRunningQueryThreshold;
685 extern UINT16 g_sessionAgentPort;
686 extern UINT32 g_zoneUIN;
687 extern UINT32 g_tunnelKeepaliveInterval;
688 extern UINT16 g_syslogListenPort;
689
690 extern Config *g_config;
691
692 extern UINT32 g_acceptErrors;
693 extern UINT32 g_acceptedConnections;
694 extern UINT32 g_rejectedConnections;
695
696 extern CommSession **g_pSessionList;
697 extern MUTEX g_hSessionListAccess;
698 extern ThreadPool *g_snmpProxyThreadPool;
699 extern ThreadPool *g_commThreadPool;
700
701 #ifdef _WIN32
702 extern TCHAR g_windowsEventSourceName[];
703 #endif /* _WIN32 */
704
705 #endif /* _nxagentd_h_ */