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