diff -ruN zabbix-2.2.4.orig/src/libs/zbxsysinfo/linux/diskio.c zabbix-2.2.4/src/libs/zbxsysinfo/linux/diskio.c --- zabbix-2.2.4.orig/src/libs/zbxsysinfo/linux/diskio.c 2014-06-23 16:12:56.000000000 +0200 +++ zabbix-2.2.4/src/libs/zbxsysinfo/linux/diskio.c 2014-06-28 23:46:41.070429606 +0200 @@ -17,10 +17,12 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ +#include #include "common.h" #include "sysinfo.h" #include "stats.h" #include "diskdevices.h" +#include "log.h" #define ZBX_DEV_PFX "/dev/" #define ZBX_DEV_READ 0 @@ -68,6 +70,8 @@ ) continue #endif +extern char *CONFIG_DISK_FILTER; + int get_diskstat(const char *devname, zbx_uint64_t *dstat) { FILE *f; @@ -75,11 +79,16 @@ int i, ret = FAIL, dev_exists = FAIL; zbx_uint64_t ds[ZBX_DSTAT_MAX], rdev_major, rdev_minor; zbx_stat_t dev_st; - int found = 0; + int is_re, found = 0; + regex_t re; for (i = 0; i < ZBX_DSTAT_MAX; i++) dstat[i] = (zbx_uint64_t)__UINT64_C(0); + if ( (devname == NULL || '\0' == *devname || 0 == strcmp(devname, "all")) + && CONFIG_DISK_FILTER != NULL) + devname = CONFIG_DISK_FILTER; + if (NULL != devname && '\0' != *devname && 0 != strcmp(devname, "all")) { *dev_path = '\0'; @@ -94,20 +103,25 @@ if (NULL == (f = fopen(INFO_FILE_NAME, "r"))) return ret; + if ('^' == *devname || '(' == *devname) + is_re = (regcomp(&re, devname, REG_EXTENDED|REG_NOSUB) == 0); + else + is_re = 0; + + zabbix_log(LOG_LEVEL_DEBUG, "get_diskstat: is_re=%d, if_name=[%s]", is_re, devname); + while (NULL != fgets(tmp, sizeof(tmp), f)) { PARSE(tmp); - if (NULL != devname && '\0' != *devname && 0 != strcmp(devname, "all")) + if (is_re || (NULL != devname && '\0' != *devname && 0 != strcmp(devname, "all"))) { - if (0 != strcmp(name, devname)) + if (is_re ? regexec(&re, name, (size_t) 0, NULL, 0) : strcmp (devname, name)) { if (SUCCEED != dev_exists || major(dev_st.st_rdev) != rdev_major || minor(dev_st.st_rdev) != rdev_minor) continue; } - else - found = 1; } dstat[ZBX_DSTAT_R_OPER] += ds[ZBX_DSTAT_R_OPER]; @@ -116,10 +130,10 @@ dstat[ZBX_DSTAT_W_SECT] += ds[ZBX_DSTAT_W_SECT]; ret = SUCCEED; - - if (1 == found) - break; } + + if (is_re) regfree(&re); + zbx_fclose(f); return ret; diff -ruN zabbix-2.2.4.orig/src/libs/zbxsysinfo/linux/net.c zabbix-2.2.4/src/libs/zbxsysinfo/linux/net.c --- zabbix-2.2.4.orig/src/libs/zbxsysinfo/linux/net.c 2014-06-23 16:12:56.000000000 +0200 +++ zabbix-2.2.4/src/libs/zbxsysinfo/linux/net.c 2014-06-28 23:40:59.689361152 +0200 @@ -17,9 +17,11 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ +#include #include "common.h" #include "sysinfo.h" #include "zbxjson.h" +#include "log.h" typedef struct { @@ -37,13 +39,28 @@ static int get_net_stat(const char *if_name, net_stat_t *result) { - int ret = SYSINFO_RET_FAIL; - char line[MAX_STRING_LEN], name[MAX_STRING_LEN], *p; - FILE *f; + extern char *CONFIG_NIC_FILTER; + int ret = SYSINFO_RET_FAIL; + char line[MAX_STRING_LEN], name[MAX_STRING_LEN], *p; + FILE *f; + net_stat_t tmpstat; + int is_re, found; + regex_t re; + + memset(result, 0, sizeof(*result)); if (NULL == if_name || '\0' == *if_name) return SYSINFO_RET_FAIL; + if (0 == strcmp (if_name, "all") && CONFIG_NIC_FILTER != NULL) + if_name = CONFIG_NIC_FILTER; + + if ('^' == *if_name || '(' == *if_name) + is_re = (regcomp(&re, if_name, REG_EXTENDED|REG_NOSUB) == 0); + else + is_re = 0; + zabbix_log(LOG_LEVEL_DEBUG, "get_net_stat: is_re=%d, if_name=[%s]", is_re, if_name); + if (NULL != (f = fopen("/proc/net/dev", "r"))) { while (NULL != fgets(line, sizeof(line), f)) @@ -58,20 +75,29 @@ ZBX_FS_UI64 "\t" ZBX_FS_UI64 "\t" ZBX_FS_UI64 "\t" ZBX_FS_UI64 "\t%*s\t" ZBX_FS_UI64 "\t%*s\t%*s\n", name, - &(result->ibytes), /* bytes */ - &(result->ipackets), /* packets */ - &(result->ierr), /* errs */ - &(result->idrop), /* drop */ - &(result->obytes), /* bytes */ - &(result->opackets), /* packets */ - &(result->oerr), /* errs */ - &(result->odrop), /* drop */ - &(result->colls))) /* icolls */ + &tmpstat.ibytes, /* bytes */ + &tmpstat.ipackets, /* packets */ + &tmpstat.ierr, /* errs */ + &tmpstat.idrop, /* drop */ + &tmpstat.obytes, /* bytes */ + &tmpstat.opackets, /* packets*/ + &tmpstat.oerr, /* errs */ + &tmpstat.odrop, /* drop */ + &tmpstat.colls)) /* icolls */ { - if (0 == strcmp(name, if_name)) + if (!(is_re ? regexec(&re, name, (size_t) 0, NULL, 0) : strcmp (if_name, name))) { + result->ibytes += tmpstat.ibytes; + result->ipackets += tmpstat.ipackets; + result->ierr += tmpstat.ierr; + result->idrop += tmpstat.idrop; + result->obytes += tmpstat.obytes; + result->opackets += tmpstat.opackets; + result->oerr += tmpstat.oerr; + result->odrop += tmpstat.odrop; + result->colls += tmpstat.colls; + ret = SYSINFO_RET_OK; - break; } } } @@ -79,8 +105,7 @@ zbx_fclose(f); } - if (ret != SYSINFO_RET_OK) - memset(result, 0, sizeof(net_stat_t)); + if (is_re) regfree(&re); return ret; } diff -ruN zabbix-2.2.4.orig/src/zabbix_agent/active.h zabbix-2.2.4/src/zabbix_agent/active.h --- zabbix-2.2.4.orig/src/zabbix_agent/active.h 2014-06-23 16:12:56.000000000 +0200 +++ zabbix-2.2.4/src/zabbix_agent/active.h 2014-06-28 23:40:59.689361152 +0200 @@ -32,6 +32,9 @@ extern int CONFIG_MAX_LINES_PER_SECOND; extern char *CONFIG_LISTEN_IP; extern int CONFIG_LISTEN_PORT; +extern char *CONFIG_DISK_FILTER; +extern char *CONFIG_NIC_FILTER; + /* define minimal and maximal values of lines to send by agent */ /* per second for checks `log' and `eventlog', used to parse key parameters */ diff -ruN zabbix-2.2.4.orig/src/zabbix_agent/zabbix_agentd.c zabbix-2.2.4/src/zabbix_agent/zabbix_agentd.c --- zabbix-2.2.4.orig/src/zabbix_agent/zabbix_agentd.c 2014-06-23 16:12:56.000000000 +0200 +++ zabbix-2.2.4/src/zabbix_agent/zabbix_agentd.c 2014-06-28 23:40:59.690361178 +0200 @@ -467,6 +467,10 @@ {"PerfCounter", &CONFIG_PERF_COUNTERS, TYPE_MULTISTRING, PARM_OPT, 0, 0}, #endif + {"DiskFilter", &CONFIG_DISK_FILTER, TYPE_STRING, + PARM_OPT, 0, 0}, + {"NicFilter", &CONFIG_NIC_FILTER, TYPE_STRING, + PARM_OPT, 0, 0}, {NULL} }; diff -ruN zabbix-2.2.4.orig/src/zabbix_agent/zbxconf.c zabbix-2.2.4/src/zabbix_agent/zbxconf.c --- zabbix-2.2.4.orig/src/zabbix_agent/zbxconf.c 2014-06-23 16:12:56.000000000 +0200 +++ zabbix-2.2.4/src/zabbix_agent/zbxconf.c 2014-06-28 23:40:59.690361178 +0200 @@ -61,6 +61,8 @@ #if defined(_WINDOWS) char **CONFIG_PERF_COUNTERS = NULL; #endif +char *CONFIG_DISK_FILTER = NULL; +char *CONFIG_NIC_FILTER = NULL; /****************************************************************************** * * diff -ruN zabbix-2.2.4.orig/src/zabbix_agent/zbxconf.h zabbix-2.2.4/src/zabbix_agent/zbxconf.h --- zabbix-2.2.4.orig/src/zabbix_agent/zbxconf.h 2014-06-23 16:12:56.000000000 +0200 +++ zabbix-2.2.4/src/zabbix_agent/zbxconf.h 2014-06-28 23:40:59.691361203 +0200 @@ -39,6 +39,8 @@ #ifdef _WINDOWS extern char **CONFIG_PERF_COUNTERS; #endif +extern char *CONFIG_DISK_FILTER; +extern char *CONFIG_NIC_FILTER; void load_aliases(char **lines); void load_user_parameters(char **lines);