pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/sysutils/zabbix



Module Name:    pkgsrc
Committed By:   he
Date:           Sun Mar 26 11:58:58 UTC 2023

Modified Files:
        pkgsrc/sysutils/zabbix: Makefile distinfo
Added Files:
        pkgsrc/sysutils/zabbix/patches: patch-src_libs_zbxsysinfo_netbsd_net.c

Log Message:
zabbix: rewrite to use sysctl(), code lifted from netstat/if.c.

This rewrites src/libs/zbxsysinfo/netbsd/net.c's to not do
"kmem groveling" but instead use the more modern sysctl()
method which is now the preferred method to get network stats.

This fixes the build on netbsd-10, and has been built and tested
on 8.2, and build-verified on 9.3.

OK'ed by gdt@

Bump PKGREVISION.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 pkgsrc/sysutils/zabbix/Makefile
cvs rdiff -u -r1.22 -r1.23 pkgsrc/sysutils/zabbix/distinfo
cvs rdiff -u -r0 -r1.1 \
    pkgsrc/sysutils/zabbix/patches/patch-src_libs_zbxsysinfo_netbsd_net.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/sysutils/zabbix/Makefile
diff -u pkgsrc/sysutils/zabbix/Makefile:1.46 pkgsrc/sysutils/zabbix/Makefile:1.47
--- pkgsrc/sysutils/zabbix/Makefile:1.46        Wed Nov 23 16:21:10 2022
+++ pkgsrc/sysutils/zabbix/Makefile     Sun Mar 26 11:58:58 2023
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.46 2022/11/23 16:21:10 adam Exp $
+# $NetBSD: Makefile,v 1.47 2023/03/26 11:58:58 he Exp $
 
-PKGREVISION= 9
+PKGREVISION= 10
 .include "Makefile.common"
 
 COMMENT=       Enterprise-class Monitoring Solution for Everyone

Index: pkgsrc/sysutils/zabbix/distinfo
diff -u pkgsrc/sysutils/zabbix/distinfo:1.22 pkgsrc/sysutils/zabbix/distinfo:1.23
--- pkgsrc/sysutils/zabbix/distinfo:1.22        Tue Oct 26 11:20:29 2021
+++ pkgsrc/sysutils/zabbix/distinfo     Sun Mar 26 11:58:58 2023
@@ -1,10 +1,11 @@
-$NetBSD: distinfo,v 1.22 2021/10/26 11:20:29 nia Exp $
+$NetBSD: distinfo,v 1.23 2023/03/26 11:58:58 he Exp $
 
 BLAKE2s (zabbix-4.0.24.tar.gz) = 99cbad42171b86b62636b6d498ba344c99762ea98ecff80c47497f6ef49f7c61
 SHA512 (zabbix-4.0.24.tar.gz) = ec4d4bbfc3ce1ea10a4e6cf96c10e4495ce2ea154dc297544ae107d4cb7451e3fc76e25d7822f40a809a87a268c54abb8a9d49869942f2009c0a7f92ff6abaf3
 Size (zabbix-4.0.24.tar.gz) = 17404177 bytes
 SHA1 (patch-frontends_php_locale_add__new__language.sh) = 71be94363ee58490d2ee3ef4bc6b800cfc99e90a
 SHA1 (patch-frontends_php_locale_make__mo.sh) = 5b0f25dfe1aa8befb5eeda79e1aa002bd0adddf7
+SHA1 (patch-src_libs_zbxsysinfo_netbsd_net.c) = 7d3d35b2f0e7b06cb0b371279e4b9d959adbe51e
 SHA1 (patch-src_zabbix__agent_Makefile.in) = 55149e2969d0e6e54c537750ca1bde11c9b690d7
 SHA1 (patch-src_zabbix__proxy_Makefile.in) = 2e7dbe6e8554bbe2c1cb1074a308661ae44bb977
 SHA1 (patch-src_zabbix__server_Makefile.in) = bfcb02e8450df163a038adbae83a7e17fda0a9a9

Added files:

Index: pkgsrc/sysutils/zabbix/patches/patch-src_libs_zbxsysinfo_netbsd_net.c
diff -u /dev/null pkgsrc/sysutils/zabbix/patches/patch-src_libs_zbxsysinfo_netbsd_net.c:1.1
--- /dev/null   Sun Mar 26 11:58:58 2023
+++ pkgsrc/sysutils/zabbix/patches/patch-src_libs_zbxsysinfo_netbsd_net.c       Sun Mar 26 11:58:58 2023
@@ -0,0 +1,160 @@
+$NetBSD: patch-src_libs_zbxsysinfo_netbsd_net.c,v 1.1 2023/03/26 11:58:58 he Exp $
+
+Plug in parts of the code from netstat's if.c, to transform
+from being a kmem groveller to using sysctl() to get interface
+statistics.
+
+--- src/libs/zbxsysinfo/netbsd/net.c.orig      2020-08-24 07:46:37.000000000 +0000
++++ src/libs/zbxsysinfo/netbsd/net.c
+@@ -22,21 +22,140 @@
+ #include "zbxjson.h"
+ #include "log.h"
+ 
++#include <net/route.h>
++#include <net/if.h>
++#include <net/if_dl.h>
++#include <net/if_types.h>
++
++#if 0 /* used by old code */
+ static struct nlist kernel_symbols[] =
+ {
+       {"_ifnet", N_UNDF, 0, 0, 0},
+       {"_tcbtable", N_UNDF, 0, 0, 0},
+       {NULL, 0, 0, 0, 0}
+ };
++#endif
++
++static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
++
++static void
++get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
++{
++        int i;
++
++        for (i = 0; i < RTAX_MAX; i++) {
++                if (addrs & (1 << i)) {
++                        rti_info[i] = sa;
++                        sa = (struct sockaddr *)((char *)(sa) +
++                            RT_ROUNDUP(sa->sa_len));
++                } else
++                        rti_info[i] = NULL;
++        }
++}
++
+ 
+ #define IFNET_ID 0
+ 
+ static int    get_ifdata(const char *if_name,
+-              zbx_uint64_t *ibytes, zbx_uint64_t *ipackets, zbx_uint64_t *ierrors, zbx_uint64_t *idropped,
+-              zbx_uint64_t *obytes, zbx_uint64_t *opackets, zbx_uint64_t *oerrors,
+-              zbx_uint64_t *tbytes, zbx_uint64_t *tpackets, zbx_uint64_t *terrors,
++              zbx_uint64_t *ibytes, zbx_uint64_t *ipackets,
++              zbx_uint64_t *ierrors, zbx_uint64_t *idropped,
++              zbx_uint64_t *obytes, zbx_uint64_t *opackets,
++              zbx_uint64_t *oerrors, zbx_uint64_t *tbytes,
++              zbx_uint64_t *tpackets, zbx_uint64_t *terrors,
+               zbx_uint64_t *icollisions, char **error)
+ {
++      struct if_msghdr *ifm;
++      int mib[6] = { CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
++      static char *buf = NULL;
++      static size_t olen;
++      size_t len;
++      char *next, *lim, *cp;
++      struct rt_msghdr *rtm;
++      struct if_data *ifd = NULL;
++      struct sockaddr *sa, *rti_info[RTAX_MAX];
++      struct sockaddr_dl *sdl;
++      char name[IFNAMSIZ + 1];
++      int ifindex = 0;
++      int ret = SYSINFO_RET_FAIL;
++
++      if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1)
++              return FAIL;
++      if (len > olen) {
++              free(buf);
++              if ((buf = malloc(len)) == NULL) {
++                      *error = zbx_strdup(NULL, "sysctl get-length failed");
++                      return FAIL;
++              }
++              olen = len;
++      }
++      if (sysctl(mib, 6, buf, &len, NULL, 0) == -1) {
++              *error = zbx_strdup(NULL, "sysctl get-if-list failed");
++              return FAIL;
++      }
++
++      lim = buf + len;
++      for (next = buf; next < lim; next += rtm->rtm_msglen) {
++              /* struct if_data_ext dext; */
++
++              rtm = (struct rt_msghdr *)next;
++              if (rtm->rtm_version != RTM_VERSION)
++                      continue;
++
++              switch (rtm->rtm_type) {
++              case RTM_IFINFO:
++                      ifm = (struct if_msghdr *)next;
++                      ifd = &ifm->ifm_data;
++
++                      sa = (struct sockaddr *)(ifm + 1);
++                      get_rtaddrs(ifm->ifm_addrs, sa, rti_info);
++
++                      sdl = (struct sockaddr_dl *)rti_info[RTAX_IFP];
++
++                      bzero(name, sizeof(name));
++                      if (sdl->sdl_nlen >= IFNAMSIZ)
++                              memcpy(name, sdl->sdl_data, IFNAMSIZ - 1);
++                      else if (sdl->sdl_nlen > 0)
++                              memcpy(name, sdl->sdl_data, sdl->sdl_nlen);
++
++                      if (if_name != NULL && strcmp(name, if_name) != 0)
++                              continue;
++
++                      ifindex = sdl->sdl_index;
++
++                      if (ibytes)
++                              *ibytes = ifd->ifi_ibytes;
++                      if (ipackets)
++                              *ipackets = ifd->ifi_ipackets;
++                      if (ierrors)
++                              *ierrors = ifd->ifi_ierrors;
++                      if (idropped)
++                              *idropped = ifd->ifi_iqdrops;
++                      if (obytes)
++                              *obytes = ifd->ifi_obytes;
++                      if (opackets)
++                              *opackets = ifd->ifi_opackets;
++                      if (oerrors)
++                              *oerrors = ifd->ifi_oerrors;
++                      if (tbytes)
++                              *tbytes = ifd->ifi_ibytes +
++                                      ifd->ifi_obytes;
++                      if (tpackets)
++                              *tpackets = ifd->ifi_ipackets +
++                                      ifd->ifi_opackets;
++                      if (terrors)
++                              *terrors = ifd->ifi_ierrors +
++                                      ifd->ifi_oerrors;
++                      if (icollisions)
++                              *icollisions = ifd->ifi_collisions;
++
++                      ret = SYSINFO_RET_OK;
++              default:
++                      continue;
++              }
++      }
++
++#if 0 /* old code uses nlist & kmem groveling */
++
+       struct ifnet_head       head;
+       struct ifnet            *ifp;
+       struct ifnet            v;
+@@ -143,6 +262,7 @@ static int get_ifdata(const char *if_nam
+               *error = zbx_strdup(NULL, "Cannot find information for this network interface.");
+               return SYSINFO_RET_FAIL;
+       }
++#endif
+ 
+       return ret;
+ }



Home | Main Index | Thread Index | Old Index