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