added basic check for agent running in VM
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 14 Jul 2017 08:17:04 +0000 (11:17 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 14 Jul 2017 08:17:04 +0000 (11:17 +0300)
configure.ac
include/nms_agent.h
src/agent/core/getparam.cpp

index 2a66318..434aa39 100644 (file)
@@ -1701,6 +1701,31 @@ AC_CHECK_HEADERS([net/if.h net/if_arp.h net/if_dl.h net/if_types.h],,,
 
 
 #--------------------------------------------------------------------
+# Checks for __get_cpuid
+#--------------------------------------------------------------------
+
+AC_CHECK_HEADERS([cpuid.h])
+AC_MSG_CHECKING(for __get_cpuid)
+AC_LANG_PUSH([C++])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#if HAVE_CPUID_H
+#include <cpuid.h>
+#endif
+]],[[
+       unsigned int eax, ebx, ecx, edx;
+       return __get_cpuid(0x01, &eax, &ebx, &ecx, &edx);
+]])
+],[
+       AC_MSG_RESULT(yes)
+       AC_DEFINE(HAVE_GET_CPUID,1,Define to 1 if __get_cpuid function is available)
+],[
+       AC_MSG_RESULT(no)
+       AC_DEFINE(HAVE_GET_CPUID,0,Define to 1 if __get_cpuid function is available)
+])
+AC_LANG_POP([C++])
+
+
+#--------------------------------------------------------------------
 # Checks for alloca
 #--------------------------------------------------------------------
 
index eca8810..30a8b8e 100644 (file)
 #define DCIDESC_SYSTEM_CPU_MODEL                  _T("CPU {instance}: model")
 #define DCIDESC_SYSTEM_CPU_PHYSICAL_ID            _T("CPU {instance}: physical ID")
 #define DCIDESC_SYSTEM_HOSTNAME                   _T("Host name")
+#define DCIDESC_SYSTEM_IS_VIRTUAL                 _T("Virtual system indicator")
 #define DCIDESC_SYSTEM_MEMORY_PHYSICAL_AVAILABLE  _T("Available physical memory")
 #define DCIDESC_SYSTEM_MEMORY_PHYSICAL_AVAILABLE_PCT _T("Percentage of available physical memory")
 #define DCIDESC_SYSTEM_MEMORY_PHYSICAL_BUFFERS    _T("Physical memory used for buffers")
index be65668..002ae39 100644 (file)
 
 #include "nxagentd.h"
 
+#if HAVE_CPUID_H
+#include <cpuid.h>
+#endif
+
 /**
  * Parameter handlers
  */
@@ -242,6 +246,36 @@ static LONG H_FlagValue(const TCHAR *param, const TCHAR *arg, TCHAR *value, Abst
    return SYSINFO_RC_SUCCESS;
 }
 
+#if HAVE_GET_CPUID
+
+/**
+ * Handler for System.IsVirtual parameter
+ */
+static LONG H_SystemIsVirtual(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session)
+{
+   unsigned int eax, ebx, ecx, edx;
+   if (__get_cpuid(0x1, &eax, &ebx, &ecx, &edx) != 1)
+      return SYSINFO_RC_UNSUPPORTED;
+   ret_int(value, (ecx & 0x80000000) != 0 ? 1 : 0);
+   return SYSINFO_RC_SUCCESS;
+}
+
+#elif defined(_WIN32)
+
+/**
+ * Handler for System.IsVirtual parameter
+ */
+static LONG H_SystemIsVirtual(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session)
+{
+   int data[4];
+   __cpuid(data, 0x01);
+   ret_int(value, (data[2] & 0x80000000) != 0 ? 1 : 0);
+   return SYSINFO_RC_SUCCESS;
+}
+
+#endif
+
+
 /**
  * Standard agent's parameters
  */
@@ -267,6 +301,7 @@ static NETXMS_SUBAGENT_PARAM m_stdParams[] =
    { _T("PhysicalDisk.Temperature(*)"), H_PhysicalDiskInfo, _T("T"), DCI_DT_INT, DCIDESC_PHYSICALDISK_TEMPERATURE },
    { _T("System.CPU.Count"), H_CPUCount, NULL, DCI_DT_UINT, DCIDESC_SYSTEM_CPU_COUNT },
    { _T("System.Hostname"), H_HostName, NULL, DCI_DT_STRING, DCIDESC_SYSTEM_HOSTNAME },
+   { _T("System.IsVirtual"), H_SystemIsVirtual, NULL, DCI_DT_INTEGER, DCIDESC_SYSTEM_IS_VIRTUAL },
    { _T("System.Memory.Physical.Available"), H_MemoryInfo, (TCHAR *)MEMINFO_PHYSICAL_FREE, DCI_DT_UINT64, DCIDESC_SYSTEM_MEMORY_PHYSICAL_AVAILABLE },
    { _T("System.Memory.Physical.AvailablePerc"), H_MemoryInfo, (TCHAR *)MEMINFO_PHYSICAL_FREE_PCT, DCI_DT_FLOAT, DCIDESC_SYSTEM_MEMORY_PHYSICAL_AVAILABLE_PCT },
    { _T("System.Memory.Physical.Free"), H_MemoryInfo, (TCHAR *)MEMINFO_PHYSICAL_FREE, DCI_DT_UINT64, DCIDESC_SYSTEM_MEMORY_PHYSICAL_FREE },
@@ -282,6 +317,10 @@ static NETXMS_SUBAGENT_PARAM m_stdParams[] =
    { _T("System.Uname"), H_SystemUname, NULL, DCI_DT_STRING, DCIDESC_SYSTEM_UNAME },
 #endif
 
+#if HAVE_GET_CPUID
+   { _T("System.IsVirtual"), H_SystemIsVirtual, NULL, DCI_DT_INT, DCIDESC_SYSTEM_IS_VIRTUAL },
+#endif
+
    { _T("Agent.AcceptedConnections"), H_UIntPtr, (TCHAR *)&g_acceptedConnections, DCI_DT_UINT, DCIDESC_AGENT_ACCEPTEDCONNECTIONS },
    { _T("Agent.AcceptErrors"), H_UIntPtr, (TCHAR *)&g_acceptErrors, DCI_DT_UINT, DCIDESC_AGENT_ACCEPTERRORS },
    { _T("Agent.ActiveConnections"), H_ActiveConnections, NULL, DCI_DT_UINT, DCIDESC_AGENT_ACTIVECONNECTIONS },