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