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