Initial agent-side code for agent to server connections
[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 "messages.h"
36 #include "nxsnmp.h"
37 #include "localdb.h"
38
39 #ifdef _NETWARE
40 #undef SEVERITY_CRITICAL
41 #endif
42
43 #ifdef _WIN32
44 #include <aclapi.h>
45 #endif
46
47
48 /**
49 * Version
50 */
51
52 #ifdef _DEBUG
53 #define DEBUG_SUFFIX _T("-debug")
54 #else
55 #define DEBUG_SUFFIX _T("")
56 #endif
57 #define AGENT_VERSION_STRING NETXMS_VERSION_STRING DEBUG_SUFFIX
58
59 /**
60 * Default files
61 */
62 #if defined(_WIN32)
63 #define AGENT_DEFAULT_CONFIG _T("{search}")
64 #define AGENT_DEFAULT_CONFIG_D _T("{search}")
65 #define AGENT_DEFAULT_LOG _T("C:\\nxagentd.log")
66 #define AGENT_DEFAULT_FILE_STORE _T("C:\\")
67 #define AGENT_DEFAULT_DATA_DIR _T("{default}")
68 #elif defined(_NETWARE)
69 #define AGENT_DEFAULT_CONFIG "SYS:ETC/nxagentd.conf"
70 #define AGENT_DEFAULT_CONFIG_D "SYS:ETC/nxagentd.conf.d"
71 #define AGENT_DEFAULT_LOG "SYS:ETC/nxagentd.log"
72 #define AGENT_DEFAULT_FILE_STORE "SYS:\\"
73 #define AGENT_DEFAULT_DATA_DIR "SYS:ETC"
74 #elif defined(_IPSO)
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")
80 #else
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")
85 #define AGENT_DEFAULT_DATA_DIR _T("{default}")
86 #endif
87
88
89 /**
90 * Constants
91 */
92 #ifdef _WIN32
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
96 #else
97 #define NXAGENTD_SYSLOG_NAME _T("nxagentd")
98 #endif
99
100 #define MAX_PSUFFIX_LENGTH 32
101 #define MAX_SERVERS 32
102 #define MAX_ESA_USER_NAME 64
103 #define MAX_AGENT_MSG_SIZE 4194304
104
105
106 #define AF_DAEMON 0x00000001
107 #define AF_USE_SYSLOG 0x00000002
108 #define AF_SUBAGENT_LOADER 0x00000004
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
117 #define AF_ENABLE_SNMP_PROXY 0x00000800
118 #define AF_SHUTDOWN 0x00001000
119 #define AF_INTERACTIVE_SERVICE 0x00002000
120 #define AF_REGISTER 0x00004000
121 #define AF_ENABLE_WATCHDOG 0x00008000
122 #define AF_CATCH_EXCEPTIONS 0x00010000
123 #define AF_WRITE_FULL_DUMP 0x00020000
124 #define AF_ENABLE_CONTROL_CONNECTOR 0x00040000
125 #define AF_DISABLE_IPV4 0x00080000
126 #define AF_DISABLE_IPV6 0x00100000
127 #define AF_ENABLE_SNMP_TRAP_PROXY 0x00200000
128 #define AF_BACKGROUND_LOG_WRITER 0x00400000
129 #define AF_ENABLE_SYSLOG_PROXY 0x00800000
130
131 // Flags for component failures
132 #define FAIL_OPEN_LOG 0x00000001
133 #define FAIL_OPEN_DATABASE 0x00000002
134 #define FAIL_UPGRADE_DATABASE 0x00000004
135
136 #ifdef _WIN32
137
138 /**
139 * Request types for H_MemoryInfo
140 */
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
153 /**
154 * Request types for H_DiskInfo
155 */
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
164 /**
165 * Thread pool stats
166 */
167 enum 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 };
179
180 /**
181 * Request types for H_DirInfo
182 */
183 #define DIRINFO_FILE_COUNT 1
184 #define DIRINFO_FILE_SIZE 2
185 #define DIRINFO_FOLDER_COUNT 3
186
187 /**
188 * Request types for H_FileTime
189 */
190 #define FILETIME_ATIME 1
191 #define FILETIME_MTIME 2
192 #define FILETIME_CTIME 3
193
194 /**
195 * Action types
196 */
197 #define AGENT_ACTION_EXEC 1
198 #define AGENT_ACTION_SUBAGENT 2
199 #define AGENT_ACTION_SHELLEXEC 3
200
201 /**
202 * Action definition structure
203 */
204 typedef struct
205 {
206 TCHAR szName[MAX_PARAM_NAME];
207 int iType;
208 union
209 {
210 TCHAR *pszCmdLine; // to TCHAR
211 struct __subagentAction
212 {
213 LONG (*fpHandler)(const TCHAR *, StringList *, const TCHAR *, AbstractCommSession *);
214 const TCHAR *pArg;
215 TCHAR szSubagentName[MAX_PATH];
216 } sa;
217 } handler;
218 TCHAR szDescription[MAX_DB_STRING];
219 } ACTION;
220
221 /**
222 * Loaded subagent information
223 */
224 struct SUBAGENT
225 {
226 HMODULE hModule; // Subagent's module handle
227 NETXMS_SUBAGENT_INFO *pInfo; // Information provided by subagent
228 TCHAR szName[MAX_PATH]; // Name of the module // to TCHAR by LWX
229 #ifdef _NETWARE
230 char szEntryPoint[256]; // Name of agent's entry point
231 #endif
232 };
233
234 /**
235 * External subagent information
236 */
237 class ExternalSubagent
238 {
239 private:
240 TCHAR m_name[MAX_SUBAGENT_NAME];
241 TCHAR m_user[MAX_ESA_USER_NAME];
242 HPIPE m_pipe;
243 bool m_connected;
244 MsgWaitQueue *m_msgQueue;
245 UINT32 m_requestId;
246 MUTEX m_mutexPipeWrite;
247
248 bool sendMessage(NXCPMessage *msg);
249 NXCPMessage *waitForMessage(WORD code, UINT32 id);
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);
254
255 public:
256 ExternalSubagent(const TCHAR *name, const TCHAR *user);
257 ~ExternalSubagent();
258
259 void connect(HPIPE hPipe);
260
261 bool isConnected() { return m_connected; }
262 const TCHAR *getName() { return m_name; }
263 const TCHAR *getUserName() { return m_user; }
264
265 UINT32 getParameter(const TCHAR *name, TCHAR *buffer);
266 UINT32 getTable(const TCHAR *name, Table *value);
267 UINT32 getList(const TCHAR *name, StringList *value);
268 void listParameters(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
269 void listParameters(StringList *list);
270 void listLists(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
271 void listLists(StringList *list);
272 void listTables(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
273 void listTables(StringList *list);
274 void shutdown();
275 };
276
277 /**
278 * Server information
279 */
280 class ServerInfo
281 {
282 private:
283 char *m_name;
284 InetAddress m_address;
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
293 public:
294 ServerInfo(const TCHAR *name, bool control, bool master);
295 ~ServerInfo();
296
297 bool match(const InetAddress &addr);
298
299 bool isMaster() { return m_master; }
300 bool isControl() { return m_control; }
301 };
302
303 /**
304 * Pending request information
305 */
306 struct 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
320 /**
321 * Communication session
322 */
323 class CommSession : public AbstractCommSession
324 {
325 private:
326 SOCKET m_hSocket;
327 Queue *m_sendQueue;
328 Queue *m_processingQueue;
329 THREAD m_hWriteThread;
330 THREAD m_hProcessingThread;
331 THREAD m_hProxyReadThread;
332 UINT64 m_serverId;
333 InetAddress m_serverAddr; // IP address of connected host
334 UINT32 m_dwIndex;
335 bool m_authenticated;
336 bool m_masterServer;
337 bool m_controlServer;
338 bool m_proxyConnection;
339 bool m_acceptData;
340 bool m_acceptTraps;
341 bool m_acceptFileUpdates;
342 bool m_ipv6Aware;
343 bool m_bulkReconciliationSupported;
344 int m_hCurrFile;
345 UINT32 m_fileRqId;
346 StreamCompressor *m_compressor;
347 NXCPEncryptionContext *m_pCtx;
348 time_t m_ts; // Last activity timestamp
349 SOCKET m_hProxySocket; // Socket for proxy connection
350 MUTEX m_socketWriteMutex;
351 VolatileCounter m_requestId;
352 MsgWaitQueue *m_responseQueue;
353
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);
367
368 void readThread();
369 void writeThread();
370 void processingThread();
371 void proxyReadThread();
372 void proxySnmpRequest(NXCPMessage *request);
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 *);
378
379 public:
380 CommSession(SOCKET hSocket, const InetAddress &serverAddr, bool masterServer, bool controlServer);
381 virtual ~CommSession();
382
383 void run();
384 void disconnect();
385
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))); }
388 virtual bool sendFile(UINT32 requestId, const TCHAR *file, long offset);
389 virtual UINT32 doRequest(NXCPMessage *msg, UINT32 timeout);
390 virtual NXCPMessage *doRequestEx(NXCPMessage *msg, UINT32 timeout);
391 virtual UINT32 generateRequestId();
392
393 virtual UINT64 getServerId() { return m_serverId; }
394 virtual const InetAddress& getServerAddress() { return m_serverAddr; }
395
396 virtual bool isIPv6Aware() { return m_ipv6Aware; }
397
398 UINT32 getIndex() { return m_dwIndex; }
399 void setIndex(UINT32 dwIndex) { if (m_dwIndex == INVALID_INDEX) m_dwIndex = dwIndex; }
400
401 time_t getTimeStamp() { return m_ts; }
402 void updateTimeStamp() { m_ts = time(NULL); }
403
404 bool canAcceptData() { return m_acceptData; }
405 bool canAcceptTraps() { return m_acceptTraps; }
406 bool canAcceptFileUpdates() { return m_acceptFileUpdates; }
407 bool isBulkReconciliationSupported() { return m_bulkReconciliationSupported; }
408
409 virtual bool isMasterServer() { return m_masterServer; }
410 virtual bool isControlServer() { return m_controlServer; }
411
412 virtual UINT32 openFile(TCHAR* nameOfFile, UINT32 requestId);
413 };
414
415 /**
416 * Session agent connector
417 */
418 class SessionAgentConnector : public RefCountObject
419 {
420 private:
421 UINT32 m_id;
422 SOCKET m_socket;
423 MUTEX m_mutex;
424 NXCP_BUFFER m_msgBuffer;
425 MsgWaitQueue m_msgQueue;
426 UINT32 m_sessionId;
427 TCHAR *m_sessionName;
428 INT16 m_sessionState;
429 TCHAR *m_userName;
430 VolatileCounter m_requestId;
431
432 void readThread();
433 bool sendMessage(NXCPMessage *msg);
434 UINT32 nextRequestId() { return InterlockedIncrement(&m_requestId); }
435
436 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
437
438 public:
439 SessionAgentConnector(UINT32 id, SOCKET s);
440 virtual ~SessionAgentConnector();
441
442 void run();
443 void disconnect();
444
445 UINT32 getId() { return m_id; }
446 UINT32 getSessionId() { return m_sessionId; }
447 INT16 getSessionState() { return m_sessionState; }
448 const TCHAR *getSessionName() { return CHECK_NULL(m_sessionName); }
449 const TCHAR *getUserName() { return CHECK_NULL(m_userName); }
450
451 bool testConnection();
452 void takeScreenshot(NXCPMessage *msg);
453 };
454
455 /**
456 * Class to reciever traps
457 */
458 class SNMP_TrapProxyTransport : public SNMP_UDPTransport
459 {
460 public:
461 SNMP_TrapProxyTransport(SOCKET hSocket);
462
463 int readRawMessage(BYTE **rawData, UINT32 timeout, struct sockaddr *sender, socklen_t *addrSize);
464 };
465
466 /**
467 * SNMP target
468 */
469 class SNMPTarget : public RefCountObject
470 {
471 private:
472 uuid m_guid;
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
484 public:
485 SNMPTarget(UINT64 serverId, NXCPMessage *msg, UINT32 baseId);
486 SNMPTarget(DB_RESULT hResult, int row);
487 virtual ~SNMPTarget();
488
489 const uuid& getGuid() const { return m_guid; }
490 SNMP_Transport *getTransport(UINT16 port);
491
492 bool saveToDatabase();
493 };
494
495 /**
496 * Functions
497 */
498 BOOL Initialize();
499 void Shutdown();
500 void Main();
501
502 void ConsolePrintf(const TCHAR *pszFormat, ...)
503 #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
504 __attribute__ ((format(printf, 1, 2)))
505 #endif
506 ;
507
508 void DebugPrintf(UINT32 dwSessionId, int level, const TCHAR *pszFormat, ...)
509 #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
510 __attribute__ ((format(printf, 3, 4)))
511 #endif
512 ;
513
514 void BuildFullPath(TCHAR *pszFileName, TCHAR *pszFullPath);
515
516 BOOL DownloadConfig(TCHAR *pszServer);
517
518 BOOL InitParameterList();
519
520 void AddParameter(const TCHAR *szName, LONG (* fpHandler)(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *), const TCHAR *pArg,
521 int iDataType, const TCHAR *pszDescription);
522 void AddPushParameter(const TCHAR *name, int dataType, const TCHAR *description);
523 void AddList(const TCHAR *name, LONG (* handler)(const TCHAR *, const TCHAR *, StringList *, AbstractCommSession *), const TCHAR *arg);
524 void AddTable(const TCHAR *name, LONG (* handler)(const TCHAR *, const TCHAR *, Table *, AbstractCommSession *),
525 const TCHAR *arg, const TCHAR *instanceColumns, const TCHAR *description,
526 int numColumns, NETXMS_SUBAGENT_TABLE_COLUMN *columns);
527 BOOL AddExternalParameter(TCHAR *pszCfgLine, BOOL bShellExec, BOOL bIsList);
528 UINT32 GetParameterValue(UINT32 sessionId, const TCHAR *param, TCHAR *value, AbstractCommSession *session);
529 UINT32 GetListValue(UINT32 sessionId, const TCHAR *param, StringList *value, AbstractCommSession *session);
530 UINT32 GetTableValue(UINT32 sessionId, const TCHAR *pParam, Table *value, AbstractCommSession *session);
531 void GetParameterList(NXCPMessage *pMsg);
532 void GetEnumList(NXCPMessage *pMsg);
533 void GetTableList(NXCPMessage *pMsg);
534 BOOL LoadSubAgent(TCHAR *szModuleName);
535 void UnloadAllSubAgents();
536 BOOL InitSubAgent(HMODULE hModule, const TCHAR *pszModuleName,
537 BOOL (* SubAgentInit)(NETXMS_SUBAGENT_INFO **, Config *),
538 const TCHAR *pszEntryPoint);
539 BOOL ProcessCmdBySubAgent(UINT32 dwCommand, NXCPMessage *pRequest, NXCPMessage *pResponse, AbstractCommSession *session);
540 BOOL AddAction(const TCHAR *pszName, int iType, const TCHAR *pArg,
541 LONG (*fpHandler)(const TCHAR *, StringList *, const TCHAR *, AbstractCommSession *session),
542 const TCHAR *pszSubAgent, const TCHAR *pszDescription);
543 BOOL AddActionFromConfig(TCHAR *pszLine, BOOL bShellExec);
544 UINT32 ExecAction(const TCHAR *action, StringList *args, AbstractCommSession *session);
545 UINT32 ExecActionWithOutput(CommSession *session, UINT32 requestId, const TCHAR *action, StringList *args);
546 UINT32 ExecuteCommand(TCHAR *pszCommand, StringList *pArgs, pid_t *pid);
547 UINT32 ExecuteShellCommand(TCHAR *pszCommand, StringList *pArgs);
548
549 void StartParamProvidersPoller();
550 bool AddParametersProvider(const TCHAR *line);
551 LONG GetParameterValueFromExtProvider(const TCHAR *name, TCHAR *buffer);
552 void ListParametersFromExtProviders(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
553 void ListParametersFromExtProviders(StringList *list);
554
555 bool AddExternalSubagent(const TCHAR *config);
556 UINT32 GetParameterValueFromExtSubagent(const TCHAR *name, TCHAR *buffer);
557 UINT32 GetTableValueFromExtSubagent(const TCHAR *name, Table *value);
558 UINT32 GetListValueFromExtSubagent(const TCHAR *name, StringList *value);
559 void ListParametersFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
560 void ListParametersFromExtSubagents(StringList *list);
561 void ListListsFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
562 void ListListsFromExtSubagents(StringList *list);
563 void ListTablesFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
564 void ListTablesFromExtSubagents(StringList *list);
565 bool SendMessageToPipe(HPIPE hPipe, NXCP_MESSAGE *msg);
566 bool SendMessageToMasterAgent(NXCPMessage *msg);
567 bool SendRawMessageToMasterAgent(NXCP_MESSAGE *msg);
568 void ShutdownExtSubagents();
569
570 void RegisterApplicationAgent(const TCHAR *name);
571 UINT32 GetParameterValueFromAppAgent(const TCHAR *name, TCHAR *buffer);
572
573 BOOL WaitForProcess(const TCHAR *name);
574
575 UINT32 UpgradeAgent(TCHAR *pszPkgFile);
576
577 void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, int iNumArgs, TCHAR **ppArgList);
578 void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, const char *pszFormat, ...);
579 void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, const char *pszFormat, va_list args);
580 void ForwardTrap(NXCPMessage *msg);
581
582 void StartPushConnector();
583 bool PushData(const TCHAR *parameter, const TCHAR *value, UINT32 objectId, time_t timestamp);
584
585 void StartStorageDiscoveryConnector();
586
587 void StartControlConnector();
588 bool SendControlMessage(NXCPMessage *msg);
589
590 void StartSessionAgentConnector();
591 SessionAgentConnector *AcquireSessionAgentConnector(const TCHAR *sessionName);
592
593 UINT32 GenerateMessageId();
594
595 void ConfigureDataCollection(UINT64 serverId, NXCPMessage *msg);
596
597 bool EnumerateSessions(EnumerationCallbackResult (* callback)(AbstractCommSession *, void* ), void *data);
598 AbstractCommSession *FindServerSession(UINT64 serverId);
599 AbstractCommSession *FindServerSession(bool (*comparator)(AbstractCommSession *, void *), void *userData);
600
601 #ifdef _WIN32
602
603 void InitService();
604 void InstallService(TCHAR *execName, TCHAR *confFile, int debugLevel);
605 void RemoveService();
606 void StartAgentService();
607 void StopAgentService();
608 bool WaitForService(DWORD dwDesiredState);
609 void InstallEventSource(const TCHAR *path);
610 void RemoveEventSource();
611
612 TCHAR *GetPdhErrorText(UINT32 dwError, TCHAR *pszBuffer, int iBufSize);
613
614 #endif
615
616
617 /**
618 * Global variables
619 */
620 extern UINT32 g_dwFlags;
621 extern UINT32 g_failFlags;
622 extern TCHAR g_szLogFile[];
623 extern TCHAR g_szSharedSecret[];
624 extern TCHAR g_szConfigFile[];
625 extern TCHAR g_szFileStore[];
626 extern TCHAR g_szConfigServer[];
627 extern TCHAR g_szRegistrar[];
628 extern TCHAR g_szListenAddress[];
629 extern TCHAR g_szConfigIncludeDir[];
630 extern TCHAR g_szConfigPolicyDir[];
631 extern TCHAR g_szLogParserDirectory[];
632 extern TCHAR g_szDataDirectory[];
633 extern TCHAR g_masterAgent[];
634 extern TCHAR g_szSNMPTrapListenAddress[];
635 extern UINT16 g_wListenPort;
636 extern ObjectArray<ServerInfo> g_serverList;
637 extern UINT32 g_dwServerCount;
638 extern time_t g_tmAgentStartTime;
639 extern TCHAR g_szPlatformSuffix[];
640 extern UINT32 g_dwStartupDelay;
641 extern UINT32 g_dwIdleTimeout;
642 extern UINT32 g_dwMaxSessions;
643 extern UINT32 g_dwExecTimeout;
644 extern UINT32 g_dwSNMPTimeout;
645 extern UINT32 g_dwSNMPTrapPort;
646 extern UINT32 g_longRunningQueryThreshold;
647 extern UINT16 g_sessionAgentPort;
648 extern UINT32 g_zoneId;
649 extern UINT16 g_syslogListenPort;
650
651 extern Config *g_config;
652
653 extern UINT32 g_dwAcceptErrors;
654 extern UINT32 g_dwAcceptedConnections;
655 extern UINT32 g_dwRejectedConnections;
656
657 extern CommSession **g_pSessionList;
658 extern MUTEX g_hSessionListAccess;
659 extern ThreadPool *g_snmpProxyThreadPool;
660
661 #ifdef _WIN32
662 extern TCHAR g_windowsEventSourceName[];
663 #endif /* _WIN32 */
664
665 #endif /* _nxagentd_h_ */