Source
SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
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;
}
zbx_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;
ns->colls = (zbx_uint64_t)ps_netif.collisions;
return SYSINFO_RET_OK;