fixed OpenBSD 6.1 compatibility issues
authorvictor <victor@build-openbsd-61-x64.office.radensolutions.com>
Thu, 10 Aug 2017 18:46:46 +0000 (21:46 +0300)
committervictor <victor@build-openbsd-61-x64.office.radensolutions.com>
Thu, 10 Aug 2017 18:46:46 +0000 (21:46 +0300)
ChangeLog
configure.ac
include/nms_util.h
src/agent/subagents/openbsd/Makefile.am
src/agent/subagents/openbsd/disk.cpp
src/agent/subagents/openbsd/disk.h
src/agent/subagents/openbsd/net.cpp
src/agent/subagents/openbsd/net.h
src/agent/subagents/openbsd/openbsd.cpp
src/agent/subagents/openbsd/system.cpp
src/agent/subagents/openbsd/system.h

index 49b2965..ffd8eea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@
 - Fixed bug in STP-based topology discovery
 - Fixed unrestricted node poller queue growth when discovery from SNMP traps or syslog is on
 - Server's database password can be supplied by external tool
+- Fixed OpenBSD compatibility issues
 - NXSL:
        - New class "InetAddress"
        - New attribute "ipAddressList" for class "Interface"
index 5b2b75b..4d36bb0 100644 (file)
@@ -2414,10 +2414,16 @@ fi
 #--------------------------------------------------------------------
 
 if test "x$PLATFORM" = "xOpenBSD"; then
+       AC_CHECK_DECLS([SIOCGIFDATA],,,[
+#if HAVE_SYS_SOCKIO_H
+#include <sys/sockio.h>
+#endif
+       ])
        AC_MSG_CHECKING(if kvm_getprocs requires sizeof kinfo_proc argument)
         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 #include <sys/param.h>
 #include <sys/proc.h>
+#include <sys/sysctl.h>
 #include <kvm.h>
 #include <sys/user.h>
         ]],[[
@@ -2437,6 +2443,7 @@ if test "x$PLATFORM" = "xOpenBSD"; then
         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 #include <sys/param.h>
 #include <sys/proc.h>
+#include <sys/sysctl.h>
 #include <kvm.h>
 #include <sys/user.h>
         ]],[[
index 98f9ed3..ea275b4 100644 (file)
@@ -1514,6 +1514,7 @@ union SockAddrBuffer
 /**
  * sockaddr length calculation
  */
+#undef SA_LEN
 #ifdef WITH_IPV6
 #define SA_LEN(sa) (((sa)->sa_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))
 #else
index 765f7b9..3a1a149 100644 (file)
@@ -13,7 +13,7 @@ AM_CXXFLAGS=-fpermissive
 SUBAGENT = openbsd
 
 pkglib_LTLIBRARIES = openbsd.la
-openbsd_la_SOURCES = openbsd.cpp system.cpp disk.cpp net.cpp
+openbsd_la_SOURCES = disk.cpp net.cpp openbsd.cpp system.cpp
 openbsd_la_CPPFLAGS=-I@top_srcdir@/include
 openbsd_la_LDFLAGS = -module -avoid-version -export-symbols ../platform-subagent.sym
 openbsd_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la -lkvm
index e06fa17..16c25c8 100644 (file)
 
 #include "disk.h"
 
-LONG H_DiskInfo(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+LONG H_DiskInfo(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session)
 {
        int nRet = SYSINFO_RC_ERROR;
        char szArg[512] = {0};
        struct statfs s;
 
-       AgentGetParameterArg(pszParam, 1, szArg, sizeof(szArg));
+       AgentGetParameterArgA(pszParam, 1, szArg, sizeof(szArg));
 
        if (szArg[0] != 0 && statfs(szArg, &s) == 0)
        {
@@ -75,30 +75,3 @@ LONG H_DiskInfo(const char *pszParam, const char *pArg, char *pValue, AbstractCo
 
        return nRet;
 }
-
-///////////////////////////////////////////////////////////////////////////////
-/*
-
-$Log: not supported by cvs2svn $
-Revision 1.2  2007/09/27 09:20:41  alk
-DISK_* params fixed in all subagents
-
-Revision 1.1  2006/03/07 09:42:48  alk
-OpenBSD subagent incorporated
-flex params changed in libnxsl's makefile
-
-Revision 1.1  2005/01/17 17:14:32  alk
-freebsd agent, incomplete (but working)
-
-Revision 1.1  2004/10/22 22:08:34  alk
-source restructured;
-implemented:
-       Net.IP.Forwarding
-       Net.IP6.Forwarding
-       Process.Count(*)
-       Net.ArpCache
-       Net.InterfaceList (if-type not implemented yet)
-       System.ProcessList
-
-
-*/
index 164948e..bc2f4c5 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /* 
 ** NetXMS subagent for FreeBSD
 ** Copyright (C) 2004 Alex Kirhenshtein
@@ -34,26 +32,6 @@ enum
        DISK_TOTAL,
 };
 
-LONG H_DiskInfo(const char *, const char *, char *, AbstractCommSession *);
+LONG H_DiskInfo(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
 
 #endif // __DISK_H__
-
-///////////////////////////////////////////////////////////////////////////////
-/*
-
-$Log: not supported by cvs2svn $
-Revision 1.1  2005/01/17 17:14:32  alk
-freebsd agent, incomplete (but working)
-
-Revision 1.1  2004/10/22 22:08:34  alk
-source restructured;
-implemented:
-       Net.IP.Forwarding
-       Net.IP6.Forwarding
-       Process.Count(*)
-       Net.ArpCache
-       Net.InterfaceList (if-type not implemented yet)
-       System.ProcessList
-
-
-*/
index f77598d..0a6b410 100644 (file)
@@ -1,8 +1,6 @@
-/* $Id$ */
-
 /* 
 ** NetXMS subagent for FreeBSD
-** Copyright (C) 2004 Alex Kirhenshtein
+** Copyright (C) 2004-2017 Raden Solutions SIA
 ** Copyright (C) 2008 Mark Ibell
 **
 ** This program is free software; you can redistribute it and/or modify
 #include <kvm.h>
 #include <nlist.h>
 
+#if HAVE_NET_IF_VAR_H
+#include <net/if_var.h>
+#endif
+
 #include "net.h"
 
 typedef struct t_Addr
@@ -68,9 +70,9 @@ struct nlist nl[] = {
 
 kvm_t *kvmd = NULL;
 
-LONG H_NetIpForwarding(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+LONG H_NetIpForwarding(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *value, AbstractCommSession *session)
 {
-       int nVer = (int)pArg;
+       int nVer = CAST_FROM_POINTER(pArg, int);
        int nRet = SYSINFO_RC_ERROR;
        int mib[4];
        size_t nSize = sizeof(mib), nValSize;
@@ -91,7 +93,7 @@ LONG H_NetIpForwarding(const char *pszParam, const char *pArg, char *pValue, Abs
        {
                if (nVal == 0 || nVal == 1)
                {
-                       ret_int(pValue, nVal);
+                       ret_int(value, nVal);
                        nRet = SYSINFO_RC_SUCCESS;
                }
        }
@@ -99,12 +101,12 @@ LONG H_NetIpForwarding(const char *pszParam, const char *pArg, char *pValue, Abs
        return nRet;
 }
 
-LONG H_NetIfAdmStatus(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+LONG H_NetIfAdmStatus(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *value, AbstractCommSession *session)
 {
        int nRet = SYSINFO_RC_SUCCESS;
        char szArg[512];
 
-   AgentGetParameterArg(pszParam, 1, szArg, sizeof(szArg));
+   AgentGetParameterArgA(pszParam, 1, szArg, sizeof(szArg));
 
        if (szArg[0] != 0)
        {
@@ -131,19 +133,19 @@ LONG H_NetIfAdmStatus(const char *pszParam, const char *pArg, char *pValue, Abst
                                int flags;
 
                                memset(&ifr, 0, sizeof(ifr));
-                               nx_strncpy(ifr.ifr_name, szArg, sizeof(ifr.ifr_name));
+                               strlcpy(ifr.ifr_name, szArg, sizeof(ifr.ifr_name));
                                if (ioctl(nSocket, SIOCGIFFLAGS, (caddr_t)&ifr) >= 0)
                                {
                                        flags = ifr.ifr_flags;
                                        if ((flags & IFF_UP) == IFF_UP)
                                        {
                                                // enabled
-                                               ret_int(pValue, 1);
+                                               ret_int(value, 1);
                                                nRet = SYSINFO_RC_SUCCESS;
                                        }
                                        else
                                        {
-                                               ret_int(pValue, 2);
+                                               ret_int(value, 2);
                                                nRet = SYSINFO_RC_SUCCESS;
                                        }
                                }
@@ -155,12 +157,12 @@ LONG H_NetIfAdmStatus(const char *pszParam, const char *pArg, char *pValue, Abst
        return nRet;
 }
 
-LONG H_NetIfLink(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+LONG H_NetIfLink(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *value, AbstractCommSession *session)
 {
        int nRet = SYSINFO_RC_SUCCESS;
        char szArg[512];
 
-   AgentGetParameterArg(pszParam, 1, szArg, sizeof(szArg));
+   AgentGetParameterArgA(pszParam, 1, szArg, sizeof(szArg));
 
        if (szArg[0] != 0)
        {
@@ -186,25 +188,25 @@ LONG H_NetIfLink(const char *pszParam, const char *pArg, char *pValue, AbstractC
                                struct ifmediareq ifmr;
 
                                memset(&ifmr, 0, sizeof(ifmr));
-                               nx_strncpy(ifmr.ifm_name, szArg, sizeof(ifmr.ifm_name));
+                               strlcpy(ifmr.ifm_name, szArg, sizeof(ifmr.ifm_name));
                                if (ioctl(nSocket, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0)
                                {
                                        if ((ifmr.ifm_status & IFM_AVALID) == IFM_AVALID &&
                                                        (ifmr.ifm_status & IFM_ACTIVE) == IFM_ACTIVE)
                                        {
-                                               ret_int(pValue, 1);
+                                               ret_int(value, 1);
                                                nRet = SYSINFO_RC_SUCCESS;
                                        }
                                        else
                                        {
-                                               ret_int(pValue, 0);
+                                               ret_int(value, 0);
                                                nRet = SYSINFO_RC_SUCCESS;
                                        }
                                }
             else if (errno == EINVAL || errno == ENOTTY)
             {
                // ifmedia not supported, assume the status is NORMAL
-               ret_int(pValue, 1);
+               ret_int(value, 1);
                nRet = SYSINFO_RC_SUCCESS;
             }
                                close(nSocket);
@@ -215,7 +217,10 @@ LONG H_NetIfLink(const char *pszParam, const char *pArg, char *pValue, AbstractC
        return nRet;
 }
 
-LONG H_NetArpCache(const char *pszParam, const char *pArg, StringList *pValue, AbstractCommSession *session)
+/**
+ * Handler for Net.ArpCache list
+ */
+LONG H_NetArpCache(const TCHAR *pszParam, const TCHAR *pArg, StringList *value, AbstractCommSession *session)
 {
        int nRet = SYSINFO_RC_ERROR;
        FILE *hFile;
@@ -278,13 +283,16 @@ LONG H_NetArpCache(const char *pszParam, const char *pArg, StringList *pValue, A
                                inet_ntoa(pSin->sin_addr),
                                pSdl->sdl_index);
 
-               pValue->add(szBuff);
+               value->addMBString(szBuff);
        }
 
        return nRet;
 }
 
-LONG H_NetRoutingTable(const char *pszParam, const char *pArg, StringList *pValue, AbstractCommSession *session)
+/**
+ * Handler for Net.IP.RoutingTable list
+ */
+LONG H_NetRoutingTable(const TCHAR *pszParam, const TCHAR *pArg, StringList *value, AbstractCommSession *session)
 {
 #define sa2sin(x) ((struct sockaddr_in *)x)
 #define ROUNDUP(a) \
@@ -387,7 +395,7 @@ LONG H_NetRoutingTable(const char *pszParam, const char *pArg, StringList *pValu
                                                (rtm->rtm_flags & RTF_GATEWAY) == 0 ? 3 : 4);
                                strcat(szOut, szTmp);
 
-                               pValue->add(szOut);
+                               value->addMBString(szOut);
                        }
                }
 
@@ -400,7 +408,10 @@ LONG H_NetRoutingTable(const char *pszParam, const char *pArg, StringList *pValu
        return nRet;
 }
 
-LONG H_NetIfList(const char *pszParam, const char *pArg, StringList *pValue, AbstractCommSession *session)
+/**
+ * Handler for Net.InterfaceList list
+ */
+LONG H_NetIfList(const TCHAR *pszParam, const TCHAR *pArg, StringList *value, AbstractCommSession *session)
 {
        int nRet = SYSINFO_RC_ERROR;
        struct ifaddrs *pIfAddr, *pNext;
@@ -478,49 +489,54 @@ LONG H_NetIfList(const char *pszParam, const char *pArg, StringList *pValue, Abs
 
                if (nRet == SYSINFO_RC_SUCCESS)
                {
+#if HAVE_DECL_SIOCGIFDATA
+                       int s = socket(AF_INET, SOCK_DGRAM, 0);
+#endif
                        for (i = 0; i < nIfCount; i++)
                        {
-                               int j;
-                               char szOut[1024];
+                               int ifType = IFTYPE_OTHER;
+                               int mtu = 0;
+#if HAVE_DECL_SIOCGIFDATA
+                               struct ifreq ifr;
+                       struct if_data ifdata;
+                               strlcpy(ifr.ifr_name, pList[i].name, sizeof(ifr.ifr_name));
+                               ifr.ifr_data = (caddr_t)&ifdata;
+                       if (ioctl(s, SIOCGIFDATA, (caddr_t)&ifr) == 0)
+                               {
+                                       ifType = ifdata.ifi_type;
+                                       mtu = ifdata.ifi_mtu;
+                               }
+#endif
 
+                               char szOut[1024];
+                               char macAddr[32];
                                if (pList[i].addrCount == 0)
                                {
-                                       snprintf(szOut, sizeof(szOut), "%d 0.0.0.0/0 %d %s %s",
+                                       snprintf(szOut, sizeof(szOut), "%d 0.0.0.0/0 %d(%d) %s %s",
                                                        pList[i].index,
-                                                       IFTYPE_OTHER,
-                                                       ether_ntoa(pList[i].mac),
+                                                       ifType, mtu,
+                                                       BinToStrA(pList[i].mac, 6, macAddr),
                                                        pList[i].name);
-                                       pValue->add(szOut);
+                                       value->addMBString(szOut);
                                }
                                else
                                {
-                                       for (j = 0; j < pList[i].addrCount; j++)
+                                       for(int j = 0; j < pList[i].addrCount; j++)
                                        {
-                                               if (j > 0)
-                                               {
-                                                       snprintf(szOut, sizeof(szOut), "%d %s/%d %d %s %s:%d",
-                                                                       pList[i].index,
-                                                                       inet_ntoa(pList[i].addr[j].ip),
-                                                                       pList[i].addr[j].mask,
-                                                                       IFTYPE_OTHER,
-                                                                       ether_ntoa(pList[i].mac),
-                                                                       pList[i].name,
-                                                                       j - 1);
-                                               }
-                                               else
-                                               {
-                                                       snprintf(szOut, sizeof(szOut), "%d %s/%d %d %s %s",
-                                                                       pList[i].index,
-                                                                       inet_ntoa(pList[i].addr[j].ip),
-                                                                       pList[i].addr[j].mask,
-                                                                       IFTYPE_OTHER,
-                                                                       ether_ntoa(pList[i].mac),
-                                                                       pList[i].name);
-                                               }
-                                               pValue->add(szOut);
+                                               snprintf(szOut, sizeof(szOut), "%d %s/%d %d(%d) %s %s",
+                                                               pList[i].index,
+                                                               inet_ntoa(pList[i].addr[j].ip),
+                                                               pList[i].addr[j].mask,
+                                                               ifType, mtu,
+                                                               BinToStrA(pList[i].mac, 6, macAddr),
+                                                               pList[i].name);
+                                               value->addMBString(szOut);
                                        }
                                }
                        }
+#if HAVE_DECL_SIOCGIFDATA
+                       close(s);
+#endif
                }
 
                for (i = 0; i < nIfCount; i++)
@@ -547,150 +563,172 @@ LONG H_NetIfList(const char *pszParam, const char *pArg, StringList *pValue, Abs
        return nRet;
 }
 
-LONG H_NetIfInfoFromKVM(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+#if HAVE_DECL_SIOCGIFDATA
+
+/**
+ * Handler for interface stats parameters obtained via ioctl SIOCGIFDATA
+ */
+LONG H_NetIfInfoFromIOCTL(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session)
 {
-       int nRet = SYSINFO_RC_SUCCESS;
-       char szArg[512];
-       u_long ifnetaddr;
-       struct ifnet ifnet;
-       struct ifnet_head ifnethead;
-       char szName[IFNAMSIZ];
+   char ifName[64];
+   if (!AgentGetParameterArgA(param, 1, ifName, sizeof(ifName)))
+      return SYSINFO_RC_UNSUPPORTED;
 
-       AgentGetParameterArg(pszParam, 1, szArg, sizeof(szArg));
+   if (ifName[0] == 0)
+      return SYSINFO_RC_UNSUPPORTED;
 
-       if (szArg[0] != 0)
-       {
-               if (szArg[0] >= '0' && szArg[0] <= '9')
-               {
-                       // index
-                       if (if_indextoname(atoi(szArg), szArg) != szArg)
-                       {
-                               // not found
-                               nRet = SYSINFO_RC_ERROR;
-                       }
-               }
+   if (ifName[0] >= '0' && ifName[0] <= '9')
+   {
+      if (if_indextoname(atoi(ifName), ifName) != ifName)
+         return SYSINFO_RC_NO_SUCH_INSTANCE;
+   }
 
-               if (nRet == SYSINFO_RC_SUCCESS)
-               {
-                       nRet = SYSINFO_RC_ERROR;
+       int s = socket(AF_INET, SOCK_DGRAM, 0);
+       if (s == -1)
+               return SYSINFO_RC_ERROR;
 
-                       if (kvmd == NULL) {
-                               kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL);
-                               if (kvmd == NULL)
-                                       return SYSINFO_RC_ERROR;
-                               if (kvm_nlist(kvmd, nl) < 0)
-                                       return SYSINFO_RC_ERROR;
-                               if (nl[0].n_type == 0)
-                                       return SYSINFO_RC_ERROR;
-                       }
-                       ifnetaddr = nl[N_IFNET].n_value;
-                       if (kvm_read(kvmd, ifnetaddr, &ifnethead, sizeof(ifnethead)) != sizeof(ifnethead))
-                               return SYSINFO_RC_ERROR;
-                       ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead);
-                       while (ifnetaddr) {
-                               if (kvm_read(kvmd, ifnetaddr, &ifnet, sizeof(ifnet)) != sizeof(ifnet))
-                                       return SYSINFO_RC_ERROR;
-                               ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_list);
-                               strlcpy(szName, ifnet.if_xname, sizeof(szName));
-                               if (strcmp(szName, szArg) == 0) {
-                                       nRet = SYSINFO_RC_SUCCESS;
-                                       switch((long)pArg)
-                                       {
-                                               case IF_INFO_BYTES_IN:
-                                                       ret_uint(pValue, ifnet.if_ibytes);
-                                                       break;
-                                               case IF_INFO_BYTES_OUT:
-                                                       ret_uint(pValue, ifnet.if_obytes);
-                                                       break;
-                                               case IF_INFO_IN_ERRORS:
-                                                       ret_uint(pValue, ifnet.if_ierrors);
-                                                       break;
-                                               case IF_INFO_OUT_ERRORS:
-                                                       ret_uint(pValue, ifnet.if_oerrors);
-                                                       break;
-                                               case IF_INFO_PACKETS_IN:
-                                                       ret_uint(pValue, ifnet.if_ipackets);
-                                                       break;
-                                               case IF_INFO_PACKETS_OUT:
-                                                       ret_uint(pValue, ifnet.if_opackets);
-                                                       break;
-                                               default:
-                                                       nRet = SYSINFO_RC_UNSUPPORTED;
-                                                       break;
-                                       }
-                                       break;
-                               }
-                               else
-                                       continue;
-                       }
+       struct ifreq ifr;
+   struct if_data ifdata;
+       strlcpy(ifr.ifr_name, ifName, sizeof(ifr.ifr_name));
+       ifr.ifr_data = (caddr_t)&ifdata;
+
+       LONG ret = SYSINFO_RC_SUCCESS;
+   if (ioctl(s, SIOCGIFDATA, (caddr_t)&ifr) == 0)
+       {
+               switch(CAST_FROM_POINTER(arg, int))
+               {
+                       case IF_INFO_BYTES_IN:
+                               ret_uint(value, (UINT32)ifdata.ifi_ibytes);
+                               break;
+                       case IF_INFO_BYTES_IN_64:
+                               ret_uint64(value, ifdata.ifi_ibytes);
+                               break;
+                       case IF_INFO_BYTES_OUT:
+                               ret_uint(value, (UINT32)ifdata.ifi_obytes);
+                               break;
+                       case IF_INFO_BYTES_OUT_64:
+                               ret_uint64(value, ifdata.ifi_obytes);
+                               break;
+                       case IF_INFO_IN_ERRORS:
+                               ret_uint(value, (UINT32)ifdata.ifi_ierrors);
+                               break;
+                       case IF_INFO_IN_ERRORS_64:
+                               ret_uint64(value, ifdata.ifi_ierrors);
+                               break;
+                       case IF_INFO_OUT_ERRORS:
+                               ret_uint(value, (UINT32)ifdata.ifi_oerrors);
+                               break;
+                       case IF_INFO_OUT_ERRORS_64:
+                               ret_uint64(value, ifdata.ifi_oerrors);
+                               break;
+                       case IF_INFO_PACKETS_IN:
+                               ret_uint(value, (UINT32)ifdata.ifi_ipackets);
+                               break;
+                       case IF_INFO_PACKETS_IN_64:
+                               ret_uint64(value, ifdata.ifi_ipackets);
+                               break;
+                       case IF_INFO_PACKETS_OUT:
+                               ret_uint(value, (UINT32)ifdata.ifi_opackets);
+                               break;
+                       case IF_INFO_PACKETS_OUT_64:
+                               ret_uint64(value, ifdata.ifi_opackets);
+                               break;
+                       case IF_INFO_MTU:
+                               ret_uint(value, ifdata.ifi_mtu);
+                               break;
+                       case IF_INFO_SPEED:
+                               ret_uint64(value, ifdata.ifi_baudrate);
+                               break;
+                       default:
+                               ret = SYSINFO_RC_UNSUPPORTED;
+                               break;
                }
        }
 
-       return nRet;
+       close(s);
+       return ret;
 }
 
-///////////////////////////////////////////////////////////////////////////////
-/*
+#else
 
-$Log: not supported by cvs2svn $
-Revision 1.10  2005/10/17 20:45:46  victor
-Fixed incorrect usage of strncpy
-
-Revision 1.9  2005/08/22 23:00:05  alk
-Net.IP.RoutingTable added
-
-Revision 1.8  2005/06/12 17:58:36  victor
-Net.Interface.AdminStatus should return 2 for disabled interfaces
-
-Revision 1.7  2005/05/30 16:31:58  alk
-fix: InterfaceList now return interfaces w/o IP address
-
-Revision 1.6  2005/05/23 20:30:28  alk
-! memory allocation for address list now in sizeof * count, fixes "mixing" lists of aliases
-
-Revision 1.5  2005/03/10 19:04:07  alk
-implemented:
-       Net.Interface.AdminStatus(*)
-       Net.Interface.Link(*)
-
-Revision 1.4  2005/03/10 12:23:56  alk
-issue #18
-alias handling on inet interfaces
-status: fixed
-
-Revision 1.3  2005/02/14 17:03:37  alk
-issue #9
+/**
+ * Handler for interface stats parameters obtained via KVM
+ */
+LONG H_NetIfInfoFromKVM(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *value, AbstractCommSession *session)
+{
+       char ifName[512];
+       if (!AgentGetParameterArgA(pszParam, 1, ifName, sizeof(ifName)))
+      return SYSINFO_RC_UNSUPPORTED;
 
-mask calculation chaged to BitsInMask()
+       if (ifName[0] == 0)
+      return SYSINFO_RC_UNSUPPORTED;
 
-Revision 1.2  2005/01/23 05:08:06  alk
-+ System.CPU.Count
-+ System.Memory.Physical.*
-+ System.ProcessCount
-+ System.ProcessList
+       if (ifName[0] >= '0' && ifName[0] <= '9')
+       {
+               if (if_indextoname(atoi(ifName), ifName) != ifName)
+                       return SYSINFO_RC_NO_SUCH_INSTANCE;
+       }
 
-Revision 1.1  2005/01/17 17:14:32  alk
-freebsd agent, incomplete (but working)
+       if (kvmd == NULL)
+       {
+               kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL);
+               if (kvmd == NULL)
+                       return SYSINFO_RC_ERROR;
+               if (kvm_nlist(kvmd, nl) < 0)
+                       return SYSINFO_RC_ERROR;
+               if (nl[0].n_type == 0)
+                       return SYSINFO_RC_ERROR;
+       }
 
-Revision 1.4  2005/01/05 12:21:24  victor
-- Added wrappers for new and delete from gcc2 libraries
-- sys/stat.h and fcntl.h included in nms_common.h
+       struct ifnet ifnet;
+       struct ifnet_head ifnethead;
 
-Revision 1.3  2004/11/25 08:01:27  victor
-Processing of interface list will be stopped on error
+       u_long ifnetaddr = nl[N_IFNET].n_value;
+       if (kvm_read(kvmd, ifnetaddr, &ifnethead, sizeof(ifnethead)) != sizeof(ifnethead))
+               return SYSINFO_RC_ERROR;
+       ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead);
 
-Revision 1.2  2004/10/23 22:53:23  alk
-ArpCache: ignore incomplete entries
+       int nRet = SYSINFO_RC_NO_SUCH_INSTANCE;
+       while(ifnetaddr != 0)
+       {
+               if (kvm_read(kvmd, ifnetaddr, &ifnet, sizeof(ifnet)) != sizeof(ifnet))
+                       return SYSINFO_RC_ERROR;
+               ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_list);
 
-Revision 1.1  2004/10/22 22:08:34  alk
-source restructured;
-implemented:
-       Net.IP.Forwarding
-       Net.IP6.Forwarding
-       Process.Count(*)
-       Net.ArpCache
-       Net.InterfaceList (if-type not implemented yet)
-       System.ProcessList
+               char szName[IFNAMSIZ];
+               strlcpy(szName, ifnet.if_xname, sizeof(szName));
+               if (strcmp(szName, szArg) == 0)
+               {
+                       nRet = SYSINFO_RC_SUCCESS;
+                       switch((long)pArg)
+                       {
+                               case IF_INFO_BYTES_IN:
+                                       ret_uint(value, ifnet.if_ibytes);
+                                       break;
+                               case IF_INFO_BYTES_OUT:
+                                       ret_uint(value, ifnet.if_obytes);
+                                       break;
+                               case IF_INFO_IN_ERRORS:
+                                       ret_uint(value, ifnet.if_ierrors);
+                                       break;
+                               case IF_INFO_OUT_ERRORS:
+                                       ret_uint(value, ifnet.if_oerrors);
+                                       break;
+                               case IF_INFO_PACKETS_IN:
+                                       ret_uint(value, ifnet.if_ipackets);
+                                       break;
+                               case IF_INFO_PACKETS_OUT:
+                                       ret_uint(value, ifnet.if_opackets);
+                                       break;
+                               default:
+                                       nRet = SYSINFO_RC_UNSUPPORTED;
+                                       break;
+                       }
+                       break;
+               }
+       }
 
+       return nRet;
+}
 
-*/
+#endif /* HAVE_DECL_SIOCGIFDATA */
index 3fd4bd6..95a722f 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /* 
 ** NetXMS subagent for FreeBSD
 ** Copyright (C) 2004 Alex Kirhenshtein
 #ifndef __NET_H__
 #define __NET_H__
 
-#define IF_INFO_ADMIN_STATUS     0
-#define IF_INFO_OPER_STATUS      1
-#define IF_INFO_BYTES_IN         2
-#define IF_INFO_BYTES_OUT        3
-#define IF_INFO_DESCRIPTION      4
-#define IF_INFO_IN_ERRORS        5
-#define IF_INFO_OUT_ERRORS       6
-#define IF_INFO_PACKETS_IN       7
-#define IF_INFO_PACKETS_OUT      8
-#define IF_INFO_SPEED            9
-
-LONG H_NetIpForwarding(const char *, const char *, char *, AbstractCommSession *);
-LONG H_NetIfAdmStatus(const char *, const char *, char *, AbstractCommSession *);
-LONG H_NetIfLink(const char *, const char *, char *, AbstractCommSession *);
-LONG H_NetArpCache(const char *, const char *, StringList *, AbstractCommSession *);
-LONG H_NetIfList(const char *, const char *, StringList *, AbstractCommSession *);
-LONG H_NetRoutingTable(const char *, const char *, StringList *, AbstractCommSession *);
-LONG H_NetIfInfoFromKVM(const char *, const char *, char *, AbstractCommSession *);
+/**
+ * Interface stats codes
+ */
+enum InterfaceStats
+{
+       IF_INFO_ADMIN_STATUS,
+       IF_INFO_OPER_STATUS,
+       IF_INFO_BYTES_IN,
+       IF_INFO_BYTES_IN_64,
+       IF_INFO_BYTES_OUT,
+       IF_INFO_BYTES_OUT_64,
+       IF_INFO_DESCRIPTION,
+       IF_INFO_IN_ERRORS,
+       IF_INFO_IN_ERRORS_64,
+       IF_INFO_OUT_ERRORS,
+       IF_INFO_OUT_ERRORS_64,
+       IF_INFO_PACKETS_IN,
+       IF_INFO_PACKETS_IN_64,
+       IF_INFO_PACKETS_OUT,
+       IF_INFO_PACKETS_OUT_64,
+       IF_INFO_SPEED,
+       IF_INFO_MTU
+};
+
+LONG H_NetIpForwarding(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+LONG H_NetIfAdmStatus(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+LONG H_NetIfLink(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+LONG H_NetArpCache(const TCHAR *, const TCHAR *, StringList *, AbstractCommSession *);
+LONG H_NetIfList(const TCHAR *, const TCHAR *, StringList *, AbstractCommSession *);
+LONG H_NetRoutingTable(const TCHAR *, const TCHAR *, StringList *, AbstractCommSession *);
+#if HAVE_DECL_SIOCGIFDATA
+LONG H_NetIfInfoFromIOCTL(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+#else
+LONG H_NetIfInfoFromKVM(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+#endif
 
 #endif // __NET_H__
-
-///////////////////////////////////////////////////////////////////////////////
-/*
-
-$Log: not supported by cvs2svn $
-Revision 1.3  2005/08/22 23:00:05  alk
-Net.IP.RoutingTable added
-
-Revision 1.2  2005/03/10 19:04:07  alk
-implemented:
-       Net.Interface.AdminStatus(*)
-       Net.Interface.Link(*)
-
-Revision 1.1  2005/01/17 17:14:32  alk
-freebsd agent, incomplete (but working)
-
-Revision 1.1  2004/10/22 22:08:34  alk
-source restructured;
-implemented:
-       Net.IP.Forwarding
-       Net.IP6.Forwarding
-       Process.Count(*)
-       Net.ArpCache
-       Net.InterfaceList (if-type not implemented yet)
-       System.ProcessList
-
-
-*/
index a3e7049..af8b504 100644 (file)
 #include "system.h"
 #include "disk.h"
 
-//
-// Subagent information
-//
-
+/**
+ * Supported parameters
+ */
 static NETXMS_SUBAGENT_PARAM m_parameters[] =
 {
-       { "System.CPU.Count",             H_CpuCount,        NULL,
-               DCI_DT_UINT,    DCIDESC_PROCESS_COUNT },
-
-       { "Disk.Avail(*)",                H_DiskInfo,        (char *)DISK_AVAIL,
+       { _T("Disk.Avail(*)"),                H_DiskInfo,        (const TCHAR *)DISK_AVAIL,
                DCI_DT_DEPRECATED,      DCIDESC_DEPRECATED },
-       { "Disk.AvailPerc(*)",            H_DiskInfo,        (char *)DISK_AVAIL_PERC,
+       { _T("Disk.AvailPerc(*)"),            H_DiskInfo,        (const TCHAR *)DISK_AVAIL_PERC,
                DCI_DT_DEPRECATED,      DCIDESC_DEPRECATED },
-       { "Disk.Free(*)",                 H_DiskInfo,        (char *)DISK_FREE,
+       { _T("Disk.Free(*)"),                 H_DiskInfo,        (const TCHAR *)DISK_FREE,
                DCI_DT_DEPRECATED,      DCIDESC_DEPRECATED },
-       { "Disk.FreePerc(*)",             H_DiskInfo,        (char *)DISK_FREE_PERC,
+       { _T("Disk.FreePerc(*)"),             H_DiskInfo,        (const TCHAR *)DISK_FREE_PERC,
                DCI_DT_DEPRECATED,      DCIDESC_DEPRECATED },
-       { "Disk.Total(*)",                H_DiskInfo,        (char *)DISK_TOTAL,
+       { _T("Disk.Total(*)"),                H_DiskInfo,        (const TCHAR *)DISK_TOTAL,
                DCI_DT_DEPRECATED,      DCIDESC_DEPRECATED },
-       { "Disk.Used(*)",                 H_DiskInfo,        (char *)DISK_USED,
+       { _T("Disk.Used(*)"),                 H_DiskInfo,        (const TCHAR *)DISK_USED,
                DCI_DT_DEPRECATED,      DCIDESC_DEPRECATED },
-       { "Disk.UsedPerc(*)",             H_DiskInfo,        (char *)DISK_USED_PERC,
+       { _T("Disk.UsedPerc(*)"),             H_DiskInfo,        (const TCHAR *)DISK_USED_PERC,
                DCI_DT_DEPRECATED,      DCIDESC_DEPRECATED },
 
-       { "FileSystem.Avail(*)",                H_DiskInfo,        (char *)DISK_AVAIL,
+       { _T("FileSystem.Avail(*)"),                H_DiskInfo,        (const TCHAR *)DISK_AVAIL,
                DCI_DT_UINT64,  DCIDESC_FS_AVAIL },
-       { "FileSystem.AvailPerc(*)",            H_DiskInfo,        (char *)DISK_AVAIL_PERC,
+       { _T("FileSystem.AvailPerc(*)"),            H_DiskInfo,        (const TCHAR *)DISK_AVAIL_PERC,
                DCI_DT_FLOAT,   DCIDESC_FS_AVAILPERC },
-       { "FileSystem.Free(*)",                 H_DiskInfo,        (char *)DISK_FREE,
+       { _T("FileSystem.Free(*)"),                 H_DiskInfo,        (const TCHAR *)DISK_FREE,
                DCI_DT_UINT64,  DCIDESC_FS_FREE },
-       { "FileSystem.FreePerc(*)",             H_DiskInfo,        (char *)DISK_FREE_PERC,
+       { _T("FileSystem.FreePerc(*)"),             H_DiskInfo,        (const TCHAR *)DISK_FREE_PERC,
                DCI_DT_FLOAT,   DCIDESC_FS_FREEPERC },
-       { "FileSystem.Total(*)",                H_DiskInfo,        (char *)DISK_TOTAL,
+       { _T("FileSystem.Total(*)"),                H_DiskInfo,        (const TCHAR *)DISK_TOTAL,
                DCI_DT_UINT64,  DCIDESC_FS_TOTAL },
-       { "FileSystem.Used(*)",                 H_DiskInfo,        (char *)DISK_USED,
+       { _T("FileSystem.Used(*)"),                 H_DiskInfo,        (const TCHAR *)DISK_USED,
                DCI_DT_UINT64,  DCIDESC_FS_USED },
-       { "FileSystem.UsedPerc(*)",             H_DiskInfo,        (char *)DISK_USED_PERC,
+       { _T("FileSystem.UsedPerc(*)"),             H_DiskInfo,        (const TCHAR *)DISK_USED_PERC,
                DCI_DT_FLOAT,   DCIDESC_FS_USEDPERC },
 
-       { "Net.IP.Forwarding",            H_NetIpForwarding, (char *)4,
-               DCI_DT_INT,             DCIDESC_NET_IP_FORWARDING },
-       { "Net.IP6.Forwarding",           H_NetIpForwarding, (char *)6,
-               DCI_DT_INT,             DCIDESC_NET_IP6_FORWARDING },
-       { "Net.Interface.AdminStatus(*)", H_NetIfAdmStatus,  NULL,
-               DCI_DT_INT,             DCIDESC_NET_INTERFACE_ADMINSTATUS },
-       { "Net.Interface.Link(*)",        H_NetIfLink,       NULL,
-               DCI_DT_DEPRECATED,              DCIDESC_DEPRECATED },
-       { "Net.Interface.OperStatus(*)",        H_NetIfLink,       NULL,
-               DCI_DT_INT,             DCIDESC_NET_INTERFACE_OPERSTATUS },
-       { "Net.Interface.BytesIn(*)",     H_NetIfInfoFromKVM, (char *)IF_INFO_BYTES_IN,
-               DCI_DT_UINT64,          DCIDESC_NET_INTERFACE_BYTESIN },
-       { "Net.Interface.BytesOut(*)",    H_NetIfInfoFromKVM, (char *)IF_INFO_BYTES_OUT,
-               DCI_DT_UINT64,          DCIDESC_NET_INTERFACE_BYTESOUT },
-       { "Net.Interface.InErrors(*)",    H_NetIfInfoFromKVM, (char *)IF_INFO_IN_ERRORS,
-               DCI_DT_UINT64,          DCIDESC_NET_INTERFACE_INERRORS },
-       { "Net.Interface.OutErrors(*)",   H_NetIfInfoFromKVM, (char *)IF_INFO_OUT_ERRORS,
-               DCI_DT_UINT64,          DCIDESC_NET_INTERFACE_OUTERRORS },
-       { "Net.Interface.PacketsIn(*)",   H_NetIfInfoFromKVM, (char *)IF_INFO_PACKETS_IN,
-               DCI_DT_UINT64,          DCIDESC_NET_INTERFACE_PACKETSIN },
-       { "Net.Interface.PacketsOut(*)",  H_NetIfInfoFromKVM, (char *)IF_INFO_PACKETS_OUT,
-               DCI_DT_UINT64,          DCIDESC_NET_INTERFACE_PACKETSOUT },
-
-       { "Process.Count(*)",             H_ProcessCount,    (char *)0,
+       { _T("Net.Interface.AdminStatus(*)"), H_NetIfAdmStatus, NULL, DCI_DT_INT, DCIDESC_NET_INTERFACE_ADMINSTATUS },
+       { _T("Net.Interface.Link(*)"), H_NetIfLink, NULL, DCI_DT_DEPRECATED, DCIDESC_DEPRECATED },
+       { _T("Net.Interface.OperStatus(*)"), H_NetIfLink, NULL, DCI_DT_INT, DCIDESC_NET_INTERFACE_OPERSTATUS },
+
+#if HAVE_DECL_SIOCGIFDATA
+       { _T("Net.Interface.BytesIn(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_BYTES_IN, DCI_DT_UINT, DCIDESC_NET_INTERFACE_BYTESIN },
+       { _T("Net.Interface.BytesIn64(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_BYTES_IN, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_BYTESIN },
+       { _T("Net.Interface.BytesOut(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_BYTES_OUT, DCI_DT_UINT, DCIDESC_NET_INTERFACE_BYTESOUT },
+       { _T("Net.Interface.BytesOut64(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_BYTES_OUT, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_BYTESOUT },
+       { _T("Net.Interface.InErrors(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_IN_ERRORS, DCI_DT_UINT, DCIDESC_NET_INTERFACE_INERRORS },
+       { _T("Net.Interface.InErrors64(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_IN_ERRORS, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_INERRORS },
+       { _T("Net.Interface.MTU(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_MTU, DCI_DT_UINT, DCIDESC_NET_INTERFACE_MTU },
+       { _T("Net.Interface.OutErrors(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_OUT_ERRORS, DCI_DT_UINT, DCIDESC_NET_INTERFACE_OUTERRORS },
+       { _T("Net.Interface.OutErrors64(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_OUT_ERRORS, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_OUTERRORS },
+       { _T("Net.Interface.PacketsIn(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_PACKETS_IN, DCI_DT_UINT, DCIDESC_NET_INTERFACE_PACKETSIN },
+       { _T("Net.Interface.PacketsIn64(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_PACKETS_IN, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_PACKETSIN },
+       { _T("Net.Interface.PacketsOut(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_PACKETS_OUT, DCI_DT_UINT, DCIDESC_NET_INTERFACE_PACKETSOUT },
+       { _T("Net.Interface.PacketsOut64(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_PACKETS_OUT_64, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_PACKETSOUT },
+       { _T("Net.Interface.Speed(*)"), H_NetIfInfoFromIOCTL, (const TCHAR *)IF_INFO_SPEED, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_SPEED },
+#else
+       { _T("Net.Interface.BytesIn(*)"), H_NetIfInfoFromKVM, (const TCHAR *)IF_INFO_BYTES_IN, DCI_DT_UINT, DCIDESC_NET_INTERFACE_BYTESIN },
+       { _T("Net.Interface.BytesOut(*)"), H_NetIfInfoFromKVM, (const TCHAR *)IF_INFO_BYTES_OUT, DCI_DT_UINT, DCIDESC_NET_INTERFACE_BYTESOUT },
+       { _T("Net.Interface.InErrors(*)"), H_NetIfInfoFromKVM, (const TCHAR *)IF_INFO_IN_ERRORS, DCI_DT_UINT, DCIDESC_NET_INTERFACE_INERRORS },
+       { _T("Net.Interface.OutErrors(*)"), H_NetIfInfoFromKVM, (const TCHAR *)IF_INFO_OUT_ERRORS, DCI_DT_UINT, DCIDESC_NET_INTERFACE_OUTERRORS },
+       { _T("Net.Interface.PacketsIn(*)"), H_NetIfInfoFromKVM, (const TCHAR *)IF_INFO_PACKETS_IN, DCI_DT_UINT, DCIDESC_NET_INTERFACE_PACKETSIN },
+       { _T("Net.Interface.PacketsOut(*)"), H_NetIfInfoFromKVM, (const TCHAR *)IF_INFO_PACKETS_OUT, DCI_DT_UINT, DCIDESC_NET_INTERFACE_PACKETSOUT },
+#endif
+
+       { _T("Net.IP.Forwarding"), H_NetIpForwarding, (const TCHAR *)4, DCI_DT_INT, DCIDESC_NET_IP_FORWARDING },
+       { _T("Net.IP6.Forwarding"), H_NetIpForwarding, (const TCHAR *)6, DCI_DT_INT, DCIDESC_NET_IP6_FORWARDING },
+
+       { _T("Process.Count(*)"),             H_ProcessCount,    (const TCHAR *)0,
                DCI_DT_UINT,    DCIDESC_PROCESS_COUNT },
-       { "System.ProcessCount",          H_ProcessCount,    (char *)1,
+       { _T("System.ProcessCount"),          H_ProcessCount,    (const TCHAR *)1,
                DCI_DT_UINT,    DCIDESC_SYSTEM_PROCESSCOUNT },
 
-       { "System.CPU.LoadAvg",           H_CpuLoad,         NULL,
+       { _T("System.CPU.Count"), H_CpuCount, NULL, DCI_DT_UINT,        DCIDESC_PROCESS_COUNT },
+
+       { _T("System.CPU.LoadAvg"),           H_CpuLoad,         NULL,
                DCI_DT_FLOAT,   DCIDESC_SYSTEM_CPU_LOADAVG },
-       { "System.CPU.LoadAvg5",          H_CpuLoad,         NULL,
+       { _T("System.CPU.LoadAvg5"),          H_CpuLoad,         NULL,
                DCI_DT_FLOAT,   DCIDESC_SYSTEM_CPU_LOADAVG5 },
-       { "System.CPU.LoadAvg15",         H_CpuLoad,         NULL,
+       { _T("System.CPU.LoadAvg15"),         H_CpuLoad,         NULL,
                DCI_DT_FLOAT,   DCIDESC_SYSTEM_CPU_LOADAVG15 },
 /*
-       { "System.CPU.Usage",             H_CpuUsage,        NULL,
+       { _T("System.CPU.Usage"),             H_CpuUsage,        NULL,
        DCI_DT_FLOAT,   DCIDESC_SYSTEM_CPU_USAGE },
-       { "System.CPU.Usage5",            H_CpuUsage,        NULL,
+       { _T("System.CPU.Usage5"),            H_CpuUsage,        NULL,
        DCI_DT_FLOAT,   DCIDESC_SYSTEM_CPU_USAGE5 },
-       { "System.CPU.Usage15",           H_CpuUsage,        NULL,
+       { _T("System.CPU.Usage15"),           H_CpuUsage,        NULL,
        DCI_DT_FLOAT,   DCIDESC_SYSTEM_CPU_USAGE15 },
 */
-       { "System.Hostname",              H_Hostname,        NULL,
+       { _T("System.Hostname"),              H_Hostname,        NULL,
                DCI_DT_FLOAT,   DCIDESC_SYSTEM_HOSTNAME },
-       { "System.Memory.Physical.Free",  H_MemoryInfo,      (char *)PHYSICAL_FREE,
+       { _T("System.Memory.Physical.Free"),  H_MemoryInfo,      (const TCHAR *)PHYSICAL_FREE,
                DCI_DT_UINT64,  DCIDESC_SYSTEM_MEMORY_PHYSICAL_FREE },
-       { "System.Memory.Physical.Total", H_MemoryInfo,      (char *)PHYSICAL_TOTAL,
+       { _T("System.Memory.Physical.Total"), H_MemoryInfo,      (const TCHAR *)PHYSICAL_TOTAL,
                DCI_DT_UINT64,  DCIDESC_SYSTEM_MEMORY_PHYSICAL_TOTAL },
-       { "System.Memory.Physical.Used",  H_MemoryInfo,      (char *)PHYSICAL_USED,
+       { _T("System.Memory.Physical.Used"),  H_MemoryInfo,      (const TCHAR *)PHYSICAL_USED,
                DCI_DT_UINT64,  DCIDESC_SYSTEM_MEMORY_PHYSICAL_USED },
-       { "System.Memory.Swap.Free",      H_MemoryInfo,      (char *)SWAP_FREE,
+       { _T("System.Memory.Swap.Free"),      H_MemoryInfo,      (const TCHAR *)SWAP_FREE,
                DCI_DT_UINT64,  DCIDESC_SYSTEM_MEMORY_SWAP_FREE },
-       { "System.Memory.Swap.Total",     H_MemoryInfo,      (char *)SWAP_TOTAL,
+       { _T("System.Memory.Swap.Total"),     H_MemoryInfo,      (const TCHAR *)SWAP_TOTAL,
                DCI_DT_UINT64,  DCIDESC_SYSTEM_MEMORY_SWAP_TOTAL },
-       { "System.Memory.Swap.Used",      H_MemoryInfo,      (char *)SWAP_USED,
+       { _T("System.Memory.Swap.Used"),      H_MemoryInfo,      (const TCHAR *)SWAP_USED,
                DCI_DT_UINT64,  DCIDESC_SYSTEM_MEMORY_SWAP_USED },
-       { "System.Memory.Virtual.Free",   H_MemoryInfo,      (char *)VIRTUAL_FREE,
+       { _T("System.Memory.Virtual.Free"),   H_MemoryInfo,      (const TCHAR *)VIRTUAL_FREE,
                DCI_DT_UINT64,  DCIDESC_SYSTEM_MEMORY_VIRTUAL_FREE },
-       { "System.Memory.Virtual.Total",  H_MemoryInfo,      (char *)VIRTUAL_TOTAL,
+       { _T("System.Memory.Virtual.Total"),  H_MemoryInfo,      (const TCHAR *)VIRTUAL_TOTAL,
                DCI_DT_UINT64,  DCIDESC_SYSTEM_MEMORY_VIRTUAL_TOTAL },
-       { "System.Memory.Virtual.Used",   H_MemoryInfo,      (char *)VIRTUAL_USED,
+       { _T("System.Memory.Virtual.Used"),   H_MemoryInfo,      (const TCHAR *)VIRTUAL_USED,
                DCI_DT_UINT64,  DCIDESC_SYSTEM_MEMORY_VIRTUAL_USED },
-       { "System.Uname",                 H_Uname,           NULL,
+       { _T("System.Uname"),                 H_Uname,           NULL,
                DCI_DT_STRING,  DCIDESC_SYSTEM_UNAME },
-       { "System.Uptime",                H_Uptime,          NULL,
+       { _T("System.Uptime"),                H_Uptime,          NULL,
                DCI_DT_UINT,    DCIDESC_SYSTEM_UPTIME },
 
-       { "Agent.SourcePackageSupport",   H_SourcePkgSupport,NULL,
+       { _T("Agent.SourcePackageSupport"),   H_SourcePkgSupport,NULL,
                DCI_DT_INT,             DCIDESC_AGENT_SOURCEPACKAGESUPPORT },
 };
 
-static NETXMS_SUBAGENT_LIST m_enums[] =
+/**
+ * Supported lists
+ */
+static NETXMS_SUBAGENT_LIST m_lists[] =
 {
-       { "Net.ArpCache",                 H_NetArpCache,     NULL },
-       { "Net.InterfaceList",            H_NetIfList,       NULL },
-       { "Net.IP.RoutingTable",          H_NetRoutingTable, NULL },
-       { "System.ProcessList",           H_ProcessList,     NULL },
+       { _T("Net.ArpCache"),                 H_NetArpCache,     NULL },
+       { _T("Net.InterfaceList"),            H_NetIfList,       NULL },
+       { _T("Net.IP.RoutingTable"),          H_NetRoutingTable, NULL },
+       { _T("System.ProcessList"),           H_ProcessList,     NULL },
 };
 
+/**
+ * Subagent information
+ */
 static NETXMS_SUBAGENT_INFO m_info =
 {
        NETXMS_SUBAGENT_INFO_MAGIC,
-       "OpenBSD",
+       _T("OpenBSD"),
        NETXMS_VERSION_STRING,
        NULL, NULL, NULL,
        sizeof(m_parameters) / sizeof(NETXMS_SUBAGENT_PARAM),
        m_parameters,
-       sizeof(m_enums) / sizeof(NETXMS_SUBAGENT_LIST),
-       m_enums,
+       sizeof(m_lists) / sizeof(NETXMS_SUBAGENT_LIST),
+       m_lists,
        0, NULL,        // tables
    0, NULL,    // actions
        0, NULL // push parameters
 };
 
-//
-// Entry point for NetXMS agent
-//
-
+/**
+ * Entry point for NetXMS agent
+ */
 DECLARE_SUBAGENT_ENTRY_POINT(OPENBSD)
 {
        *ppInfo = &m_info;
        return TRUE;
 }
 
-
-//
-// Entry points for server
-//
-
+/**
+ * Entry point for server - interface list
+ */
 extern "C" BOOL __NxSubAgentGetIfList(StringList *pValue)
 {
-       return H_NetIfList("Net.InterfaceList", NULL, pValue, NULL) == SYSINFO_RC_SUCCESS;
+       return H_NetIfList(_T("Net.InterfaceList"), NULL, pValue, NULL) == SYSINFO_RC_SUCCESS;
 }
 
+/**
+ * Entry point for server - ARP cache
+ */
 extern "C" BOOL __NxSubAgentGetArpCache(StringList *pValue)
 {
-       return H_NetArpCache("Net.ArpCache", NULL, pValue, NULL) == SYSINFO_RC_SUCCESS;
+       return H_NetArpCache(_T("Net.ArpCache"), NULL, pValue, NULL) == SYSINFO_RC_SUCCESS;
 }
index 1e919d9..9ef9060 100644 (file)
@@ -1,6 +1,7 @@
 /* 
 ** NetXMS subagent for OpenBSD
 ** Copyright (C) 2006 C.T.Co 
+** Copyright (C) 2017 Raden Solutions SIA
 **
 ** 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
@@ -29,6 +30,7 @@
 #include <sys/proc.h>
 #include <sys/user.h>
 #include <sys/swap.h>
+#include <sys/vmmeter.h>
 #include <fcntl.h>
 #include <kvm.h>
 #include <paths.h>
@@ -36,7 +38,7 @@
 
 #include "system.h"
 
-LONG H_Uptime(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+LONG H_Uptime(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session)
 {
        int mib[2] = { CTL_KERN, KERN_BOOTTIME };
        time_t nNow;
@@ -64,7 +66,7 @@ LONG H_Uptime(const char *pszParam, const char *pArg, char *pValue, AbstractComm
    return nUptime > 0 ? SYSINFO_RC_SUCCESS : SYSINFO_RC_ERROR;
 }
 
-LONG H_Uname(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+LONG H_Uname(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session)
 {
        struct utsname utsName;
        int nRet = SYSINFO_RC_ERROR;
@@ -78,7 +80,7 @@ LONG H_Uname(const char *pszParam, const char *pArg, char *pValue, AbstractCommS
                                utsName.machine);
                // TODO: processor & platform
 
-               ret_string(pValue, szBuff);
+               ret_mbstring(pValue, szBuff);
 
                nRet = SYSINFO_RC_SUCCESS;
        }
@@ -86,21 +88,21 @@ LONG H_Uname(const char *pszParam, const char *pArg, char *pValue, AbstractCommS
    return nRet;
 }
 
-LONG H_Hostname(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+LONG H_Hostname(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session)
 {
        int nRet = SYSINFO_RC_ERROR;
        char szBuff[128];
 
        if (gethostname(szBuff, sizeof(szBuff)) == 0)
        {
-       ret_string(pValue, szBuff);
+       ret_mbstring(pValue, szBuff);
                nRet = SYSINFO_RC_SUCCESS;
        }
 
    return nRet;
 }
 
-LONG H_CpuLoad(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+LONG H_CpuLoad(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session)
 {
        int nRet = SYSINFO_RC_ERROR;
        char szArg[128] = {0};
@@ -130,12 +132,12 @@ LONG H_CpuLoad(const char *pszParam, const char *pArg, char *pValue, AbstractCom
        return nRet;
 }
 
-LONG H_CpuUsage(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+LONG H_CpuUsage(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session)
 {
        return SYSINFO_RC_UNSUPPORTED;
 }
 
-LONG H_CpuCount(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+LONG H_CpuCount(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session)
 {
        int nRet = SYSINFO_RC_ERROR;
        int mib[] = {CTL_HW, HW_NCPU};
@@ -152,7 +154,7 @@ LONG H_CpuCount(const char *pszParam, const char *pArg, char *pValue, AbstractCo
        return nRet;
 }
 
-LONG H_ProcessCount(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+LONG H_ProcessCount(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session)
 {
        int nRet = SYSINFO_RC_ERROR;
        char szArg[128] = {0};
@@ -162,7 +164,7 @@ LONG H_ProcessCount(const char *pszParam, const char *pArg, char *pValue, Abstra
        kvm_t *kd;
        struct kinfo_proc *kp;
 
-       AgentGetParameterArg(pszParam, 1, szArg, sizeof(szArg));
+       AgentGetParameterArgA(pszParam, 1, szArg, sizeof(szArg));
 
        kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL);
        if (kd != 0)
@@ -207,7 +209,7 @@ LONG H_ProcessCount(const char *pszParam, const char *pArg, char *pValue, Abstra
        return nRet;
 }
 
-LONG H_MemoryInfo(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+LONG H_MemoryInfo(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session)
 {
        int nRet = SYSINFO_RC_ERROR;
        FILE *hFile;
@@ -228,7 +230,7 @@ LONG H_MemoryInfo(const char *pszParam, const char *pArg, char *pValue, Abstract
        nUsedVirtCount = 0;
        nSwapTotal = nSwapUsed = 0;
 
-       AgentGetParameterArg(pszParam, 1, szArg, sizeof(szArg));
+       AgentGetParameterArgA(pszParam, 1, szArg, sizeof(szArg));
 
        // Physical memory
 
@@ -254,10 +256,10 @@ LONG H_MemoryInfo(const char *pszParam, const char *pArg, char *pValue, Abstract
        }
        else
        {
-               if ((int)pArg != PHYSICAL_FREE &&
-                   (int)pArg != PHYSICAL_TOTAL &&
-                   (int)pArg != PHYSICAL_USED &&
-                   (int)pArg != VIRTUAL_USED)
+               if (CAST_FROM_POINTER(pArg, int) != PHYSICAL_FREE &&
+                   CAST_FROM_POINTER(pArg, int) != PHYSICAL_TOTAL &&
+                   CAST_FROM_POINTER(pArg, int) != PHYSICAL_USED &&
+                   CAST_FROM_POINTER(pArg, int) != VIRTUAL_USED)
                nRet = SYSINFO_RC_ERROR;
        }
 
@@ -268,7 +270,7 @@ LONG H_MemoryInfo(const char *pszParam, const char *pArg, char *pValue, Abstract
 
        if (nRet == SYSINFO_RC_SUCCESS)
        {
-               switch((int)pArg)
+               switch(CAST_FROM_POINTER(pArg, int))
                {
                case PHYSICAL_FREE: // ph-free
                        ret_uint64(pValue, PAGES_TO_BYTES(nFreePhysCount));
@@ -308,7 +310,7 @@ LONG H_MemoryInfo(const char *pszParam, const char *pArg, char *pValue, Abstract
        return nRet;
 }
 
-LONG H_ProcessList(const char *pszParam, const char *pArg, StringList *pValue, AbstractCommSession *session)
+LONG H_ProcessList(const TCHAR *pszParam, const TCHAR *pArg, StringList *pValue, AbstractCommSession *session)
 {
        int nRet = SYSINFO_RC_ERROR;
        int nCount = -1;
@@ -338,7 +340,7 @@ LONG H_ProcessList(const char *pszParam, const char *pArg, StringList *pValue, A
                                                kp[i].p_pid, kp[i].p_comm
 #endif
                                                );
-                               pValue->add(szBuff);
+                               pValue->addMBString(szBuff);
                        }
                }
 
@@ -356,59 +358,8 @@ LONG H_ProcessList(const char *pszParam, const char *pArg, StringList *pValue, A
 //
 // stub
 //
-LONG H_SourcePkgSupport(const char *pszParam, const char *pArg, char *pValue, AbstractCommSession *session)
+LONG H_SourcePkgSupport(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session)
 {
        ret_int(pValue, 1);
        return SYSINFO_RC_SUCCESS;
 }
-
-
-///////////////////////////////////////////////////////////////////////////////
-/*
-
-$Log: not supported by cvs2svn $
-Revision 1.8  2005/05/30 14:39:32  alk
-* process list now works via kvm, compatible with freebsd 5+
-
-Revision 1.7  2005/05/29 22:44:59  alk
-* configure: pthreads & fbsd5+; detection code should be rewriten!
-* another ugly hack: agent's process info disabled for fbsd5+: struct kinfo_proc changed; m/b fix it tomorow
-* server/nxadm & fbsd5.1: a**holes, in 5.1 there no define with version in readline.h...
-
-Revision 1.6  2005/01/24 19:51:16  alk
-reurn types/comments added
-Process.Count(*)/System.ProcessCount fixed
-
-Revision 1.5  2005/01/23 05:36:11  alk
-+ System.Memory.Swap.*
-+ System.Memory.Virtual.*
-
-NB! r/o access to /dev/mem required! (e.g. chgrp kmem ; chmod g+s)
-
-Revision 1.4  2005/01/23 05:14:49  alk
-System's PageSize used instead of Hardware PageSize
-
-Revision 1.3  2005/01/23 05:08:06  alk
-+ System.CPU.Count
-+ System.Memory.Physical.*
-+ System.ProcessCount
-+ System.ProcessList
-
-Revision 1.2  2005/01/17 23:25:47  alk
-Agent.SourcePackageSupport added
-
-Revision 1.1  2005/01/17 17:14:32  alk
-freebsd agent, incomplete (but working)
-
-Revision 1.1  2004/10/22 22:08:35  alk
-source restructured;
-implemented:
-       Net.IP.Forwarding
-       Net.IP6.Forwarding
-       Process.Count(*)
-       Net.ArpCache
-       Net.InterfaceList (if-type not implemented yet)
-       System.ProcessList
-
-
-*/
index e6e8fb7..7848f7f 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /* 
 ** NetXMS subagent for FreeBSD
 ** Copyright (C) 2004 Alex Kirhenshtein
@@ -36,45 +34,16 @@ enum
        VIRTUAL_TOTAL,
 };
 
-LONG H_ProcessList(const char *, const char *, StringList *, AbstractCommSession *);
-LONG H_Uptime(const char *, const char *, char *, AbstractCommSession *);
-LONG H_Uname(const char *, const char *, char *, AbstractCommSession *);
-LONG H_Hostname(const char *, const char *, char *, AbstractCommSession *);
-LONG H_Hostname(const char *, const char *, char *, AbstractCommSession *);
-LONG H_CpuCount(const char *, const char *, char *, AbstractCommSession *);
-LONG H_CpuLoad(const char *, const char *, char *, AbstractCommSession *);
-LONG H_CpuUsage(const char *, const char *, char *, AbstractCommSession *);
-LONG H_ProcessCount(const char *, const char *, char *, AbstractCommSession *);
-LONG H_MemoryInfo(const char *, const char *, char *, AbstractCommSession *);
-LONG H_SourcePkgSupport(const char *, const char *, char *, AbstractCommSession *);
+LONG H_ProcessList(const TCHAR *, const TCHAR *, StringList *, AbstractCommSession *);
+LONG H_Uptime(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+LONG H_Uname(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+LONG H_Hostname(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+LONG H_Hostname(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+LONG H_CpuCount(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+LONG H_CpuLoad(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+LONG H_CpuUsage(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+LONG H_ProcessCount(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+LONG H_MemoryInfo(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
+LONG H_SourcePkgSupport(const TCHAR *, const TCHAR *, TCHAR *, AbstractCommSession *);
 
 #endif // __SYSTEM_H__
-
-///////////////////////////////////////////////////////////////////////////////
-/*
-
-$Log: not supported by cvs2svn $
-Revision 1.3  2005/01/23 05:08:06  alk
-+ System.CPU.Count
-+ System.Memory.Physical.*
-+ System.ProcessCount
-+ System.ProcessList
-
-Revision 1.2  2005/01/17 23:25:48  alk
-Agent.SourcePackageSupport added
-
-Revision 1.1  2005/01/17 17:14:32  alk
-freebsd agent, incomplete (but working)
-
-Revision 1.1  2004/10/22 22:08:35  alk
-source restructured;
-implemented:
-       Net.IP.Forwarding
-       Net.IP6.Forwarding
-       Process.Count(*)
-       Net.ArpCache
-       Net.InterfaceList (if-type not implemented yet)
-       System.ProcessList
-
-
-*/