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