initial version of XEN subagent
authorVictor Kirhenshtein <victor@netxms.org>
Mon, 17 Jul 2017 18:37:05 +0000 (21:37 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Mon, 17 Jul 2017 18:37:05 +0000 (21:37 +0300)
ChangeLog
configure.ac
src/agent/subagents/xen/.cproject [new file with mode: 0644]
src/agent/subagents/xen/.project [new file with mode: 0644]
src/agent/subagents/xen/.settings/language.settings.xml [new file with mode: 0644]
src/agent/subagents/xen/Makefile.am [new file with mode: 0644]
src/agent/subagents/xen/host.cpp [new file with mode: 0644]
src/agent/subagents/xen/vm.cpp [new file with mode: 0644]
src/agent/subagents/xen/xen.cpp [new file with mode: 0644]
src/agent/subagents/xen/xen.h [new file with mode: 0644]

index b9abd86..650166e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@
 * 2.1.1
 *
 
+- XEN monitoring subagent
+- Fixed issues with agent tunnels
 - Management console:
        - Improved status map
 
index 434aa39..04b6875 100644 (file)
@@ -109,8 +109,13 @@ DISABLE_READLINE="yes"
 TUXEDO_LIBS=""
 TUXEDO_TPINIT=""
 MONGODB_LIBS=""
+VMGR_CPPFLAGS=""
+VMGR_LDFLAGS=""
 VMGR_LIBS=""
 LIBVIRT_BASE=""
+XEN_CPPFLAGS=""
+XEN_LDFLAGS=""
+XEN_LIBS=""
 DISABLE_IPV6="no"
 IPV6_SUPPORT="no"
 INSTALL_LIBPATH=""
@@ -357,6 +362,12 @@ AC_ARG_WITH(libvirt,
        fi
 fi ])
 
+AC_ARG_WITH(xen,
+[AS_HELP_STRING(--with-xen,build XEN subagent)],
+[ if test "x$withval" != "xno" ; then
+       COMPONENTS="$COMPONENTS xen"
+fi ])
+
 AC_ARG_WITH(sqlite,
 [AS_HELP_STRING(--with-sqlite,build SQLite database driver)],
 [ if test "x$withval" != "xno" ; then
@@ -684,7 +695,7 @@ AC_ARG_WITH(dist,
 [AS_HELP_STRING(--with-dist,for maintainers only)],
        DB_DRIVERS="mysql mariadb pgsql odbc mssql sqlite oracle db2 informix"
        MODULES="appagent jansson libexpat libstrophe libtre zlib libnetxms install sqlite snmp libnxsl libnxmb libnxlp libnxcc db server smsdrv agent client nxscript nxcproxy nxlptest tools"
-       SUBAGENT_DIRS="linux ds18x20 freebsd openbsd minix mqtt mysql netbsd sunos aix ipso hpux odbcquery informix oracle lmsensors darwin rpi java jmx bind9 ubntlw netsvc db2 tuxedo mongodb ssh vmgr"
+       SUBAGENT_DIRS="linux ds18x20 freebsd openbsd minix mqtt mysql netbsd sunos aix ipso hpux odbcquery informix oracle lmsensors darwin rpi java jmx bind9 ubntlw netsvc db2 tuxedo mongodb ssh vmgr xen"
        AGENT_DIRS="libnxtux"
        SMSDRV_DIRS="anysms kannel mymobile nexmo nxagent slack smseagle text2reach websms"
    HDLINK_DIRS="jira redmine"
@@ -983,6 +994,11 @@ if test $? = 0; then
        SUBAGENT_DIRS="$SUBAGENT_DIRS vmgr"
 fi
 
+check_substr "$COMPONENTS" "xen"
+if test $? = 0; then
+       SUBAGENT_DIRS="$SUBAGENT_DIRS xen"
+fi
+
 check_substr "$COMPONENTS" "sdk"
 if test $? = 0; then
        if test "x$STATIC_BUILD" = "xyes"; then
@@ -3294,6 +3310,26 @@ if test $? = 0; then
        LIBS="$OLD_LIBS"
 fi
 
+
+#--------------------------------------------------------------------
+# XEN
+#--------------------------------------------------------------------
+
+check_substr "$COMPONENTS" "xen"
+if test $? = 0; then
+       OLD_CPPFLAGS="$CPPFLAGS"
+       OLD_LDFLAGS="$LDFLAGS"
+       OLD_LIBS="$LIBS"
+
+       AC_CHECK_HEADER(libxl.h,,AC_MSG_ERROR([*** Cannot find libxl.h - check your libxen installation ***]))
+       AC_CHECK_LIB(xenlight, libxl_ctx_alloc, [ XEN_LIBS="$XEN_LIBS -lxenlight" ])
+       AC_CHECK_LIB(xenctrl, xc_vcpu_getinfo, [ XEN_LIBS="$XEN_LIBS -lxenctrl" ])
+
+       CPPFLAGS="$OLD_CPPFLAGS"
+       LDFLAGS="$OLD_LDFLAGS"
+       LIBS="$OLD_LIBS"
+fi
+
 #--------------------------------------------------------------------
 # Other settings
 #--------------------------------------------------------------------
@@ -3424,6 +3460,7 @@ AC_SUBST(DB2_LIBS)
 AC_SUBST(INFORMIX_CPPFLAGS)
 AC_SUBST(INFORMIX_LDFLAGS)
 AC_SUBST(INFORMIX_LIBS)
+AC_SUBST(INSTALL_LIBPATH)
 AC_SUBST(OBJECT_MODE)
 AC_SUBST(SQLFLAGS)
 AC_SUBST(SHLIB_SUFFIX)
@@ -3440,7 +3477,9 @@ AC_SUBST(MQTT_LIBS)
 AC_SUBST(VMGR_CPPFLAGS)
 AC_SUBST(VMGR_LDFLAGS)
 AC_SUBST(VMGR_LIBS)
-AC_SUBST(INSTALL_LIBPATH)
+AC_SUBST(XEN_CPPFLAGS)
+AC_SUBST(XEN_LDFLAGS)
+AC_SUBST(XEN_LIBS)
 AC_SUBST(ZEROMQ_CPPFLAGS)
 AC_SUBST(ZEROMQ_LDFLAGS)
 
@@ -3557,6 +3596,7 @@ AC_CONFIG_FILES([
        src/agent/subagents/winnt/Makefile
        src/agent/subagents/winperf/Makefile
        src/agent/subagents/wmi/Makefile
+       src/agent/subagents/xen/Makefile
        src/agent/tools/Makefile
        src/agent/tools/nxappget/Makefile
        src/agent/tools/nxapush/Makefile
@@ -3933,6 +3973,16 @@ if test "x${VMGR_LIBS}" != "x"; then
        echo "Vmgr LIBS               : ${VMGR_LIBS}"
 fi
 
+if test "x${XEN_CPPFLAGS}" != "x"; then
+       echo "XEN CPPFLAGS            : ${XEN_CPPFLAGS}"
+fi
+if test "x${XEN_LDFLAGS}" != "x"; then
+       echo "XEN LDFLAGS             : ${XEN_LDFLAGS}"
+fi
+if test "x${XEN_LIBS}" != "x"; then
+       echo "XEN LIBS                : ${XEN_LIBS}"
+fi
+
 FLAGS_CPP="src/tools/nxdevcfg/flags.cpp"
 echo "/* Automatically generated by configure */" > $FLAGS_CPP
 echo "#include <nms_common.h>" >> $FLAGS_CPP
diff --git a/src/agent/subagents/xen/.cproject b/src/agent/subagents/xen/.cproject
new file mode 100644 (file)
index 0000000..8a46400
--- /dev/null
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+       <storageModule moduleId="org.eclipse.cdt.core.settings">
+               <cconfiguration id="cdt.managedbuild.toolchain.gnu.base.1879118006">
+                       <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.1879118006" moduleId="org.eclipse.cdt.core.settings" name="Default">
+                               <externalSettings/>
+                               <extensions>
+                                       <extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
+                                       <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                               </extensions>
+                       </storageModule>
+                       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+                               <configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.1879118006" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
+                                       <folderInfo id="cdt.managedbuild.toolchain.gnu.base.1879118006.618236511" name="/" resourcePath="">
+                                               <toolChain id="cdt.managedbuild.toolchain.gnu.base.656360340" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.base">
+                                                       <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.base.1432132950" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
+                                                       <builder id="cdt.managedbuild.target.gnu.builder.base.357956055" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.archiver.base.1745594922" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1323409798" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
+                                                               <option id="gnu.cpp.compiler.option.include.paths.1091427981" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}/include&quot;"/>
+                                                               </option>
+                                                               <option id="gnu.cpp.compiler.option.preprocessor.def.837873137" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols">
+                                                                       <listOptionValue builtIn="false" value="_THREAD_SAFE"/>
+                                                                       <listOptionValue builtIn="false" value="TRE_WCHAR=1"/>
+                                                                       <listOptionValue builtIn="false" value="UNICODE"/>
+                                                                       <listOptionValue builtIn="false" value="_GNU_SOURCE"/>
+                                                               </option>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1947725873" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
+                                                       </tool>
+                                                       <tool id="cdt.managedbuild.tool.gnu.c.compiler.base.533829074" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
+                                                               <option id="gnu.c.compiler.option.include.paths.1883983763" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}/include&quot;"/>
+                                                               </option>
+                                                               <option id="gnu.c.compiler.option.preprocessor.def.symbols.768561745" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" useByScannerDiscovery="false" valueType="definedSymbols">
+                                                                       <listOptionValue builtIn="false" value="_THREAD_SAFE"/>
+                                                                       <listOptionValue builtIn="false" value="TRE_WCHAR=1"/>
+                                                                       <listOptionValue builtIn="false" value="UNICODE"/>
+                                                                       <listOptionValue builtIn="false" value="_GNU_SOURCE"/>
+                                                               </option>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1444968183" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
+                                                       </tool>
+                                                       <tool id="cdt.managedbuild.tool.gnu.c.linker.base.730989706" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.1839192823" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
+                                                               <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.52304013" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
+                                                                       <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
+                                                                       <additionalInput kind="additionalinput" paths="$(LIBS)"/>
+                                                               </inputType>
+                                                       </tool>
+                                                       <tool id="cdt.managedbuild.tool.gnu.assembler.base.1627015329" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
+                                                               <option id="gnu.both.asm.option.include.paths.584538064" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}/include&quot;"/>
+                                                               </option>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1650631957" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
+                                                       </tool>
+                                               </toolChain>
+                                       </folderInfo>
+                               </configuration>
+                       </storageModule>
+                       <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+               </cconfiguration>
+       </storageModule>
+       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+               <project id="xen.null.192690484" name="xen"/>
+       </storageModule>
+       <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+       <storageModule moduleId="refreshScope"/>
+       <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
+       <storageModule moduleId="scannerConfiguration">
+               <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+               <scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.1879118006;cdt.managedbuild.toolchain.gnu.base.1879118006.618236511;cdt.managedbuild.tool.gnu.c.compiler.base.533829074;cdt.managedbuild.tool.gnu.c.compiler.input.1444968183">
+                       <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+               </scannerConfigBuildInfo>
+               <scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.1879118006;cdt.managedbuild.toolchain.gnu.base.1879118006.618236511;cdt.managedbuild.tool.gnu.cpp.compiler.base.1323409798;cdt.managedbuild.tool.gnu.cpp.compiler.input.1947725873">
+                       <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+               </scannerConfigBuildInfo>
+       </storageModule>
+</cproject>
diff --git a/src/agent/subagents/xen/.project b/src/agent/subagents/xen/.project
new file mode 100644 (file)
index 0000000..0cfca65
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>xen</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+                       <triggers>clean,full,incremental,</triggers>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+                       <triggers>full,incremental,</triggers>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.cdt.core.cnature</nature>
+               <nature>org.eclipse.cdt.core.ccnature</nature>
+               <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+               <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+       </natures>
+</projectDescription>
diff --git a/src/agent/subagents/xen/.settings/language.settings.xml b/src/agent/subagents/xen/.settings/language.settings.xml
new file mode 100644 (file)
index 0000000..44f22b2
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<project>
+       <configuration id="cdt.managedbuild.toolchain.gnu.base.1879118006" name="Default">
+               <extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
+                       <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
+                       <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
+                       <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                               <language-scope id="org.eclipse.cdt.core.gcc"/>
+                               <language-scope id="org.eclipse.cdt.core.g++"/>
+                       </provider>
+                       <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
+               </extension>
+       </configuration>
+</project>
diff --git a/src/agent/subagents/xen/Makefile.am b/src/agent/subagents/xen/Makefile.am
new file mode 100644 (file)
index 0000000..69b6077
--- /dev/null
@@ -0,0 +1,18 @@
+SUBAGENT = xen
+
+pkglib_LTLIBRARIES = xen.la
+xen_la_SOURCES = host.cpp vm.cpp xen.cpp
+xen_la_CPPFLAGS=-I@top_srcdir@/include @XEN_CPPFLAGS@
+xen_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym @XEN_LDFLAGS@
+xen_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la @XEN_LIBS@
+
+EXTRA_DIST = xen.h xen.vcproj
+
+if !STATIC_BUILD
+install-exec-hook:
+       if test "x`uname -s`" = "xAIX" ; then OBJECT_MODE=@OBJECT_MODE@ $(AR) x $(DESTDIR)$(pkglibdir)/$(SUBAGENT).a $(DESTDIR)$(pkglibdir)/$(SUBAGENT)@SHLIB_SUFFIX@ ; rm -f $(DESTDIR)$(pkglibdir)/$(SUBAGENT).a ; fi
+       mv -f $(DESTDIR)$(pkglibdir)/$(SUBAGENT)@SHLIB_SUFFIX@ $(DESTDIR)$(pkglibdir)/$(SUBAGENT).nsm
+       rm -f $(DESTDIR)$(pkglibdir)/$(SUBAGENT).la
+       rm -f $(DESTDIR)$(libdir)/libnsm_$(SUBAGENT)@SHLIB_SUFFIX@
+       ln -s netxms/$(SUBAGENT).nsm $(DESTDIR)$(libdir)/libnsm_$(SUBAGENT)@SHLIB_SUFFIX@
+endif
diff --git a/src/agent/subagents/xen/host.cpp b/src/agent/subagents/xen/host.cpp
new file mode 100644 (file)
index 0000000..ea60a15
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+** NetXMS XEN hypervisor subagent
+** Copyright (C) 2017 Raden Solutions
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: host.cpp
+**
+**/
+
+#include "xen.h"
+
+/**
+ * Handler for XEN.Host.Version
+ */
+LONG H_XenHostVersion(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session)
+{
+   libxl_ctx *ctx;
+   XEN_CONNECT(ctx);
+
+   const libxl_version_info *v = libxl_get_version_info(ctx);
+   _sntprintf(value, MAX_RESULT_LENGTH, _T("%d.%d%hs"), v->xen_version_major, v->xen_version_minor, v->xen_version_extra);
+
+   libxl_ctx_free(ctx);
+   return SYSINFO_RC_SUCCESS;
+}
diff --git a/src/agent/subagents/xen/vm.cpp b/src/agent/subagents/xen/vm.cpp
new file mode 100644 (file)
index 0000000..aca822d
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+** NetXMS XEN hypervisor subagent
+** Copyright (C) 2017 Raden Solutions
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: vm.cpp
+**
+**/
+
+#include "xen.h"
+
+/**
+ * Handler for XEN.VirtualMachines list
+ */
+LONG H_XenDomainList(const TCHAR *param, const TCHAR *arg, StringList *value, AbstractCommSession *session)
+{
+   libxl_ctx *ctx;
+   XEN_CONNECT(ctx);
+
+   LONG rc = SYSINFO_RC_ERROR;
+
+   int count = 0;
+   libxl_dominfo *domains = libxl_list_domain(ctx, &count);
+   if (domains != NULL)
+   {
+      for(int i = 0; i < count; i++)
+      {
+         value->addMBString(libxl_domid_to_name(ctx, domains[i].domid));
+      }
+      libxl_dominfo_list_free(domains, count);
+      rc = SYSINFO_RC_SUCCESS;
+   }
+   else
+   {
+      nxlog_debug(4, _T("XEN: call to libxl_list_domain failed"));
+   }
+
+   libxl_ctx_free(ctx);
+   return rc;
+}
+
+/**
+ * Handler for XEN.VirtualMachines table
+ */
+LONG H_XenDomainTable(const TCHAR *param, const TCHAR *arg, Table *value, AbstractCommSession *session)
+{
+   libxl_ctx *ctx;
+   XEN_CONNECT(ctx);
+
+   LONG rc = SYSINFO_RC_ERROR;
+
+   int count = 0;
+   libxl_dominfo *domains = libxl_list_domain(ctx, &count);
+   if (domains != NULL)
+   {
+      value->addColumn(_T("ID"), DCI_DT_INT, _T("ID"), true);
+      value->addColumn(_T("NAME"), DCI_DT_STRING, _T("Name"));
+      value->addColumn(_T("STATE"), DCI_DT_STRING, _T("State"));
+      value->addColumn(_T("MEM_CURRENT"), DCI_DT_UINT64, _T("Current memory"));
+      value->addColumn(_T("MEM_SHARED"), DCI_DT_UINT64, _T("Shared memory"));
+      value->addColumn(_T("MEM_PAGED"), DCI_DT_UINT64, _T("Paged memory"));
+      value->addColumn(_T("MEM_OUTSTANDING"), DCI_DT_UINT64, _T("Outstanding memory"));
+      value->addColumn(_T("MEM_MAX"), DCI_DT_UINT64, _T("Max memory"));
+      value->addColumn(_T("CPU_COUNT"), DCI_DT_INT, _T("CPU count"));
+      value->addColumn(_T("CPU_TIME"), DCI_DT_UINT64, _T("CPU time"));
+
+      for(int i = 0; i < count; i++)
+      {
+         value->addRow();
+
+         libxl_dominfo *d = &domains[i];
+         value->set(0, d->domid);
+         value->set(1, libxl_domid_to_name(ctx, d->domid));
+
+         TCHAR state[6] = _T("-----");
+         if (d->running)
+            state[0] = _T('R');
+         if (d->blocked)
+            state[1] = _T('B');
+         if (d->paused)
+            state[2] = _T('P');
+         if (d->shutdown)
+            state[3] = _T('S');
+         if (d->dying)
+            state[4] = _T('D');
+         value->set(2, state);
+
+         value->set(3, d->current_memkb * _LL(1024));
+         value->set(4, d->shared_memkb * _LL(1024));
+         value->set(5, d->paged_memkb * _LL(1024));
+         value->set(6, d->outstanding_memkb * _LL(1024));
+         value->set(7, d->max_memkb * _LL(1024));
+
+         value->set(8, d->vcpu_online);
+         value->set(9, (UINT64)d->cpu_time);
+      }
+      libxl_dominfo_list_free(domains, count);
+      rc = SYSINFO_RC_SUCCESS;
+   }
+   else
+   {
+      nxlog_debug(4, _T("XEN: call to libxl_list_domain failed"));
+   }
+
+   libxl_ctx_free(ctx);
+   return rc;
+}
diff --git a/src/agent/subagents/xen/xen.cpp b/src/agent/subagents/xen/xen.cpp
new file mode 100644 (file)
index 0000000..d1d16b8
--- /dev/null
@@ -0,0 +1,161 @@
+/*
+** NetXMS XEN hypervisor subagent
+** Copyright (C) 2017 Raden Solutions
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: xen.cpp
+**
+**/
+
+#include "xen.h"
+
+/**
+ * Handlers
+ */
+LONG H_XenDomainList(const TCHAR *param, const TCHAR *arg, StringList *value, AbstractCommSession *session);
+LONG H_XenDomainTable(const TCHAR *param, const TCHAR *arg, Table *value, AbstractCommSession *session);
+LONG H_XenHostVersion(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
+
+/**
+ * Convert XEN log level into NetXMS debug level
+ */
+inline int ConvertLogLevel(xentoollog_level level)
+{
+   if (level >= XTL_ERROR)
+      return 1;
+   if (level >= XTL_WARN)
+      return 3;
+   if (level >= XTL_NOTICE)
+      return 4;
+   return 5;
+}
+
+/**
+ * Write log message
+ */
+static void LogMessage(struct xentoollog_logger *logger,
+                     xentoollog_level level,
+                     int errnoval /* or -1 */,
+                     const char *context /* eg "xc", "xl", may be 0 */,
+                     const char *format /* without level, context, \n */,
+                     va_list al)
+{
+   char msg[4096];
+   vsnprintf(msg, 4096, format, al);
+   nxlog_debug(ConvertLogLevel(level), _T("XEN: [%hs] (%hs): %hs"), xtl_level_to_string(level), context, msg);
+}
+
+/**
+ * Write progress message
+ */
+static void LogProgress(struct xentoollog_logger *logger,
+                     const char *context /* see above */,
+                     const char *doing_what /* no \r,\n */,
+                     int percent, unsigned long done, unsigned long total)
+{
+}
+
+/**
+ * Destroy logger
+ */
+static void LogDestroy(struct xentoollog_logger *logger)
+{
+}
+
+/**
+ * Logger definition
+ */
+xentoollog_logger g_xenLogger = { LogMessage, LogProgress, LogDestroy };
+
+/**
+ * Called by master agent at unload
+ */
+static void SubagentShutdown()
+{
+}
+
+/**
+ * Subagent initialization
+ */
+static BOOL SubagentInit(Config *config)
+{
+   return TRUE;
+}
+
+/**
+ * Parameters
+ */
+static NETXMS_SUBAGENT_PARAM s_parameters[] =
+{
+       { _T("XEN.Host.Version"), H_XenHostVersion, NULL, DCI_DT_STRING, _T("XEN host: version") }
+};
+
+/**
+ * Lists
+ */
+static NETXMS_SUBAGENT_LIST s_lists[] =
+{
+       { _T("XEN.VirtualMachines"), H_XenDomainList, NULL }
+};
+
+/**
+ * Tables
+ */
+static NETXMS_SUBAGENT_TABLE s_tables[] =
+{
+    { _T("XEN.VirtualMachines"), H_XenDomainTable, NULL, _T("ID"), _T("XEN: virtual machines (domains)") }
+};
+
+/**
+ * Subagent information
+ */
+static NETXMS_SUBAGENT_INFO m_info =
+{
+       NETXMS_SUBAGENT_INFO_MAGIC,
+       _T("PING"), NETXMS_VERSION_STRING,
+       SubagentInit, SubagentShutdown, NULL,
+       sizeof(s_parameters) / sizeof(NETXMS_SUBAGENT_PARAM),
+       s_parameters,
+       sizeof(s_lists) / sizeof(NETXMS_SUBAGENT_LIST),
+       s_lists,
+       sizeof(s_tables) / sizeof(NETXMS_SUBAGENT_TABLE),
+       s_tables,       // tables
+   0, NULL,    // actions
+       0, NULL // push parameters
+};
+
+/**
+ * Entry point for NetXMS agent
+ */
+DECLARE_SUBAGENT_ENTRY_POINT(XEN)
+{
+       *ppInfo = &m_info;
+       return TRUE;
+}
+
+#ifdef _WIN32
+
+/**
+ * DLL entry point
+ */
+BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
+{
+       if (dwReason == DLL_PROCESS_ATTACH)
+               DisableThreadLibraryCalls(hInstance);
+       return TRUE;
+}
+
+#endif
diff --git a/src/agent/subagents/xen/xen.h b/src/agent/subagents/xen/xen.h
new file mode 100644 (file)
index 0000000..4c7882d
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+** NetXMS XEN hypervisor subagent
+** Copyright (C) 2017 Raden Solutions
+ **
+ ** This program is free software; you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation; either version 2 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program; if not, write to the Free Software
+ ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ **
+ **/
+
+#ifndef _xen_h_
+#define _xen_h_
+
+#include <nms_common.h>
+#include <nms_agent.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <libxl.h>
+#include <libxl_utils.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * Logger definition
+ */
+extern xentoollog_logger g_xenLogger;
+
+/**
+ * Connect to XEN host - common macro for parameter handlers
+ */
+#define XEN_CONNECT(ctx) do { \
+   int rc = libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, &g_xenLogger); \
+   if (rc != 0) \
+   { \
+      nxlog_debug(5, _T("XEN: libxl_ctx_alloc failed (%d)"), rc); \
+      return SYSINFO_RC_ERROR; \
+   } \
+} while(0)
+
+#endif