implemented agent parameter Agent.IsExternalSubagentConnected
[public/netxms.git] / src / agent / core / getparam.cpp
CommitLineData
060c5a11 1/*
5039dede 2** NetXMS multiplatform core agent
82493366 3** Copyright (C) 2003-2016 Victor Kirhenshtein
5039dede
AK
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 useful,
11** but WITHOUT 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: getparam.cpp
20**
21**/
22
23#include "nxagentd.h"
24
38e9a5bd
VK
25#if defined(_WIN32)
26#include <intrin.h>
27#elif HAVE_CPUID_H
1217cb75
VK
28#include <cpuid.h>
29#endif
30
0f506caa
VK
31/**
32 * Parameter handlers
33 */
786773f7 34LONG H_ActionList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session);
df26f039 35LONG H_ActiveConnections(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
e1d760ac 36LONG H_AgentProxyStats(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
060c5a11 37LONG H_AgentTraps(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
38LONG H_AgentUptime(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
39LONG H_CRC32(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
df26f039 40LONG H_DataCollectorQueueSize(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
060c5a11 41LONG H_DirInfo(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
786773f7
VK
42LONG H_ExternalParameter(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
43LONG H_ExternalList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session);
a85cab20 44LONG H_ExternalTable(const TCHAR *cmd, const TCHAR *arg, Table *value, AbstractCommSession *session);
060c5a11 45LONG H_FileTime(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
ec4679d1 46LONG H_IsExtSubagentConnected(const TCHAR *pszCmd, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session);
df26f039 47LONG H_IsSubagentLoaded(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
060c5a11 48LONG H_MD5Hash(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
786773f7
VK
49LONG H_PlatformName(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
50LONG H_ResolverAddrByName(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
51LONG H_ResolverNameByAddr(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
52LONG H_SessionAgents(const TCHAR *cmd, const TCHAR *arg, Table *value, AbstractCommSession *session);
060c5a11 53LONG H_SHA1Hash(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
786773f7 54LONG H_SNMPProxyStats(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
060c5a11 55LONG H_SubAgentList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session);
56LONG H_SubAgentTable(const TCHAR *cmd, const TCHAR *arg, Table *value, AbstractCommSession *session);
2564bde8 57LONG H_SyslogStats(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
060c5a11 58LONG H_SystemTime(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
374afd7b
VK
59LONG H_ThreadPoolInfo(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
60LONG H_ThreadPoolList(const TCHAR *param, const TCHAR *arg, StringList *value, AbstractCommSession *session);
5039dede
AK
61
62#ifdef _WIN32
060c5a11 63LONG H_CPUCount(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
4a675f94 64LONG H_DiskInfo(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
060c5a11 65LONG H_FileSystems(const TCHAR *cmd, const TCHAR *arg, Table *value, AbstractCommSession *session);
4a675f94
VK
66LONG H_FileSystemType(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
67LONG H_HostName(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
68LONG H_MemoryInfo(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
060c5a11 69LONG H_MountPoints(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session);
4a675f94
VK
70LONG H_PhysicalDiskInfo(const TCHAR *cmd, const TCHAR *arg, TCHAR *pValue, AbstractCommSession *session);
71LONG H_SystemUname(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
5039dede
AK
72#endif
73
0f506caa
VK
74/**
75 * Static data
76 */
5039dede
AK
77static NETXMS_SUBAGENT_PARAM *m_pParamList = NULL;
78static int m_iNumParams = 0;
f480bdd4
VK
79static NETXMS_SUBAGENT_PUSHPARAM *m_pPushParamList = NULL;
80static int m_iNumPushParams = 0;
4687826e 81static NETXMS_SUBAGENT_LIST *m_pEnumList = NULL;
5039dede 82static int m_iNumEnums = 0;
4687826e
VK
83static NETXMS_SUBAGENT_TABLE *m_pTableList = NULL;
84static int m_iNumTables = 0;
967893bb
VK
85static UINT32 m_dwTimedOutRequests = 0;
86static UINT32 m_dwAuthenticationFailures = 0;
87static UINT32 m_dwProcessedRequests = 0;
88static UINT32 m_dwFailedRequests = 0;
89static UINT32 m_dwUnsupportedRequests = 0;
5039dede 90
0f506caa
VK
91/**
92 * Handler for parameters which always returns string constant
93 */
060c5a11 94static LONG H_StringConstant(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session)
5039dede
AK
95{
96 ret_string(value, arg);
97 return SYSINFO_RC_SUCCESS;
5039dede
AK
98}
99
0f506caa 100/**
967893bb 101 * Handler for parameters which returns UINT32 value from specific variable
0f506caa 102 */
060c5a11 103static LONG H_UIntPtr(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session)
5039dede 104{
967893bb 105 ret_uint(value, *((UINT32 *)arg));
5039dede
AK
106 return SYSINFO_RC_SUCCESS;
107}
108
0f506caa
VK
109/**
110 * Handler for Agent.SupportedCiphers
060c5a11 111 */
112static LONG H_SupportedCiphers(const TCHAR *pszCmd, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session)
5039dede 113{
967893bb 114 UINT32 dwCiphers;
5039dede 115
72334e60 116 dwCiphers = NXCPGetSupportedCiphers();
5039dede
AK
117 if (dwCiphers == 0)
118 {
bf3b7f79 119 ret_string(pValue, _T("NONE"));
5039dede
AK
120 }
121 else
122 {
123 *pValue = 0;
43a6f3ca 124 if (dwCiphers & NXCP_SUPPORT_AES_256)
bf3b7f79 125 _tcscat(pValue, _T("AES-256 "));
43a6f3ca 126 if (dwCiphers & NXCP_SUPPORT_AES_128)
9e9d631e 127 _tcscat(pValue, _T("AES-128 "));
43a6f3ca 128 if (dwCiphers & NXCP_SUPPORT_BLOWFISH_256)
e6336a90 129 _tcscat(pValue, _T("BF-256 "));
43a6f3ca 130 if (dwCiphers & NXCP_SUPPORT_BLOWFISH_128)
e6336a90 131 _tcscat(pValue, _T("BF-128 "));
43a6f3ca 132 if (dwCiphers & NXCP_SUPPORT_IDEA)
bf3b7f79 133 _tcscat(pValue, _T("IDEA "));
43a6f3ca 134 if (dwCiphers & NXCP_SUPPORT_3DES)
bf3b7f79
VK
135 _tcscat(pValue, _T("3DES "));
136 pValue[_tcslen(pValue) - 1] = 0;
5039dede
AK
137 }
138 return SYSINFO_RC_SUCCESS;
139}
140
0f506caa
VK
141/**
142 * Handler for parameters list
143 */
060c5a11 144static LONG H_ParamList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session)
5039dede
AK
145{
146 int i;
147
148 for(i = 0; i < m_iNumParams; i++)
4687826e
VK
149 if (m_pParamList[i].dataType != DCI_DT_DEPRECATED)
150 value->add(m_pParamList[i].name);
9795113c 151 ListParametersFromExtProviders(value);
0df58041 152 ListParametersFromExtSubagents(value);
5039dede
AK
153 return SYSINFO_RC_SUCCESS;
154}
155
0f506caa
VK
156/**
157 * Handler for push parameters list
158 */
060c5a11 159static LONG H_PushParamList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session)
f480bdd4
VK
160{
161 int i;
162
163 for(i = 0; i < m_iNumPushParams; i++)
164 value->add(m_pPushParamList[i].name);
165 return SYSINFO_RC_SUCCESS;
166}
167
0f506caa
VK
168/**
169 * Handler for enums list
170 */
060c5a11 171static LONG H_EnumList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session)
5039dede
AK
172{
173 int i;
174
175 for(i = 0; i < m_iNumEnums; i++)
4687826e 176 value->add(m_pEnumList[i].name);
0f506caa 177 ListListsFromExtSubagents(value);
4687826e
VK
178 return SYSINFO_RC_SUCCESS;
179}
180
0f506caa
VK
181/**
182 * Handler for table list
183 */
060c5a11 184static LONG H_TableList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session)
4687826e
VK
185{
186 int i;
187
188 for(i = 0; i < m_iNumTables; i++)
189 value->add(m_pTableList[i].name);
0f506caa 190 ListTablesFromExtSubagents(value);
5039dede
AK
191 return SYSINFO_RC_SUCCESS;
192}
193
7b30e5ae
VK
194/**
195 * Handler for component statuses based on failure flags
196 */
197static LONG H_ComponentStatus(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session)
198{
199 UINT32 result = 0;
200 switch(*pArg)
201 {
202 case 'D':
203 if ((g_failFlags & FAIL_OPEN_DATABASE) != 0)
204 result++;
c5459490 205 if ((g_failFlags & FAIL_UPGRADE_DATABASE) != 0)
7b30e5ae
VK
206 result++;
207 break;
208 case 'L':
209 if ((g_failFlags & FAIL_OPEN_LOG) != 0)
210 result++;
211 break;
212 }
213
214 ret_uint(pValue, result);
215 return SYSINFO_RC_SUCCESS;
216}
217
218/**
219 * Handler for local database counters
220 */
221static LONG H_LocalDatabaseCounters(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session)
222{
223 LIBNXDB_PERF_COUNTERS counters;
224 DBGetPerfCounters(&counters);
225 switch(*pArg)
226 {
227 case 'F':
228 ret_int64(pValue, counters.failedQueries);
229 break;
230 case 'L':
231 ret_int64(pValue, counters.longRunningQueries);
232 break;
233 case 'T':
234 ret_int64(pValue, counters.totalQueries);
235 break;
236 default:
237 return SYSINFO_RC_UNSUPPORTED;
238 }
239 return SYSINFO_RC_SUCCESS;
240}
241
786773f7
VK
242/**
243 * Handler for flag query parameters
244 */
245static LONG H_FlagValue(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session)
246{
247 UINT32 flag = CAST_FROM_POINTER(arg, UINT32);
248 ret_int(value, (g_dwFlags & flag) ? 1 : 0);
249 return SYSINFO_RC_SUCCESS;
250}
251
1217cb75
VK
252#if HAVE_GET_CPUID
253
254/**
255 * Handler for System.IsVirtual parameter
256 */
257static LONG H_SystemIsVirtual(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session)
258{
259 unsigned int eax, ebx, ecx, edx;
260 if (__get_cpuid(0x1, &eax, &ebx, &ecx, &edx) != 1)
261 return SYSINFO_RC_UNSUPPORTED;
262 ret_int(value, (ecx & 0x80000000) != 0 ? 1 : 0);
263 return SYSINFO_RC_SUCCESS;
264}
265
266#elif defined(_WIN32)
267
268/**
269 * Handler for System.IsVirtual parameter
270 */
271static LONG H_SystemIsVirtual(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session)
272{
273 int data[4];
274 __cpuid(data, 0x01);
275 ret_int(value, (data[2] & 0x80000000) != 0 ? 1 : 0);
276 return SYSINFO_RC_SUCCESS;
277}
278
279#endif
280
281
0f506caa
VK
282/**
283 * Standard agent's parameters
284 */
5039dede
AK
285static NETXMS_SUBAGENT_PARAM m_stdParams[] =
286{
287#ifdef _WIN32
bf3b7f79
VK
288 { _T("Disk.Free(*)"), H_DiskInfo, (TCHAR *)DISKINFO_FREE_BYTES, DCI_DT_DEPRECATED, DCIDESC_DEPRECATED },
289 { _T("Disk.FreePerc(*)"), H_DiskInfo, (TCHAR *)DISKINFO_FREE_SPACE_PCT, DCI_DT_DEPRECATED, DCIDESC_DEPRECATED },
290 { _T("Disk.Total(*)"), H_DiskInfo, (TCHAR *)DISKINFO_TOTAL_BYTES, DCI_DT_DEPRECATED, DCIDESC_DEPRECATED },
291 { _T("Disk.Used(*)"), H_DiskInfo, (TCHAR *)DISKINFO_USED_BYTES, DCI_DT_DEPRECATED, DCIDESC_DEPRECATED },
292 { _T("Disk.UsedPerc(*)"), H_DiskInfo, (TCHAR *)DISKINFO_USED_SPACE_PCT, DCI_DT_DEPRECATED, DCIDESC_DEPRECATED },
293 { _T("FileSystem.Free(*)"), H_DiskInfo, (TCHAR *)DISKINFO_FREE_BYTES, DCI_DT_UINT64, DCIDESC_FS_FREE },
294 { _T("FileSystem.FreePerc(*)"), H_DiskInfo, (TCHAR *)DISKINFO_FREE_SPACE_PCT, DCI_DT_FLOAT, DCIDESC_FS_FREEPERC },
295 { _T("FileSystem.Total(*)"), H_DiskInfo, (TCHAR *)DISKINFO_TOTAL_BYTES, DCI_DT_UINT64, DCIDESC_FS_TOTAL },
4a675f94 296 { _T("FileSystem.Type(*)"), H_FileSystemType, NULL, DCI_DT_STRING, DCIDESC_FS_TYPE },
bf3b7f79
VK
297 { _T("FileSystem.Used(*)"), H_DiskInfo, (TCHAR *)DISKINFO_USED_BYTES, DCI_DT_UINT64, DCIDESC_FS_USED },
298 { _T("FileSystem.UsedPerc(*)"), H_DiskInfo, (TCHAR *)DISKINFO_USED_SPACE_PCT, DCI_DT_FLOAT, DCIDESC_FS_USEDPERC },
bf3b7f79
VK
299 { _T("PhysicalDisk.Firmware(*)"), H_PhysicalDiskInfo, _T("F"), DCI_DT_STRING, DCIDESC_PHYSICALDISK_FIRMWARE },
300 { _T("PhysicalDisk.Model(*)"), H_PhysicalDiskInfo, _T("M"), DCI_DT_STRING, DCIDESC_PHYSICALDISK_MODEL },
301 { _T("PhysicalDisk.SerialNumber(*)"), H_PhysicalDiskInfo, _T("N"), DCI_DT_STRING, DCIDESC_PHYSICALDISK_SERIALNUMBER },
302 { _T("PhysicalDisk.SmartAttr(*)"), H_PhysicalDiskInfo, _T("A"), DCI_DT_STRING, DCIDESC_PHYSICALDISK_SMARTATTR },
303 { _T("PhysicalDisk.SmartStatus(*)"), H_PhysicalDiskInfo, _T("S"), DCI_DT_INT, DCIDESC_PHYSICALDISK_SMARTSTATUS },
304 { _T("PhysicalDisk.Temperature(*)"), H_PhysicalDiskInfo, _T("T"), DCI_DT_INT, DCIDESC_PHYSICALDISK_TEMPERATURE },
305 { _T("System.CPU.Count"), H_CPUCount, NULL, DCI_DT_UINT, DCIDESC_SYSTEM_CPU_COUNT },
306 { _T("System.Hostname"), H_HostName, NULL, DCI_DT_STRING, DCIDESC_SYSTEM_HOSTNAME },
38e9a5bd 307 { _T("System.IsVirtual"), H_SystemIsVirtual, NULL, DCI_DT_INT, DCIDESC_SYSTEM_IS_VIRTUAL },
2658158a 308 { _T("System.Memory.Physical.Available"), H_MemoryInfo, (TCHAR *)MEMINFO_PHYSICAL_FREE, DCI_DT_UINT64, DCIDESC_SYSTEM_MEMORY_PHYSICAL_AVAILABLE },
2d6a0083 309 { _T("System.Memory.Physical.AvailablePerc"), H_MemoryInfo, (TCHAR *)MEMINFO_PHYSICAL_FREE_PCT, DCI_DT_FLOAT, DCIDESC_SYSTEM_MEMORY_PHYSICAL_AVAILABLE_PCT },
bf3b7f79 310 { _T("System.Memory.Physical.Free"), H_MemoryInfo, (TCHAR *)MEMINFO_PHYSICAL_FREE, DCI_DT_UINT64, DCIDESC_SYSTEM_MEMORY_PHYSICAL_FREE },
2d6a0083 311 { _T("System.Memory.Physical.FreePerc"), H_MemoryInfo, (TCHAR *)MEMINFO_PHYSICAL_FREE_PCT, DCI_DT_FLOAT, DCIDESC_SYSTEM_MEMORY_PHYSICAL_FREE_PCT },
bf3b7f79
VK
312 { _T("System.Memory.Physical.Total"), H_MemoryInfo, (TCHAR *)MEMINFO_PHYSICAL_TOTAL, DCI_DT_UINT64, DCIDESC_SYSTEM_MEMORY_PHYSICAL_TOTAL },
313 { _T("System.Memory.Physical.Used"), H_MemoryInfo, (TCHAR *)MEMINFO_PHYSICAL_USED, DCI_DT_UINT64, DCIDESC_SYSTEM_MEMORY_PHYSICAL_USED },
2d6a0083 314 { _T("System.Memory.Physical.UsedPerc"), H_MemoryInfo, (TCHAR *)MEMINFO_PHYSICAL_USED_PCT, DCI_DT_FLOAT, DCIDESC_SYSTEM_MEMORY_PHYSICAL_USED_PCT },
bf3b7f79 315 { _T("System.Memory.Virtual.Free"), H_MemoryInfo, (TCHAR *)MEMINFO_VIRTUAL_FREE, DCI_DT_UINT64, DCIDESC_SYSTEM_MEMORY_VIRTUAL_FREE },
2d6a0083 316 { _T("System.Memory.Virtual.FreePerc"), H_MemoryInfo, (TCHAR *)MEMINFO_VIRTUAL_FREE_PCT, DCI_DT_FLOAT, DCIDESC_SYSTEM_MEMORY_VIRTUAL_FREE_PCT },
bf3b7f79
VK
317 { _T("System.Memory.Virtual.Total"), H_MemoryInfo, (TCHAR *)MEMINFO_VIRTUAL_TOTAL, DCI_DT_UINT64, DCIDESC_SYSTEM_MEMORY_VIRTUAL_TOTAL },
318 { _T("System.Memory.Virtual.Used"), H_MemoryInfo, (TCHAR *)MEMINFO_VIRTUAL_USED, DCI_DT_UINT64, DCIDESC_SYSTEM_MEMORY_VIRTUAL_USED },
2d6a0083 319 { _T("System.Memory.Virtual.UsedPerc"), H_MemoryInfo, (TCHAR *)MEMINFO_VIRTUAL_USED_PCT, DCI_DT_FLOAT, DCIDESC_SYSTEM_MEMORY_VIRTUAL_USED_PCT },
bf3b7f79 320 { _T("System.Uname"), H_SystemUname, NULL, DCI_DT_STRING, DCIDESC_SYSTEM_UNAME },
5039dede 321#endif
7b30e5ae 322
1217cb75
VK
323#if HAVE_GET_CPUID
324 { _T("System.IsVirtual"), H_SystemIsVirtual, NULL, DCI_DT_INT, DCIDESC_SYSTEM_IS_VIRTUAL },
325#endif
326
da8453a5
VK
327 { _T("Agent.AcceptedConnections"), H_UIntPtr, (TCHAR *)&g_acceptedConnections, DCI_DT_UINT, DCIDESC_AGENT_ACCEPTEDCONNECTIONS },
328 { _T("Agent.AcceptErrors"), H_UIntPtr, (TCHAR *)&g_acceptErrors, DCI_DT_UINT, DCIDESC_AGENT_ACCEPTERRORS },
bf3b7f79
VK
329 { _T("Agent.ActiveConnections"), H_ActiveConnections, NULL, DCI_DT_UINT, DCIDESC_AGENT_ACTIVECONNECTIONS },
330 { _T("Agent.AuthenticationFailures"), H_UIntPtr, (TCHAR *)&m_dwAuthenticationFailures, DCI_DT_UINT, DCIDESC_AGENT_AUTHENTICATIONFAILURES },
331 { _T("Agent.ConfigurationServer"), H_StringConstant, g_szConfigServer, DCI_DT_STRING, DCIDESC_AGENT_CONFIG_SERVER },
df26f039 332 { _T("Agent.DataCollectorQueueSize"), H_DataCollectorQueueSize, NULL, DCI_DT_UINT, DCIDESC_AGENT_DATACOLLQUEUESIZE },
bf3b7f79
VK
333 { _T("Agent.FailedRequests"), H_UIntPtr, (TCHAR *)&m_dwFailedRequests, DCI_DT_UINT, DCIDESC_AGENT_FAILEDREQUESTS },
334 { _T("Agent.GeneratedTraps"), H_AgentTraps, _T("G"), DCI_DT_UINT64, DCIDESC_AGENT_GENERATED_TRAPS },
05db3127 335 { _T("Agent.IsSubagentLoaded(*)"), H_IsSubagentLoaded, NULL, DCI_DT_INT, DCIDESC_AGENT_IS_SUBAGENT_LOADED },
ec4679d1 336 { _T("Agent.IsExternalSubagentConnected(*)"), H_IsExtSubagentConnected, NULL, DCI_DT_INT, DCIDESC_AGENT_IS_EXT_SUBAGENT_CONNECTED },
bf3b7f79 337 { _T("Agent.LastTrapTime"), H_AgentTraps, _T("T"), DCI_DT_UINT64, DCIDESC_AGENT_LAST_TRAP_TIME },
7b30e5ae
VK
338 { _T("Agent.LocalDatabase.FailedQueries"), H_LocalDatabaseCounters, _T("F"), DCI_DT_UINT64, DCIDESC_AGENT_LOCALDB_FAILED_QUERIES },
339 { _T("Agent.LocalDatabase.LongRunningQueries"), H_LocalDatabaseCounters, _T("L"), DCI_DT_UINT64, DCIDESC_AGENT_LOCALDB_SLOW_QUERIES },
340 { _T("Agent.LocalDatabase.Status"), H_ComponentStatus, _T("D"), DCI_DT_UINT, DCIDESC_AGENT_LOCALDB_STATUS },
341 { _T("Agent.LocalDatabase.TotalQueries"), H_LocalDatabaseCounters, _T("T"), DCI_DT_UINT64, DCIDESC_AGENT_LOCALDB_TOTAL_QUERIES },
342 { _T("Agent.LogFile.Status"), H_ComponentStatus, _T("L"), DCI_DT_UINT, DCIDESC_AGENT_LOG_STATUS },
bf3b7f79 343 { _T("Agent.ProcessedRequests"), H_UIntPtr, (TCHAR *)&m_dwProcessedRequests, DCI_DT_UINT, DCIDESC_AGENT_PROCESSEDREQUESTS },
e1d760ac
VK
344 { _T("Agent.Proxy.ActiveSessions"), H_AgentProxyStats, _T("A"), DCI_DT_UINT, DCIDESC_AGENT_PROXY_ACTIVESESSIONS },
345 { _T("Agent.Proxy.ConnectionRequests"), H_AgentProxyStats, _T("C"), DCI_DT_UINT64, DCIDESC_AGENT_PROXY_CONNECTIONREQUESTS },
346 { _T("Agent.Proxy.IsEnabled"), H_FlagValue, CAST_TO_POINTER(AF_ENABLE_PROXY, TCHAR *), DCI_DT_UINT, DCIDESC_AGENT_PROXY_ISENABLED },
bf3b7f79 347 { _T("Agent.Registrar"), H_StringConstant, g_szRegistrar, DCI_DT_STRING, DCIDESC_AGENT_REGISTRAR },
da8453a5 348 { _T("Agent.RejectedConnections"), H_UIntPtr, (TCHAR *)&g_rejectedConnections, DCI_DT_UINT, DCIDESC_AGENT_REJECTEDCONNECTIONS },
bf3b7f79 349 { _T("Agent.SentTraps"), H_AgentTraps, _T("S"), DCI_DT_UINT64, DCIDESC_AGENT_SENT_TRAPS },
786773f7
VK
350 { _T("Agent.SNMP.IsProxyEnabled"), H_FlagValue, CAST_TO_POINTER(AF_ENABLE_SNMP_PROXY, TCHAR *), DCI_DT_UINT, DCIDESC_AGENT_SNMP_ISPROXYENABLED },
351 { _T("Agent.SNMP.IsTrapProxyEnabled"), H_FlagValue, CAST_TO_POINTER(AF_ENABLE_SNMP_TRAP_PROXY, TCHAR *), DCI_DT_UINT, DCIDESC_AGENT_SNMP_ISPROXYENABLED },
352 { _T("Agent.SNMP.Requests"), H_SNMPProxyStats, _T("R"), DCI_DT_UINT64, DCIDESC_AGENT_SNMP_REQUESTS },
353 { _T("Agent.SNMP.Responses"), H_SNMPProxyStats, _T("r"), DCI_DT_UINT64, DCIDESC_AGENT_SNMP_RESPONSES },
354 { _T("Agent.SNMP.ServerRequests"), H_SNMPProxyStats, _T("S"), DCI_DT_UINT64, DCIDESC_AGENT_SNMP_SERVERREQUESTS },
bf3b7f79
VK
355 { _T("Agent.SourcePackageSupport"), H_StringConstant, _T("0"), DCI_DT_INT, DCIDESC_AGENT_SOURCEPACKAGESUPPORT },
356 { _T("Agent.SupportedCiphers"), H_SupportedCiphers, NULL, DCI_DT_STRING, DCIDESC_AGENT_SUPPORTEDCIPHERS },
786773f7
VK
357 { _T("Agent.SyslogProxy.IsEnabled"), H_FlagValue, CAST_TO_POINTER(AF_ENABLE_SYSLOG_PROXY, TCHAR *), DCI_DT_UINT, DCIDESC_AGENT_SYSLOGPROXY_ISENABLED },
358 { _T("Agent.SyslogProxy.ReceivedMessages"), H_SyslogStats, _T("R"), DCI_DT_UINT64, DCIDESC_AGENT_SYSLOGPROXY_RECEIVEDMSGS },
359 { _T("Agent.SyslogProxy.QueueSize"), H_SyslogStats, _T("Q"), DCI_DT_UINT, DCIDESC_AGENT_SYSLOGPROXY_QUEUESIZE },
374afd7b
VK
360 { _T("Agent.ThreadPool.ActiveRequests(*)"), H_ThreadPoolInfo, (TCHAR *)THREAD_POOL_REQUESTS, DCI_DT_UINT, DCIDESC_AGENT_THREADPOOL_ACTIVEREQUESTS },
361 { _T("Agent.ThreadPool.CurrSize(*)"), H_ThreadPoolInfo, (TCHAR *)THREAD_POOL_CURR_SIZE, DCI_DT_UINT, DCIDESC_AGENT_THREADPOOL_CURRSIZE },
362 { _T("Agent.ThreadPool.Load(*)"), H_ThreadPoolInfo, (TCHAR *)THREAD_POOL_LOAD, DCI_DT_UINT, DCIDESC_AGENT_THREADPOOL_LOAD },
363 { _T("Agent.ThreadPool.LoadAverage(*)"), H_ThreadPoolInfo, (TCHAR *)THREAD_POOL_LOADAVG_1, DCI_DT_UINT, DCIDESC_AGENT_THREADPOOL_LOADAVG },
364 { _T("Agent.ThreadPool.LoadAverage5(*)"), H_ThreadPoolInfo, (TCHAR *)THREAD_POOL_LOADAVG_5, DCI_DT_UINT, DCIDESC_AGENT_THREADPOOL_LOADAVG_5 },
365 { _T("Agent.ThreadPool.LoadAverage15(*)"), H_ThreadPoolInfo, (TCHAR *)THREAD_POOL_LOADAVG_15, DCI_DT_UINT, DCIDESC_AGENT_THREADPOOL_LOADAVG_15 },
366 { _T("Agent.ThreadPool.MaxSize(*)"), H_ThreadPoolInfo, (TCHAR *)THREAD_POOL_MAX_SIZE, DCI_DT_UINT, DCIDESC_AGENT_THREADPOOL_MAXSIZE },
367 { _T("Agent.ThreadPool.MinSize(*)"), H_ThreadPoolInfo, (TCHAR *)THREAD_POOL_MIN_SIZE, DCI_DT_UINT, DCIDESC_AGENT_THREADPOOL_MINSIZE },
368 { _T("Agent.ThreadPool.Usage(*)"), H_ThreadPoolInfo, (TCHAR *)THREAD_POOL_USAGE, DCI_DT_UINT, DCIDESC_AGENT_THREADPOOL_USAGE },
bf3b7f79
VK
369 { _T("Agent.TimedOutRequests"), H_UIntPtr, (TCHAR *)&m_dwTimedOutRequests, DCI_DT_UINT, DCIDESC_AGENT_TIMEDOUTREQUESTS },
370 { _T("Agent.UnsupportedRequests"), H_UIntPtr, (TCHAR *)&m_dwUnsupportedRequests, DCI_DT_UINT, DCIDESC_AGENT_UNSUPPORTEDREQUESTS },
371 { _T("Agent.Uptime"), H_AgentUptime, NULL, DCI_DT_UINT, DCIDESC_AGENT_UPTIME },
70af47c2 372 { _T("Agent.Version"), H_StringConstant, NETXMS_BUILD_TAG, DCI_DT_STRING, DCIDESC_AGENT_VERSION },
bf3b7f79 373 { _T("File.Count(*)"), H_DirInfo, (TCHAR *)DIRINFO_FILE_COUNT, DCI_DT_UINT, DCIDESC_FILE_COUNT },
5ad4ed06 374 { _T("File.FolderCount(*)"), H_DirInfo, (TCHAR *)DIRINFO_FOLDER_COUNT, DCI_DT_UINT, DCIDESC_FILE_FOLDERCOUNT },
bf3b7f79
VK
375 { _T("File.Hash.CRC32(*)"), H_CRC32, NULL, DCI_DT_UINT, DCIDESC_FILE_HASH_CRC32 },
376 { _T("File.Hash.MD5(*)"), H_MD5Hash, NULL, DCI_DT_STRING, DCIDESC_FILE_HASH_MD5 },
377 { _T("File.Hash.SHA1(*)"), H_SHA1Hash, NULL, DCI_DT_STRING, DCIDESC_FILE_HASH_SHA1 },
378 { _T("File.Size(*)"), H_DirInfo, (TCHAR *)DIRINFO_FILE_SIZE, DCI_DT_UINT64, DCIDESC_FILE_SIZE },
379 { _T("File.Time.Access(*)"), H_FileTime, (TCHAR *)FILETIME_ATIME, DCI_DT_UINT64, DCIDESC_FILE_TIME_ACCESS },
380 { _T("File.Time.Change(*)"), H_FileTime, (TCHAR *)FILETIME_CTIME, DCI_DT_UINT64, DCIDESC_FILE_TIME_CHANGE },
381 { _T("File.Time.Modify(*)"), H_FileTime, (TCHAR *)FILETIME_MTIME, DCI_DT_UINT64, DCIDESC_FILE_TIME_MODIFY },
ecdf8898
VK
382 { _T("Net.Resolver.AddressByName(*)"), H_ResolverAddrByName, NULL, DCI_DT_STRING, DCIDESC_NET_RESOLVER_ADDRBYNAME },
383 { _T("Net.Resolver.NameByAddress(*)"), H_ResolverNameByAddr, NULL, DCI_DT_STRING, DCIDESC_NET_RESOLVER_NAMEBYADDR },
8ce7501b 384 { _T("System.CurrentTime"), H_SystemTime, NULL, DCI_DT_INT64, DCIDESC_SYSTEM_CURRENTTIME },
bf3b7f79 385 { _T("System.PlatformName"), H_PlatformName, NULL, DCI_DT_STRING, DCIDESC_SYSTEM_PLATFORMNAME }
5039dede
AK
386};
387
8e334368
VK
388/**
389 * Standard agent's lists
390 */
4687826e 391static NETXMS_SUBAGENT_LIST m_stdLists[] =
5039dede 392{
adcfd040
VK
393#ifdef _WIN32
394 { _T("FileSystem.MountPoints"), H_MountPoints, NULL },
395#endif
bf3b7f79
VK
396 { _T("Agent.ActionList"), H_ActionList, NULL },
397 { _T("Agent.SubAgentList"), H_SubAgentList, NULL },
4687826e 398 { _T("Agent.SupportedLists"), H_EnumList, NULL },
bf3b7f79 399 { _T("Agent.SupportedParameters"), H_ParamList, NULL },
4687826e 400 { _T("Agent.SupportedPushParameters"), H_PushParamList, NULL },
374afd7b
VK
401 { _T("Agent.SupportedTables"), H_TableList, NULL },
402 { _T("Agent.ThreadPools"), H_ThreadPoolList, NULL }
5039dede
AK
403};
404
8e334368
VK
405/**
406 * Standard agent's tables
407 */
a8799146
VK
408static NETXMS_SUBAGENT_TABLE m_stdTables[] =
409{
74540dab 410 { _T("Agent.SessionAgents"), H_SessionAgents, NULL, _T("SESSION_ID"), DCTDESC_AGENT_SUBAGENTS },
215637cc 411 { _T("Agent.SubAgents"), H_SubAgentTable, NULL, _T("NAME"), DCTDESC_AGENT_SUBAGENTS },
a8799146
VK
412#ifdef _WIN32
413 { _T("FileSystem.Volumes"), H_FileSystems, NULL, _T("VOLUME"), DCTDESC_FILESYSTEM_VOLUMES }
414#endif
415};
416
8e334368
VK
417/**
418 * Initialize dynamic parameters list from default static list
419 */
8f9299d1 420BOOL InitParameterList()
5039dede 421{
19c93c7c 422 if ((m_pParamList != NULL) || (m_pEnumList != NULL) || (m_pTableList != NULL))
5039dede
AK
423 return FALSE;
424
425 m_iNumParams = sizeof(m_stdParams) / sizeof(NETXMS_SUBAGENT_PARAM);
19c93c7c
AK
426 if (m_iNumParams > 0)
427 {
428 m_pParamList = (NETXMS_SUBAGENT_PARAM *)malloc(sizeof(NETXMS_SUBAGENT_PARAM) * m_iNumParams);
429 if (m_pParamList == NULL)
430 return FALSE;
431 memcpy(m_pParamList, m_stdParams, sizeof(NETXMS_SUBAGENT_PARAM) * m_iNumParams);
432 }
5039dede 433
4687826e 434 m_iNumEnums = sizeof(m_stdLists) / sizeof(NETXMS_SUBAGENT_LIST);
19c93c7c
AK
435 if (m_iNumEnums > 0)
436 {
437 m_pEnumList = (NETXMS_SUBAGENT_LIST *)malloc(sizeof(NETXMS_SUBAGENT_LIST) * m_iNumEnums);
438 if (m_pEnumList == NULL)
439 return FALSE;
440 memcpy(m_pEnumList, m_stdLists, sizeof(NETXMS_SUBAGENT_LIST) * m_iNumEnums);
441 }
5039dede 442
3dbcfa3a 443 m_iNumTables = sizeof(m_stdTables) / sizeof(NETXMS_SUBAGENT_TABLE);
19c93c7c
AK
444 if (m_iNumTables > 0)
445 {
446 m_pTableList = (NETXMS_SUBAGENT_TABLE *)malloc(sizeof(NETXMS_SUBAGENT_TABLE) * m_iNumTables);
447 if (m_pTableList == NULL)
448 return FALSE;
449 memcpy(m_pTableList, m_stdTables, sizeof(NETXMS_SUBAGENT_TABLE) * m_iNumTables);
450 }
a8799146 451
5039dede
AK
452 return TRUE;
453}
454
074498ac
VK
455/**
456 * Add push parameter to list
457 * by LWX
458 */
f480bdd4
VK
459void AddPushParameter(const TCHAR *name, int dataType, const TCHAR *description)
460{
461 int i;
462
463 // Search for existing parameter
464 for(i = 0; i < m_iNumPushParams; i++)
bf3b7f79 465 if (!_tcsicmp(m_pPushParamList[i].name, name))
f480bdd4
VK
466 break;
467 if (i < m_iNumPushParams)
468 {
469 // Replace existing attributes
470 m_pPushParamList[i].dataType = dataType;
471 nx_strncpy(m_pPushParamList[i].description, description, MAX_DB_STRING);
472 }
473 else
474 {
475 // Add new parameter
476 m_pPushParamList = (NETXMS_SUBAGENT_PUSHPARAM *)realloc(m_pPushParamList, sizeof(NETXMS_SUBAGENT_PUSHPARAM) * (m_iNumPushParams + 1));
060c5a11 477 nx_strncpy(m_pPushParamList[m_iNumPushParams].name, name, MAX_PARAM_NAME - 1);
f480bdd4 478 m_pPushParamList[m_iNumPushParams].dataType = dataType;
060c5a11 479 nx_strncpy(m_pPushParamList[m_iNumPushParams].description, description, MAX_DB_STRING);
f480bdd4
VK
480 m_iNumPushParams++;
481 }
482}
483
074498ac
VK
484/**
485 * Add parameter to list
060c5a11 486 */
487void AddParameter(const TCHAR *pszName, LONG (* fpHandler)(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *), const TCHAR *pArg,
bf3b7f79 488 int iDataType, const TCHAR *pszDescription)
5039dede
AK
489{
490 int i;
491
492 // Search for existing parameter
493 for(i = 0; i < m_iNumParams; i++)
4687826e 494 if (!_tcsicmp(m_pParamList[i].name, pszName))
5039dede
AK
495 break;
496 if (i < m_iNumParams)
497 {
498 // Replace existing handler and attributes
4687826e
VK
499 m_pParamList[i].handler = fpHandler;
500 m_pParamList[i].dataType = iDataType;
501 nx_strncpy(m_pParamList[i].description, pszDescription, MAX_DB_STRING);
5039dede
AK
502
503 // If we are replacing System.PlatformName, add pointer to
504 // platform suffix as argument, otherwise, use supplied pArg
bf3b7f79 505 if (!_tcscmp(pszName, _T("System.PlatformName")))
5039dede 506 {
4687826e 507 m_pParamList[i].arg = g_szPlatformSuffix; // to be TCHAR
5039dede
AK
508 }
509 else
510 {
4687826e 511 m_pParamList[i].arg = pArg;
5039dede
AK
512 }
513 }
514 else
515 {
516 // Add new parameter
517 m_pParamList = (NETXMS_SUBAGENT_PARAM *)realloc(m_pParamList, sizeof(NETXMS_SUBAGENT_PARAM) * (m_iNumParams + 1));
4687826e
VK
518 nx_strncpy(m_pParamList[m_iNumParams].name, pszName, MAX_PARAM_NAME - 1);
519 m_pParamList[m_iNumParams].handler = fpHandler;
520 m_pParamList[m_iNumParams].arg = pArg;
521 m_pParamList[m_iNumParams].dataType = iDataType;
522 nx_strncpy(m_pParamList[m_iNumParams].description, pszDescription, MAX_DB_STRING);
5039dede
AK
523 m_iNumParams++;
524 }
525}
526
074498ac
VK
527/**
528 * Add list
060c5a11 529 */
530void AddList(const TCHAR *name, LONG (* handler)(const TCHAR *, const TCHAR *, StringList *, AbstractCommSession *), const TCHAR *arg)
5039dede
AK
531{
532 int i;
533
534 // Search for existing enum
535 for(i = 0; i < m_iNumEnums; i++)
4687826e 536 if (!_tcsicmp(m_pEnumList[i].name, name))
5039dede
AK
537 break;
538 if (i < m_iNumEnums)
539 {
540 // Replace existing handler and arg
4687826e
VK
541 m_pEnumList[i].handler = handler;
542 m_pEnumList[i].arg = arg;
5039dede
AK
543 }
544 else
545 {
546 // Add new enum
4687826e
VK
547 m_pEnumList = (NETXMS_SUBAGENT_LIST *)realloc(m_pEnumList, sizeof(NETXMS_SUBAGENT_LIST) * (m_iNumEnums + 1));
548 nx_strncpy(m_pEnumList[m_iNumEnums].name, name, MAX_PARAM_NAME - 1);
549 m_pEnumList[m_iNumEnums].handler = handler;
550 m_pEnumList[m_iNumEnums].arg = arg;
5039dede
AK
551 m_iNumEnums++;
552 }
553}
554
074498ac
VK
555/**
556 * Add table
060c5a11 557 */
558void AddTable(const TCHAR *name, LONG (* handler)(const TCHAR *, const TCHAR *, Table *, AbstractCommSession *), const TCHAR *arg,
cb97f4dd 559 const TCHAR *instanceColumns, const TCHAR *description, int numColumns, NETXMS_SUBAGENT_TABLE_COLUMN *columns)
4687826e
VK
560{
561 int i;
562
563 // Search for existing table
564 for(i = 0; i < m_iNumTables; i++)
565 if (!_tcsicmp(m_pTableList[i].name, name))
566 break;
567 if (i < m_iNumTables)
568 {
569 // Replace existing handler and arg
570 m_pTableList[i].handler = handler;
571 m_pTableList[i].arg = arg;
86c126f5
VK
572 nx_strncpy(m_pTableList[m_iNumTables].instanceColumns, instanceColumns, MAX_COLUMN_NAME * MAX_INSTANCE_COLUMNS);
573 nx_strncpy(m_pTableList[m_iNumTables].description, description, MAX_DB_STRING);
cb97f4dd
VK
574 m_pTableList[i].numColumns = numColumns;
575 m_pTableList[i].columns = columns;
4687826e
VK
576 }
577 else
578 {
86c126f5 579 // Add new table
4687826e 580 m_pTableList = (NETXMS_SUBAGENT_TABLE *)realloc(m_pTableList, sizeof(NETXMS_SUBAGENT_TABLE) * (m_iNumTables + 1));
074498ac 581 nx_strncpy(m_pTableList[m_iNumTables].name, name, MAX_PARAM_NAME);
4687826e
VK
582 m_pTableList[m_iNumTables].handler = handler;
583 m_pTableList[m_iNumTables].arg = arg;
86c126f5 584 nx_strncpy(m_pTableList[m_iNumTables].instanceColumns, instanceColumns, MAX_COLUMN_NAME * MAX_INSTANCE_COLUMNS);
074498ac 585 nx_strncpy(m_pTableList[m_iNumTables].description, description, MAX_DB_STRING);
cb97f4dd
VK
586 m_pTableList[m_iNumTables].numColumns = numColumns;
587 m_pTableList[m_iNumTables].columns = columns;
4687826e
VK
588 m_iNumTables++;
589 }
590}
591
074498ac 592/**
a85cab20 593 * Add external parameter or list
060c5a11 594 */
a85cab20 595bool AddExternalParameter(TCHAR *config, bool shellExec, bool isList)
5039dede 596{
a85cab20
VK
597 TCHAR *cmdLine = _tcschr(config, _T(':'));
598 if (cmdLine == NULL)
599 return false;
600
601 *cmdLine = 0;
602 cmdLine++;
603 Trim(config);
604 Trim(cmdLine);
605 if ((*config == 0) || (*cmdLine == 0))
606 return false;
607
608 TCHAR *arg = (TCHAR *)malloc((_tcslen(cmdLine) + 2) * sizeof(TCHAR));
609 arg[0] = shellExec ? _T('S') : _T('E');
610 _tcscpy(&arg[1], cmdLine);
611 if (isList)
b5ded63e 612 {
a85cab20 613 AddList(config, H_ExternalList, arg);
b5ded63e
AK
614 }
615 else
616 {
a85cab20 617 AddParameter(config, H_ExternalParameter, arg, DCI_DT_STRING, _T(""));
b5ded63e 618 }
a85cab20
VK
619 return true;
620}
621
622/**
623 * Add external table
624 */
625bool AddExternalTable(TCHAR *config, bool shellExec)
626{
627 TCHAR *options = _tcschr(config, _T(':'));
628 if (options == NULL)
629 return false;
630 *options = 0;
631 options++;
632
633 TCHAR *cmdLine = _tcschr(options, _T(':'));
634 if (cmdLine == NULL)
635 return false;
636 *cmdLine = 0;
637 cmdLine++;
638
639 Trim(config);
640 Trim(options);
641 Trim(cmdLine);
642 if ((*config == 0) || (*options == 0) || (*cmdLine == 0))
643 return false;
644
645 TCHAR instanceColumns[256] = _T("");
646 ExtractNamedOptionValue(options, _T("instanceColumns"), instanceColumns, 256);
647
648 TCHAR description[256] = _T("");
649 ExtractNamedOptionValue(options, _T("description"), description, 256);
650
651 TCHAR separator[16] = _T(",");
652 ExtractNamedOptionValue(options, _T("separator"), separator, 16);
653 if (separator[0] == _T('\\'))
654 {
655 switch(separator[1])
656 {
657 case 'n':
658 separator[0] = _T('\n');
659 break;
660 case 'r':
661 separator[0] = _T('\r');
662 break;
663 case 's':
664 separator[0] = _T(' ');
665 break;
666 case 't':
667 separator[0] = _T('\t');
668 break;
669 case 'u':
670 separator[0] = (TCHAR)_tcstoul(&separator[2], NULL, 10);
671 break;
672 }
673 }
674
675 TCHAR *arg = (TCHAR *)malloc((_tcslen(cmdLine) + 3) * sizeof(TCHAR));
676 arg[0] = separator[0];
677 arg[1] = shellExec ? _T('S') : _T('E');
678 _tcscpy(&arg[2], cmdLine);
679 AddTable(config, H_ExternalTable, arg, instanceColumns, description, 0, NULL);
680 return true;
5039dede
AK
681}
682
0f506caa
VK
683/**
684 * Get parameter's value
685 */
da8453a5 686UINT32 GetParameterValue(const TCHAR *param, TCHAR *value, AbstractCommSession *session)
5039dede
AK
687{
688 int i, rc;
967893bb 689 UINT32 dwErrorCode;
5039dede 690
da8453a5 691 session->debugPrintf(5, _T("Requesting parameter \"%s\""), param);
5039dede 692 for(i = 0; i < m_iNumParams; i++)
9795113c 693 {
87fff547 694 if (MatchString(m_pParamList[i].name, param, FALSE))
5039dede 695 {
87fff547 696 rc = m_pParamList[i].handler(param, m_pParamList[i].arg, value, session);
5039dede
AK
697 switch(rc)
698 {
699 case SYSINFO_RC_SUCCESS:
700 dwErrorCode = ERR_SUCCESS;
701 m_dwProcessedRequests++;
702 break;
703 case SYSINFO_RC_ERROR:
704 dwErrorCode = ERR_INTERNAL_ERROR;
705 m_dwFailedRequests++;
706 break;
82493366
VK
707 case SYSINFO_RC_NO_SUCH_INSTANCE:
708 dwErrorCode = ERR_NO_SUCH_INSTANCE;
709 m_dwFailedRequests++;
710 break;
5039dede
AK
711 case SYSINFO_RC_UNSUPPORTED:
712 dwErrorCode = ERR_UNKNOWN_PARAMETER;
713 m_dwUnsupportedRequests++;
714 break;
715 default:
87fff547 716 nxlog_write(MSG_UNEXPECTED_IRC, EVENTLOG_ERROR_TYPE, "ds", rc, param);
5039dede
AK
717 dwErrorCode = ERR_INTERNAL_ERROR;
718 m_dwFailedRequests++;
719 break;
720 }
721 break;
722 }
9795113c
VK
723 }
724
5039dede
AK
725 if (i == m_iNumParams)
726 {
87fff547 727 rc = GetParameterValueFromExtProvider(param, value);
9795113c
VK
728 if (rc == SYSINFO_RC_SUCCESS)
729 {
730 dwErrorCode = ERR_SUCCESS;
731 m_dwProcessedRequests++;
732 }
733 else
734 {
735 dwErrorCode = ERR_UNKNOWN_PARAMETER;
83b20bab
VK
736 }
737 }
738
739 if ((dwErrorCode == ERR_UNKNOWN_PARAMETER) && (i == m_iNumParams))
740 {
87fff547 741 dwErrorCode = GetParameterValueFromAppAgent(param, value);
83b20bab
VK
742 if (dwErrorCode == ERR_SUCCESS)
743 {
744 m_dwProcessedRequests++;
745 }
746 else if (dwErrorCode != ERR_UNKNOWN_PARAMETER)
747 {
748 m_dwFailedRequests++;
9795113c 749 }
5039dede 750 }
0df58041 751
0f506caa 752 if ((dwErrorCode == ERR_UNKNOWN_PARAMETER) && (i == m_iNumParams))
0df58041 753 {
87fff547 754 dwErrorCode = GetParameterValueFromExtSubagent(param, value);
0df58041
VK
755 if (dwErrorCode == ERR_SUCCESS)
756 {
757 m_dwProcessedRequests++;
758 }
759 else if (dwErrorCode == ERR_UNKNOWN_PARAMETER)
760 {
761 m_dwUnsupportedRequests++;
762 }
763 else
764 {
765 m_dwFailedRequests++;
766 }
767 }
09c6a939 768
da8453a5 769 session->debugPrintf(7, _T("GetParameterValue(): result is %d (%s)"), (int)dwErrorCode,
09c6a939 770 dwErrorCode == ERR_SUCCESS ? _T("SUCCESS") : (dwErrorCode == ERR_UNKNOWN_PARAMETER ? _T("UNKNOWN_PARAMETER") : _T("INTERNAL_ERROR")));
5039dede
AK
771 return dwErrorCode;
772}
773
0f506caa
VK
774/**
775 * Get list's value
776 */
da8453a5 777UINT32 GetListValue(const TCHAR *param, StringList *value, AbstractCommSession *session)
5039dede
AK
778{
779 int i, rc;
967893bb 780 UINT32 dwErrorCode;
5039dede 781
da8453a5 782 session->debugPrintf(5, _T("Requesting list \"%s\""), param);
5039dede 783 for(i = 0; i < m_iNumEnums; i++)
0f506caa 784 {
87fff547 785 if (MatchString(m_pEnumList[i].name, param, FALSE))
4687826e 786 {
87fff547 787 rc = m_pEnumList[i].handler(param, m_pEnumList[i].arg, value, session);
4687826e
VK
788 switch(rc)
789 {
790 case SYSINFO_RC_SUCCESS:
791 dwErrorCode = ERR_SUCCESS;
792 m_dwProcessedRequests++;
793 break;
794 case SYSINFO_RC_ERROR:
795 dwErrorCode = ERR_INTERNAL_ERROR;
796 m_dwFailedRequests++;
797 break;
82493366
VK
798 case SYSINFO_RC_NO_SUCH_INSTANCE:
799 dwErrorCode = ERR_NO_SUCH_INSTANCE;
800 m_dwFailedRequests++;
801 break;
4687826e
VK
802 case SYSINFO_RC_UNSUPPORTED:
803 dwErrorCode = ERR_UNKNOWN_PARAMETER;
804 m_dwUnsupportedRequests++;
805 break;
806 default:
87fff547 807 nxlog_write(MSG_UNEXPECTED_IRC, EVENTLOG_ERROR_TYPE, "ds", rc, param);
4687826e
VK
808 dwErrorCode = ERR_INTERNAL_ERROR;
809 m_dwFailedRequests++;
810 break;
811 }
812 break;
813 }
0f506caa
VK
814 }
815
816 if (i == m_iNumEnums)
4687826e 817 {
87fff547 818 dwErrorCode = GetListValueFromExtSubagent(param, value);
0f506caa
VK
819 if (dwErrorCode == ERR_SUCCESS)
820 {
821 m_dwProcessedRequests++;
822 }
823 else if (dwErrorCode == ERR_UNKNOWN_PARAMETER)
824 {
825 m_dwUnsupportedRequests++;
826 }
827 else
828 {
829 m_dwFailedRequests++;
830 }
4687826e 831 }
09c6a939 832
da8453a5 833 session->debugPrintf(7, _T("GetListValue(): result is %d (%s)"), (int)dwErrorCode,
09c6a939 834 dwErrorCode == ERR_SUCCESS ? _T("SUCCESS") : (dwErrorCode == ERR_UNKNOWN_PARAMETER ? _T("UNKNOWN_PARAMETER") : _T("INTERNAL_ERROR")));
4687826e
VK
835 return dwErrorCode;
836}
837
0f506caa
VK
838/**
839 * Get table's value
840 */
da8453a5 841UINT32 GetTableValue(const TCHAR *param, Table *value, AbstractCommSession *session)
4687826e
VK
842{
843 int i, rc;
967893bb 844 UINT32 dwErrorCode;
4687826e 845
da8453a5 846 session->debugPrintf(5, _T("Requesting table \"%s\""), param);
4687826e 847 for(i = 0; i < m_iNumTables; i++)
0f506caa 848 {
87fff547 849 if (MatchString(m_pTableList[i].name, param, FALSE))
5039dede 850 {
cb97f4dd
VK
851 // pre-fill table columns if specified in table definition
852 if (m_pTableList[i].numColumns > 0)
853 {
854 for(int c = 0; c < m_pTableList[i].numColumns; c++)
855 {
856 NETXMS_SUBAGENT_TABLE_COLUMN *col = &m_pTableList[i].columns[c];
857 value->addColumn(col->name, col->dataType, col->displayName, col->isInstance);
858 }
859 }
860
87fff547 861 rc = m_pTableList[i].handler(param, m_pTableList[i].arg, value, session);
5039dede
AK
862 switch(rc)
863 {
864 case SYSINFO_RC_SUCCESS:
865 dwErrorCode = ERR_SUCCESS;
866 m_dwProcessedRequests++;
867 break;
868 case SYSINFO_RC_ERROR:
869 dwErrorCode = ERR_INTERNAL_ERROR;
870 m_dwFailedRequests++;
871 break;
82493366
VK
872 case SYSINFO_RC_NO_SUCH_INSTANCE:
873 dwErrorCode = ERR_NO_SUCH_INSTANCE;
874 m_dwFailedRequests++;
875 break;
5039dede
AK
876 case SYSINFO_RC_UNSUPPORTED:
877 dwErrorCode = ERR_UNKNOWN_PARAMETER;
878 m_dwUnsupportedRequests++;
879 break;
880 default:
87fff547 881 nxlog_write(MSG_UNEXPECTED_IRC, EVENTLOG_ERROR_TYPE, "ds", rc, param);
5039dede
AK
882 dwErrorCode = ERR_INTERNAL_ERROR;
883 m_dwFailedRequests++;
884 break;
885 }
886 break;
887 }
0f506caa
VK
888 }
889
890 if (i == m_iNumTables)
5039dede 891 {
87fff547 892 dwErrorCode = GetTableValueFromExtSubagent(param, value);
0f506caa
VK
893 if (dwErrorCode == ERR_SUCCESS)
894 {
895 m_dwProcessedRequests++;
896 }
897 else if (dwErrorCode == ERR_UNKNOWN_PARAMETER)
898 {
899 m_dwUnsupportedRequests++;
900 }
901 else
902 {
903 m_dwFailedRequests++;
904 }
5039dede 905 }
09c6a939 906
da8453a5 907 session->debugPrintf(7, _T("GetTableValue(): result is %d (%s)"), (int)dwErrorCode,
09c6a939 908 dwErrorCode == ERR_SUCCESS ? _T("SUCCESS") : (dwErrorCode == ERR_UNKNOWN_PARAMETER ? _T("UNKNOWN_PARAMETER") : _T("INTERNAL_ERROR")));
5039dede
AK
909 return dwErrorCode;
910}
911
0f506caa
VK
912/**
913 * Put complete list of supported parameters into NXCP message
914 */
b368969c 915void GetParameterList(NXCPMessage *pMsg)
5039dede
AK
916{
917 int i;
967893bb 918 UINT32 dwId, count;
5039dede 919
f480bdd4 920 // Parameters
8f9299d1 921 for(i = 0, count = 0, dwId = VID_PARAM_LIST_BASE; i < m_iNumParams; i++)
5039dede 922 {
4687826e 923 if (m_pParamList[i].dataType != DCI_DT_DEPRECATED)
8f9299d1 924 {
b368969c
VK
925 pMsg->setField(dwId++, m_pParamList[i].name);
926 pMsg->setField(dwId++, m_pParamList[i].description);
927 pMsg->setField(dwId++, (WORD)m_pParamList[i].dataType);
c8abed74 928 count++;
8f9299d1 929 }
f480bdd4 930 }
9795113c 931 ListParametersFromExtProviders(pMsg, &dwId, &count);
0df58041 932 ListParametersFromExtSubagents(pMsg, &dwId, &count);
b368969c 933 pMsg->setField(VID_NUM_PARAMETERS, count);
f480bdd4
VK
934
935 // Push parameters
b368969c 936 pMsg->setField(VID_NUM_PUSH_PARAMETERS, (UINT32)m_iNumPushParams);
f480bdd4
VK
937 for(i = 0, dwId = VID_PUSHPARAM_LIST_BASE; i < m_iNumPushParams; i++)
938 {
b368969c
VK
939 pMsg->setField(dwId++, m_pPushParamList[i].name);
940 pMsg->setField(dwId++, m_pPushParamList[i].description);
941 pMsg->setField(dwId++, (WORD)m_pPushParamList[i].dataType);
f480bdd4
VK
942 }
943
4687826e 944 // Lists
b368969c 945 pMsg->setField(VID_NUM_ENUMS, (UINT32)m_iNumEnums);
f480bdd4
VK
946 for(i = 0, dwId = VID_ENUM_LIST_BASE; i < m_iNumEnums; i++)
947 {
b368969c 948 pMsg->setField(dwId++, m_pEnumList[i].name);
4687826e 949 }
0f506caa 950 ListListsFromExtSubagents(pMsg, &dwId, &count);
4687826e
VK
951
952 // Tables
b368969c 953 pMsg->setField(VID_NUM_TABLES, (UINT32)m_iNumTables);
4687826e
VK
954 for(i = 0, dwId = VID_TABLE_LIST_BASE; i < m_iNumTables; i++)
955 {
b368969c
VK
956 pMsg->setField(dwId++, m_pTableList[i].name);
957 pMsg->setField(dwId++, m_pTableList[i].instanceColumns);
958 pMsg->setField(dwId++, m_pTableList[i].description);
5039dede 959 }
0f506caa
VK
960 ListTablesFromExtSubagents(pMsg, &dwId, &count);
961}
962
963/**
964 * Put list of supported tables into NXCP message
965 */
b368969c 966void GetTableList(NXCPMessage *pMsg)
0f506caa
VK
967{
968 int i;
967893bb 969 UINT32 dwId, count;
0f506caa 970
b368969c 971 pMsg->setField(VID_NUM_TABLES, (UINT32)m_iNumTables);
0f506caa
VK
972 for(i = 0, dwId = VID_TABLE_LIST_BASE; i < m_iNumTables; i++)
973 {
b368969c
VK
974 pMsg->setField(dwId++, m_pTableList[i].name);
975 pMsg->setField(dwId++, m_pTableList[i].instanceColumns);
976 pMsg->setField(dwId++, m_pTableList[i].description);
0f506caa
VK
977 }
978 ListTablesFromExtSubagents(pMsg, &dwId, &count);
979}
980
981/**
982 * Put list of supported lists (enums) into NXCP message
983 */
b368969c 984void GetEnumList(NXCPMessage *pMsg)
0f506caa
VK
985{
986 int i;
967893bb 987 UINT32 dwId, count;
0f506caa 988
b368969c 989 pMsg->setField(VID_NUM_ENUMS, (UINT32)m_iNumEnums);
0f506caa
VK
990 for(i = 0, dwId = VID_ENUM_LIST_BASE; i < m_iNumEnums; i++)
991 {
b368969c 992 pMsg->setField(dwId++, m_pEnumList[i].name);
0f506caa
VK
993 }
994 ListListsFromExtSubagents(pMsg, &dwId, &count);
5039dede 995}