Source
SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix 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
** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
typedef struct
{
zbx_uint64_t ibytes;
zbx_uint64_t ipackets;
zbx_uint64_t ierr;
zbx_uint64_t obytes;
zbx_uint64_t opackets;
zbx_uint64_t oerr;
zbx_uint64_t colls;
}
net_stat_t;
static int get_net_stat(const char *if_name, net_stat_t *ns, char **error)
{
perfstat_id_t ps_id;
perfstat_netinterface_t ps_netif;
if (NULL == if_name || '\0' == *if_name)
{
*error = zbx_strdup(NULL, "Network interface name cannot be empty.");
return SYSINFO_RET_FAIL;
}
strscpy(ps_id.name, if_name);
if (-1 == perfstat_netinterface(&ps_id, &ps_netif, sizeof(ps_netif), 1))
{
*error = zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno));
return SYSINFO_RET_FAIL;
}
ns->ibytes = (zbx_uint64_t)ps_netif.ibytes;
ns->ipackets = (zbx_uint64_t)ps_netif.ipackets;
ns->ierr = (zbx_uint64_t)ps_netif.ierrors;
ns->obytes = (zbx_uint64_t)ps_netif.obytes;
ns->opackets = (zbx_uint64_t)ps_netif.opackets;
ns->oerr = (zbx_uint64_t)ps_netif.oerrors;