summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-11-01 15:52:10 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-11-01 15:52:10 +0000
commit2c9ca1001703a1ba0ae7b6d4cd238ebd44148fdc (patch)
treefc0cf11a6f9aff4e59bcef0f20986dc08fed12f3 /src
parent12b9d9858224301d1abb19f08956964c6fabd9a0 (diff)
downloadzabbix-2c9ca1001703a1ba0ae7b6d4cd238ebd44148fdc.tar.gz
zabbix-2c9ca1001703a1ba0ae7b6d4cd238ebd44148fdc.tar.xz
zabbix-2c9ca1001703a1ba0ae7b6d4cd238ebd44148fdc.zip
- added new interface of sysinfo function for others platforms (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@2237 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
-rw-r--r--src/libs/zbxsysinfo/freebsd/cpu.c431
-rw-r--r--src/libs/zbxsysinfo/freebsd/diskio.c405
-rw-r--r--src/libs/zbxsysinfo/freebsd/diskspace.c413
-rw-r--r--src/libs/zbxsysinfo/freebsd/freebsd.c489
-rw-r--r--src/libs/zbxsysinfo/freebsd/inodes.c296
-rw-r--r--src/libs/zbxsysinfo/freebsd/memory.c338
-rw-r--r--src/libs/zbxsysinfo/freebsd/proc.c489
-rw-r--r--src/libs/zbxsysinfo/freebsd/sensors.c180
-rw-r--r--src/libs/zbxsysinfo/freebsd/swap.c264
-rw-r--r--src/libs/zbxsysinfo/freebsd/uptime.c141
-rw-r--r--src/libs/zbxsysinfo/hpux/cpu.c431
-rw-r--r--src/libs/zbxsysinfo/hpux/diskio.c405
-rw-r--r--src/libs/zbxsysinfo/hpux/diskspace.c413
-rw-r--r--src/libs/zbxsysinfo/hpux/inodes.c296
-rw-r--r--src/libs/zbxsysinfo/hpux/memory.c338
-rw-r--r--src/libs/zbxsysinfo/hpux/proc.c493
-rw-r--r--src/libs/zbxsysinfo/hpux/sensors.c180
-rw-r--r--src/libs/zbxsysinfo/hpux/swap.c264
-rw-r--r--src/libs/zbxsysinfo/hpux/uptime.c141
-rw-r--r--src/libs/zbxsysinfo/netbsd/cpu.c431
-rw-r--r--src/libs/zbxsysinfo/netbsd/diskio.c405
-rw-r--r--src/libs/zbxsysinfo/netbsd/diskspace.c413
-rw-r--r--src/libs/zbxsysinfo/netbsd/inodes.c296
-rw-r--r--src/libs/zbxsysinfo/netbsd/memory.c338
-rw-r--r--src/libs/zbxsysinfo/netbsd/netbsd.c489
-rw-r--r--src/libs/zbxsysinfo/netbsd/proc.c493
-rw-r--r--src/libs/zbxsysinfo/netbsd/sensors.c180
-rw-r--r--src/libs/zbxsysinfo/netbsd/swap.c264
-rw-r--r--src/libs/zbxsysinfo/netbsd/uptime.c141
-rw-r--r--src/libs/zbxsysinfo/openbsd/cpu.c431
-rw-r--r--src/libs/zbxsysinfo/openbsd/diskio.c405
-rw-r--r--src/libs/zbxsysinfo/openbsd/diskspace.c413
-rw-r--r--src/libs/zbxsysinfo/openbsd/inodes.c296
-rw-r--r--src/libs/zbxsysinfo/openbsd/memory.c338
-rw-r--r--src/libs/zbxsysinfo/openbsd/openbsd.c489
-rw-r--r--src/libs/zbxsysinfo/openbsd/proc.c493
-rw-r--r--src/libs/zbxsysinfo/openbsd/sensors.c180
-rw-r--r--src/libs/zbxsysinfo/openbsd/swap.c264
-rw-r--r--src/libs/zbxsysinfo/openbsd/uptime.c141
-rw-r--r--src/libs/zbxsysinfo/osf/cpu.c431
-rw-r--r--src/libs/zbxsysinfo/osf/diskio.c405
-rw-r--r--src/libs/zbxsysinfo/osf/diskspace.c417
-rw-r--r--src/libs/zbxsysinfo/osf/inodes.c296
-rw-r--r--src/libs/zbxsysinfo/osf/memory.c412
-rw-r--r--src/libs/zbxsysinfo/osf/osf.c489
-rw-r--r--src/libs/zbxsysinfo/osf/proc.c493
-rw-r--r--src/libs/zbxsysinfo/osf/sensors.c180
-rw-r--r--src/libs/zbxsysinfo/osf/swap.c264
-rw-r--r--src/libs/zbxsysinfo/osf/uptime.c141
-rw-r--r--src/libs/zbxsysinfo/osx/cpu.c431
-rw-r--r--src/libs/zbxsysinfo/osx/diskio.c405
-rw-r--r--src/libs/zbxsysinfo/osx/diskspace.c413
-rw-r--r--src/libs/zbxsysinfo/osx/inodes.c296
-rw-r--r--src/libs/zbxsysinfo/osx/memory.c338
-rw-r--r--src/libs/zbxsysinfo/osx/osx.c490
-rw-r--r--src/libs/zbxsysinfo/osx/proc.c493
-rw-r--r--src/libs/zbxsysinfo/osx/sensors.c180
-rw-r--r--src/libs/zbxsysinfo/osx/swap.c264
-rw-r--r--src/libs/zbxsysinfo/osx/uptime.c141
-rw-r--r--src/libs/zbxsysinfo/solaris/net.c6
-rw-r--r--src/libs/zbxsysinfo/unknown/cpu.c431
-rw-r--r--src/libs/zbxsysinfo/unknown/diskio.c405
-rw-r--r--src/libs/zbxsysinfo/unknown/diskspace.c413
-rw-r--r--src/libs/zbxsysinfo/unknown/inodes.c296
-rw-r--r--src/libs/zbxsysinfo/unknown/memory.c338
-rw-r--r--src/libs/zbxsysinfo/unknown/proc.c488
-rw-r--r--src/libs/zbxsysinfo/unknown/sensors.c180
-rw-r--r--src/libs/zbxsysinfo/unknown/swap.c264
-rw-r--r--src/libs/zbxsysinfo/unknown/unknown.c489
-rw-r--r--src/libs/zbxsysinfo/unknown/uptime.c141
70 files changed, 13206 insertions, 10531 deletions
diff --git a/src/libs/zbxsysinfo/freebsd/cpu.c b/src/libs/zbxsysinfo/freebsd/cpu.c
index f8e94125..4e7e1502 100644
--- a/src/libs/zbxsysinfo/freebsd/cpu.c
+++ b/src/libs/zbxsysinfo/freebsd/cpu.c
@@ -19,183 +19,161 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-/* AIX CPU */
-#ifdef HAVE_KNLIST_H
- #include <knlist.h>
-#endif
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_CPU_IDLE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle1]",value,msg,mlen_max);
+ return get_stat("cpu[idle1]", flags, result);
}
-int SYSTEM_CPU_IDLE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle5]",value,msg,mlen_max);
+ return get_stat("cpu[idle5]", flags, result);
}
-int SYSTEM_CPU_IDLE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle15]",value,msg,mlen_max);
+ return get_stat("cpu[idle15]", flags, result);
}
-int SYSTEM_CPU_NICE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice1]",value,msg,mlen_max);
+ return get_stat("cpu[nice1]", flags, result);
}
-int SYSTEM_CPU_NICE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ return get_stat("cpu[nice5]", flags, result);
+}
+static int SYSTEM_CPU_NICE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice5]",value,msg,mlen_max);
+ return get_stat("cpu[nice15]", flags, result);
}
-int SYSTEM_CPU_NICE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+
+static int SYSTEM_CPU_USER1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice15]",value,msg,mlen_max);
+ return get_stat("cpu[user1]", flags, result);
}
-int SYSTEM_CPU_USER1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user1]",value,msg,mlen_max);
+ return get_stat("cpu[user5]", flags, result);
}
-int SYSTEM_CPU_USER5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user5]",value,msg,mlen_max);
+ return get_stat("cpu[user15]", flags, result);
}
-int SYSTEM_CPU_USER15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user15]",value,msg,mlen_max);
+ return get_stat("cpu[system1]", flags, result);
}
-int SYSTEM_CPU_SYS1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system1]",value,msg,mlen_max);
+ return get_stat("cpu[system5]", flags, result);
}
-int SYSTEM_CPU_SYS5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system5]",value,msg,mlen_max);
+ return get_stat("cpu[system15]", flags, result);
}
-int SYSTEM_CPU_SYS15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+int OLD_CPU(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system15]",value,msg,mlen_max);
+ return get_stat(cmd, flags, result);
+}
+
+int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"idle", "avg1" , SYSTEM_CPU_IDLE1},
+ {"idle", "avg5" , SYSTEM_CPU_IDLE5},
+ {"idle", "avg15", SYSTEM_CPU_IDLE15},
+ {"nice", "avg1" , SYSTEM_CPU_NICE1},
+ {"nice", "avg5" , SYSTEM_CPU_NICE5},
+ {"nice", "avg15", SYSTEM_CPU_NICE15},
+ {"user", "avg1" , SYSTEM_CPU_USER1},
+ {"user", "avg5" , SYSTEM_CPU_USER5},
+ {"user", "avg15", SYSTEM_CPU_USER15},
+ {"system", "avg1" , SYSTEM_CPU_SYS1},
+ {"system", "avg5" , SYSTEM_CPU_SYS5},
+ {"system", "avg15", SYSTEM_CPU_SYS15},
+ {0, 0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "user");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+ }
+ return SYSINFO_RET_FAIL;
}
/* AIX CPU info */
@@ -232,14 +210,19 @@ static int getloadavg_kmem(double loadavg[], int nelem)
}
#endif
-int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[0];
return SYSINFO_RET_OK;
}
else
@@ -250,24 +233,33 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_1_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_1_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,1,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,1, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -278,20 +270,29 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return SYSINFO_RET_FAIL;
}
- *value=loadavg[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[0];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -300,14 +301,19 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
#endif
}
-int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[1];
return SYSINFO_RET_OK;
}
else
@@ -318,24 +324,33 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_5_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_5_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,2,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,2, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -346,20 +361,29 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[1];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -368,14 +392,19 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#endif
}
-int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[2];
return SYSINFO_RET_OK;
}
else
@@ -386,24 +415,33 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_15_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_15_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,3,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,3, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -414,20 +452,29 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[2];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -435,3 +482,69 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#endif
#endif
}
+
+int SYSTEM_CPU_LOAD(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"avg1" , SYSTEM_CPU_LOAD1},
+ {"avg5" , SYSTEM_CPU_LOAD5},
+ {"avg15", SYSTEM_CPU_LOAD15},
+ {0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/freebsd/diskio.c b/src/libs/zbxsysinfo/freebsd/diskio.c
index 11da801b..23d0c450 100644
--- a/src/libs/zbxsysinfo/freebsd/diskio.c
+++ b/src/libs/zbxsysinfo/freebsd/diskio.c
@@ -19,271 +19,358 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int DISKREADOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+
+ return get_stat(key, flags, result);
+}
+
+int VFS_DEV_WRITE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
- return get_stat(key,value,msg,mlen_max);
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKWRITEOPS1},
+ {"ops", "avg5" , DISKWRITEOPS5},
+ {"ops", "avg15", DISKWRITEOPS15},
+ {"bps", "avg1" , DISKWRITEBLKS1},
+ {"bps", "avg5" , DISKWRITEBLKS5},
+ {"bps", "avg15", DISKWRITEBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
}
-int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int VFS_DEV_READ(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKREADOPS1},
+ {"ops", "avg5" , DISKREADOPS5},
+ {"ops", "avg15", DISKREADOPS15},
+ {"bps", "avg1" , DISKREADBLKS1},
+ {"bps", "avg5" , DISKREADBLKS5},
+ {"bps", "avg15", DISKREADBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+static int DISK_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",2,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",2,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",3,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",3,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",4,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",4,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",5,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",5,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",6,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",6,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
+
+int OLD_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"disk_io") == 0)
+ {
+ ret = DISK_IO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rio") == 0)
+ {
+ ret = DISK_RIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wio") == 0)
+ {
+ ret = DISK_WIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rblk") == 0)
+ {
+ ret = DISK_RBLK(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wblk") == 0)
+ {
+ ret = DISK_WBLK(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/freebsd/diskspace.c b/src/libs/zbxsysinfo/freebsd/diskspace.c
index b0955ef6..e2120ac6 100644
--- a/src/libs/zbxsysinfo/freebsd/diskspace.c
+++ b/src/libs/zbxsysinfo/freebsd/diskspace.c
@@ -19,302 +19,227 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
+#include "common.h"
+#include "sysinfo.h"
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
+int get_fs_size_stat(char *fs, double *total, double *free, double *usage)
+{
+#ifdef HAVE_SYS_STATVFS_H
+ struct statvfs s;
+#else
+ struct statfs s;
#endif
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
+ assert(fs);
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
#endif
+ {
+ return SYSINFO_RET_FAIL;
+ }
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
+#ifdef HAVE_SYS_STATVFS_H
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_frsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bavail * (s.f_frsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bavail) * (s.f_frsize / 1024.0));
+#else
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_bsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bfree * (s.f_bsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0));
+#endif
+ return SYSINFO_RET_OK;
+}
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
+static int VFS_FS_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
+ assert(result);
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
+ clean_result(result);
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
-#include "common.h"
-#include "sysinfo.h"
+ return SYSINFO_RET_OK;
+}
-int VFS_FS_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return s.f_bavail * (s.f_bsize / 1024.0);*/
- *value=s.f_bavail * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_bavail * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- return SYSINFO_RET_FAIL;
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_USED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return (s.f_blocks-s.f_bavail) * (s.f_bsize / 1024.0);*/
- *value=(s.f_blocks-s.f_bavail) * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=blocks_used * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_size_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
- return SYSINFO_RET_FAIL;
-#endif
}
-int VFS_FS_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return s.f_blocks * (s.f_bsize / 1024.0);*/
- *value= s.f_blocks * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_blocks * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- return SYSINFO_RET_FAIL;
-#endif
+ if(get_fs_size_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double used;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_USED(cmd, mountPoint, &used, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
- if(total == 0)
- {
- return SYSINFO_RET_FAIL;
- }
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_size_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
- *value = 100*used/total;
- return SYSINFO_RET_OK;
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+int VFS_FS_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if(SYSINFO_RET_OK != VFS_FS_FREE(cmd, mountPoint, &free, msg, mlen_max))
+ FS_FNCLIST fl[] =
+ {
+ {"free" , VFS_FS_FREE},
+ {"total" , VFS_FS_TOTAL},
+ {"used", VFS_FS_USED},
+ {"pfree" , VFS_FS_PFREE},
+ {"pused" , VFS_FS_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
{
- return SYSINFO_RET_FAIL;
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if(total == 0)
+
+ for(i=0; fl[i].mode!=0; i++)
{
- return SYSINFO_RET_FAIL;
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+
+ return SYSINFO_RET_FAIL;
}
diff --git a/src/libs/zbxsysinfo/freebsd/freebsd.c b/src/libs/zbxsysinfo/freebsd/freebsd.c
index e04ef0e7..df66bf38 100644
--- a/src/libs/zbxsysinfo/freebsd/freebsd.c
+++ b/src/libs/zbxsysinfo/freebsd/freebsd.c
@@ -18,254 +18,179 @@
**/
#include "config.h"
+#include "common.h"
#include "sysinfo.h"
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_CPU_IDLE1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_IDLE5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_IDLE15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int VFS_FS_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_USED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_PUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-
-int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int VFS_FILE_ATIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_CKSUM(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_CTIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_MD5SUM(const char *cmd, const char *filename, char **value, const char *msg, int mlen_max);
-int VFS_FILE_MTIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_REGEXP(const char *cmd, const char *filename, char **value, const char *msg, int mlen_max);
-int VFS_FILE_REGMATCH(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_SIZE(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_EXISTS(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-
-int VFS_FS_INODE_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_INODE_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-
-
-int KERNEL_MAXFILES(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int KERNEL_MAXPROC(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int NET_IF_IBYTES1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_IBYTES5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_IBYTES15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int NET_IF_OBYTES1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_OBYTES5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_OBYTES15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int DISKREADOPS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADOPS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADOPS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int AGENT_PING(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int PROC_NUM(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int PROC_MEMORY(const char *cmd, const char *param, double *value, const char *msg, int mlen_max);
-
-int PROCCOUNT(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SENSOR_TEMP1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SENSOR_TEMP2(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SENSOR_TEMP3(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int TCP_LISTEN(const char *cmd, const char *porthex,double *value, const char *msg, int mlen_max);
-
-int EXECUTE(const char *cmd, const char *command,double *value, const char *msg, int mlen_max);
-int EXECUTE_STR(const char *cmd, const char *command, const char *parameter, char **value, const char *msg, int mlen_max);
-int AGENT_VERSION(const char *cmd, const char *command,char **value, const char *msg, int mlen_max);
-
-
-int CHECK_SERVICE(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-int CHECK_SERVICE_PERF(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-int CHECK_PORT(const char *cmd, const char *ip_and_port,double *value, const char *msg, int mlen_max);
-int CHECK_DNS(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-
ZBX_METRIC parameters_specific[]=
-/* KEY FUNCTION (if double) FUNCTION (if string) PARAM*/
+/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
/* Outdated */
-
- {"cksum[*]" ,VFS_FILE_CKSUM, 0, "/etc/services"},
- {"cpu[idle1]" ,SYSTEM_CPU_IDLE1, 0, 0},
- {"cpu[idle5]" ,SYSTEM_CPU_IDLE5, 0, 0},
- {"cpu[idle15]" ,SYSTEM_CPU_IDLE15, 0, 0},
- {"cpu[nice1]" ,SYSTEM_CPU_NICE1, 0, 0},
- {"cpu[nice5]" ,SYSTEM_CPU_NICE5, 0, 0},
- {"cpu[nice15]" ,SYSTEM_CPU_NICE15, 0, 0},
- {"cpu[system1]" ,SYSTEM_CPU_SYS1, 0, 0},
- {"cpu[system5]" ,SYSTEM_CPU_SYS5, 0, 0},
- {"cpu[system15]" ,SYSTEM_CPU_SYS15, 0, 0},
- {"cpu[user1]" ,SYSTEM_CPU_USER1, 0, 0},
- {"cpu[user5]" ,SYSTEM_CPU_USER5, 0, 0},
- {"cpu[user15]" ,SYSTEM_CPU_USER15, 0, 0},
- {"diskfree[*]" ,VFS_FS_FREE, 0, "/"},
- {"disktotal[*]" ,VFS_FS_TOTAL, 0, "/"},
- {"diskused[*]" ,VFS_FS_USED, 0, "/"},
- {"diskfree_perc[*]" ,VFS_FS_PFREE, 0, "/"},
- {"diskused_perc[*]" ,VFS_FS_PUSED, 0, "/"},
- {"file[*]" ,VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize[*]" ,VFS_FILE_SIZE, 0, "/etc/passwd"},
- {"inodefree[*]" ,VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal[*]" ,VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc[*]" ,VFS_FS_INODE_PFREE, 0, "/"},
- {"kern[maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kern[maxproc]" ,KERNEL_MAXPROC, 0, 0},
- {"md5sum[*]" ,0, VFS_FILE_MD5SUM, "/etc/services"},
- {"memory[buffers]" ,VM_MEMORY_BUFFERS, 0, 0},
- {"memory[cached]" ,VM_MEMORY_CACHED, 0, 0},
- {"memory[free]" ,VM_MEMORY_FREE, 0, 0},
- {"memory[shared]" ,VM_MEMORY_SHARED, 0, 0},
- {"memory[total]" ,VM_MEMORY_TOTAL, 0, 0},
- {"netloadin1[*]" ,NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5[*]" ,NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15[*]" ,NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1[*]" ,NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5[*]" ,NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15[*]" ,NET_IF_OBYTES15, 0, "lo"},
- {"ping" ,AGENT_PING, 0, 0},
- {"proc_cnt[*]" ,PROC_NUM, 0, "inetd"},
- {"swap[free]" ,SYSTEM_SWAP_FREE, 0, 0},
- {"swap[total]" ,SYSTEM_SWAP_TOTAL, 0, 0},
- {"system[procload]" ,SYSTEM_CPU_LOAD1, 0, 0},
- {"system[procload5]" ,SYSTEM_CPU_LOAD5, 0, 0},
- {"system[procload15]" ,SYSTEM_CPU_LOAD15, 0, 0},
- {"system[hostname]" ,0, EXECUTE_STR, "hostname"},
- {"system[uname]" ,0, EXECUTE_STR, "uname -a"},
- {"system[uptime]" ,SYSTEM_UPTIME, 0, 0},
- {"system[users]" ,EXECUTE, 0,"who|wc -l"},
- {"version[zabbix_agent]", 0, AGENT_VERSION, 0},
+/* incorrect OLD naming */
+ {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
+/*
+ {"cpu[idle1]", 0, 0, 0, 0},
+ {"cpu[idle5]", 0, 0, 0, 0},
+ {"cpu[idle15]", 0, 0, 0, 0},
+ {"cpu[nice1]", 0, 0, 0, 0},
+ {"cpu[nice5]", 0, 0, 0, 0},
+ {"cpu[nice15]", 0, 0, 0, 0},
+ {"cpu[system1]", 0, 0, 0, 0},
+ {"cpu[system5]", 0, 0, 0, 0},
+ {"cpu[system15]", 0, 0, 0, 0},
+ {"cpu[user1]", 0, 0, 0, 0},
+ {"cpu[user5]", 0, 0, 0, 0},
+ {"cpu[user15]", 0, 0, 0, 0},
+*/
+ {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
+/*
+ {"io[disk_io]", 0, 0, 0, 0},
+ {"io[disk_rio]", 0, 0, 0, 0},
+ {"io[disk_wio]", 0, 0, 0, 0},
+ {"io[disk_rblk]", 0, 0, 0, 0},
+ {"io[disk_wblk]", 0, 0, 0, 0},
+*/
+ {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
+/*
+ {"kern[maxfiles]", 0, 0, 0, 0},
+ {"kern[maxproc]", 0, 0, 0, 0},
+*/
+ {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
+/*
+ {"memory[buffers]", 0, 0, 0, 0},
+ {"memory[cached]", 0, 0, 0, 0},
+ {"memory[free]", 0, 0, 0, 0},
+ {"memory[shared]", 0, 0, 0, 0},
+ {"memory[total]", 0, 0, 0, 0},
+*/
+ {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
+/*
+ {"system[proccount]", 0, 0, 0, 0},
+
+ {"system[procload]", 0, 0, 0, 0},
+ {"system[procload5]", 0, 0, 0, 0},
+ {"system[procload15]", 0, 0, 0, 0},
+ {"system[hostname]", 0, 0, 0, 0},
+ {"system[uname]", 0, 0, 0, 0},
+ {"system[uptime]", 0, 0, 0, 0},
+ {"system[users]", 0, 0, 0, 0},
+
+ {"system[procrunning]", 0, 0, 0, 0},
+*/
+ {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
+/*
+ {"sensor[temp1]", 0, 0, 0, 0},
+ {"sensor[temp2]", 0, 0, 0, 0},
+ {"sensor[temp3]", 0, 0, 0, 0},
+*/
+ {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
+/*
+ {"swap[free]", 0, 0, 0, 0},
+ {"swap[total]", 0, 0, 0, 0},
+*/
+ {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
+/*
+ {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
+*/
+/* correct OLD naming */
+/*
+ {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
+*/
+/*
+ {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
+ {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
+ {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
+ {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
+ {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
+*/
+/*
+ {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+*/
+/*
+ {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
+ {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
+ {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
+*/
+/*
+ {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
+*/
+/*
+ {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
+ {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
+ {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
+ {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
+ {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
+ {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
+*/
+/*
+ {"ping", 0, AGENT_PING, 0, 0},
+*/
/* New naming */
-
- {"agent.ping" ,AGENT_PING, 0, 0},
- {"agent.version", 0, AGENT_VERSION, 0},
-
- {"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
-
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
- {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
-
- {"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers" ,VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached" ,VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free" ,VM_MEMORY_FREE, 0, 0},
-
- {"vfs.fs.free[*]" ,VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total[*]" ,VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used[*]" ,VFS_FS_USED, 0, "/"},
-
- {"vfs.fs.pfree[*]" ,VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused[*]" ,VFS_FS_PUSED, 0, "/"},
-
- {"vfs.fs.inode.free[*]" ,VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total[*]",VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree[*]",VFS_FS_INODE_PFREE, 0, "/"},
-
- {"vfs.file.atime[*]" ,VFS_FILE_ATIME, 0, "/etc/passwd"},
- {"vfs.file.cksum[*]" ,VFS_FILE_CKSUM, 0, "/etc/services"},
- {"vfs.file.ctime[*]" ,VFS_FILE_CTIME, 0, "/etc/passwd"},
- {"vfs.file.exists[*]" ,VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"vfs.file.md5sum[*]" ,0, VFS_FILE_MD5SUM, "/etc/services"},
- {"vfs.file.mtime[*]" ,VFS_FILE_MTIME, 0, "/etc/passwd"},
- {"vfs.file.regexp[*]" ,0, VFS_FILE_REGEXP, "/etc/passwd,root"},
- {"vfs.file.regmatch[*]" ,VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
- {"vfs.file.size[*]" ,VFS_FILE_SIZE, 0, "/etc/passwd"},
-
- {"system.cpu.idle1" ,SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5" ,SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15" ,SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1" ,SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5" ,SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15" ,SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1" ,SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5" ,SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15" ,SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1" ,SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5" ,SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15" ,SYSTEM_CPU_USER15, 0, 0},
-
- {"net.if.ibytes1[*]" ,NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5[*]" ,NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15[*]" ,NET_IF_IBYTES15, 0, "lo"},
- {"net.if.obytes1[*]" ,NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5[*]" ,NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15[*]" ,NET_IF_OBYTES15, 0, "lo"},
-
- {"disk_read_ops1[*]" ,DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5[*]" ,DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15[*]" ,DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1[*]" ,DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5[*]" ,DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15[*]" ,DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1[*]" ,DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5[*]" ,DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15[*]" ,DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1[*]" ,DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5[*]" ,DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15[*]" ,DISKWRITEBLKS15, 0, "hda"},
-
- {"sensor[temp1]" ,SENSOR_TEMP1, 0, 0},
- {"sensor[temp2]" ,SENSOR_TEMP2, 0, 0},
- {"sensor[temp3]" ,SENSOR_TEMP3, 0, 0},
-
- {"system.cpu.load1" ,SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5" ,SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15" ,SYSTEM_CPU_LOAD15, 0, 0},
-
- {"system.hostname" ,0, EXECUTE_STR, "hostname"},
-
- {"system.swap.free" ,SYSTEM_SWAP_FREE, 0, 0},
- {"system.swap.total" ,SYSTEM_SWAP_TOTAL, 0, 0},
-
- {"system.uname" ,0, EXECUTE_STR, "uname -a"},
- {"system.uptime" ,SYSTEM_UPTIME, 0, 0},
- {"system.users.num" ,EXECUTE, 0,"who|wc -l"},
+/*
+ {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
+ {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
+ {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
+ {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
+ {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
+ {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
+ {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
+ {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
+ {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
+ {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
+ {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
+ {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
+*/
+/*
+ {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
+ {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
+ {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
+ {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
+ {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
+*/
+/*
+ {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
+ {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
+ {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
+ {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
+ {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
+*/
+/*
+ {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
+ {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
+ {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
+*/
+/*
+ {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
+ {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
+ {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
+
+ {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
+ {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
+ {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
+*/
+/*
+ {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
+ {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
+ {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
+
+ {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
+ {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
+ {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
+
+ {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
+ {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
+ {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
+
+ {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
+ {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
+ {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
+*/
+/*
+ {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
+ {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
+ {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
+*/
/****************************************
All these perameters require more than 1 second to retrieve.
@@ -277,30 +202,66 @@ ZBX_METRIC parameters_specific[]=
{"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
***************************************/
- {"io[disk_io]" ,DISK_IO, 0, 0},
- {"io[disk_rio]" ,DISK_RIO, 0, 0},
- {"io[disk_wio]" ,DISK_WIO, 0, 0},
- {"io[disk_rblk]" ,DISK_RBLK, 0, 0},
- {"io[disk_wblk]" ,DISK_WBLK, 0, 0},
-
-
-
- {"system[proccount]" ,PROCCOUNT, 0, 0},
-
-#ifdef HAVE_PROC_LOADAVG
- {"system[procrunning]" ,EXECUTE, 0, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '"},
-#endif
-
/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-
- {"net[listen_23]" ,TCP_LISTEN, 0, "0017"},
- {"net[listen_80]" ,TCP_LISTEN, 0, "0050"},
-
- {"check_port[*]" ,CHECK_PORT, 0, "80"},
-
- {"check_service[*]" ,CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"dns[*]" ,CHECK_DNS, 0, "127.0.0.1,localhost"},
- {"check_service_perf[*]",CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+/*
+ {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
+ {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
+ {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+*/
+/*
+ {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+*/
+ {"agent.ping", 0, AGENT_PING, 0, 0},
+ {"agent.version", 0, AGENT_VERSION, 0, 0},
+
+ {"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
+ {"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+
+ {"vfs.file.atime", CF_USEUPARAM, VFS_FILE_ATIME, 0, "/etc/passwd"},
+ {"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
+ {"vfs.file.ctime", CF_USEUPARAM, VFS_FILE_CTIME, 0, "/etc/passwd"},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
+ {"vfs.file.mtime", CF_USEUPARAM, VFS_FILE_MTIME, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+
+/************************************
+ * NEW FUNCTIONS *
+ ************************************/
+
+ {"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+
+ {"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
+ {"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
+ {"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+
+ {"net.if.in", CF_USEUPARAM, NET_IF_IN, 0, "lo,bytes"},
+ {"net.if.out", CF_USEUPARAM, NET_IF_OUT, 0, "lo,bytes"},
+
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
+
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
+
+ {"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
+
+ {"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
+ {"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+
+ {"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
+
+ {"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
+
+ {"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
+
+ {"system.hostname", 0, SYSTEM_HOSTNAME, 0, 0},
+
+ {"system.uname", 0, SYSTEM_UNAME, 0, 0},
+ {"system.uptime", 0, SYSTEM_UPTIME, 0, 0},
+ {"system.users.num", 0, SYSTEM_UNUM, 0, 0},
{0}
};
diff --git a/src/libs/zbxsysinfo/freebsd/inodes.c b/src/libs/zbxsysinfo/freebsd/inodes.c
index da92ca93..c8109f28 100644
--- a/src/libs/zbxsysinfo/freebsd/inodes.c
+++ b/src/libs/zbxsysinfo/freebsd/inodes.c
@@ -19,144 +19,226 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-
-/* FreeBSD/MacOS/OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int VFS_FS_INODE_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int get_fs_inodes_stat(char *fs, double *total, double *free, double *usage)
{
#ifdef HAVE_SYS_STATVFS_H
struct statvfs s;
-
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- *value=s.f_favail;
- return SYSINFO_RET_OK;
#else
struct statfs s;
- long blocks_used;
- long blocks_percent_used;
-
- if ( statfs( (char *)mountPoint, &s) != 0 )
+#endif
+
+ assert(fs);
+
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
+#endif
{
return SYSINFO_RET_FAIL;
}
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_ffree;
- return SYSINFO_RET_OK;
-
- }
- return SYSINFO_RET_FAIL;
+ if(total)
+ (*total) = (double)(s.f_files);
+#ifdef HAVE_SYS_STATVFS_H
+ if(free)
+ (*free) = (double)(s.f_favail);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_favail);
+#else
+ if(free)
+ (*free) = (double)(s.ffree);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_ffree);
#endif
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
return SYSINFO_RET_FAIL;
- }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- *value=s.f_files;
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+}
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_files;
- return SYSINFO_RET_OK;
+static int VFS_FS_INODE_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- }
- return SYSINFO_RET_FAIL;
-#endif
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_inodes_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
+
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_INODE_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+int VFS_FS_INODE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if(SYSINFO_RET_OK != VFS_FS_INODE_FREE(cmd, mountPoint, &free, msg, mlen_max))
+ FS_FNCLIST fl[] =
{
- return SYSINFO_RET_FAIL;
+ {"free" , VFS_FS_INODE_FREE},
+ {"total" , VFS_FS_INODE_TOTAL},
+ {"used", VFS_FS_INODE_USED},
+ {"pfree" , VFS_FS_INODE_PFREE},
+ {"pused" , VFS_FS_INODE_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if(total == 0)
+
+ for(i=0; fl[i].mode!=0; i++)
{
- return SYSINFO_RET_FAIL;
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+
+ return SYSINFO_RET_FAIL;
}
+
diff --git a/src/libs/zbxsysinfo/freebsd/memory.c b/src/libs/zbxsysinfo/freebsd/memory.c
index ae4e6b03..7dc0fcbe 100644
--- a/src/libs/zbxsysinfo/freebsd/memory.c
+++ b/src/libs/zbxsysinfo/freebsd/memory.c
@@ -19,123 +19,10 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
/* Get CACHED memory in bytes */
@@ -145,8 +32,12 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
FILE *f;
char *t;
char c[MAX_STRING_LEN];
- double result = SYSINFO_RET_FAIL;
+ double res = 0;
+ assert(result);
+
+ clean_result(result);
+
f=fopen("/proc/meminfo","r");
if(NULL == f)
{
@@ -158,30 +49,40 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
{
t=(char *)strtok(c," ");
t=(char *)strtok(NULL," ");
- sscanf(t, "%lf", &result );
+ sscanf(t, "%lf", &res );
break;
}
}
fclose(f);
- *value=result;
+ result->type |= AR_DOUBLE;
+ result->dbl=res;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_BUFFERS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_BUFFERRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.bufferram * (double)info.mem_unit;
+ result->dbl=(double)info.bufferram * (double)info.mem_unit;
#else
- *value=(double)info.bufferram;
+ result->dbl=(double)info.bufferram;
#endif
return SYSINFO_RET_OK;
}
@@ -190,21 +91,30 @@ int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, con
return SYSINFO_RET_FAIL;
}
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_SHARED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_SHAREDRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.sharedram * (double)info.mem_unit;
+ result->dbl=(double)info.sharedram * (double)info.mem_unit;
#else
- *value=(double)info.sharedram;
+ result->dbl=(double)info.sharedram;
#endif
return SYSINFO_RET_OK;
}
@@ -212,36 +122,47 @@ int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_armshr<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_armshr<<2);
return SYSINFO_RET_OK;
#else
return SYSINFO_RET_FAIL;
#endif
-#endif
}
-int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -251,19 +172,24 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
/* Get page size */
page = pst.page_size;
/* Total physical memory in bytes */
- *value=(double)page*pst.physical_memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)page*pst.physical_memory;
return SYSINFO_RET_OK;
}
-#else
-#ifdef HAVE_SYSINFO_TOTALRAM
+#elif defined(HAVE_SYSINFO_TOTALRAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalram * (double)info.mem_unit;
+ result->dbl=(double)info.totalram * (double)info.mem_unit;
#else
- *value=(double)info.totalram;
+ result->dbl=(double)info.totalram;
#endif
return SYSINFO_RET_OK;
}
@@ -271,31 +197,39 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_rm<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_rm<<2);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_SYSCTL_H
+#elif defined(HAVE_SYS_SYSCTL_H)
static int mib[] = { CTL_HW, HW_PHYSMEM };
size_t len;
unsigned int memory;
int ret;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(memory);
if(0==sysctl(mib,2,&memory,&len,NULL,0))
{
- *value=(double)memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)memory;
ret=SYSINFO_RET_OK;
}
else
@@ -304,26 +238,34 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
-#endif
-#endif
-#endif
-#endif
}
-int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
struct pst_dynamic dyn;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -352,20 +294,25 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
*/
/* Free memory in bytes */
- *value=(double)dyn.psd_free * page;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)dyn.psd_free * page;
return SYSINFO_RET_OK;
}
}
-#else
-#ifdef HAVE_SYSINFO_FREERAM
+#elif defined(HAVE_SYSINFO_FREERAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.freeram * (double)info.mem_unit;
+ result->dbl=(double)info.freeram * (double)info.mem_unit;
#else
- *value=(double)info.freeram;
+ result->dbl=(double)info.freeram;
#endif
return SYSINFO_RET_OK;
}
@@ -373,28 +320,35 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_free<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_free<<2);
return SYSINFO_RET_OK;
-#else
/* OS/X */
-#ifdef HAVE_MACH_HOST_INFO_H
+#elif defined(HAVE_MACH_HOST_INFO_H)
vm_statistics_data_t page_info;
vm_size_t pagesize;
mach_msg_type_number_t count;
kern_return_t kret;
int ret;
+ assert(result);
+
+ clean_result(result);
+
pagesize = 0;
kret = host_page_size (mach_host_self(), &pagesize);
@@ -412,7 +366,8 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
pu = pw+pa+pi;
- *value=(double)pf;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)pf;
ret = SYSINFO_RET_OK;
}
else
@@ -421,10 +376,63 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
-#endif
-#endif
-#endif
-#endif
}
+
+int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#define MEM_FNCLIST struct mem_fnclist_s
+MEM_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ MEM_FNCLIST fl[] =
+ {
+ {"free", VM_MEMORY_FREE},
+ {"shared", VM_MEMORY_SHARED},
+ {"total", VM_MEMORY_TOTAL},
+ {"buffers", VM_MEMORY_BUFFERS},
+ {"cached", VM_MEMORY_CACHED},
+ {0, 0}
+ };
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/freebsd/proc.c b/src/libs/zbxsysinfo/freebsd/proc.c
index 7d9cf8c0..d80dac13 100644
--- a/src/libs/zbxsysinfo/freebsd/proc.c
+++ b/src/libs/zbxsysinfo/freebsd/proc.c
@@ -19,173 +19,57 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-
-#ifdef HAVE_PWD_H
-# include <pwd.h>
-#endif
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
+#include "common.h"
+#include "sysinfo.h"
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
+#define DO_SUM 0
+#define DO_MAX 1
+#define DO_MIN 2
+#define DO_AVG 3
+
+int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#if defined(HAVE_PROC_1_STATUS)
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-#ifdef HAVE_SYS_PROC_H
- #include <sys/proc.h>
-#endif
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int do_task = DO_SUM;
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-#include "common.h"
-#include "sysinfo.h"
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
-/*
-#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
-#define SDI(m) FDI("%s", m) // string info
-#define IDI(i) FDI("%i", i) // integer info
-*/
-int PROC_MEMORY(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
-{
- /* in this moment this function for this platform unsupported */
- return SYSINFO_RET_FAIL;
-}
+ FILE *f;
-int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
-{
-/* ??? */
-#if defined(HAVE_PROC_0_PSINFO)
- DIR *dir;
- struct dirent *entries;
- struct stat buf;
-
- char filename[MAX_STRING_LEN];
- char procname[MAX_STRING_LEN];
-
- int proc_ok = 0;
- int usr_ok = 0;
- int stat_ok = 0;
+ double memsize = -1;
+ int proccount = 0;
- char pr_state = 0;
-
- int fd;
-/* In the correct procfs.h, the structure name is psinfo_t */
- psinfo_t psinfo;
+ assert(result);
- int proccount=0;
-
+ clean_result(result);
+
if(num_param(param) > 3)
{
- return SYSINFO_RET_FAIL;
+ return SYSINFO_RET_FAIL;
}
-
+
if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
{
- return SYSINFO_RET_FAIL;
- }
+ return SYSINFO_RET_FAIL;
+ }
if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
{
@@ -193,130 +77,216 @@ int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg,
}
else
{
- if(usrname[0] != 0)
- {
- usrinfo = getpwnam(usrname);
- if(usrinfo == NULL)
- {
- /* incorrect user name */
- return SYSINFO_RET_FAIL;
- }
- }
- }
-
- if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ if(usrname[0] != 0)
{
- strscpy(procstat,"all");
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
}
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ strscpy(mode, "sum");
+ }
- if(strcmp(procstat,"run") == 0)
- {
- /* running */
- pr_state = SRUN;
- }
- else if(strcmp(procstat,"sleep") == 0)
- {
- /* awaiting an event */
- pr_state = SSLEEP;
- }
- else if(strcmp(procstat,"zomb") == 0)
- {
- pr_state = SZOMB;
- }
- else if(strcmp(procstat,"all") == 0)
- {
- procstat[0] = 0;
- }
- else
- {
+ if(strcmp(mode,"avg") == 0)
+ {
+ do_task = DO_AVG;
+ }
+ else if(strcmp(mode,"max") == 0)
+ {
+ do_task = DO_MAX;
+ }
+ else if(strcmp(mode,"min") == 0)
+ {
+ do_task = DO_MIN;
+ }
+ else if(strcmp(mode,"sum") == 0)
+ {
+ do_task = DO_SUM;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
return SYSINFO_RET_FAIL;
- }
-
- dir=opendir("/proc");
- if(NULL == dir)
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ usr_ok = 0;
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ /* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+ /* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
{
- return SYSINFO_RET_FAIL;
+ continue;
}
- while((entries=readdir(dir))!=NULL)
+ if(stat(filename,&buf)==0)
{
- proc_ok = 0;
- usr_ok = 0;
- stat_ok = 0;
-
- strscpy(filename,"/proc/");
- strncat(filename,entries->d_name,MAX_STRING_LEN);
- strncat(filename,"/psinfo",MAX_STRING_LEN);
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
- if(stat(filename,&buf)==0)
+ if(procname[0] != 0)
{
- fd = open (filename, O_RDONLY);
- if (fd != -1)
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
{
- if(read(fd, &psinfo, sizeof(psinfo)) == -1)
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && usr_ok)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li %s\n", name1, &lvalue, name2) != 3)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"VmSize:") != 0)
{
- close(fd);
- closedir(dir);
- return SYSINFO_RET_FAIL;
+ continue;
+ }
+
+ proccount++;
+
+ if(strcasecmp(name2, "kB") == 0)
+ {
+ lvalue <<= 10;
+ }
+ else if(strcasecmp(name2, "mB") == 0)
+ {
+ lvalue <<= 20;
+ }
+ else if(strcasecmp(name2, "GB") == 0)
+ {
+ lvalue <<= 30;
+ }
+ else if(strcasecmp(name2, "TB") == 0)
+ {
+ lvalue <<= 40;
+ }
+
+ if(memsize < 0)
+ {
+ memsize = (double) lvalue;
}
else
{
- if(procname[0] != 0)
- {
- if(strcmp(procname, psinfo.pr_fname) == 0)
- {
- proc_ok = 1;
- }
- }
- else
- {
- proc_ok = 1;
- }
-
- if(usrinfo != NULL)
- {
- /* uid_t pr_uid; real user id */
- if(usrinfo->pw_uid == psinfo.pr_uid)
- {
- usr_ok = 1;
- }
- }
- else
+ if(do_task == DO_MAX)
{
- usr_ok = 1;
+ memsize = MAX(memsize, (double) lvalue);
}
-
- if(procstat[0] != 0)
+ else if(do_task == DO_MIN)
{
- /* char pr_state; numeric lwp state */
- if(psinfo.pr_lwp.pr_state == pr_state)
- {
- state_ok = 1;
- }
+ memsize = MIN(memsize, (double) lvalue);
}
else
{
- usr_ok = 1;
- }
-
- if(proc_ok && usr_ok && state_ok)
- {
- proccount++;
+ memsize += (double) lvalue;
}
}
- close (fd);
- }
- else
- {
- continue;
+
+ break;
}
}
+
+
+ fclose(f);
}
- closedir(dir);
- *value=(double)proccount;
- return SYSINFO_RET_OK;
-
-#elif defined(HAVE_PROC_1_STATUS)
+ }
+ closedir(dir);
+
+ if(memsize < 0)
+ {
+ /* incorrect process name */
+ memsize = 0;
+ }
+
+ if(do_task == DO_AVG)
+ {
+ memsize /= (double)proccount;
+ }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = memsize;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
+}
+
+int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#if defined(HAVE_PROC_1_STATUS)
DIR *dir;
struct dirent *entries;
@@ -340,6 +310,10 @@ int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg,
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
int proccount = 0;
if(num_param(param) > 3)
@@ -369,10 +343,15 @@ int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg,
}
}
- if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
- {
- strscpy(procstat,"all");
- }
+ if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ {
+ procstat[0] = '\0';
+ }
+
+ if(procstat[0] == '\0')
+ {
+ strscpy(procstat, "all");
+ }
if(strcmp(procstat,"run") == 0)
{
@@ -515,10 +494,10 @@ int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg,
}
closedir(dir);
- *value = (double) proccount;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double) proccount;
return SYSINFO_RET_OK;
#else
return SYSINFO_RET_FAIL;
#endif
}
-
diff --git a/src/libs/zbxsysinfo/freebsd/sensors.c b/src/libs/zbxsysinfo/freebsd/sensors.c
index 32042922..956ca3d1 100644
--- a/src/libs/zbxsysinfo/freebsd/sensors.c
+++ b/src/libs/zbxsysinfo/freebsd/sensors.c
@@ -19,125 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -148,6 +35,10 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -173,7 +64,8 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -187,7 +79,7 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP2(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -198,6 +90,10 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -223,7 +119,8 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -237,7 +134,7 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP3(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -248,6 +145,10 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -273,7 +174,8 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -286,3 +188,43 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
closedir(dir);
return SYSINFO_RET_FAIL;
}
+
+int OLD_SENSOR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"temp1") == 0)
+ {
+ ret = SENSOR_TEMP1(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp2") == 0)
+ {
+ ret = SENSOR_TEMP2(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp3") == 0)
+ {
+ ret = SENSOR_TEMP3(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/freebsd/swap.c b/src/libs/zbxsysinfo/freebsd/swap.c
index db059f78..3d80fec9 100644
--- a/src/libs/zbxsysinfo/freebsd/swap.c
+++ b/src/libs/zbxsysinfo/freebsd/swap.c
@@ -19,124 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
+
/* Solaris. */
#ifndef HAVE_SYSINFO_FREESWAP
#ifdef HAVE_SYS_SWAP_SWAPTABLE
@@ -203,17 +91,22 @@ point them all to the same buffer */
#endif
#endif
-int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_FREESWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.freeswap * (double)info.mem_unit;
+ result->dbl = (double)info.freeswap * (double)info.mem_unit;
#else
- *value=(double)info.freeswap;
+ result->dbl = (double)info.freeswap;
#endif
return SYSINFO_RET_OK;
}
@@ -226,27 +119,41 @@ int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
+ assert(result);
+
+ clean_result(result);
+
get_swapinfo(&swaptotal,&swapfree);
- *value=swapfree;
+ result->type |= AR_DOUBLE;
+ result->dbl = swapfree;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
-int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_TOTALSWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalswap * (double)info.mem_unit;
+ result->dbl = (double)info.totalswap * (double)info.mem_unit;
#else
- *value=(double)info.totalswap;
+ result->dbl = (double)info.totalswap;
#endif
return SYSINFO_RET_OK;
}
@@ -259,12 +166,125 @@ int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
- get_swapinfo(&swaptotal,&swapfree);
+ assert(result);
+
+ clean_result(result);
- *value=(double)swaptotal;
+ get_swapinfo(&swaptotal,&swapfree);
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)swaptotal;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
+
+int SYSTEM_SWAP_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define SWP_FNCLIST struct swp_fnclist_s
+SWP_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ SWP_FNCLIST fl[] =
+ {
+ {"total", SYSTEM_SWAP_FREE},
+ {"free", SYSTEM_SWAP_TOTAL},
+ {0, 0}
+ };
+
+ char swapdev[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(swapdev[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(swapdev, "all");
+ }
+
+ if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "free");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+int OLD_SWAP(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"free") == 0)
+ {
+ ret = SYSTEM_SWAP_FREE(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"total") == 0)
+ {
+ ret = SYSTEM_SWAP_TOTAL(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/freebsd/uptime.c b/src/libs/zbxsysinfo/freebsd/uptime.c
index 88eee810..a38b2bd7 100644
--- a/src/libs/zbxsysinfo/freebsd/uptime.c
+++ b/src/libs/zbxsysinfo/freebsd/uptime.c
@@ -19,130 +19,22 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_UPTIME
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
- *value=(double)info.uptime;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)info.uptime;
return SYSINFO_RET_OK;
}
else
@@ -155,6 +47,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
struct timeval uptime;
int now;
+ assert(result);
+
+ clean_result(result);
+
mib[0]=CTL_KERN;
mib[1]=KERN_BOOTTIME;
@@ -167,8 +63,8 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
}
now=time(NULL);
-
- *value=(double)(now-uptime.tv_sec);
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)(now-uptime.tv_sec);
return SYSINFO_RET_OK;
#else
/* Solaris */
@@ -180,6 +76,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
long hz;
long secs;
+ assert(result);
+
+ clean_result(result);
+
hz = sysconf(_SC_CLK_TCK);
/* open kstat */
@@ -207,9 +107,14 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
/* close kstat */
kstat_close(kc);
- *value=(double)secs;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)secs;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
diff --git a/src/libs/zbxsysinfo/hpux/cpu.c b/src/libs/zbxsysinfo/hpux/cpu.c
index 49898f3d..4e7e1502 100644
--- a/src/libs/zbxsysinfo/hpux/cpu.c
+++ b/src/libs/zbxsysinfo/hpux/cpu.c
@@ -19,183 +19,161 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-/* AIX CPU */
-#ifdef HAVE_KNLIST_H
- #include <knlist.h>
-#endif
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_CPU_IDLE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle1]",value,msg,mlen_max);
+ return get_stat("cpu[idle1]", flags, result);
}
-int SYSTEM_CPU_IDLE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle5]",value,msg,mlen_max);
+ return get_stat("cpu[idle5]", flags, result);
}
-int SYSTEM_CPU_IDLE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle15]",value,msg,mlen_max);
+ return get_stat("cpu[idle15]", flags, result);
}
-int SYSTEM_CPU_NICE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice1]",value,msg,mlen_max);
+ return get_stat("cpu[nice1]", flags, result);
}
-int SYSTEM_CPU_NICE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ return get_stat("cpu[nice5]", flags, result);
+}
+static int SYSTEM_CPU_NICE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice5]",value,msg,mlen_max);
+ return get_stat("cpu[nice15]", flags, result);
}
-int SYSTEM_CPU_NICE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+
+static int SYSTEM_CPU_USER1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice15]",value,msg,mlen_max);
+ return get_stat("cpu[user1]", flags, result);
}
-int SYSTEM_CPU_USER1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user1]",value,msg,mlen_max);
+ return get_stat("cpu[user5]", flags, result);
}
-int SYSTEM_CPU_USER5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user5]",value,msg,mlen_max);
+ return get_stat("cpu[user15]", flags, result);
}
-int SYSTEM_CPU_USER15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user15]",value,msg,mlen_max);
+ return get_stat("cpu[system1]", flags, result);
}
-int SYSTEM_CPU_SYS1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system1]",value,msg,mlen_max);
+ return get_stat("cpu[system5]", flags, result);
}
-int SYSTEM_CPU_SYS5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system5]",value,msg,mlen_max);
+ return get_stat("cpu[system15]", flags, result);
}
-int SYSTEM_CPU_SYS15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+int OLD_CPU(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system15]",value,msg,mlen_max);
+ return get_stat(cmd, flags, result);
+}
+
+int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"idle", "avg1" , SYSTEM_CPU_IDLE1},
+ {"idle", "avg5" , SYSTEM_CPU_IDLE5},
+ {"idle", "avg15", SYSTEM_CPU_IDLE15},
+ {"nice", "avg1" , SYSTEM_CPU_NICE1},
+ {"nice", "avg5" , SYSTEM_CPU_NICE5},
+ {"nice", "avg15", SYSTEM_CPU_NICE15},
+ {"user", "avg1" , SYSTEM_CPU_USER1},
+ {"user", "avg5" , SYSTEM_CPU_USER5},
+ {"user", "avg15", SYSTEM_CPU_USER15},
+ {"system", "avg1" , SYSTEM_CPU_SYS1},
+ {"system", "avg5" , SYSTEM_CPU_SYS5},
+ {"system", "avg15", SYSTEM_CPU_SYS15},
+ {0, 0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "user");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+ }
+ return SYSINFO_RET_FAIL;
}
/* AIX CPU info */
@@ -232,14 +210,19 @@ static int getloadavg_kmem(double loadavg[], int nelem)
}
#endif
-int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value)
+int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[0];
return SYSINFO_RET_OK;
}
else
@@ -250,24 +233,33 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value)
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_1_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_1_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,1,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,1, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -278,20 +270,29 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value)
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return SYSINFO_RET_FAIL;
}
- *value=loadavg[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[0];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -300,14 +301,19 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value)
#endif
}
-int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[1];
return SYSINFO_RET_OK;
}
else
@@ -318,24 +324,33 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_5_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_5_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,2,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,2, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -346,20 +361,29 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[1];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -368,14 +392,19 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#endif
}
-int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[2];
return SYSINFO_RET_OK;
}
else
@@ -386,24 +415,33 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_15_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_15_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,3,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,3, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -414,20 +452,29 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[2];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -435,3 +482,69 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#endif
#endif
}
+
+int SYSTEM_CPU_LOAD(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"avg1" , SYSTEM_CPU_LOAD1},
+ {"avg5" , SYSTEM_CPU_LOAD5},
+ {"avg15", SYSTEM_CPU_LOAD15},
+ {0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/hpux/diskio.c b/src/libs/zbxsysinfo/hpux/diskio.c
index 11da801b..23d0c450 100644
--- a/src/libs/zbxsysinfo/hpux/diskio.c
+++ b/src/libs/zbxsysinfo/hpux/diskio.c
@@ -19,271 +19,358 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int DISKREADOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+
+ return get_stat(key, flags, result);
+}
+
+int VFS_DEV_WRITE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
- return get_stat(key,value,msg,mlen_max);
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKWRITEOPS1},
+ {"ops", "avg5" , DISKWRITEOPS5},
+ {"ops", "avg15", DISKWRITEOPS15},
+ {"bps", "avg1" , DISKWRITEBLKS1},
+ {"bps", "avg5" , DISKWRITEBLKS5},
+ {"bps", "avg15", DISKWRITEBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
}
-int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int VFS_DEV_READ(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKREADOPS1},
+ {"ops", "avg5" , DISKREADOPS5},
+ {"ops", "avg15", DISKREADOPS15},
+ {"bps", "avg1" , DISKREADBLKS1},
+ {"bps", "avg5" , DISKREADBLKS5},
+ {"bps", "avg15", DISKREADBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+static int DISK_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",2,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",2,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",3,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",3,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",4,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",4,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",5,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",5,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",6,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",6,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
+
+int OLD_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"disk_io") == 0)
+ {
+ ret = DISK_IO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rio") == 0)
+ {
+ ret = DISK_RIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wio") == 0)
+ {
+ ret = DISK_WIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rblk") == 0)
+ {
+ ret = DISK_RBLK(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wblk") == 0)
+ {
+ ret = DISK_WBLK(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/hpux/diskspace.c b/src/libs/zbxsysinfo/hpux/diskspace.c
index b0955ef6..e2120ac6 100644
--- a/src/libs/zbxsysinfo/hpux/diskspace.c
+++ b/src/libs/zbxsysinfo/hpux/diskspace.c
@@ -19,302 +19,227 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
+#include "common.h"
+#include "sysinfo.h"
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
+int get_fs_size_stat(char *fs, double *total, double *free, double *usage)
+{
+#ifdef HAVE_SYS_STATVFS_H
+ struct statvfs s;
+#else
+ struct statfs s;
#endif
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
+ assert(fs);
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
#endif
+ {
+ return SYSINFO_RET_FAIL;
+ }
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
+#ifdef HAVE_SYS_STATVFS_H
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_frsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bavail * (s.f_frsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bavail) * (s.f_frsize / 1024.0));
+#else
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_bsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bfree * (s.f_bsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0));
+#endif
+ return SYSINFO_RET_OK;
+}
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
+static int VFS_FS_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
+ assert(result);
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
+ clean_result(result);
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
-#include "common.h"
-#include "sysinfo.h"
+ return SYSINFO_RET_OK;
+}
-int VFS_FS_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return s.f_bavail * (s.f_bsize / 1024.0);*/
- *value=s.f_bavail * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_bavail * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- return SYSINFO_RET_FAIL;
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_USED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return (s.f_blocks-s.f_bavail) * (s.f_bsize / 1024.0);*/
- *value=(s.f_blocks-s.f_bavail) * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=blocks_used * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_size_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
- return SYSINFO_RET_FAIL;
-#endif
}
-int VFS_FS_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return s.f_blocks * (s.f_bsize / 1024.0);*/
- *value= s.f_blocks * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_blocks * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- return SYSINFO_RET_FAIL;
-#endif
+ if(get_fs_size_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double used;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_USED(cmd, mountPoint, &used, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
- if(total == 0)
- {
- return SYSINFO_RET_FAIL;
- }
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_size_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
- *value = 100*used/total;
- return SYSINFO_RET_OK;
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+int VFS_FS_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if(SYSINFO_RET_OK != VFS_FS_FREE(cmd, mountPoint, &free, msg, mlen_max))
+ FS_FNCLIST fl[] =
+ {
+ {"free" , VFS_FS_FREE},
+ {"total" , VFS_FS_TOTAL},
+ {"used", VFS_FS_USED},
+ {"pfree" , VFS_FS_PFREE},
+ {"pused" , VFS_FS_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
{
- return SYSINFO_RET_FAIL;
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if(total == 0)
+
+ for(i=0; fl[i].mode!=0; i++)
{
- return SYSINFO_RET_FAIL;
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+
+ return SYSINFO_RET_FAIL;
}
diff --git a/src/libs/zbxsysinfo/hpux/inodes.c b/src/libs/zbxsysinfo/hpux/inodes.c
index da92ca93..c8109f28 100644
--- a/src/libs/zbxsysinfo/hpux/inodes.c
+++ b/src/libs/zbxsysinfo/hpux/inodes.c
@@ -19,144 +19,226 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-
-/* FreeBSD/MacOS/OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int VFS_FS_INODE_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int get_fs_inodes_stat(char *fs, double *total, double *free, double *usage)
{
#ifdef HAVE_SYS_STATVFS_H
struct statvfs s;
-
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- *value=s.f_favail;
- return SYSINFO_RET_OK;
#else
struct statfs s;
- long blocks_used;
- long blocks_percent_used;
-
- if ( statfs( (char *)mountPoint, &s) != 0 )
+#endif
+
+ assert(fs);
+
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
+#endif
{
return SYSINFO_RET_FAIL;
}
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_ffree;
- return SYSINFO_RET_OK;
-
- }
- return SYSINFO_RET_FAIL;
+ if(total)
+ (*total) = (double)(s.f_files);
+#ifdef HAVE_SYS_STATVFS_H
+ if(free)
+ (*free) = (double)(s.f_favail);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_favail);
+#else
+ if(free)
+ (*free) = (double)(s.ffree);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_ffree);
#endif
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
return SYSINFO_RET_FAIL;
- }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- *value=s.f_files;
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+}
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_files;
- return SYSINFO_RET_OK;
+static int VFS_FS_INODE_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- }
- return SYSINFO_RET_FAIL;
-#endif
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_inodes_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
+
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_INODE_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+int VFS_FS_INODE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if(SYSINFO_RET_OK != VFS_FS_INODE_FREE(cmd, mountPoint, &free, msg, mlen_max))
+ FS_FNCLIST fl[] =
{
- return SYSINFO_RET_FAIL;
+ {"free" , VFS_FS_INODE_FREE},
+ {"total" , VFS_FS_INODE_TOTAL},
+ {"used", VFS_FS_INODE_USED},
+ {"pfree" , VFS_FS_INODE_PFREE},
+ {"pused" , VFS_FS_INODE_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if(total == 0)
+
+ for(i=0; fl[i].mode!=0; i++)
{
- return SYSINFO_RET_FAIL;
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+
+ return SYSINFO_RET_FAIL;
}
+
diff --git a/src/libs/zbxsysinfo/hpux/memory.c b/src/libs/zbxsysinfo/hpux/memory.c
index ae4e6b03..7dc0fcbe 100644
--- a/src/libs/zbxsysinfo/hpux/memory.c
+++ b/src/libs/zbxsysinfo/hpux/memory.c
@@ -19,123 +19,10 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
/* Get CACHED memory in bytes */
@@ -145,8 +32,12 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
FILE *f;
char *t;
char c[MAX_STRING_LEN];
- double result = SYSINFO_RET_FAIL;
+ double res = 0;
+ assert(result);
+
+ clean_result(result);
+
f=fopen("/proc/meminfo","r");
if(NULL == f)
{
@@ -158,30 +49,40 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
{
t=(char *)strtok(c," ");
t=(char *)strtok(NULL," ");
- sscanf(t, "%lf", &result );
+ sscanf(t, "%lf", &res );
break;
}
}
fclose(f);
- *value=result;
+ result->type |= AR_DOUBLE;
+ result->dbl=res;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_BUFFERS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_BUFFERRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.bufferram * (double)info.mem_unit;
+ result->dbl=(double)info.bufferram * (double)info.mem_unit;
#else
- *value=(double)info.bufferram;
+ result->dbl=(double)info.bufferram;
#endif
return SYSINFO_RET_OK;
}
@@ -190,21 +91,30 @@ int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, con
return SYSINFO_RET_FAIL;
}
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_SHARED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_SHAREDRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.sharedram * (double)info.mem_unit;
+ result->dbl=(double)info.sharedram * (double)info.mem_unit;
#else
- *value=(double)info.sharedram;
+ result->dbl=(double)info.sharedram;
#endif
return SYSINFO_RET_OK;
}
@@ -212,36 +122,47 @@ int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_armshr<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_armshr<<2);
return SYSINFO_RET_OK;
#else
return SYSINFO_RET_FAIL;
#endif
-#endif
}
-int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -251,19 +172,24 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
/* Get page size */
page = pst.page_size;
/* Total physical memory in bytes */
- *value=(double)page*pst.physical_memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)page*pst.physical_memory;
return SYSINFO_RET_OK;
}
-#else
-#ifdef HAVE_SYSINFO_TOTALRAM
+#elif defined(HAVE_SYSINFO_TOTALRAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalram * (double)info.mem_unit;
+ result->dbl=(double)info.totalram * (double)info.mem_unit;
#else
- *value=(double)info.totalram;
+ result->dbl=(double)info.totalram;
#endif
return SYSINFO_RET_OK;
}
@@ -271,31 +197,39 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_rm<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_rm<<2);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_SYSCTL_H
+#elif defined(HAVE_SYS_SYSCTL_H)
static int mib[] = { CTL_HW, HW_PHYSMEM };
size_t len;
unsigned int memory;
int ret;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(memory);
if(0==sysctl(mib,2,&memory,&len,NULL,0))
{
- *value=(double)memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)memory;
ret=SYSINFO_RET_OK;
}
else
@@ -304,26 +238,34 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
-#endif
-#endif
-#endif
-#endif
}
-int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
struct pst_dynamic dyn;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -352,20 +294,25 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
*/
/* Free memory in bytes */
- *value=(double)dyn.psd_free * page;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)dyn.psd_free * page;
return SYSINFO_RET_OK;
}
}
-#else
-#ifdef HAVE_SYSINFO_FREERAM
+#elif defined(HAVE_SYSINFO_FREERAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.freeram * (double)info.mem_unit;
+ result->dbl=(double)info.freeram * (double)info.mem_unit;
#else
- *value=(double)info.freeram;
+ result->dbl=(double)info.freeram;
#endif
return SYSINFO_RET_OK;
}
@@ -373,28 +320,35 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_free<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_free<<2);
return SYSINFO_RET_OK;
-#else
/* OS/X */
-#ifdef HAVE_MACH_HOST_INFO_H
+#elif defined(HAVE_MACH_HOST_INFO_H)
vm_statistics_data_t page_info;
vm_size_t pagesize;
mach_msg_type_number_t count;
kern_return_t kret;
int ret;
+ assert(result);
+
+ clean_result(result);
+
pagesize = 0;
kret = host_page_size (mach_host_self(), &pagesize);
@@ -412,7 +366,8 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
pu = pw+pa+pi;
- *value=(double)pf;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)pf;
ret = SYSINFO_RET_OK;
}
else
@@ -421,10 +376,63 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
-#endif
-#endif
-#endif
-#endif
}
+
+int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#define MEM_FNCLIST struct mem_fnclist_s
+MEM_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ MEM_FNCLIST fl[] =
+ {
+ {"free", VM_MEMORY_FREE},
+ {"shared", VM_MEMORY_SHARED},
+ {"total", VM_MEMORY_TOTAL},
+ {"buffers", VM_MEMORY_BUFFERS},
+ {"cached", VM_MEMORY_CACHED},
+ {0, 0}
+ };
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/hpux/proc.c b/src/libs/zbxsysinfo/hpux/proc.c
index 7f5c596b..d80dac13 100644
--- a/src/libs/zbxsysinfo/hpux/proc.c
+++ b/src/libs/zbxsysinfo/hpux/proc.c
@@ -19,32 +19,485 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
#include "common.h"
#include "sysinfo.h"
-/*
-#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
-#define SDI(m) FDI("%s", m) // string info
-#define IDI(i) FDI("%i", i) // integer info
-*/
-int PROC_MEMORY(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+#define DO_SUM 0
+#define DO_MAX 1
+#define DO_MIN 2
+#define DO_AVG 3
+
+int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- /* in this moment this function for this platform unsupported */
- return SYSINFO_RET_FAIL;
+#if defined(HAVE_PROC_1_STATUS)
+
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int do_task = DO_SUM;
+
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ FILE *f;
+
+ double memsize = -1;
+ int proccount = 0;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ strscpy(mode, "sum");
+ }
+
+ if(strcmp(mode,"avg") == 0)
+ {
+ do_task = DO_AVG;
+ }
+ else if(strcmp(mode,"max") == 0)
+ {
+ do_task = DO_MAX;
+ }
+ else if(strcmp(mode,"min") == 0)
+ {
+ do_task = DO_MIN;
+ }
+ else if(strcmp(mode,"sum") == 0)
+ {
+ do_task = DO_SUM;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ usr_ok = 0;
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ /* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+ /* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && usr_ok)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li %s\n", name1, &lvalue, name2) != 3)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"VmSize:") != 0)
+ {
+ continue;
+ }
+
+ proccount++;
+
+ if(strcasecmp(name2, "kB") == 0)
+ {
+ lvalue <<= 10;
+ }
+ else if(strcasecmp(name2, "mB") == 0)
+ {
+ lvalue <<= 20;
+ }
+ else if(strcasecmp(name2, "GB") == 0)
+ {
+ lvalue <<= 30;
+ }
+ else if(strcasecmp(name2, "TB") == 0)
+ {
+ lvalue <<= 40;
+ }
+
+ if(memsize < 0)
+ {
+ memsize = (double) lvalue;
+ }
+ else
+ {
+ if(do_task == DO_MAX)
+ {
+ memsize = MAX(memsize, (double) lvalue);
+ }
+ else if(do_task == DO_MIN)
+ {
+ memsize = MIN(memsize, (double) lvalue);
+ }
+ else
+ {
+ memsize += (double) lvalue;
+ }
+ }
+
+ break;
+ }
+ }
+
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ if(memsize < 0)
+ {
+ /* incorrect process name */
+ memsize = 0;
+ }
+
+ if(do_task == DO_AVG)
+ {
+ memsize /= (double)proccount;
+ }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = memsize;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
}
-int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- /* in this moment this function for this platform unsupported */
+#if defined(HAVE_PROC_1_STATUS)
+
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char procstat[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int stat_ok = 0;
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ FILE *f;
+
+ assert(result);
+
+ clean_result(result);
+
+ int proccount = 0;
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ {
+ procstat[0] = '\0';
+ }
+
+ if(procstat[0] == '\0')
+ {
+ strscpy(procstat, "all");
+ }
+
+ if(strcmp(procstat,"run") == 0)
+ {
+ strscpy(procstat,"R");
+ }
+ else if(strcmp(procstat,"sleep") == 0)
+ {
+ strscpy(procstat,"S");
+ }
+ else if(strcmp(procstat,"zomb") == 0)
+ {
+ strscpy(procstat,"Z");
+ }
+ else if(strcmp(procstat,"all") == 0)
+ {
+ procstat[0] = 0;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ stat_ok = 0;
+ usr_ok = 0;
+
+/* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+/* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(procstat[0] != 0)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%s\n", name1, name2) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"State:") != 0)
+ {
+ continue;
+ }
+
+ if(strcmp(name2, procstat))
+ {
+ stat_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ stat_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && stat_ok && usr_ok)
+ {
+ proccount++;
+ }
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (double) proccount;
+ return SYSINFO_RET_OK;
+#else
return SYSINFO_RET_FAIL;
+#endif
}
-
diff --git a/src/libs/zbxsysinfo/hpux/sensors.c b/src/libs/zbxsysinfo/hpux/sensors.c
index 32042922..956ca3d1 100644
--- a/src/libs/zbxsysinfo/hpux/sensors.c
+++ b/src/libs/zbxsysinfo/hpux/sensors.c
@@ -19,125 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -148,6 +35,10 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -173,7 +64,8 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -187,7 +79,7 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP2(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -198,6 +90,10 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -223,7 +119,8 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -237,7 +134,7 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP3(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -248,6 +145,10 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -273,7 +174,8 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -286,3 +188,43 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
closedir(dir);
return SYSINFO_RET_FAIL;
}
+
+int OLD_SENSOR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"temp1") == 0)
+ {
+ ret = SENSOR_TEMP1(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp2") == 0)
+ {
+ ret = SENSOR_TEMP2(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp3") == 0)
+ {
+ ret = SENSOR_TEMP3(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/hpux/swap.c b/src/libs/zbxsysinfo/hpux/swap.c
index db059f78..3d80fec9 100644
--- a/src/libs/zbxsysinfo/hpux/swap.c
+++ b/src/libs/zbxsysinfo/hpux/swap.c
@@ -19,124 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
+
/* Solaris. */
#ifndef HAVE_SYSINFO_FREESWAP
#ifdef HAVE_SYS_SWAP_SWAPTABLE
@@ -203,17 +91,22 @@ point them all to the same buffer */
#endif
#endif
-int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_FREESWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.freeswap * (double)info.mem_unit;
+ result->dbl = (double)info.freeswap * (double)info.mem_unit;
#else
- *value=(double)info.freeswap;
+ result->dbl = (double)info.freeswap;
#endif
return SYSINFO_RET_OK;
}
@@ -226,27 +119,41 @@ int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
+ assert(result);
+
+ clean_result(result);
+
get_swapinfo(&swaptotal,&swapfree);
- *value=swapfree;
+ result->type |= AR_DOUBLE;
+ result->dbl = swapfree;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
-int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_TOTALSWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalswap * (double)info.mem_unit;
+ result->dbl = (double)info.totalswap * (double)info.mem_unit;
#else
- *value=(double)info.totalswap;
+ result->dbl = (double)info.totalswap;
#endif
return SYSINFO_RET_OK;
}
@@ -259,12 +166,125 @@ int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
- get_swapinfo(&swaptotal,&swapfree);
+ assert(result);
+
+ clean_result(result);
- *value=(double)swaptotal;
+ get_swapinfo(&swaptotal,&swapfree);
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)swaptotal;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
+
+int SYSTEM_SWAP_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define SWP_FNCLIST struct swp_fnclist_s
+SWP_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ SWP_FNCLIST fl[] =
+ {
+ {"total", SYSTEM_SWAP_FREE},
+ {"free", SYSTEM_SWAP_TOTAL},
+ {0, 0}
+ };
+
+ char swapdev[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(swapdev[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(swapdev, "all");
+ }
+
+ if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "free");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+int OLD_SWAP(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"free") == 0)
+ {
+ ret = SYSTEM_SWAP_FREE(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"total") == 0)
+ {
+ ret = SYSTEM_SWAP_TOTAL(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/hpux/uptime.c b/src/libs/zbxsysinfo/hpux/uptime.c
index 88eee810..a38b2bd7 100644
--- a/src/libs/zbxsysinfo/hpux/uptime.c
+++ b/src/libs/zbxsysinfo/hpux/uptime.c
@@ -19,130 +19,22 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_UPTIME
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
- *value=(double)info.uptime;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)info.uptime;
return SYSINFO_RET_OK;
}
else
@@ -155,6 +47,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
struct timeval uptime;
int now;
+ assert(result);
+
+ clean_result(result);
+
mib[0]=CTL_KERN;
mib[1]=KERN_BOOTTIME;
@@ -167,8 +63,8 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
}
now=time(NULL);
-
- *value=(double)(now-uptime.tv_sec);
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)(now-uptime.tv_sec);
return SYSINFO_RET_OK;
#else
/* Solaris */
@@ -180,6 +76,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
long hz;
long secs;
+ assert(result);
+
+ clean_result(result);
+
hz = sysconf(_SC_CLK_TCK);
/* open kstat */
@@ -207,9 +107,14 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
/* close kstat */
kstat_close(kc);
- *value=(double)secs;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)secs;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
diff --git a/src/libs/zbxsysinfo/netbsd/cpu.c b/src/libs/zbxsysinfo/netbsd/cpu.c
index f8e94125..4e7e1502 100644
--- a/src/libs/zbxsysinfo/netbsd/cpu.c
+++ b/src/libs/zbxsysinfo/netbsd/cpu.c
@@ -19,183 +19,161 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-/* AIX CPU */
-#ifdef HAVE_KNLIST_H
- #include <knlist.h>
-#endif
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_CPU_IDLE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle1]",value,msg,mlen_max);
+ return get_stat("cpu[idle1]", flags, result);
}
-int SYSTEM_CPU_IDLE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle5]",value,msg,mlen_max);
+ return get_stat("cpu[idle5]", flags, result);
}
-int SYSTEM_CPU_IDLE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle15]",value,msg,mlen_max);
+ return get_stat("cpu[idle15]", flags, result);
}
-int SYSTEM_CPU_NICE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice1]",value,msg,mlen_max);
+ return get_stat("cpu[nice1]", flags, result);
}
-int SYSTEM_CPU_NICE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ return get_stat("cpu[nice5]", flags, result);
+}
+static int SYSTEM_CPU_NICE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice5]",value,msg,mlen_max);
+ return get_stat("cpu[nice15]", flags, result);
}
-int SYSTEM_CPU_NICE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+
+static int SYSTEM_CPU_USER1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice15]",value,msg,mlen_max);
+ return get_stat("cpu[user1]", flags, result);
}
-int SYSTEM_CPU_USER1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user1]",value,msg,mlen_max);
+ return get_stat("cpu[user5]", flags, result);
}
-int SYSTEM_CPU_USER5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user5]",value,msg,mlen_max);
+ return get_stat("cpu[user15]", flags, result);
}
-int SYSTEM_CPU_USER15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user15]",value,msg,mlen_max);
+ return get_stat("cpu[system1]", flags, result);
}
-int SYSTEM_CPU_SYS1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system1]",value,msg,mlen_max);
+ return get_stat("cpu[system5]", flags, result);
}
-int SYSTEM_CPU_SYS5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system5]",value,msg,mlen_max);
+ return get_stat("cpu[system15]", flags, result);
}
-int SYSTEM_CPU_SYS15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+int OLD_CPU(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system15]",value,msg,mlen_max);
+ return get_stat(cmd, flags, result);
+}
+
+int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"idle", "avg1" , SYSTEM_CPU_IDLE1},
+ {"idle", "avg5" , SYSTEM_CPU_IDLE5},
+ {"idle", "avg15", SYSTEM_CPU_IDLE15},
+ {"nice", "avg1" , SYSTEM_CPU_NICE1},
+ {"nice", "avg5" , SYSTEM_CPU_NICE5},
+ {"nice", "avg15", SYSTEM_CPU_NICE15},
+ {"user", "avg1" , SYSTEM_CPU_USER1},
+ {"user", "avg5" , SYSTEM_CPU_USER5},
+ {"user", "avg15", SYSTEM_CPU_USER15},
+ {"system", "avg1" , SYSTEM_CPU_SYS1},
+ {"system", "avg5" , SYSTEM_CPU_SYS5},
+ {"system", "avg15", SYSTEM_CPU_SYS15},
+ {0, 0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "user");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+ }
+ return SYSINFO_RET_FAIL;
}
/* AIX CPU info */
@@ -232,14 +210,19 @@ static int getloadavg_kmem(double loadavg[], int nelem)
}
#endif
-int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[0];
return SYSINFO_RET_OK;
}
else
@@ -250,24 +233,33 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_1_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_1_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,1,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,1, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -278,20 +270,29 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return SYSINFO_RET_FAIL;
}
- *value=loadavg[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[0];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -300,14 +301,19 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
#endif
}
-int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[1];
return SYSINFO_RET_OK;
}
else
@@ -318,24 +324,33 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_5_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_5_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,2,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,2, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -346,20 +361,29 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[1];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -368,14 +392,19 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#endif
}
-int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[2];
return SYSINFO_RET_OK;
}
else
@@ -386,24 +415,33 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_15_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_15_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,3,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,3, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -414,20 +452,29 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[2];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -435,3 +482,69 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#endif
#endif
}
+
+int SYSTEM_CPU_LOAD(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"avg1" , SYSTEM_CPU_LOAD1},
+ {"avg5" , SYSTEM_CPU_LOAD5},
+ {"avg15", SYSTEM_CPU_LOAD15},
+ {0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/netbsd/diskio.c b/src/libs/zbxsysinfo/netbsd/diskio.c
index 11da801b..23d0c450 100644
--- a/src/libs/zbxsysinfo/netbsd/diskio.c
+++ b/src/libs/zbxsysinfo/netbsd/diskio.c
@@ -19,271 +19,358 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int DISKREADOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+
+ return get_stat(key, flags, result);
+}
+
+int VFS_DEV_WRITE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
- return get_stat(key,value,msg,mlen_max);
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKWRITEOPS1},
+ {"ops", "avg5" , DISKWRITEOPS5},
+ {"ops", "avg15", DISKWRITEOPS15},
+ {"bps", "avg1" , DISKWRITEBLKS1},
+ {"bps", "avg5" , DISKWRITEBLKS5},
+ {"bps", "avg15", DISKWRITEBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
}
-int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int VFS_DEV_READ(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKREADOPS1},
+ {"ops", "avg5" , DISKREADOPS5},
+ {"ops", "avg15", DISKREADOPS15},
+ {"bps", "avg1" , DISKREADBLKS1},
+ {"bps", "avg5" , DISKREADBLKS5},
+ {"bps", "avg15", DISKREADBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+static int DISK_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",2,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",2,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",3,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",3,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",4,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",4,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",5,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",5,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",6,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",6,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
+
+int OLD_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"disk_io") == 0)
+ {
+ ret = DISK_IO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rio") == 0)
+ {
+ ret = DISK_RIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wio") == 0)
+ {
+ ret = DISK_WIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rblk") == 0)
+ {
+ ret = DISK_RBLK(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wblk") == 0)
+ {
+ ret = DISK_WBLK(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/netbsd/diskspace.c b/src/libs/zbxsysinfo/netbsd/diskspace.c
index b0955ef6..e2120ac6 100644
--- a/src/libs/zbxsysinfo/netbsd/diskspace.c
+++ b/src/libs/zbxsysinfo/netbsd/diskspace.c
@@ -19,302 +19,227 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
+#include "common.h"
+#include "sysinfo.h"
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
+int get_fs_size_stat(char *fs, double *total, double *free, double *usage)
+{
+#ifdef HAVE_SYS_STATVFS_H
+ struct statvfs s;
+#else
+ struct statfs s;
#endif
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
+ assert(fs);
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
#endif
+ {
+ return SYSINFO_RET_FAIL;
+ }
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
+#ifdef HAVE_SYS_STATVFS_H
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_frsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bavail * (s.f_frsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bavail) * (s.f_frsize / 1024.0));
+#else
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_bsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bfree * (s.f_bsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0));
+#endif
+ return SYSINFO_RET_OK;
+}
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
+static int VFS_FS_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
+ assert(result);
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
+ clean_result(result);
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
-#include "common.h"
-#include "sysinfo.h"
+ return SYSINFO_RET_OK;
+}
-int VFS_FS_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return s.f_bavail * (s.f_bsize / 1024.0);*/
- *value=s.f_bavail * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_bavail * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- return SYSINFO_RET_FAIL;
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_USED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return (s.f_blocks-s.f_bavail) * (s.f_bsize / 1024.0);*/
- *value=(s.f_blocks-s.f_bavail) * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=blocks_used * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_size_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
- return SYSINFO_RET_FAIL;
-#endif
}
-int VFS_FS_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return s.f_blocks * (s.f_bsize / 1024.0);*/
- *value= s.f_blocks * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_blocks * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- return SYSINFO_RET_FAIL;
-#endif
+ if(get_fs_size_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double used;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_USED(cmd, mountPoint, &used, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
- if(total == 0)
- {
- return SYSINFO_RET_FAIL;
- }
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_size_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
- *value = 100*used/total;
- return SYSINFO_RET_OK;
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+int VFS_FS_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if(SYSINFO_RET_OK != VFS_FS_FREE(cmd, mountPoint, &free, msg, mlen_max))
+ FS_FNCLIST fl[] =
+ {
+ {"free" , VFS_FS_FREE},
+ {"total" , VFS_FS_TOTAL},
+ {"used", VFS_FS_USED},
+ {"pfree" , VFS_FS_PFREE},
+ {"pused" , VFS_FS_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
{
- return SYSINFO_RET_FAIL;
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if(total == 0)
+
+ for(i=0; fl[i].mode!=0; i++)
{
- return SYSINFO_RET_FAIL;
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+
+ return SYSINFO_RET_FAIL;
}
diff --git a/src/libs/zbxsysinfo/netbsd/inodes.c b/src/libs/zbxsysinfo/netbsd/inodes.c
index da92ca93..c8109f28 100644
--- a/src/libs/zbxsysinfo/netbsd/inodes.c
+++ b/src/libs/zbxsysinfo/netbsd/inodes.c
@@ -19,144 +19,226 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-
-/* FreeBSD/MacOS/OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int VFS_FS_INODE_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int get_fs_inodes_stat(char *fs, double *total, double *free, double *usage)
{
#ifdef HAVE_SYS_STATVFS_H
struct statvfs s;
-
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- *value=s.f_favail;
- return SYSINFO_RET_OK;
#else
struct statfs s;
- long blocks_used;
- long blocks_percent_used;
-
- if ( statfs( (char *)mountPoint, &s) != 0 )
+#endif
+
+ assert(fs);
+
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
+#endif
{
return SYSINFO_RET_FAIL;
}
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_ffree;
- return SYSINFO_RET_OK;
-
- }
- return SYSINFO_RET_FAIL;
+ if(total)
+ (*total) = (double)(s.f_files);
+#ifdef HAVE_SYS_STATVFS_H
+ if(free)
+ (*free) = (double)(s.f_favail);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_favail);
+#else
+ if(free)
+ (*free) = (double)(s.ffree);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_ffree);
#endif
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
return SYSINFO_RET_FAIL;
- }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- *value=s.f_files;
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+}
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_files;
- return SYSINFO_RET_OK;
+static int VFS_FS_INODE_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- }
- return SYSINFO_RET_FAIL;
-#endif
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_inodes_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
+
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_INODE_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+int VFS_FS_INODE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if(SYSINFO_RET_OK != VFS_FS_INODE_FREE(cmd, mountPoint, &free, msg, mlen_max))
+ FS_FNCLIST fl[] =
{
- return SYSINFO_RET_FAIL;
+ {"free" , VFS_FS_INODE_FREE},
+ {"total" , VFS_FS_INODE_TOTAL},
+ {"used", VFS_FS_INODE_USED},
+ {"pfree" , VFS_FS_INODE_PFREE},
+ {"pused" , VFS_FS_INODE_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if(total == 0)
+
+ for(i=0; fl[i].mode!=0; i++)
{
- return SYSINFO_RET_FAIL;
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+
+ return SYSINFO_RET_FAIL;
}
+
diff --git a/src/libs/zbxsysinfo/netbsd/memory.c b/src/libs/zbxsysinfo/netbsd/memory.c
index ae4e6b03..7dc0fcbe 100644
--- a/src/libs/zbxsysinfo/netbsd/memory.c
+++ b/src/libs/zbxsysinfo/netbsd/memory.c
@@ -19,123 +19,10 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
/* Get CACHED memory in bytes */
@@ -145,8 +32,12 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
FILE *f;
char *t;
char c[MAX_STRING_LEN];
- double result = SYSINFO_RET_FAIL;
+ double res = 0;
+ assert(result);
+
+ clean_result(result);
+
f=fopen("/proc/meminfo","r");
if(NULL == f)
{
@@ -158,30 +49,40 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
{
t=(char *)strtok(c," ");
t=(char *)strtok(NULL," ");
- sscanf(t, "%lf", &result );
+ sscanf(t, "%lf", &res );
break;
}
}
fclose(f);
- *value=result;
+ result->type |= AR_DOUBLE;
+ result->dbl=res;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_BUFFERS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_BUFFERRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.bufferram * (double)info.mem_unit;
+ result->dbl=(double)info.bufferram * (double)info.mem_unit;
#else
- *value=(double)info.bufferram;
+ result->dbl=(double)info.bufferram;
#endif
return SYSINFO_RET_OK;
}
@@ -190,21 +91,30 @@ int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, con
return SYSINFO_RET_FAIL;
}
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_SHARED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_SHAREDRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.sharedram * (double)info.mem_unit;
+ result->dbl=(double)info.sharedram * (double)info.mem_unit;
#else
- *value=(double)info.sharedram;
+ result->dbl=(double)info.sharedram;
#endif
return SYSINFO_RET_OK;
}
@@ -212,36 +122,47 @@ int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_armshr<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_armshr<<2);
return SYSINFO_RET_OK;
#else
return SYSINFO_RET_FAIL;
#endif
-#endif
}
-int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -251,19 +172,24 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
/* Get page size */
page = pst.page_size;
/* Total physical memory in bytes */
- *value=(double)page*pst.physical_memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)page*pst.physical_memory;
return SYSINFO_RET_OK;
}
-#else
-#ifdef HAVE_SYSINFO_TOTALRAM
+#elif defined(HAVE_SYSINFO_TOTALRAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalram * (double)info.mem_unit;
+ result->dbl=(double)info.totalram * (double)info.mem_unit;
#else
- *value=(double)info.totalram;
+ result->dbl=(double)info.totalram;
#endif
return SYSINFO_RET_OK;
}
@@ -271,31 +197,39 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_rm<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_rm<<2);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_SYSCTL_H
+#elif defined(HAVE_SYS_SYSCTL_H)
static int mib[] = { CTL_HW, HW_PHYSMEM };
size_t len;
unsigned int memory;
int ret;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(memory);
if(0==sysctl(mib,2,&memory,&len,NULL,0))
{
- *value=(double)memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)memory;
ret=SYSINFO_RET_OK;
}
else
@@ -304,26 +238,34 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
-#endif
-#endif
-#endif
-#endif
}
-int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
struct pst_dynamic dyn;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -352,20 +294,25 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
*/
/* Free memory in bytes */
- *value=(double)dyn.psd_free * page;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)dyn.psd_free * page;
return SYSINFO_RET_OK;
}
}
-#else
-#ifdef HAVE_SYSINFO_FREERAM
+#elif defined(HAVE_SYSINFO_FREERAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.freeram * (double)info.mem_unit;
+ result->dbl=(double)info.freeram * (double)info.mem_unit;
#else
- *value=(double)info.freeram;
+ result->dbl=(double)info.freeram;
#endif
return SYSINFO_RET_OK;
}
@@ -373,28 +320,35 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_free<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_free<<2);
return SYSINFO_RET_OK;
-#else
/* OS/X */
-#ifdef HAVE_MACH_HOST_INFO_H
+#elif defined(HAVE_MACH_HOST_INFO_H)
vm_statistics_data_t page_info;
vm_size_t pagesize;
mach_msg_type_number_t count;
kern_return_t kret;
int ret;
+ assert(result);
+
+ clean_result(result);
+
pagesize = 0;
kret = host_page_size (mach_host_self(), &pagesize);
@@ -412,7 +366,8 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
pu = pw+pa+pi;
- *value=(double)pf;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)pf;
ret = SYSINFO_RET_OK;
}
else
@@ -421,10 +376,63 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
-#endif
-#endif
-#endif
-#endif
}
+
+int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#define MEM_FNCLIST struct mem_fnclist_s
+MEM_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ MEM_FNCLIST fl[] =
+ {
+ {"free", VM_MEMORY_FREE},
+ {"shared", VM_MEMORY_SHARED},
+ {"total", VM_MEMORY_TOTAL},
+ {"buffers", VM_MEMORY_BUFFERS},
+ {"cached", VM_MEMORY_CACHED},
+ {0, 0}
+ };
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/netbsd/netbsd.c b/src/libs/zbxsysinfo/netbsd/netbsd.c
index e04ef0e7..df66bf38 100644
--- a/src/libs/zbxsysinfo/netbsd/netbsd.c
+++ b/src/libs/zbxsysinfo/netbsd/netbsd.c
@@ -18,254 +18,179 @@
**/
#include "config.h"
+#include "common.h"
#include "sysinfo.h"
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_CPU_IDLE1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_IDLE5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_IDLE15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int VFS_FS_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_USED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_PUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-
-int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int VFS_FILE_ATIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_CKSUM(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_CTIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_MD5SUM(const char *cmd, const char *filename, char **value, const char *msg, int mlen_max);
-int VFS_FILE_MTIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_REGEXP(const char *cmd, const char *filename, char **value, const char *msg, int mlen_max);
-int VFS_FILE_REGMATCH(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_SIZE(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_EXISTS(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-
-int VFS_FS_INODE_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_INODE_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-
-
-int KERNEL_MAXFILES(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int KERNEL_MAXPROC(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int NET_IF_IBYTES1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_IBYTES5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_IBYTES15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int NET_IF_OBYTES1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_OBYTES5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_OBYTES15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int DISKREADOPS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADOPS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADOPS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int AGENT_PING(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int PROC_NUM(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int PROC_MEMORY(const char *cmd, const char *param, double *value, const char *msg, int mlen_max);
-
-int PROCCOUNT(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SENSOR_TEMP1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SENSOR_TEMP2(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SENSOR_TEMP3(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int TCP_LISTEN(const char *cmd, const char *porthex,double *value, const char *msg, int mlen_max);
-
-int EXECUTE(const char *cmd, const char *command,double *value, const char *msg, int mlen_max);
-int EXECUTE_STR(const char *cmd, const char *command, const char *parameter, char **value, const char *msg, int mlen_max);
-int AGENT_VERSION(const char *cmd, const char *command,char **value, const char *msg, int mlen_max);
-
-
-int CHECK_SERVICE(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-int CHECK_SERVICE_PERF(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-int CHECK_PORT(const char *cmd, const char *ip_and_port,double *value, const char *msg, int mlen_max);
-int CHECK_DNS(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-
ZBX_METRIC parameters_specific[]=
-/* KEY FUNCTION (if double) FUNCTION (if string) PARAM*/
+/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
/* Outdated */
-
- {"cksum[*]" ,VFS_FILE_CKSUM, 0, "/etc/services"},
- {"cpu[idle1]" ,SYSTEM_CPU_IDLE1, 0, 0},
- {"cpu[idle5]" ,SYSTEM_CPU_IDLE5, 0, 0},
- {"cpu[idle15]" ,SYSTEM_CPU_IDLE15, 0, 0},
- {"cpu[nice1]" ,SYSTEM_CPU_NICE1, 0, 0},
- {"cpu[nice5]" ,SYSTEM_CPU_NICE5, 0, 0},
- {"cpu[nice15]" ,SYSTEM_CPU_NICE15, 0, 0},
- {"cpu[system1]" ,SYSTEM_CPU_SYS1, 0, 0},
- {"cpu[system5]" ,SYSTEM_CPU_SYS5, 0, 0},
- {"cpu[system15]" ,SYSTEM_CPU_SYS15, 0, 0},
- {"cpu[user1]" ,SYSTEM_CPU_USER1, 0, 0},
- {"cpu[user5]" ,SYSTEM_CPU_USER5, 0, 0},
- {"cpu[user15]" ,SYSTEM_CPU_USER15, 0, 0},
- {"diskfree[*]" ,VFS_FS_FREE, 0, "/"},
- {"disktotal[*]" ,VFS_FS_TOTAL, 0, "/"},
- {"diskused[*]" ,VFS_FS_USED, 0, "/"},
- {"diskfree_perc[*]" ,VFS_FS_PFREE, 0, "/"},
- {"diskused_perc[*]" ,VFS_FS_PUSED, 0, "/"},
- {"file[*]" ,VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize[*]" ,VFS_FILE_SIZE, 0, "/etc/passwd"},
- {"inodefree[*]" ,VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal[*]" ,VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc[*]" ,VFS_FS_INODE_PFREE, 0, "/"},
- {"kern[maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kern[maxproc]" ,KERNEL_MAXPROC, 0, 0},
- {"md5sum[*]" ,0, VFS_FILE_MD5SUM, "/etc/services"},
- {"memory[buffers]" ,VM_MEMORY_BUFFERS, 0, 0},
- {"memory[cached]" ,VM_MEMORY_CACHED, 0, 0},
- {"memory[free]" ,VM_MEMORY_FREE, 0, 0},
- {"memory[shared]" ,VM_MEMORY_SHARED, 0, 0},
- {"memory[total]" ,VM_MEMORY_TOTAL, 0, 0},
- {"netloadin1[*]" ,NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5[*]" ,NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15[*]" ,NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1[*]" ,NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5[*]" ,NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15[*]" ,NET_IF_OBYTES15, 0, "lo"},
- {"ping" ,AGENT_PING, 0, 0},
- {"proc_cnt[*]" ,PROC_NUM, 0, "inetd"},
- {"swap[free]" ,SYSTEM_SWAP_FREE, 0, 0},
- {"swap[total]" ,SYSTEM_SWAP_TOTAL, 0, 0},
- {"system[procload]" ,SYSTEM_CPU_LOAD1, 0, 0},
- {"system[procload5]" ,SYSTEM_CPU_LOAD5, 0, 0},
- {"system[procload15]" ,SYSTEM_CPU_LOAD15, 0, 0},
- {"system[hostname]" ,0, EXECUTE_STR, "hostname"},
- {"system[uname]" ,0, EXECUTE_STR, "uname -a"},
- {"system[uptime]" ,SYSTEM_UPTIME, 0, 0},
- {"system[users]" ,EXECUTE, 0,"who|wc -l"},
- {"version[zabbix_agent]", 0, AGENT_VERSION, 0},
+/* incorrect OLD naming */
+ {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
+/*
+ {"cpu[idle1]", 0, 0, 0, 0},
+ {"cpu[idle5]", 0, 0, 0, 0},
+ {"cpu[idle15]", 0, 0, 0, 0},
+ {"cpu[nice1]", 0, 0, 0, 0},
+ {"cpu[nice5]", 0, 0, 0, 0},
+ {"cpu[nice15]", 0, 0, 0, 0},
+ {"cpu[system1]", 0, 0, 0, 0},
+ {"cpu[system5]", 0, 0, 0, 0},
+ {"cpu[system15]", 0, 0, 0, 0},
+ {"cpu[user1]", 0, 0, 0, 0},
+ {"cpu[user5]", 0, 0, 0, 0},
+ {"cpu[user15]", 0, 0, 0, 0},
+*/
+ {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
+/*
+ {"io[disk_io]", 0, 0, 0, 0},
+ {"io[disk_rio]", 0, 0, 0, 0},
+ {"io[disk_wio]", 0, 0, 0, 0},
+ {"io[disk_rblk]", 0, 0, 0, 0},
+ {"io[disk_wblk]", 0, 0, 0, 0},
+*/
+ {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
+/*
+ {"kern[maxfiles]", 0, 0, 0, 0},
+ {"kern[maxproc]", 0, 0, 0, 0},
+*/
+ {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
+/*
+ {"memory[buffers]", 0, 0, 0, 0},
+ {"memory[cached]", 0, 0, 0, 0},
+ {"memory[free]", 0, 0, 0, 0},
+ {"memory[shared]", 0, 0, 0, 0},
+ {"memory[total]", 0, 0, 0, 0},
+*/
+ {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
+/*
+ {"system[proccount]", 0, 0, 0, 0},
+
+ {"system[procload]", 0, 0, 0, 0},
+ {"system[procload5]", 0, 0, 0, 0},
+ {"system[procload15]", 0, 0, 0, 0},
+ {"system[hostname]", 0, 0, 0, 0},
+ {"system[uname]", 0, 0, 0, 0},
+ {"system[uptime]", 0, 0, 0, 0},
+ {"system[users]", 0, 0, 0, 0},
+
+ {"system[procrunning]", 0, 0, 0, 0},
+*/
+ {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
+/*
+ {"sensor[temp1]", 0, 0, 0, 0},
+ {"sensor[temp2]", 0, 0, 0, 0},
+ {"sensor[temp3]", 0, 0, 0, 0},
+*/
+ {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
+/*
+ {"swap[free]", 0, 0, 0, 0},
+ {"swap[total]", 0, 0, 0, 0},
+*/
+ {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
+/*
+ {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
+*/
+/* correct OLD naming */
+/*
+ {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
+*/
+/*
+ {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
+ {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
+ {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
+ {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
+ {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
+*/
+/*
+ {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+*/
+/*
+ {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
+ {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
+ {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
+*/
+/*
+ {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
+*/
+/*
+ {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
+ {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
+ {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
+ {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
+ {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
+ {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
+*/
+/*
+ {"ping", 0, AGENT_PING, 0, 0},
+*/
/* New naming */
-
- {"agent.ping" ,AGENT_PING, 0, 0},
- {"agent.version", 0, AGENT_VERSION, 0},
-
- {"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
-
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
- {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
-
- {"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers" ,VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached" ,VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free" ,VM_MEMORY_FREE, 0, 0},
-
- {"vfs.fs.free[*]" ,VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total[*]" ,VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used[*]" ,VFS_FS_USED, 0, "/"},
-
- {"vfs.fs.pfree[*]" ,VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused[*]" ,VFS_FS_PUSED, 0, "/"},
-
- {"vfs.fs.inode.free[*]" ,VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total[*]",VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree[*]",VFS_FS_INODE_PFREE, 0, "/"},
-
- {"vfs.file.atime[*]" ,VFS_FILE_ATIME, 0, "/etc/passwd"},
- {"vfs.file.cksum[*]" ,VFS_FILE_CKSUM, 0, "/etc/services"},
- {"vfs.file.ctime[*]" ,VFS_FILE_CTIME, 0, "/etc/passwd"},
- {"vfs.file.exists[*]" ,VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"vfs.file.md5sum[*]" ,0, VFS_FILE_MD5SUM, "/etc/services"},
- {"vfs.file.mtime[*]" ,VFS_FILE_MTIME, 0, "/etc/passwd"},
- {"vfs.file.regexp[*]" ,0, VFS_FILE_REGEXP, "/etc/passwd,root"},
- {"vfs.file.regmatch[*]" ,VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
- {"vfs.file.size[*]" ,VFS_FILE_SIZE, 0, "/etc/passwd"},
-
- {"system.cpu.idle1" ,SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5" ,SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15" ,SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1" ,SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5" ,SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15" ,SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1" ,SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5" ,SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15" ,SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1" ,SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5" ,SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15" ,SYSTEM_CPU_USER15, 0, 0},
-
- {"net.if.ibytes1[*]" ,NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5[*]" ,NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15[*]" ,NET_IF_IBYTES15, 0, "lo"},
- {"net.if.obytes1[*]" ,NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5[*]" ,NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15[*]" ,NET_IF_OBYTES15, 0, "lo"},
-
- {"disk_read_ops1[*]" ,DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5[*]" ,DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15[*]" ,DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1[*]" ,DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5[*]" ,DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15[*]" ,DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1[*]" ,DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5[*]" ,DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15[*]" ,DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1[*]" ,DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5[*]" ,DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15[*]" ,DISKWRITEBLKS15, 0, "hda"},
-
- {"sensor[temp1]" ,SENSOR_TEMP1, 0, 0},
- {"sensor[temp2]" ,SENSOR_TEMP2, 0, 0},
- {"sensor[temp3]" ,SENSOR_TEMP3, 0, 0},
-
- {"system.cpu.load1" ,SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5" ,SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15" ,SYSTEM_CPU_LOAD15, 0, 0},
-
- {"system.hostname" ,0, EXECUTE_STR, "hostname"},
-
- {"system.swap.free" ,SYSTEM_SWAP_FREE, 0, 0},
- {"system.swap.total" ,SYSTEM_SWAP_TOTAL, 0, 0},
-
- {"system.uname" ,0, EXECUTE_STR, "uname -a"},
- {"system.uptime" ,SYSTEM_UPTIME, 0, 0},
- {"system.users.num" ,EXECUTE, 0,"who|wc -l"},
+/*
+ {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
+ {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
+ {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
+ {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
+ {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
+ {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
+ {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
+ {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
+ {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
+ {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
+ {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
+ {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
+*/
+/*
+ {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
+ {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
+ {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
+ {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
+ {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
+*/
+/*
+ {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
+ {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
+ {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
+ {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
+ {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
+*/
+/*
+ {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
+ {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
+ {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
+*/
+/*
+ {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
+ {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
+ {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
+
+ {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
+ {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
+ {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
+*/
+/*
+ {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
+ {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
+ {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
+
+ {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
+ {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
+ {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
+
+ {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
+ {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
+ {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
+
+ {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
+ {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
+ {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
+*/
+/*
+ {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
+ {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
+ {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
+*/
/****************************************
All these perameters require more than 1 second to retrieve.
@@ -277,30 +202,66 @@ ZBX_METRIC parameters_specific[]=
{"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
***************************************/
- {"io[disk_io]" ,DISK_IO, 0, 0},
- {"io[disk_rio]" ,DISK_RIO, 0, 0},
- {"io[disk_wio]" ,DISK_WIO, 0, 0},
- {"io[disk_rblk]" ,DISK_RBLK, 0, 0},
- {"io[disk_wblk]" ,DISK_WBLK, 0, 0},
-
-
-
- {"system[proccount]" ,PROCCOUNT, 0, 0},
-
-#ifdef HAVE_PROC_LOADAVG
- {"system[procrunning]" ,EXECUTE, 0, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '"},
-#endif
-
/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-
- {"net[listen_23]" ,TCP_LISTEN, 0, "0017"},
- {"net[listen_80]" ,TCP_LISTEN, 0, "0050"},
-
- {"check_port[*]" ,CHECK_PORT, 0, "80"},
-
- {"check_service[*]" ,CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"dns[*]" ,CHECK_DNS, 0, "127.0.0.1,localhost"},
- {"check_service_perf[*]",CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+/*
+ {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
+ {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
+ {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+*/
+/*
+ {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+*/
+ {"agent.ping", 0, AGENT_PING, 0, 0},
+ {"agent.version", 0, AGENT_VERSION, 0, 0},
+
+ {"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
+ {"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+
+ {"vfs.file.atime", CF_USEUPARAM, VFS_FILE_ATIME, 0, "/etc/passwd"},
+ {"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
+ {"vfs.file.ctime", CF_USEUPARAM, VFS_FILE_CTIME, 0, "/etc/passwd"},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
+ {"vfs.file.mtime", CF_USEUPARAM, VFS_FILE_MTIME, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+
+/************************************
+ * NEW FUNCTIONS *
+ ************************************/
+
+ {"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+
+ {"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
+ {"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
+ {"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+
+ {"net.if.in", CF_USEUPARAM, NET_IF_IN, 0, "lo,bytes"},
+ {"net.if.out", CF_USEUPARAM, NET_IF_OUT, 0, "lo,bytes"},
+
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
+
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
+
+ {"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
+
+ {"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
+ {"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+
+ {"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
+
+ {"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
+
+ {"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
+
+ {"system.hostname", 0, SYSTEM_HOSTNAME, 0, 0},
+
+ {"system.uname", 0, SYSTEM_UNAME, 0, 0},
+ {"system.uptime", 0, SYSTEM_UPTIME, 0, 0},
+ {"system.users.num", 0, SYSTEM_UNUM, 0, 0},
{0}
};
diff --git a/src/libs/zbxsysinfo/netbsd/proc.c b/src/libs/zbxsysinfo/netbsd/proc.c
index 7f5c596b..d80dac13 100644
--- a/src/libs/zbxsysinfo/netbsd/proc.c
+++ b/src/libs/zbxsysinfo/netbsd/proc.c
@@ -19,32 +19,485 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
#include "common.h"
#include "sysinfo.h"
-/*
-#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
-#define SDI(m) FDI("%s", m) // string info
-#define IDI(i) FDI("%i", i) // integer info
-*/
-int PROC_MEMORY(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+#define DO_SUM 0
+#define DO_MAX 1
+#define DO_MIN 2
+#define DO_AVG 3
+
+int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- /* in this moment this function for this platform unsupported */
- return SYSINFO_RET_FAIL;
+#if defined(HAVE_PROC_1_STATUS)
+
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int do_task = DO_SUM;
+
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ FILE *f;
+
+ double memsize = -1;
+ int proccount = 0;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ strscpy(mode, "sum");
+ }
+
+ if(strcmp(mode,"avg") == 0)
+ {
+ do_task = DO_AVG;
+ }
+ else if(strcmp(mode,"max") == 0)
+ {
+ do_task = DO_MAX;
+ }
+ else if(strcmp(mode,"min") == 0)
+ {
+ do_task = DO_MIN;
+ }
+ else if(strcmp(mode,"sum") == 0)
+ {
+ do_task = DO_SUM;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ usr_ok = 0;
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ /* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+ /* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && usr_ok)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li %s\n", name1, &lvalue, name2) != 3)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"VmSize:") != 0)
+ {
+ continue;
+ }
+
+ proccount++;
+
+ if(strcasecmp(name2, "kB") == 0)
+ {
+ lvalue <<= 10;
+ }
+ else if(strcasecmp(name2, "mB") == 0)
+ {
+ lvalue <<= 20;
+ }
+ else if(strcasecmp(name2, "GB") == 0)
+ {
+ lvalue <<= 30;
+ }
+ else if(strcasecmp(name2, "TB") == 0)
+ {
+ lvalue <<= 40;
+ }
+
+ if(memsize < 0)
+ {
+ memsize = (double) lvalue;
+ }
+ else
+ {
+ if(do_task == DO_MAX)
+ {
+ memsize = MAX(memsize, (double) lvalue);
+ }
+ else if(do_task == DO_MIN)
+ {
+ memsize = MIN(memsize, (double) lvalue);
+ }
+ else
+ {
+ memsize += (double) lvalue;
+ }
+ }
+
+ break;
+ }
+ }
+
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ if(memsize < 0)
+ {
+ /* incorrect process name */
+ memsize = 0;
+ }
+
+ if(do_task == DO_AVG)
+ {
+ memsize /= (double)proccount;
+ }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = memsize;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
}
-int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- /* in this moment this function for this platform unsupported */
+#if defined(HAVE_PROC_1_STATUS)
+
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char procstat[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int stat_ok = 0;
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ FILE *f;
+
+ assert(result);
+
+ clean_result(result);
+
+ int proccount = 0;
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ {
+ procstat[0] = '\0';
+ }
+
+ if(procstat[0] == '\0')
+ {
+ strscpy(procstat, "all");
+ }
+
+ if(strcmp(procstat,"run") == 0)
+ {
+ strscpy(procstat,"R");
+ }
+ else if(strcmp(procstat,"sleep") == 0)
+ {
+ strscpy(procstat,"S");
+ }
+ else if(strcmp(procstat,"zomb") == 0)
+ {
+ strscpy(procstat,"Z");
+ }
+ else if(strcmp(procstat,"all") == 0)
+ {
+ procstat[0] = 0;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ stat_ok = 0;
+ usr_ok = 0;
+
+/* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+/* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(procstat[0] != 0)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%s\n", name1, name2) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"State:") != 0)
+ {
+ continue;
+ }
+
+ if(strcmp(name2, procstat))
+ {
+ stat_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ stat_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && stat_ok && usr_ok)
+ {
+ proccount++;
+ }
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (double) proccount;
+ return SYSINFO_RET_OK;
+#else
return SYSINFO_RET_FAIL;
+#endif
}
-
diff --git a/src/libs/zbxsysinfo/netbsd/sensors.c b/src/libs/zbxsysinfo/netbsd/sensors.c
index 48c6911e..956ca3d1 100644
--- a/src/libs/zbxsysinfo/netbsd/sensors.c
+++ b/src/libs/zbxsysinfo/netbsd/sensors.c
@@ -19,125 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int SENSOR_TEMP1(const char *cmd, const char *param,double *value)
+static int SENSOR_TEMP1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -148,6 +35,10 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value)
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -173,7 +64,8 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value)
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -187,7 +79,7 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value)
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP2(const char *cmd, const char *param,double *value)
+static int SENSOR_TEMP2(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -198,6 +90,10 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value)
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -223,7 +119,8 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value)
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -237,7 +134,7 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value)
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP3(const char *cmd, const char *param,double *value)
+static int SENSOR_TEMP3(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -248,6 +145,10 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value)
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -273,7 +174,8 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value)
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -286,3 +188,43 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value)
closedir(dir);
return SYSINFO_RET_FAIL;
}
+
+int OLD_SENSOR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"temp1") == 0)
+ {
+ ret = SENSOR_TEMP1(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp2") == 0)
+ {
+ ret = SENSOR_TEMP2(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp3") == 0)
+ {
+ ret = SENSOR_TEMP3(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/netbsd/swap.c b/src/libs/zbxsysinfo/netbsd/swap.c
index db059f78..3d80fec9 100644
--- a/src/libs/zbxsysinfo/netbsd/swap.c
+++ b/src/libs/zbxsysinfo/netbsd/swap.c
@@ -19,124 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
+
/* Solaris. */
#ifndef HAVE_SYSINFO_FREESWAP
#ifdef HAVE_SYS_SWAP_SWAPTABLE
@@ -203,17 +91,22 @@ point them all to the same buffer */
#endif
#endif
-int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_FREESWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.freeswap * (double)info.mem_unit;
+ result->dbl = (double)info.freeswap * (double)info.mem_unit;
#else
- *value=(double)info.freeswap;
+ result->dbl = (double)info.freeswap;
#endif
return SYSINFO_RET_OK;
}
@@ -226,27 +119,41 @@ int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
+ assert(result);
+
+ clean_result(result);
+
get_swapinfo(&swaptotal,&swapfree);
- *value=swapfree;
+ result->type |= AR_DOUBLE;
+ result->dbl = swapfree;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
-int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_TOTALSWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalswap * (double)info.mem_unit;
+ result->dbl = (double)info.totalswap * (double)info.mem_unit;
#else
- *value=(double)info.totalswap;
+ result->dbl = (double)info.totalswap;
#endif
return SYSINFO_RET_OK;
}
@@ -259,12 +166,125 @@ int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
- get_swapinfo(&swaptotal,&swapfree);
+ assert(result);
+
+ clean_result(result);
- *value=(double)swaptotal;
+ get_swapinfo(&swaptotal,&swapfree);
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)swaptotal;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
+
+int SYSTEM_SWAP_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define SWP_FNCLIST struct swp_fnclist_s
+SWP_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ SWP_FNCLIST fl[] =
+ {
+ {"total", SYSTEM_SWAP_FREE},
+ {"free", SYSTEM_SWAP_TOTAL},
+ {0, 0}
+ };
+
+ char swapdev[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(swapdev[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(swapdev, "all");
+ }
+
+ if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "free");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+int OLD_SWAP(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"free") == 0)
+ {
+ ret = SYSTEM_SWAP_FREE(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"total") == 0)
+ {
+ ret = SYSTEM_SWAP_TOTAL(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/netbsd/uptime.c b/src/libs/zbxsysinfo/netbsd/uptime.c
index 88eee810..a38b2bd7 100644
--- a/src/libs/zbxsysinfo/netbsd/uptime.c
+++ b/src/libs/zbxsysinfo/netbsd/uptime.c
@@ -19,130 +19,22 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_UPTIME
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
- *value=(double)info.uptime;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)info.uptime;
return SYSINFO_RET_OK;
}
else
@@ -155,6 +47,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
struct timeval uptime;
int now;
+ assert(result);
+
+ clean_result(result);
+
mib[0]=CTL_KERN;
mib[1]=KERN_BOOTTIME;
@@ -167,8 +63,8 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
}
now=time(NULL);
-
- *value=(double)(now-uptime.tv_sec);
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)(now-uptime.tv_sec);
return SYSINFO_RET_OK;
#else
/* Solaris */
@@ -180,6 +76,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
long hz;
long secs;
+ assert(result);
+
+ clean_result(result);
+
hz = sysconf(_SC_CLK_TCK);
/* open kstat */
@@ -207,9 +107,14 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
/* close kstat */
kstat_close(kc);
- *value=(double)secs;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)secs;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
diff --git a/src/libs/zbxsysinfo/openbsd/cpu.c b/src/libs/zbxsysinfo/openbsd/cpu.c
index f8e94125..4e7e1502 100644
--- a/src/libs/zbxsysinfo/openbsd/cpu.c
+++ b/src/libs/zbxsysinfo/openbsd/cpu.c
@@ -19,183 +19,161 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-/* AIX CPU */
-#ifdef HAVE_KNLIST_H
- #include <knlist.h>
-#endif
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_CPU_IDLE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle1]",value,msg,mlen_max);
+ return get_stat("cpu[idle1]", flags, result);
}
-int SYSTEM_CPU_IDLE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle5]",value,msg,mlen_max);
+ return get_stat("cpu[idle5]", flags, result);
}
-int SYSTEM_CPU_IDLE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle15]",value,msg,mlen_max);
+ return get_stat("cpu[idle15]", flags, result);
}
-int SYSTEM_CPU_NICE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice1]",value,msg,mlen_max);
+ return get_stat("cpu[nice1]", flags, result);
}
-int SYSTEM_CPU_NICE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ return get_stat("cpu[nice5]", flags, result);
+}
+static int SYSTEM_CPU_NICE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice5]",value,msg,mlen_max);
+ return get_stat("cpu[nice15]", flags, result);
}
-int SYSTEM_CPU_NICE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+
+static int SYSTEM_CPU_USER1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice15]",value,msg,mlen_max);
+ return get_stat("cpu[user1]", flags, result);
}
-int SYSTEM_CPU_USER1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user1]",value,msg,mlen_max);
+ return get_stat("cpu[user5]", flags, result);
}
-int SYSTEM_CPU_USER5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user5]",value,msg,mlen_max);
+ return get_stat("cpu[user15]", flags, result);
}
-int SYSTEM_CPU_USER15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user15]",value,msg,mlen_max);
+ return get_stat("cpu[system1]", flags, result);
}
-int SYSTEM_CPU_SYS1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system1]",value,msg,mlen_max);
+ return get_stat("cpu[system5]", flags, result);
}
-int SYSTEM_CPU_SYS5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system5]",value,msg,mlen_max);
+ return get_stat("cpu[system15]", flags, result);
}
-int SYSTEM_CPU_SYS15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+int OLD_CPU(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system15]",value,msg,mlen_max);
+ return get_stat(cmd, flags, result);
+}
+
+int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"idle", "avg1" , SYSTEM_CPU_IDLE1},
+ {"idle", "avg5" , SYSTEM_CPU_IDLE5},
+ {"idle", "avg15", SYSTEM_CPU_IDLE15},
+ {"nice", "avg1" , SYSTEM_CPU_NICE1},
+ {"nice", "avg5" , SYSTEM_CPU_NICE5},
+ {"nice", "avg15", SYSTEM_CPU_NICE15},
+ {"user", "avg1" , SYSTEM_CPU_USER1},
+ {"user", "avg5" , SYSTEM_CPU_USER5},
+ {"user", "avg15", SYSTEM_CPU_USER15},
+ {"system", "avg1" , SYSTEM_CPU_SYS1},
+ {"system", "avg5" , SYSTEM_CPU_SYS5},
+ {"system", "avg15", SYSTEM_CPU_SYS15},
+ {0, 0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "user");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+ }
+ return SYSINFO_RET_FAIL;
}
/* AIX CPU info */
@@ -232,14 +210,19 @@ static int getloadavg_kmem(double loadavg[], int nelem)
}
#endif
-int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[0];
return SYSINFO_RET_OK;
}
else
@@ -250,24 +233,33 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_1_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_1_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,1,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,1, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -278,20 +270,29 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return SYSINFO_RET_FAIL;
}
- *value=loadavg[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[0];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -300,14 +301,19 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
#endif
}
-int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[1];
return SYSINFO_RET_OK;
}
else
@@ -318,24 +324,33 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_5_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_5_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,2,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,2, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -346,20 +361,29 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[1];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -368,14 +392,19 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#endif
}
-int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[2];
return SYSINFO_RET_OK;
}
else
@@ -386,24 +415,33 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_15_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_15_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,3,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,3, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -414,20 +452,29 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[2];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -435,3 +482,69 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#endif
#endif
}
+
+int SYSTEM_CPU_LOAD(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"avg1" , SYSTEM_CPU_LOAD1},
+ {"avg5" , SYSTEM_CPU_LOAD5},
+ {"avg15", SYSTEM_CPU_LOAD15},
+ {0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/openbsd/diskio.c b/src/libs/zbxsysinfo/openbsd/diskio.c
index 11da801b..23d0c450 100644
--- a/src/libs/zbxsysinfo/openbsd/diskio.c
+++ b/src/libs/zbxsysinfo/openbsd/diskio.c
@@ -19,271 +19,358 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int DISKREADOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+
+ return get_stat(key, flags, result);
+}
+
+int VFS_DEV_WRITE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
- return get_stat(key,value,msg,mlen_max);
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKWRITEOPS1},
+ {"ops", "avg5" , DISKWRITEOPS5},
+ {"ops", "avg15", DISKWRITEOPS15},
+ {"bps", "avg1" , DISKWRITEBLKS1},
+ {"bps", "avg5" , DISKWRITEBLKS5},
+ {"bps", "avg15", DISKWRITEBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
}
-int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int VFS_DEV_READ(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKREADOPS1},
+ {"ops", "avg5" , DISKREADOPS5},
+ {"ops", "avg15", DISKREADOPS15},
+ {"bps", "avg1" , DISKREADBLKS1},
+ {"bps", "avg5" , DISKREADBLKS5},
+ {"bps", "avg15", DISKREADBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+static int DISK_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",2,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",2,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",3,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",3,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",4,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",4,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",5,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",5,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",6,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",6,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
+
+int OLD_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"disk_io") == 0)
+ {
+ ret = DISK_IO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rio") == 0)
+ {
+ ret = DISK_RIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wio") == 0)
+ {
+ ret = DISK_WIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rblk") == 0)
+ {
+ ret = DISK_RBLK(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wblk") == 0)
+ {
+ ret = DISK_WBLK(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/openbsd/diskspace.c b/src/libs/zbxsysinfo/openbsd/diskspace.c
index b0955ef6..e2120ac6 100644
--- a/src/libs/zbxsysinfo/openbsd/diskspace.c
+++ b/src/libs/zbxsysinfo/openbsd/diskspace.c
@@ -19,302 +19,227 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
+#include "common.h"
+#include "sysinfo.h"
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
+int get_fs_size_stat(char *fs, double *total, double *free, double *usage)
+{
+#ifdef HAVE_SYS_STATVFS_H
+ struct statvfs s;
+#else
+ struct statfs s;
#endif
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
+ assert(fs);
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
#endif
+ {
+ return SYSINFO_RET_FAIL;
+ }
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
+#ifdef HAVE_SYS_STATVFS_H
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_frsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bavail * (s.f_frsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bavail) * (s.f_frsize / 1024.0));
+#else
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_bsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bfree * (s.f_bsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0));
+#endif
+ return SYSINFO_RET_OK;
+}
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
+static int VFS_FS_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
+ assert(result);
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
+ clean_result(result);
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
-#include "common.h"
-#include "sysinfo.h"
+ return SYSINFO_RET_OK;
+}
-int VFS_FS_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return s.f_bavail * (s.f_bsize / 1024.0);*/
- *value=s.f_bavail * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_bavail * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- return SYSINFO_RET_FAIL;
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_USED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return (s.f_blocks-s.f_bavail) * (s.f_bsize / 1024.0);*/
- *value=(s.f_blocks-s.f_bavail) * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=blocks_used * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_size_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
- return SYSINFO_RET_FAIL;
-#endif
}
-int VFS_FS_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return s.f_blocks * (s.f_bsize / 1024.0);*/
- *value= s.f_blocks * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_blocks * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- return SYSINFO_RET_FAIL;
-#endif
+ if(get_fs_size_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double used;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_USED(cmd, mountPoint, &used, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
- if(total == 0)
- {
- return SYSINFO_RET_FAIL;
- }
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_size_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
- *value = 100*used/total;
- return SYSINFO_RET_OK;
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+int VFS_FS_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if(SYSINFO_RET_OK != VFS_FS_FREE(cmd, mountPoint, &free, msg, mlen_max))
+ FS_FNCLIST fl[] =
+ {
+ {"free" , VFS_FS_FREE},
+ {"total" , VFS_FS_TOTAL},
+ {"used", VFS_FS_USED},
+ {"pfree" , VFS_FS_PFREE},
+ {"pused" , VFS_FS_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
{
- return SYSINFO_RET_FAIL;
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if(total == 0)
+
+ for(i=0; fl[i].mode!=0; i++)
{
- return SYSINFO_RET_FAIL;
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+
+ return SYSINFO_RET_FAIL;
}
diff --git a/src/libs/zbxsysinfo/openbsd/inodes.c b/src/libs/zbxsysinfo/openbsd/inodes.c
index da92ca93..c8109f28 100644
--- a/src/libs/zbxsysinfo/openbsd/inodes.c
+++ b/src/libs/zbxsysinfo/openbsd/inodes.c
@@ -19,144 +19,226 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-
-/* FreeBSD/MacOS/OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int VFS_FS_INODE_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int get_fs_inodes_stat(char *fs, double *total, double *free, double *usage)
{
#ifdef HAVE_SYS_STATVFS_H
struct statvfs s;
-
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- *value=s.f_favail;
- return SYSINFO_RET_OK;
#else
struct statfs s;
- long blocks_used;
- long blocks_percent_used;
-
- if ( statfs( (char *)mountPoint, &s) != 0 )
+#endif
+
+ assert(fs);
+
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
+#endif
{
return SYSINFO_RET_FAIL;
}
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_ffree;
- return SYSINFO_RET_OK;
-
- }
- return SYSINFO_RET_FAIL;
+ if(total)
+ (*total) = (double)(s.f_files);
+#ifdef HAVE_SYS_STATVFS_H
+ if(free)
+ (*free) = (double)(s.f_favail);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_favail);
+#else
+ if(free)
+ (*free) = (double)(s.ffree);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_ffree);
#endif
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
return SYSINFO_RET_FAIL;
- }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- *value=s.f_files;
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+}
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_files;
- return SYSINFO_RET_OK;
+static int VFS_FS_INODE_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- }
- return SYSINFO_RET_FAIL;
-#endif
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_inodes_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
+
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_INODE_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+int VFS_FS_INODE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if(SYSINFO_RET_OK != VFS_FS_INODE_FREE(cmd, mountPoint, &free, msg, mlen_max))
+ FS_FNCLIST fl[] =
{
- return SYSINFO_RET_FAIL;
+ {"free" , VFS_FS_INODE_FREE},
+ {"total" , VFS_FS_INODE_TOTAL},
+ {"used", VFS_FS_INODE_USED},
+ {"pfree" , VFS_FS_INODE_PFREE},
+ {"pused" , VFS_FS_INODE_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if(total == 0)
+
+ for(i=0; fl[i].mode!=0; i++)
{
- return SYSINFO_RET_FAIL;
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+
+ return SYSINFO_RET_FAIL;
}
+
diff --git a/src/libs/zbxsysinfo/openbsd/memory.c b/src/libs/zbxsysinfo/openbsd/memory.c
index ae4e6b03..7dc0fcbe 100644
--- a/src/libs/zbxsysinfo/openbsd/memory.c
+++ b/src/libs/zbxsysinfo/openbsd/memory.c
@@ -19,123 +19,10 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
/* Get CACHED memory in bytes */
@@ -145,8 +32,12 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
FILE *f;
char *t;
char c[MAX_STRING_LEN];
- double result = SYSINFO_RET_FAIL;
+ double res = 0;
+ assert(result);
+
+ clean_result(result);
+
f=fopen("/proc/meminfo","r");
if(NULL == f)
{
@@ -158,30 +49,40 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
{
t=(char *)strtok(c," ");
t=(char *)strtok(NULL," ");
- sscanf(t, "%lf", &result );
+ sscanf(t, "%lf", &res );
break;
}
}
fclose(f);
- *value=result;
+ result->type |= AR_DOUBLE;
+ result->dbl=res;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_BUFFERS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_BUFFERRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.bufferram * (double)info.mem_unit;
+ result->dbl=(double)info.bufferram * (double)info.mem_unit;
#else
- *value=(double)info.bufferram;
+ result->dbl=(double)info.bufferram;
#endif
return SYSINFO_RET_OK;
}
@@ -190,21 +91,30 @@ int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, con
return SYSINFO_RET_FAIL;
}
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_SHARED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_SHAREDRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.sharedram * (double)info.mem_unit;
+ result->dbl=(double)info.sharedram * (double)info.mem_unit;
#else
- *value=(double)info.sharedram;
+ result->dbl=(double)info.sharedram;
#endif
return SYSINFO_RET_OK;
}
@@ -212,36 +122,47 @@ int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_armshr<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_armshr<<2);
return SYSINFO_RET_OK;
#else
return SYSINFO_RET_FAIL;
#endif
-#endif
}
-int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -251,19 +172,24 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
/* Get page size */
page = pst.page_size;
/* Total physical memory in bytes */
- *value=(double)page*pst.physical_memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)page*pst.physical_memory;
return SYSINFO_RET_OK;
}
-#else
-#ifdef HAVE_SYSINFO_TOTALRAM
+#elif defined(HAVE_SYSINFO_TOTALRAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalram * (double)info.mem_unit;
+ result->dbl=(double)info.totalram * (double)info.mem_unit;
#else
- *value=(double)info.totalram;
+ result->dbl=(double)info.totalram;
#endif
return SYSINFO_RET_OK;
}
@@ -271,31 +197,39 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_rm<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_rm<<2);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_SYSCTL_H
+#elif defined(HAVE_SYS_SYSCTL_H)
static int mib[] = { CTL_HW, HW_PHYSMEM };
size_t len;
unsigned int memory;
int ret;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(memory);
if(0==sysctl(mib,2,&memory,&len,NULL,0))
{
- *value=(double)memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)memory;
ret=SYSINFO_RET_OK;
}
else
@@ -304,26 +238,34 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
-#endif
-#endif
-#endif
-#endif
}
-int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
struct pst_dynamic dyn;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -352,20 +294,25 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
*/
/* Free memory in bytes */
- *value=(double)dyn.psd_free * page;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)dyn.psd_free * page;
return SYSINFO_RET_OK;
}
}
-#else
-#ifdef HAVE_SYSINFO_FREERAM
+#elif defined(HAVE_SYSINFO_FREERAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.freeram * (double)info.mem_unit;
+ result->dbl=(double)info.freeram * (double)info.mem_unit;
#else
- *value=(double)info.freeram;
+ result->dbl=(double)info.freeram;
#endif
return SYSINFO_RET_OK;
}
@@ -373,28 +320,35 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_free<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_free<<2);
return SYSINFO_RET_OK;
-#else
/* OS/X */
-#ifdef HAVE_MACH_HOST_INFO_H
+#elif defined(HAVE_MACH_HOST_INFO_H)
vm_statistics_data_t page_info;
vm_size_t pagesize;
mach_msg_type_number_t count;
kern_return_t kret;
int ret;
+ assert(result);
+
+ clean_result(result);
+
pagesize = 0;
kret = host_page_size (mach_host_self(), &pagesize);
@@ -412,7 +366,8 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
pu = pw+pa+pi;
- *value=(double)pf;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)pf;
ret = SYSINFO_RET_OK;
}
else
@@ -421,10 +376,63 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
-#endif
-#endif
-#endif
-#endif
}
+
+int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#define MEM_FNCLIST struct mem_fnclist_s
+MEM_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ MEM_FNCLIST fl[] =
+ {
+ {"free", VM_MEMORY_FREE},
+ {"shared", VM_MEMORY_SHARED},
+ {"total", VM_MEMORY_TOTAL},
+ {"buffers", VM_MEMORY_BUFFERS},
+ {"cached", VM_MEMORY_CACHED},
+ {0, 0}
+ };
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/openbsd/openbsd.c b/src/libs/zbxsysinfo/openbsd/openbsd.c
index e04ef0e7..df66bf38 100644
--- a/src/libs/zbxsysinfo/openbsd/openbsd.c
+++ b/src/libs/zbxsysinfo/openbsd/openbsd.c
@@ -18,254 +18,179 @@
**/
#include "config.h"
+#include "common.h"
#include "sysinfo.h"
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_CPU_IDLE1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_IDLE5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_IDLE15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int VFS_FS_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_USED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_PUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-
-int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int VFS_FILE_ATIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_CKSUM(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_CTIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_MD5SUM(const char *cmd, const char *filename, char **value, const char *msg, int mlen_max);
-int VFS_FILE_MTIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_REGEXP(const char *cmd, const char *filename, char **value, const char *msg, int mlen_max);
-int VFS_FILE_REGMATCH(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_SIZE(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_EXISTS(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-
-int VFS_FS_INODE_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_INODE_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-
-
-int KERNEL_MAXFILES(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int KERNEL_MAXPROC(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int NET_IF_IBYTES1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_IBYTES5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_IBYTES15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int NET_IF_OBYTES1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_OBYTES5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_OBYTES15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int DISKREADOPS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADOPS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADOPS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int AGENT_PING(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int PROC_NUM(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int PROC_MEMORY(const char *cmd, const char *param, double *value, const char *msg, int mlen_max);
-
-int PROCCOUNT(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SENSOR_TEMP1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SENSOR_TEMP2(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SENSOR_TEMP3(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int TCP_LISTEN(const char *cmd, const char *porthex,double *value, const char *msg, int mlen_max);
-
-int EXECUTE(const char *cmd, const char *command,double *value, const char *msg, int mlen_max);
-int EXECUTE_STR(const char *cmd, const char *command, const char *parameter, char **value, const char *msg, int mlen_max);
-int AGENT_VERSION(const char *cmd, const char *command,char **value, const char *msg, int mlen_max);
-
-
-int CHECK_SERVICE(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-int CHECK_SERVICE_PERF(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-int CHECK_PORT(const char *cmd, const char *ip_and_port,double *value, const char *msg, int mlen_max);
-int CHECK_DNS(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-
ZBX_METRIC parameters_specific[]=
-/* KEY FUNCTION (if double) FUNCTION (if string) PARAM*/
+/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
/* Outdated */
-
- {"cksum[*]" ,VFS_FILE_CKSUM, 0, "/etc/services"},
- {"cpu[idle1]" ,SYSTEM_CPU_IDLE1, 0, 0},
- {"cpu[idle5]" ,SYSTEM_CPU_IDLE5, 0, 0},
- {"cpu[idle15]" ,SYSTEM_CPU_IDLE15, 0, 0},
- {"cpu[nice1]" ,SYSTEM_CPU_NICE1, 0, 0},
- {"cpu[nice5]" ,SYSTEM_CPU_NICE5, 0, 0},
- {"cpu[nice15]" ,SYSTEM_CPU_NICE15, 0, 0},
- {"cpu[system1]" ,SYSTEM_CPU_SYS1, 0, 0},
- {"cpu[system5]" ,SYSTEM_CPU_SYS5, 0, 0},
- {"cpu[system15]" ,SYSTEM_CPU_SYS15, 0, 0},
- {"cpu[user1]" ,SYSTEM_CPU_USER1, 0, 0},
- {"cpu[user5]" ,SYSTEM_CPU_USER5, 0, 0},
- {"cpu[user15]" ,SYSTEM_CPU_USER15, 0, 0},
- {"diskfree[*]" ,VFS_FS_FREE, 0, "/"},
- {"disktotal[*]" ,VFS_FS_TOTAL, 0, "/"},
- {"diskused[*]" ,VFS_FS_USED, 0, "/"},
- {"diskfree_perc[*]" ,VFS_FS_PFREE, 0, "/"},
- {"diskused_perc[*]" ,VFS_FS_PUSED, 0, "/"},
- {"file[*]" ,VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize[*]" ,VFS_FILE_SIZE, 0, "/etc/passwd"},
- {"inodefree[*]" ,VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal[*]" ,VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc[*]" ,VFS_FS_INODE_PFREE, 0, "/"},
- {"kern[maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kern[maxproc]" ,KERNEL_MAXPROC, 0, 0},
- {"md5sum[*]" ,0, VFS_FILE_MD5SUM, "/etc/services"},
- {"memory[buffers]" ,VM_MEMORY_BUFFERS, 0, 0},
- {"memory[cached]" ,VM_MEMORY_CACHED, 0, 0},
- {"memory[free]" ,VM_MEMORY_FREE, 0, 0},
- {"memory[shared]" ,VM_MEMORY_SHARED, 0, 0},
- {"memory[total]" ,VM_MEMORY_TOTAL, 0, 0},
- {"netloadin1[*]" ,NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5[*]" ,NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15[*]" ,NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1[*]" ,NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5[*]" ,NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15[*]" ,NET_IF_OBYTES15, 0, "lo"},
- {"ping" ,AGENT_PING, 0, 0},
- {"proc_cnt[*]" ,PROC_NUM, 0, "inetd"},
- {"swap[free]" ,SYSTEM_SWAP_FREE, 0, 0},
- {"swap[total]" ,SYSTEM_SWAP_TOTAL, 0, 0},
- {"system[procload]" ,SYSTEM_CPU_LOAD1, 0, 0},
- {"system[procload5]" ,SYSTEM_CPU_LOAD5, 0, 0},
- {"system[procload15]" ,SYSTEM_CPU_LOAD15, 0, 0},
- {"system[hostname]" ,0, EXECUTE_STR, "hostname"},
- {"system[uname]" ,0, EXECUTE_STR, "uname -a"},
- {"system[uptime]" ,SYSTEM_UPTIME, 0, 0},
- {"system[users]" ,EXECUTE, 0,"who|wc -l"},
- {"version[zabbix_agent]", 0, AGENT_VERSION, 0},
+/* incorrect OLD naming */
+ {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
+/*
+ {"cpu[idle1]", 0, 0, 0, 0},
+ {"cpu[idle5]", 0, 0, 0, 0},
+ {"cpu[idle15]", 0, 0, 0, 0},
+ {"cpu[nice1]", 0, 0, 0, 0},
+ {"cpu[nice5]", 0, 0, 0, 0},
+ {"cpu[nice15]", 0, 0, 0, 0},
+ {"cpu[system1]", 0, 0, 0, 0},
+ {"cpu[system5]", 0, 0, 0, 0},
+ {"cpu[system15]", 0, 0, 0, 0},
+ {"cpu[user1]", 0, 0, 0, 0},
+ {"cpu[user5]", 0, 0, 0, 0},
+ {"cpu[user15]", 0, 0, 0, 0},
+*/
+ {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
+/*
+ {"io[disk_io]", 0, 0, 0, 0},
+ {"io[disk_rio]", 0, 0, 0, 0},
+ {"io[disk_wio]", 0, 0, 0, 0},
+ {"io[disk_rblk]", 0, 0, 0, 0},
+ {"io[disk_wblk]", 0, 0, 0, 0},
+*/
+ {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
+/*
+ {"kern[maxfiles]", 0, 0, 0, 0},
+ {"kern[maxproc]", 0, 0, 0, 0},
+*/
+ {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
+/*
+ {"memory[buffers]", 0, 0, 0, 0},
+ {"memory[cached]", 0, 0, 0, 0},
+ {"memory[free]", 0, 0, 0, 0},
+ {"memory[shared]", 0, 0, 0, 0},
+ {"memory[total]", 0, 0, 0, 0},
+*/
+ {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
+/*
+ {"system[proccount]", 0, 0, 0, 0},
+
+ {"system[procload]", 0, 0, 0, 0},
+ {"system[procload5]", 0, 0, 0, 0},
+ {"system[procload15]", 0, 0, 0, 0},
+ {"system[hostname]", 0, 0, 0, 0},
+ {"system[uname]", 0, 0, 0, 0},
+ {"system[uptime]", 0, 0, 0, 0},
+ {"system[users]", 0, 0, 0, 0},
+
+ {"system[procrunning]", 0, 0, 0, 0},
+*/
+ {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
+/*
+ {"sensor[temp1]", 0, 0, 0, 0},
+ {"sensor[temp2]", 0, 0, 0, 0},
+ {"sensor[temp3]", 0, 0, 0, 0},
+*/
+ {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
+/*
+ {"swap[free]", 0, 0, 0, 0},
+ {"swap[total]", 0, 0, 0, 0},
+*/
+ {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
+/*
+ {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
+*/
+/* correct OLD naming */
+/*
+ {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
+*/
+/*
+ {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
+ {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
+ {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
+ {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
+ {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
+*/
+/*
+ {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+*/
+/*
+ {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
+ {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
+ {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
+*/
+/*
+ {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
+*/
+/*
+ {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
+ {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
+ {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
+ {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
+ {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
+ {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
+*/
+/*
+ {"ping", 0, AGENT_PING, 0, 0},
+*/
/* New naming */
-
- {"agent.ping" ,AGENT_PING, 0, 0},
- {"agent.version", 0, AGENT_VERSION, 0},
-
- {"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
-
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
- {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
-
- {"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers" ,VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached" ,VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free" ,VM_MEMORY_FREE, 0, 0},
-
- {"vfs.fs.free[*]" ,VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total[*]" ,VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used[*]" ,VFS_FS_USED, 0, "/"},
-
- {"vfs.fs.pfree[*]" ,VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused[*]" ,VFS_FS_PUSED, 0, "/"},
-
- {"vfs.fs.inode.free[*]" ,VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total[*]",VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree[*]",VFS_FS_INODE_PFREE, 0, "/"},
-
- {"vfs.file.atime[*]" ,VFS_FILE_ATIME, 0, "/etc/passwd"},
- {"vfs.file.cksum[*]" ,VFS_FILE_CKSUM, 0, "/etc/services"},
- {"vfs.file.ctime[*]" ,VFS_FILE_CTIME, 0, "/etc/passwd"},
- {"vfs.file.exists[*]" ,VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"vfs.file.md5sum[*]" ,0, VFS_FILE_MD5SUM, "/etc/services"},
- {"vfs.file.mtime[*]" ,VFS_FILE_MTIME, 0, "/etc/passwd"},
- {"vfs.file.regexp[*]" ,0, VFS_FILE_REGEXP, "/etc/passwd,root"},
- {"vfs.file.regmatch[*]" ,VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
- {"vfs.file.size[*]" ,VFS_FILE_SIZE, 0, "/etc/passwd"},
-
- {"system.cpu.idle1" ,SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5" ,SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15" ,SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1" ,SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5" ,SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15" ,SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1" ,SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5" ,SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15" ,SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1" ,SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5" ,SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15" ,SYSTEM_CPU_USER15, 0, 0},
-
- {"net.if.ibytes1[*]" ,NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5[*]" ,NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15[*]" ,NET_IF_IBYTES15, 0, "lo"},
- {"net.if.obytes1[*]" ,NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5[*]" ,NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15[*]" ,NET_IF_OBYTES15, 0, "lo"},
-
- {"disk_read_ops1[*]" ,DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5[*]" ,DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15[*]" ,DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1[*]" ,DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5[*]" ,DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15[*]" ,DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1[*]" ,DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5[*]" ,DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15[*]" ,DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1[*]" ,DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5[*]" ,DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15[*]" ,DISKWRITEBLKS15, 0, "hda"},
-
- {"sensor[temp1]" ,SENSOR_TEMP1, 0, 0},
- {"sensor[temp2]" ,SENSOR_TEMP2, 0, 0},
- {"sensor[temp3]" ,SENSOR_TEMP3, 0, 0},
-
- {"system.cpu.load1" ,SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5" ,SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15" ,SYSTEM_CPU_LOAD15, 0, 0},
-
- {"system.hostname" ,0, EXECUTE_STR, "hostname"},
-
- {"system.swap.free" ,SYSTEM_SWAP_FREE, 0, 0},
- {"system.swap.total" ,SYSTEM_SWAP_TOTAL, 0, 0},
-
- {"system.uname" ,0, EXECUTE_STR, "uname -a"},
- {"system.uptime" ,SYSTEM_UPTIME, 0, 0},
- {"system.users.num" ,EXECUTE, 0,"who|wc -l"},
+/*
+ {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
+ {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
+ {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
+ {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
+ {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
+ {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
+ {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
+ {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
+ {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
+ {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
+ {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
+ {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
+*/
+/*
+ {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
+ {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
+ {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
+ {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
+ {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
+*/
+/*
+ {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
+ {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
+ {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
+ {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
+ {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
+*/
+/*
+ {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
+ {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
+ {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
+*/
+/*
+ {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
+ {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
+ {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
+
+ {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
+ {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
+ {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
+*/
+/*
+ {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
+ {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
+ {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
+
+ {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
+ {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
+ {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
+
+ {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
+ {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
+ {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
+
+ {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
+ {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
+ {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
+*/
+/*
+ {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
+ {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
+ {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
+*/
/****************************************
All these perameters require more than 1 second to retrieve.
@@ -277,30 +202,66 @@ ZBX_METRIC parameters_specific[]=
{"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
***************************************/
- {"io[disk_io]" ,DISK_IO, 0, 0},
- {"io[disk_rio]" ,DISK_RIO, 0, 0},
- {"io[disk_wio]" ,DISK_WIO, 0, 0},
- {"io[disk_rblk]" ,DISK_RBLK, 0, 0},
- {"io[disk_wblk]" ,DISK_WBLK, 0, 0},
-
-
-
- {"system[proccount]" ,PROCCOUNT, 0, 0},
-
-#ifdef HAVE_PROC_LOADAVG
- {"system[procrunning]" ,EXECUTE, 0, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '"},
-#endif
-
/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-
- {"net[listen_23]" ,TCP_LISTEN, 0, "0017"},
- {"net[listen_80]" ,TCP_LISTEN, 0, "0050"},
-
- {"check_port[*]" ,CHECK_PORT, 0, "80"},
-
- {"check_service[*]" ,CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"dns[*]" ,CHECK_DNS, 0, "127.0.0.1,localhost"},
- {"check_service_perf[*]",CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+/*
+ {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
+ {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
+ {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+*/
+/*
+ {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+*/
+ {"agent.ping", 0, AGENT_PING, 0, 0},
+ {"agent.version", 0, AGENT_VERSION, 0, 0},
+
+ {"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
+ {"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+
+ {"vfs.file.atime", CF_USEUPARAM, VFS_FILE_ATIME, 0, "/etc/passwd"},
+ {"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
+ {"vfs.file.ctime", CF_USEUPARAM, VFS_FILE_CTIME, 0, "/etc/passwd"},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
+ {"vfs.file.mtime", CF_USEUPARAM, VFS_FILE_MTIME, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+
+/************************************
+ * NEW FUNCTIONS *
+ ************************************/
+
+ {"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+
+ {"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
+ {"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
+ {"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+
+ {"net.if.in", CF_USEUPARAM, NET_IF_IN, 0, "lo,bytes"},
+ {"net.if.out", CF_USEUPARAM, NET_IF_OUT, 0, "lo,bytes"},
+
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
+
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
+
+ {"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
+
+ {"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
+ {"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+
+ {"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
+
+ {"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
+
+ {"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
+
+ {"system.hostname", 0, SYSTEM_HOSTNAME, 0, 0},
+
+ {"system.uname", 0, SYSTEM_UNAME, 0, 0},
+ {"system.uptime", 0, SYSTEM_UPTIME, 0, 0},
+ {"system.users.num", 0, SYSTEM_UNUM, 0, 0},
{0}
};
diff --git a/src/libs/zbxsysinfo/openbsd/proc.c b/src/libs/zbxsysinfo/openbsd/proc.c
index 7f5c596b..d80dac13 100644
--- a/src/libs/zbxsysinfo/openbsd/proc.c
+++ b/src/libs/zbxsysinfo/openbsd/proc.c
@@ -19,32 +19,485 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
#include "common.h"
#include "sysinfo.h"
-/*
-#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
-#define SDI(m) FDI("%s", m) // string info
-#define IDI(i) FDI("%i", i) // integer info
-*/
-int PROC_MEMORY(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+#define DO_SUM 0
+#define DO_MAX 1
+#define DO_MIN 2
+#define DO_AVG 3
+
+int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- /* in this moment this function for this platform unsupported */
- return SYSINFO_RET_FAIL;
+#if defined(HAVE_PROC_1_STATUS)
+
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int do_task = DO_SUM;
+
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ FILE *f;
+
+ double memsize = -1;
+ int proccount = 0;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ strscpy(mode, "sum");
+ }
+
+ if(strcmp(mode,"avg") == 0)
+ {
+ do_task = DO_AVG;
+ }
+ else if(strcmp(mode,"max") == 0)
+ {
+ do_task = DO_MAX;
+ }
+ else if(strcmp(mode,"min") == 0)
+ {
+ do_task = DO_MIN;
+ }
+ else if(strcmp(mode,"sum") == 0)
+ {
+ do_task = DO_SUM;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ usr_ok = 0;
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ /* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+ /* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && usr_ok)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li %s\n", name1, &lvalue, name2) != 3)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"VmSize:") != 0)
+ {
+ continue;
+ }
+
+ proccount++;
+
+ if(strcasecmp(name2, "kB") == 0)
+ {
+ lvalue <<= 10;
+ }
+ else if(strcasecmp(name2, "mB") == 0)
+ {
+ lvalue <<= 20;
+ }
+ else if(strcasecmp(name2, "GB") == 0)
+ {
+ lvalue <<= 30;
+ }
+ else if(strcasecmp(name2, "TB") == 0)
+ {
+ lvalue <<= 40;
+ }
+
+ if(memsize < 0)
+ {
+ memsize = (double) lvalue;
+ }
+ else
+ {
+ if(do_task == DO_MAX)
+ {
+ memsize = MAX(memsize, (double) lvalue);
+ }
+ else if(do_task == DO_MIN)
+ {
+ memsize = MIN(memsize, (double) lvalue);
+ }
+ else
+ {
+ memsize += (double) lvalue;
+ }
+ }
+
+ break;
+ }
+ }
+
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ if(memsize < 0)
+ {
+ /* incorrect process name */
+ memsize = 0;
+ }
+
+ if(do_task == DO_AVG)
+ {
+ memsize /= (double)proccount;
+ }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = memsize;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
}
-int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- /* in this moment this function for this platform unsupported */
+#if defined(HAVE_PROC_1_STATUS)
+
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char procstat[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int stat_ok = 0;
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ FILE *f;
+
+ assert(result);
+
+ clean_result(result);
+
+ int proccount = 0;
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ {
+ procstat[0] = '\0';
+ }
+
+ if(procstat[0] == '\0')
+ {
+ strscpy(procstat, "all");
+ }
+
+ if(strcmp(procstat,"run") == 0)
+ {
+ strscpy(procstat,"R");
+ }
+ else if(strcmp(procstat,"sleep") == 0)
+ {
+ strscpy(procstat,"S");
+ }
+ else if(strcmp(procstat,"zomb") == 0)
+ {
+ strscpy(procstat,"Z");
+ }
+ else if(strcmp(procstat,"all") == 0)
+ {
+ procstat[0] = 0;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ stat_ok = 0;
+ usr_ok = 0;
+
+/* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+/* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(procstat[0] != 0)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%s\n", name1, name2) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"State:") != 0)
+ {
+ continue;
+ }
+
+ if(strcmp(name2, procstat))
+ {
+ stat_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ stat_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && stat_ok && usr_ok)
+ {
+ proccount++;
+ }
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (double) proccount;
+ return SYSINFO_RET_OK;
+#else
return SYSINFO_RET_FAIL;
+#endif
}
-
diff --git a/src/libs/zbxsysinfo/openbsd/sensors.c b/src/libs/zbxsysinfo/openbsd/sensors.c
index 32042922..956ca3d1 100644
--- a/src/libs/zbxsysinfo/openbsd/sensors.c
+++ b/src/libs/zbxsysinfo/openbsd/sensors.c
@@ -19,125 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -148,6 +35,10 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -173,7 +64,8 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -187,7 +79,7 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP2(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -198,6 +90,10 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -223,7 +119,8 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -237,7 +134,7 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP3(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -248,6 +145,10 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -273,7 +174,8 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -286,3 +188,43 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
closedir(dir);
return SYSINFO_RET_FAIL;
}
+
+int OLD_SENSOR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"temp1") == 0)
+ {
+ ret = SENSOR_TEMP1(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp2") == 0)
+ {
+ ret = SENSOR_TEMP2(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp3") == 0)
+ {
+ ret = SENSOR_TEMP3(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/openbsd/swap.c b/src/libs/zbxsysinfo/openbsd/swap.c
index db059f78..3d80fec9 100644
--- a/src/libs/zbxsysinfo/openbsd/swap.c
+++ b/src/libs/zbxsysinfo/openbsd/swap.c
@@ -19,124 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
+
/* Solaris. */
#ifndef HAVE_SYSINFO_FREESWAP
#ifdef HAVE_SYS_SWAP_SWAPTABLE
@@ -203,17 +91,22 @@ point them all to the same buffer */
#endif
#endif
-int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_FREESWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.freeswap * (double)info.mem_unit;
+ result->dbl = (double)info.freeswap * (double)info.mem_unit;
#else
- *value=(double)info.freeswap;
+ result->dbl = (double)info.freeswap;
#endif
return SYSINFO_RET_OK;
}
@@ -226,27 +119,41 @@ int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
+ assert(result);
+
+ clean_result(result);
+
get_swapinfo(&swaptotal,&swapfree);
- *value=swapfree;
+ result->type |= AR_DOUBLE;
+ result->dbl = swapfree;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
-int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_TOTALSWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalswap * (double)info.mem_unit;
+ result->dbl = (double)info.totalswap * (double)info.mem_unit;
#else
- *value=(double)info.totalswap;
+ result->dbl = (double)info.totalswap;
#endif
return SYSINFO_RET_OK;
}
@@ -259,12 +166,125 @@ int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
- get_swapinfo(&swaptotal,&swapfree);
+ assert(result);
+
+ clean_result(result);
- *value=(double)swaptotal;
+ get_swapinfo(&swaptotal,&swapfree);
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)swaptotal;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
+
+int SYSTEM_SWAP_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define SWP_FNCLIST struct swp_fnclist_s
+SWP_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ SWP_FNCLIST fl[] =
+ {
+ {"total", SYSTEM_SWAP_FREE},
+ {"free", SYSTEM_SWAP_TOTAL},
+ {0, 0}
+ };
+
+ char swapdev[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(swapdev[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(swapdev, "all");
+ }
+
+ if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "free");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+int OLD_SWAP(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"free") == 0)
+ {
+ ret = SYSTEM_SWAP_FREE(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"total") == 0)
+ {
+ ret = SYSTEM_SWAP_TOTAL(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/openbsd/uptime.c b/src/libs/zbxsysinfo/openbsd/uptime.c
index 88eee810..a38b2bd7 100644
--- a/src/libs/zbxsysinfo/openbsd/uptime.c
+++ b/src/libs/zbxsysinfo/openbsd/uptime.c
@@ -19,130 +19,22 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_UPTIME
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
- *value=(double)info.uptime;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)info.uptime;
return SYSINFO_RET_OK;
}
else
@@ -155,6 +47,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
struct timeval uptime;
int now;
+ assert(result);
+
+ clean_result(result);
+
mib[0]=CTL_KERN;
mib[1]=KERN_BOOTTIME;
@@ -167,8 +63,8 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
}
now=time(NULL);
-
- *value=(double)(now-uptime.tv_sec);
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)(now-uptime.tv_sec);
return SYSINFO_RET_OK;
#else
/* Solaris */
@@ -180,6 +76,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
long hz;
long secs;
+ assert(result);
+
+ clean_result(result);
+
hz = sysconf(_SC_CLK_TCK);
/* open kstat */
@@ -207,9 +107,14 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
/* close kstat */
kstat_close(kc);
- *value=(double)secs;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)secs;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
diff --git a/src/libs/zbxsysinfo/osf/cpu.c b/src/libs/zbxsysinfo/osf/cpu.c
index f8e94125..4e7e1502 100644
--- a/src/libs/zbxsysinfo/osf/cpu.c
+++ b/src/libs/zbxsysinfo/osf/cpu.c
@@ -19,183 +19,161 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-/* AIX CPU */
-#ifdef HAVE_KNLIST_H
- #include <knlist.h>
-#endif
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_CPU_IDLE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle1]",value,msg,mlen_max);
+ return get_stat("cpu[idle1]", flags, result);
}
-int SYSTEM_CPU_IDLE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle5]",value,msg,mlen_max);
+ return get_stat("cpu[idle5]", flags, result);
}
-int SYSTEM_CPU_IDLE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle15]",value,msg,mlen_max);
+ return get_stat("cpu[idle15]", flags, result);
}
-int SYSTEM_CPU_NICE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice1]",value,msg,mlen_max);
+ return get_stat("cpu[nice1]", flags, result);
}
-int SYSTEM_CPU_NICE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ return get_stat("cpu[nice5]", flags, result);
+}
+static int SYSTEM_CPU_NICE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice5]",value,msg,mlen_max);
+ return get_stat("cpu[nice15]", flags, result);
}
-int SYSTEM_CPU_NICE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+
+static int SYSTEM_CPU_USER1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice15]",value,msg,mlen_max);
+ return get_stat("cpu[user1]", flags, result);
}
-int SYSTEM_CPU_USER1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user1]",value,msg,mlen_max);
+ return get_stat("cpu[user5]", flags, result);
}
-int SYSTEM_CPU_USER5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user5]",value,msg,mlen_max);
+ return get_stat("cpu[user15]", flags, result);
}
-int SYSTEM_CPU_USER15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user15]",value,msg,mlen_max);
+ return get_stat("cpu[system1]", flags, result);
}
-int SYSTEM_CPU_SYS1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system1]",value,msg,mlen_max);
+ return get_stat("cpu[system5]", flags, result);
}
-int SYSTEM_CPU_SYS5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system5]",value,msg,mlen_max);
+ return get_stat("cpu[system15]", flags, result);
}
-int SYSTEM_CPU_SYS15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+int OLD_CPU(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system15]",value,msg,mlen_max);
+ return get_stat(cmd, flags, result);
+}
+
+int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"idle", "avg1" , SYSTEM_CPU_IDLE1},
+ {"idle", "avg5" , SYSTEM_CPU_IDLE5},
+ {"idle", "avg15", SYSTEM_CPU_IDLE15},
+ {"nice", "avg1" , SYSTEM_CPU_NICE1},
+ {"nice", "avg5" , SYSTEM_CPU_NICE5},
+ {"nice", "avg15", SYSTEM_CPU_NICE15},
+ {"user", "avg1" , SYSTEM_CPU_USER1},
+ {"user", "avg5" , SYSTEM_CPU_USER5},
+ {"user", "avg15", SYSTEM_CPU_USER15},
+ {"system", "avg1" , SYSTEM_CPU_SYS1},
+ {"system", "avg5" , SYSTEM_CPU_SYS5},
+ {"system", "avg15", SYSTEM_CPU_SYS15},
+ {0, 0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "user");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+ }
+ return SYSINFO_RET_FAIL;
}
/* AIX CPU info */
@@ -232,14 +210,19 @@ static int getloadavg_kmem(double loadavg[], int nelem)
}
#endif
-int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[0];
return SYSINFO_RET_OK;
}
else
@@ -250,24 +233,33 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_1_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_1_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,1,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,1, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -278,20 +270,29 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return SYSINFO_RET_FAIL;
}
- *value=loadavg[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[0];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -300,14 +301,19 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
#endif
}
-int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[1];
return SYSINFO_RET_OK;
}
else
@@ -318,24 +324,33 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_5_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_5_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,2,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,2, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -346,20 +361,29 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[1];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -368,14 +392,19 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#endif
}
-int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[2];
return SYSINFO_RET_OK;
}
else
@@ -386,24 +415,33 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_15_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_15_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,3,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,3, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -414,20 +452,29 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[2];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -435,3 +482,69 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#endif
#endif
}
+
+int SYSTEM_CPU_LOAD(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"avg1" , SYSTEM_CPU_LOAD1},
+ {"avg5" , SYSTEM_CPU_LOAD5},
+ {"avg15", SYSTEM_CPU_LOAD15},
+ {0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/osf/diskio.c b/src/libs/zbxsysinfo/osf/diskio.c
index 11da801b..23d0c450 100644
--- a/src/libs/zbxsysinfo/osf/diskio.c
+++ b/src/libs/zbxsysinfo/osf/diskio.c
@@ -19,271 +19,358 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int DISKREADOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+
+ return get_stat(key, flags, result);
+}
+
+int VFS_DEV_WRITE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
- return get_stat(key,value,msg,mlen_max);
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKWRITEOPS1},
+ {"ops", "avg5" , DISKWRITEOPS5},
+ {"ops", "avg15", DISKWRITEOPS15},
+ {"bps", "avg1" , DISKWRITEBLKS1},
+ {"bps", "avg5" , DISKWRITEBLKS5},
+ {"bps", "avg15", DISKWRITEBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
}
-int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int VFS_DEV_READ(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKREADOPS1},
+ {"ops", "avg5" , DISKREADOPS5},
+ {"ops", "avg15", DISKREADOPS15},
+ {"bps", "avg1" , DISKREADBLKS1},
+ {"bps", "avg5" , DISKREADBLKS5},
+ {"bps", "avg15", DISKREADBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+static int DISK_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",2,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",2,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",3,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",3,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",4,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",4,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",5,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",5,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",6,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",6,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
+
+int OLD_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"disk_io") == 0)
+ {
+ ret = DISK_IO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rio") == 0)
+ {
+ ret = DISK_RIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wio") == 0)
+ {
+ ret = DISK_WIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rblk") == 0)
+ {
+ ret = DISK_RBLK(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wblk") == 0)
+ {
+ ret = DISK_WBLK(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/osf/diskspace.c b/src/libs/zbxsysinfo/osf/diskspace.c
index 06b225ee..e2120ac6 100644
--- a/src/libs/zbxsysinfo/osf/diskspace.c
+++ b/src/libs/zbxsysinfo/osf/diskspace.c
@@ -19,302 +19,227 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
+#include "common.h"
+#include "sysinfo.h"
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
+int get_fs_size_stat(char *fs, double *total, double *free, double *usage)
+{
+#ifdef HAVE_SYS_STATVFS_H
+ struct statvfs s;
+#else
+ struct statfs s;
#endif
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
+ assert(fs);
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
#endif
+ {
+ return SYSINFO_RET_FAIL;
+ }
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
+#ifdef HAVE_SYS_STATVFS_H
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_frsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bavail * (s.f_frsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bavail) * (s.f_frsize / 1024.0));
+#else
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_bsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bfree * (s.f_bsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0));
+#endif
+ return SYSINFO_RET_OK;
+}
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
+static int VFS_FS_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
+ assert(result);
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
+ clean_result(result);
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
-#include "common.h"
-#include "sysinfo.h"
+ return SYSINFO_RET_OK;
+}
-int VFS_FS_USED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return (s.f_blocks-s.f_bavail) * (s.f_bsize / 1024.0);*/
- *value=(s.f_blocks-s.f_bavail) * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=blocks_used * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- return SYSINFO_RET_FAIL;
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return s.f_blocks * (s.f_bsize / 1024.0);*/
- *value= s.f_blocks * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_blocks * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_size_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
- return SYSINFO_RET_FAIL;
-#endif
}
-int VFS_FS_PUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double used;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_USED(cmd, mountPoint, &used, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
- if(total == 0)
- {
- return SYSINFO_RET_FAIL;
- }
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- *value = 100*used/total;
- return SYSINFO_RET_OK;
+ if(get_fs_size_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_FREE(cmd, mountPoint, &free, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
- if(total == 0)
- {
- return SYSINFO_RET_FAIL;
- }
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_size_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+ return SYSINFO_RET_OK;
}
-int VFS_FS_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+int VFS_FS_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
-
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-/* return s.f_bavail * (s.f_bsize / 1024.0);*/
- *value=s.f_bavail * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if ( statfs( (char *)mountPoint, &s) != 0 )
+ FS_FNCLIST fl[] =
{
- return SYSINFO_RET_FAIL;
+ {"free" , VFS_FS_FREE},
+ {"total" , VFS_FS_TOTAL},
+ {"used", VFS_FS_USED},
+ {"pfree" , VFS_FS_PFREE},
+ {"pused" , VFS_FS_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_bavail * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
-
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- return SYSINFO_RET_FAIL;
-#endif
+
+ return SYSINFO_RET_FAIL;
}
diff --git a/src/libs/zbxsysinfo/osf/inodes.c b/src/libs/zbxsysinfo/osf/inodes.c
index da92ca93..c8109f28 100644
--- a/src/libs/zbxsysinfo/osf/inodes.c
+++ b/src/libs/zbxsysinfo/osf/inodes.c
@@ -19,144 +19,226 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-
-/* FreeBSD/MacOS/OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int VFS_FS_INODE_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int get_fs_inodes_stat(char *fs, double *total, double *free, double *usage)
{
#ifdef HAVE_SYS_STATVFS_H
struct statvfs s;
-
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- *value=s.f_favail;
- return SYSINFO_RET_OK;
#else
struct statfs s;
- long blocks_used;
- long blocks_percent_used;
-
- if ( statfs( (char *)mountPoint, &s) != 0 )
+#endif
+
+ assert(fs);
+
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
+#endif
{
return SYSINFO_RET_FAIL;
}
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_ffree;
- return SYSINFO_RET_OK;
-
- }
- return SYSINFO_RET_FAIL;
+ if(total)
+ (*total) = (double)(s.f_files);
+#ifdef HAVE_SYS_STATVFS_H
+ if(free)
+ (*free) = (double)(s.f_favail);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_favail);
+#else
+ if(free)
+ (*free) = (double)(s.ffree);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_ffree);
#endif
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
return SYSINFO_RET_FAIL;
- }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- *value=s.f_files;
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+}
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_files;
- return SYSINFO_RET_OK;
+static int VFS_FS_INODE_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- }
- return SYSINFO_RET_FAIL;
-#endif
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_inodes_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
+
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_INODE_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+int VFS_FS_INODE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if(SYSINFO_RET_OK != VFS_FS_INODE_FREE(cmd, mountPoint, &free, msg, mlen_max))
+ FS_FNCLIST fl[] =
{
- return SYSINFO_RET_FAIL;
+ {"free" , VFS_FS_INODE_FREE},
+ {"total" , VFS_FS_INODE_TOTAL},
+ {"used", VFS_FS_INODE_USED},
+ {"pfree" , VFS_FS_INODE_PFREE},
+ {"pused" , VFS_FS_INODE_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if(total == 0)
+
+ for(i=0; fl[i].mode!=0; i++)
{
- return SYSINFO_RET_FAIL;
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+
+ return SYSINFO_RET_FAIL;
}
+
diff --git a/src/libs/zbxsysinfo/osf/memory.c b/src/libs/zbxsysinfo/osf/memory.c
index d0c51bc9..7dc0fcbe 100644
--- a/src/libs/zbxsysinfo/osf/memory.c
+++ b/src/libs/zbxsysinfo/osf/memory.c
@@ -19,123 +19,10 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
/* Get CACHED memory in bytes */
@@ -145,8 +32,12 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
FILE *f;
char *t;
char c[MAX_STRING_LEN];
- double result = SYSINFO_RET_FAIL;
+ double res = 0;
+
+ assert(result);
+ clean_result(result);
+
f=fopen("/proc/meminfo","r");
if(NULL == f)
{
@@ -158,30 +49,40 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
{
t=(char *)strtok(c," ");
t=(char *)strtok(NULL," ");
- sscanf(t, "%lf", &result );
+ sscanf(t, "%lf", &res );
break;
}
}
fclose(f);
- *value=result;
+ result->type |= AR_DOUBLE;
+ result->dbl=res;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_BUFFERS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_BUFFERRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.bufferram * (double)info.mem_unit;
+ result->dbl=(double)info.bufferram * (double)info.mem_unit;
#else
- *value=(double)info.bufferram;
+ result->dbl=(double)info.bufferram;
#endif
return SYSINFO_RET_OK;
}
@@ -190,21 +91,30 @@ int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, con
return SYSINFO_RET_FAIL;
}
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_SHARED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_SHAREDRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.sharedram * (double)info.mem_unit;
+ result->dbl=(double)info.sharedram * (double)info.mem_unit;
#else
- *value=(double)info.sharedram;
+ result->dbl=(double)info.sharedram;
#endif
return SYSINFO_RET_OK;
}
@@ -212,36 +122,47 @@ int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_armshr<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_armshr<<2);
return SYSINFO_RET_OK;
#else
return SYSINFO_RET_FAIL;
#endif
-#endif
}
-int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -251,19 +172,24 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
/* Get page size */
page = pst.page_size;
/* Total physical memory in bytes */
- *value=(double)page*pst.physical_memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)page*pst.physical_memory;
return SYSINFO_RET_OK;
}
-#else
-#ifdef HAVE_SYSINFO_TOTALRAM
+#elif defined(HAVE_SYSINFO_TOTALRAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalram * (double)info.mem_unit;
+ result->dbl=(double)info.totalram * (double)info.mem_unit;
#else
- *value=(double)info.totalram;
+ result->dbl=(double)info.totalram;
#endif
return SYSINFO_RET_OK;
}
@@ -271,31 +197,39 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_rm<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_rm<<2);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_SYSCTL_H
+#elif defined(HAVE_SYS_SYSCTL_H)
static int mib[] = { CTL_HW, HW_PHYSMEM };
size_t len;
unsigned int memory;
int ret;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(memory);
if(0==sysctl(mib,2,&memory,&len,NULL,0))
{
- *value=(double)memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)memory;
ret=SYSINFO_RET_OK;
}
else
@@ -304,15 +238,201 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
+}
+
+static int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+/* Solaris */
+#ifdef HAVE_UNISTD_SYSCONF
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ return SYSINFO_RET_OK;
+#elif defined(HAVE_SYS_PSTAT_H)
+ struct pst_static pst;
+ struct pst_dynamic dyn;
+ long page;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ else
+ {
+ /* Get page size */
+ page = pst.page_size;
+/* return pst.physical_memory;*/
+
+ if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ else
+ {
+/* cout<<"total virtual memory allocated is " << dyn.psd_vm << "
+ pages, " << dyn.psd_vm * page << " bytes" << endl;
+ cout<<"active virtual memory is " << dyn.psd_avm <<" pages, " <<
+ dyn.psd_avm * page << " bytes" << endl;
+ cout<<"total real memory is " << dyn.psd_rm << " pages, " <<
+ dyn.psd_rm * page << " bytes" << endl;
+ cout<<"active real memory is " << dyn.psd_arm << " pages, " <<
+ dyn.psd_arm * page << " bytes" << endl;
+ cout<<"free memory is " << dyn.psd_free << " pages, " <<
+*/
+ /* Free memory in bytes */
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)dyn.psd_free * page;
+ return SYSINFO_RET_OK;
+ }
+ }
+#elif defined(HAVE_SYSINFO_FREERAM)
+ struct sysinfo info;
+
+ assert(result);
+
+ clean_result(result);
+
+ if( 0 == sysinfo(&info))
+ {
+ result->type |= AR_DOUBLE;
+#ifdef HAVE_SYSINFO_MEM_UNIT
+ result->dbl=(double)info.freeram * (double)info.mem_unit;
+#else
+ result->dbl=(double)info.freeram;
#endif
-#endif
-#endif
+ return SYSINFO_RET_OK;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
+ int mib[2],len;
+ struct vmtotal v;
+
+ assert(result);
+
+ clean_result(result);
+
+ len=sizeof(struct vmtotal);
+ mib[0]=CTL_VM;
+ mib[1]=VM_METER;
+
+ sysctl(mib,2,&v,&len,NULL,0);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_free<<2);
+ return SYSINFO_RET_OK;
+/* OS/X */
+#elif defined(HAVE_MACH_HOST_INFO_H)
+ vm_statistics_data_t page_info;
+ vm_size_t pagesize;
+ mach_msg_type_number_t count;
+ kern_return_t kret;
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ pagesize = 0;
+ kret = host_page_size (mach_host_self(), &pagesize);
+
+ count = HOST_VM_INFO_COUNT;
+ kret = host_statistics (mach_host_self(), HOST_VM_INFO,
+ (host_info_t)&page_info, &count);
+ if (kret == KERN_SUCCESS)
+ {
+ double pw, pa, pi, pf, pu;
+
+ pw = (double)page_info.wire_count*pagesize;
+ pa = (double)page_info.active_count*pagesize;
+ pi = (double)page_info.inactive_count*pagesize;
+ pf = (double)page_info.free_count*pagesize;
+
+ pu = pw+pa+pi;
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)pf;
+ ret = SYSINFO_RET_OK;
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+ return ret;
+#else
+ assert(result);
+
+ clean_result(result);
+
+ return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return SYSINFO_RET_FAIL;
+#define MEM_FNCLIST struct mem_fnclist_s
+MEM_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ MEM_FNCLIST fl[] =
+ {
+ {"free", VM_MEMORY_FREE},
+ {"shared", VM_MEMORY_SHARED},
+ {"total", VM_MEMORY_TOTAL},
+ {"buffers", VM_MEMORY_BUFFERS},
+ {"cached", VM_MEMORY_CACHED},
+ {0, 0}
+ };
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
}
+
diff --git a/src/libs/zbxsysinfo/osf/osf.c b/src/libs/zbxsysinfo/osf/osf.c
index 0048d346..df66bf38 100644
--- a/src/libs/zbxsysinfo/osf/osf.c
+++ b/src/libs/zbxsysinfo/osf/osf.c
@@ -18,254 +18,179 @@
**/
#include "config.h"
+#include "common.h"
#include "sysinfo.h"
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *valu, const char *msg, int mlen_maxe);
-int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_CPU_IDLE1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_IDLE5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_IDLE15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int VFS_FS_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_USED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_PUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-
-int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int VFS_FILE_ATIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_CKSUM(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_CTIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_MD5SUM(const char *cmd, const char *filename, char **value, const char *msg, int mlen_max);
-int VFS_FILE_MTIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_REGEXP(const char *cmd, const char *filename, char **value, const char *msg, int mlen_max);
-int VFS_FILE_REGMATCH(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_SIZE(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_EXISTS(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-
-int VFS_FS_INODE_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_INODE_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-
-
-int KERNEL_MAXFILES(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int KERNEL_MAXPROC(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int NET_IF_IBYTES1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_IBYTES5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_IBYTES15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int NET_IF_OBYTES1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_OBYTES5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_OBYTES15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int DISKREADOPS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADOPS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADOPS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int AGENT_PING(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int PROC_NUM(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int PROC_MEMORY(const char *cmd, const char *param, double *value, const char *msg, int mlen_max);
-
-int PROCCOUNT(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max, const char *msg, int mlen_max);
-
-int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SENSOR_TEMP1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SENSOR_TEMP2(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SENSOR_TEMP3(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int TCP_LISTEN(const char *cmd, const char *porthex,double *value, const char *msg, int mlen_max);
-
-int EXECUTE(const char *cmd, const char *command,double *value, const char *msg, int mlen_max);
-int EXECUTE_STR(const char *cmd, const char *command, const char *parameter, char **value, const char *msg, int mlen_max);
-int AGENT_VERSION(const char *cmd, const char *command,char **value, const char *msg, int mlen_max);
-
-
-int CHECK_SERVICE(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-int CHECK_SERVICE_PERF(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-int CHECK_PORT(const char *cmd, const char *ip_and_port,double *value, const char *msg, int mlen_max);
-int CHECK_DNS(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-
ZBX_METRIC parameters_specific[]=
-/* KEY FUNCTION (if double) FUNCTION (if string) PARAM*/
+/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
/* Outdated */
-
- {"cksum[*]" ,VFS_FILE_CKSUM, 0, "/etc/services"},
- {"cpu[idle1]" ,SYSTEM_CPU_IDLE1, 0, 0},
- {"cpu[idle5]" ,SYSTEM_CPU_IDLE5, 0, 0},
- {"cpu[idle15]" ,SYSTEM_CPU_IDLE15, 0, 0},
- {"cpu[nice1]" ,SYSTEM_CPU_NICE1, 0, 0},
- {"cpu[nice5]" ,SYSTEM_CPU_NICE5, 0, 0},
- {"cpu[nice15]" ,SYSTEM_CPU_NICE15, 0, 0},
- {"cpu[system1]" ,SYSTEM_CPU_SYS1, 0, 0},
- {"cpu[system5]" ,SYSTEM_CPU_SYS5, 0, 0},
- {"cpu[system15]" ,SYSTEM_CPU_SYS15, 0, 0},
- {"cpu[user1]" ,SYSTEM_CPU_USER1, 0, 0},
- {"cpu[user5]" ,SYSTEM_CPU_USER5, 0, 0},
- {"cpu[user15]" ,SYSTEM_CPU_USER15, 0, 0},
- {"diskfree[*]" ,VFS_FS_FREE, 0, "/"},
- {"disktotal[*]" ,VFS_FS_TOTAL, 0, "/"},
- {"diskused[*]" ,VFS_FS_USED, 0, "/"},
- {"diskfree_perc[*]" ,VFS_FS_PFREE, 0, "/"},
- {"diskused_perc[*]" ,VFS_FS_PUSED, 0, "/"},
- {"file[*]" ,VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize[*]" ,VFS_FILE_SIZE, 0, "/etc/passwd"},
- {"inodefree[*]" ,VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal[*]" ,VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc[*]" ,VFS_FS_INODE_PFREE, 0, "/"},
- {"kern[maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kern[maxproc]" ,KERNEL_MAXPROC, 0, 0},
- {"md5sum[*]" ,0, VFS_FILE_MD5SUM, "/etc/services"},
- {"memory[buffers]" ,VM_MEMORY_BUFFERS, 0, 0},
- {"memory[cached]" ,VM_MEMORY_CACHED, 0, 0},
- {"memory[free]" ,VM_MEMORY_FREE, 0, 0},
- {"memory[shared]" ,VM_MEMORY_SHARED, 0, 0},
- {"memory[total]" ,VM_MEMORY_TOTAL, 0, 0},
- {"netloadin1[*]" ,NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5[*]" ,NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15[*]" ,NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1[*]" ,NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5[*]" ,NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15[*]" ,NET_IF_OBYTES15, 0, "lo"},
- {"ping" ,AGENT_PING, 0, 0},
- {"proc_cnt[*]" ,PROC_NUM, 0, "inetd"},
- {"swap[free]" ,SYSTEM_SWAP_FREE, 0, 0},
- {"swap[total]" ,SYSTEM_SWAP_TOTAL, 0, 0},
- {"system[procload]" ,SYSTEM_CPU_LOAD1, 0, 0},
- {"system[procload5]" ,SYSTEM_CPU_LOAD5, 0, 0},
- {"system[procload15]" ,SYSTEM_CPU_LOAD15, 0, 0},
- {"system[hostname]" ,0, EXECUTE_STR, "hostname"},
- {"system[uname]" ,0, EXECUTE_STR, "uname -a"},
- {"system[uptime]" ,SYSTEM_UPTIME, 0, 0},
- {"system[users]" ,EXECUTE, 0,"who|wc -l"},
- {"version[zabbix_agent]", 0, AGENT_VERSION, 0},
+/* incorrect OLD naming */
+ {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
+/*
+ {"cpu[idle1]", 0, 0, 0, 0},
+ {"cpu[idle5]", 0, 0, 0, 0},
+ {"cpu[idle15]", 0, 0, 0, 0},
+ {"cpu[nice1]", 0, 0, 0, 0},
+ {"cpu[nice5]", 0, 0, 0, 0},
+ {"cpu[nice15]", 0, 0, 0, 0},
+ {"cpu[system1]", 0, 0, 0, 0},
+ {"cpu[system5]", 0, 0, 0, 0},
+ {"cpu[system15]", 0, 0, 0, 0},
+ {"cpu[user1]", 0, 0, 0, 0},
+ {"cpu[user5]", 0, 0, 0, 0},
+ {"cpu[user15]", 0, 0, 0, 0},
+*/
+ {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
+/*
+ {"io[disk_io]", 0, 0, 0, 0},
+ {"io[disk_rio]", 0, 0, 0, 0},
+ {"io[disk_wio]", 0, 0, 0, 0},
+ {"io[disk_rblk]", 0, 0, 0, 0},
+ {"io[disk_wblk]", 0, 0, 0, 0},
+*/
+ {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
+/*
+ {"kern[maxfiles]", 0, 0, 0, 0},
+ {"kern[maxproc]", 0, 0, 0, 0},
+*/
+ {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
+/*
+ {"memory[buffers]", 0, 0, 0, 0},
+ {"memory[cached]", 0, 0, 0, 0},
+ {"memory[free]", 0, 0, 0, 0},
+ {"memory[shared]", 0, 0, 0, 0},
+ {"memory[total]", 0, 0, 0, 0},
+*/
+ {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
+/*
+ {"system[proccount]", 0, 0, 0, 0},
+
+ {"system[procload]", 0, 0, 0, 0},
+ {"system[procload5]", 0, 0, 0, 0},
+ {"system[procload15]", 0, 0, 0, 0},
+ {"system[hostname]", 0, 0, 0, 0},
+ {"system[uname]", 0, 0, 0, 0},
+ {"system[uptime]", 0, 0, 0, 0},
+ {"system[users]", 0, 0, 0, 0},
+
+ {"system[procrunning]", 0, 0, 0, 0},
+*/
+ {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
+/*
+ {"sensor[temp1]", 0, 0, 0, 0},
+ {"sensor[temp2]", 0, 0, 0, 0},
+ {"sensor[temp3]", 0, 0, 0, 0},
+*/
+ {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
+/*
+ {"swap[free]", 0, 0, 0, 0},
+ {"swap[total]", 0, 0, 0, 0},
+*/
+ {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
+/*
+ {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
+*/
+/* correct OLD naming */
+/*
+ {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
+*/
+/*
+ {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
+ {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
+ {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
+ {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
+ {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
+*/
+/*
+ {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+*/
+/*
+ {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
+ {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
+ {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
+*/
+/*
+ {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
+*/
+/*
+ {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
+ {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
+ {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
+ {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
+ {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
+ {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
+*/
+/*
+ {"ping", 0, AGENT_PING, 0, 0},
+*/
/* New naming */
-
- {"agent.ping" ,AGENT_PING, 0, 0},
- {"agent.version", 0, AGENT_VERSION, 0},
-
- {"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
-
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
- {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
-
- {"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers" ,VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached" ,VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free" ,VM_MEMORY_FREE, 0, 0},
-
- {"vfs.fs.free[*]" ,VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total[*]" ,VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used[*]" ,VFS_FS_USED, 0, "/"},
-
- {"vfs.fs.pfree[*]" ,VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused[*]" ,VFS_FS_PUSED, 0, "/"},
-
- {"vfs.fs.inode.free[*]" ,VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total[*]",VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree[*]",VFS_FS_INODE_PFREE, 0, "/"},
-
- {"vfs.file.atime[*]" ,VFS_FILE_ATIME, 0, "/etc/passwd"},
- {"vfs.file.cksum[*]" ,VFS_FILE_CKSUM, 0, "/etc/services"},
- {"vfs.file.ctime[*]" ,VFS_FILE_CTIME, 0, "/etc/passwd"},
- {"vfs.file.exists[*]" ,VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"vfs.file.md5sum[*]" ,0, VFS_FILE_MD5SUM, "/etc/services"},
- {"vfs.file.mtime[*]" ,VFS_FILE_MTIME, 0, "/etc/passwd"},
- {"vfs.file.regexp[*]" ,0, VFS_FILE_REGEXP, "/etc/passwd,root"},
- {"vfs.file.regmatch[*]" ,VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
- {"vfs.file.size[*]" ,VFS_FILE_SIZE, 0, "/etc/passwd"},
-
- {"system.cpu.idle1" ,SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5" ,SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15" ,SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1" ,SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5" ,SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15" ,SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1" ,SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5" ,SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15" ,SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1" ,SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5" ,SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15" ,SYSTEM_CPU_USER15, 0, 0},
-
- {"net.if.ibytes1[*]" ,NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5[*]" ,NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15[*]" ,NET_IF_IBYTES15, 0, "lo"},
- {"net.if.obytes1[*]" ,NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5[*]" ,NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15[*]" ,NET_IF_OBYTES15, 0, "lo"},
-
- {"disk_read_ops1[*]" ,DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5[*]" ,DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15[*]" ,DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1[*]" ,DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5[*]" ,DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15[*]" ,DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1[*]" ,DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5[*]" ,DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15[*]" ,DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1[*]" ,DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5[*]" ,DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15[*]" ,DISKWRITEBLKS15, 0, "hda"},
-
- {"sensor[temp1]" ,SENSOR_TEMP1, 0, 0},
- {"sensor[temp2]" ,SENSOR_TEMP2, 0, 0},
- {"sensor[temp3]" ,SENSOR_TEMP3, 0, 0},
-
- {"system.cpu.load1" ,SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5" ,SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15" ,SYSTEM_CPU_LOAD15, 0, 0},
-
- {"system.hostname" ,0, EXECUTE_STR, "hostname"},
-
- {"system.swap.free" ,SYSTEM_SWAP_FREE, 0, 0},
- {"system.swap.total" ,SYSTEM_SWAP_TOTAL, 0, 0},
-
- {"system.uname" ,0, EXECUTE_STR, "uname -a"},
- {"system.uptime" ,SYSTEM_UPTIME, 0, 0},
- {"system.users.num" ,EXECUTE, 0,"who|wc -l"},
+/*
+ {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
+ {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
+ {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
+ {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
+ {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
+ {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
+ {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
+ {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
+ {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
+ {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
+ {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
+ {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
+*/
+/*
+ {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
+ {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
+ {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
+ {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
+ {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
+*/
+/*
+ {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
+ {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
+ {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
+ {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
+ {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
+*/
+/*
+ {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
+ {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
+ {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
+*/
+/*
+ {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
+ {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
+ {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
+
+ {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
+ {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
+ {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
+*/
+/*
+ {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
+ {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
+ {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
+
+ {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
+ {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
+ {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
+
+ {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
+ {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
+ {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
+
+ {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
+ {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
+ {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
+*/
+/*
+ {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
+ {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
+ {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
+*/
/****************************************
All these perameters require more than 1 second to retrieve.
@@ -277,30 +202,66 @@ ZBX_METRIC parameters_specific[]=
{"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
***************************************/
- {"io[disk_io]" ,DISK_IO, 0, 0},
- {"io[disk_rio]" ,DISK_RIO, 0, 0},
- {"io[disk_wio]" ,DISK_WIO, 0, 0},
- {"io[disk_rblk]" ,DISK_RBLK, 0, 0},
- {"io[disk_wblk]" ,DISK_WBLK, 0, 0},
-
-
-
- {"system[proccount]" ,PROCCOUNT, 0, 0},
-
-#ifdef HAVE_PROC_LOADAVG
- {"system[procrunning]" ,EXECUTE, 0, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '"},
-#endif
-
/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-
- {"net[listen_23]" ,TCP_LISTEN, 0, "0017"},
- {"net[listen_80]" ,TCP_LISTEN, 0, "0050"},
-
- {"check_port[*]" ,CHECK_PORT, 0, "80"},
-
- {"check_service[*]" ,CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"dns[*]" ,CHECK_DNS, 0, "127.0.0.1,localhost"},
- {"check_service_perf[*]",CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+/*
+ {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
+ {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
+ {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+*/
+/*
+ {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+*/
+ {"agent.ping", 0, AGENT_PING, 0, 0},
+ {"agent.version", 0, AGENT_VERSION, 0, 0},
+
+ {"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
+ {"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+
+ {"vfs.file.atime", CF_USEUPARAM, VFS_FILE_ATIME, 0, "/etc/passwd"},
+ {"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
+ {"vfs.file.ctime", CF_USEUPARAM, VFS_FILE_CTIME, 0, "/etc/passwd"},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
+ {"vfs.file.mtime", CF_USEUPARAM, VFS_FILE_MTIME, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+
+/************************************
+ * NEW FUNCTIONS *
+ ************************************/
+
+ {"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+
+ {"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
+ {"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
+ {"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+
+ {"net.if.in", CF_USEUPARAM, NET_IF_IN, 0, "lo,bytes"},
+ {"net.if.out", CF_USEUPARAM, NET_IF_OUT, 0, "lo,bytes"},
+
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
+
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
+
+ {"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
+
+ {"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
+ {"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+
+ {"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
+
+ {"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
+
+ {"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
+
+ {"system.hostname", 0, SYSTEM_HOSTNAME, 0, 0},
+
+ {"system.uname", 0, SYSTEM_UNAME, 0, 0},
+ {"system.uptime", 0, SYSTEM_UPTIME, 0, 0},
+ {"system.users.num", 0, SYSTEM_UNUM, 0, 0},
{0}
};
diff --git a/src/libs/zbxsysinfo/osf/proc.c b/src/libs/zbxsysinfo/osf/proc.c
index 7f5c596b..d80dac13 100644
--- a/src/libs/zbxsysinfo/osf/proc.c
+++ b/src/libs/zbxsysinfo/osf/proc.c
@@ -19,32 +19,485 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
#include "common.h"
#include "sysinfo.h"
-/*
-#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
-#define SDI(m) FDI("%s", m) // string info
-#define IDI(i) FDI("%i", i) // integer info
-*/
-int PROC_MEMORY(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+#define DO_SUM 0
+#define DO_MAX 1
+#define DO_MIN 2
+#define DO_AVG 3
+
+int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- /* in this moment this function for this platform unsupported */
- return SYSINFO_RET_FAIL;
+#if defined(HAVE_PROC_1_STATUS)
+
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int do_task = DO_SUM;
+
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ FILE *f;
+
+ double memsize = -1;
+ int proccount = 0;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ strscpy(mode, "sum");
+ }
+
+ if(strcmp(mode,"avg") == 0)
+ {
+ do_task = DO_AVG;
+ }
+ else if(strcmp(mode,"max") == 0)
+ {
+ do_task = DO_MAX;
+ }
+ else if(strcmp(mode,"min") == 0)
+ {
+ do_task = DO_MIN;
+ }
+ else if(strcmp(mode,"sum") == 0)
+ {
+ do_task = DO_SUM;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ usr_ok = 0;
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ /* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+ /* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && usr_ok)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li %s\n", name1, &lvalue, name2) != 3)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"VmSize:") != 0)
+ {
+ continue;
+ }
+
+ proccount++;
+
+ if(strcasecmp(name2, "kB") == 0)
+ {
+ lvalue <<= 10;
+ }
+ else if(strcasecmp(name2, "mB") == 0)
+ {
+ lvalue <<= 20;
+ }
+ else if(strcasecmp(name2, "GB") == 0)
+ {
+ lvalue <<= 30;
+ }
+ else if(strcasecmp(name2, "TB") == 0)
+ {
+ lvalue <<= 40;
+ }
+
+ if(memsize < 0)
+ {
+ memsize = (double) lvalue;
+ }
+ else
+ {
+ if(do_task == DO_MAX)
+ {
+ memsize = MAX(memsize, (double) lvalue);
+ }
+ else if(do_task == DO_MIN)
+ {
+ memsize = MIN(memsize, (double) lvalue);
+ }
+ else
+ {
+ memsize += (double) lvalue;
+ }
+ }
+
+ break;
+ }
+ }
+
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ if(memsize < 0)
+ {
+ /* incorrect process name */
+ memsize = 0;
+ }
+
+ if(do_task == DO_AVG)
+ {
+ memsize /= (double)proccount;
+ }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = memsize;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
}
-int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- /* in this moment this function for this platform unsupported */
+#if defined(HAVE_PROC_1_STATUS)
+
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char procstat[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int stat_ok = 0;
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ FILE *f;
+
+ assert(result);
+
+ clean_result(result);
+
+ int proccount = 0;
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ {
+ procstat[0] = '\0';
+ }
+
+ if(procstat[0] == '\0')
+ {
+ strscpy(procstat, "all");
+ }
+
+ if(strcmp(procstat,"run") == 0)
+ {
+ strscpy(procstat,"R");
+ }
+ else if(strcmp(procstat,"sleep") == 0)
+ {
+ strscpy(procstat,"S");
+ }
+ else if(strcmp(procstat,"zomb") == 0)
+ {
+ strscpy(procstat,"Z");
+ }
+ else if(strcmp(procstat,"all") == 0)
+ {
+ procstat[0] = 0;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ stat_ok = 0;
+ usr_ok = 0;
+
+/* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+/* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(procstat[0] != 0)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%s\n", name1, name2) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"State:") != 0)
+ {
+ continue;
+ }
+
+ if(strcmp(name2, procstat))
+ {
+ stat_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ stat_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && stat_ok && usr_ok)
+ {
+ proccount++;
+ }
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (double) proccount;
+ return SYSINFO_RET_OK;
+#else
return SYSINFO_RET_FAIL;
+#endif
}
-
diff --git a/src/libs/zbxsysinfo/osf/sensors.c b/src/libs/zbxsysinfo/osf/sensors.c
index 32042922..956ca3d1 100644
--- a/src/libs/zbxsysinfo/osf/sensors.c
+++ b/src/libs/zbxsysinfo/osf/sensors.c
@@ -19,125 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -148,6 +35,10 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -173,7 +64,8 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -187,7 +79,7 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP2(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -198,6 +90,10 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -223,7 +119,8 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -237,7 +134,7 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP3(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -248,6 +145,10 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -273,7 +174,8 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -286,3 +188,43 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
closedir(dir);
return SYSINFO_RET_FAIL;
}
+
+int OLD_SENSOR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"temp1") == 0)
+ {
+ ret = SENSOR_TEMP1(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp2") == 0)
+ {
+ ret = SENSOR_TEMP2(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp3") == 0)
+ {
+ ret = SENSOR_TEMP3(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/osf/swap.c b/src/libs/zbxsysinfo/osf/swap.c
index db059f78..3d80fec9 100644
--- a/src/libs/zbxsysinfo/osf/swap.c
+++ b/src/libs/zbxsysinfo/osf/swap.c
@@ -19,124 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
+
/* Solaris. */
#ifndef HAVE_SYSINFO_FREESWAP
#ifdef HAVE_SYS_SWAP_SWAPTABLE
@@ -203,17 +91,22 @@ point them all to the same buffer */
#endif
#endif
-int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_FREESWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.freeswap * (double)info.mem_unit;
+ result->dbl = (double)info.freeswap * (double)info.mem_unit;
#else
- *value=(double)info.freeswap;
+ result->dbl = (double)info.freeswap;
#endif
return SYSINFO_RET_OK;
}
@@ -226,27 +119,41 @@ int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
+ assert(result);
+
+ clean_result(result);
+
get_swapinfo(&swaptotal,&swapfree);
- *value=swapfree;
+ result->type |= AR_DOUBLE;
+ result->dbl = swapfree;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
-int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_TOTALSWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalswap * (double)info.mem_unit;
+ result->dbl = (double)info.totalswap * (double)info.mem_unit;
#else
- *value=(double)info.totalswap;
+ result->dbl = (double)info.totalswap;
#endif
return SYSINFO_RET_OK;
}
@@ -259,12 +166,125 @@ int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
- get_swapinfo(&swaptotal,&swapfree);
+ assert(result);
+
+ clean_result(result);
- *value=(double)swaptotal;
+ get_swapinfo(&swaptotal,&swapfree);
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)swaptotal;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
+
+int SYSTEM_SWAP_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define SWP_FNCLIST struct swp_fnclist_s
+SWP_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ SWP_FNCLIST fl[] =
+ {
+ {"total", SYSTEM_SWAP_FREE},
+ {"free", SYSTEM_SWAP_TOTAL},
+ {0, 0}
+ };
+
+ char swapdev[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(swapdev[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(swapdev, "all");
+ }
+
+ if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "free");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+int OLD_SWAP(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"free") == 0)
+ {
+ ret = SYSTEM_SWAP_FREE(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"total") == 0)
+ {
+ ret = SYSTEM_SWAP_TOTAL(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/osf/uptime.c b/src/libs/zbxsysinfo/osf/uptime.c
index 88eee810..a38b2bd7 100644
--- a/src/libs/zbxsysinfo/osf/uptime.c
+++ b/src/libs/zbxsysinfo/osf/uptime.c
@@ -19,130 +19,22 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_UPTIME
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
- *value=(double)info.uptime;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)info.uptime;
return SYSINFO_RET_OK;
}
else
@@ -155,6 +47,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
struct timeval uptime;
int now;
+ assert(result);
+
+ clean_result(result);
+
mib[0]=CTL_KERN;
mib[1]=KERN_BOOTTIME;
@@ -167,8 +63,8 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
}
now=time(NULL);
-
- *value=(double)(now-uptime.tv_sec);
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)(now-uptime.tv_sec);
return SYSINFO_RET_OK;
#else
/* Solaris */
@@ -180,6 +76,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
long hz;
long secs;
+ assert(result);
+
+ clean_result(result);
+
hz = sysconf(_SC_CLK_TCK);
/* open kstat */
@@ -207,9 +107,14 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
/* close kstat */
kstat_close(kc);
- *value=(double)secs;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)secs;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
diff --git a/src/libs/zbxsysinfo/osx/cpu.c b/src/libs/zbxsysinfo/osx/cpu.c
index f8e94125..4e7e1502 100644
--- a/src/libs/zbxsysinfo/osx/cpu.c
+++ b/src/libs/zbxsysinfo/osx/cpu.c
@@ -19,183 +19,161 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-/* AIX CPU */
-#ifdef HAVE_KNLIST_H
- #include <knlist.h>
-#endif
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_CPU_IDLE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle1]",value,msg,mlen_max);
+ return get_stat("cpu[idle1]", flags, result);
}
-int SYSTEM_CPU_IDLE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle5]",value,msg,mlen_max);
+ return get_stat("cpu[idle5]", flags, result);
}
-int SYSTEM_CPU_IDLE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle15]",value,msg,mlen_max);
+ return get_stat("cpu[idle15]", flags, result);
}
-int SYSTEM_CPU_NICE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice1]",value,msg,mlen_max);
+ return get_stat("cpu[nice1]", flags, result);
}
-int SYSTEM_CPU_NICE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ return get_stat("cpu[nice5]", flags, result);
+}
+static int SYSTEM_CPU_NICE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice5]",value,msg,mlen_max);
+ return get_stat("cpu[nice15]", flags, result);
}
-int SYSTEM_CPU_NICE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+
+static int SYSTEM_CPU_USER1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice15]",value,msg,mlen_max);
+ return get_stat("cpu[user1]", flags, result);
}
-int SYSTEM_CPU_USER1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user1]",value,msg,mlen_max);
+ return get_stat("cpu[user5]", flags, result);
}
-int SYSTEM_CPU_USER5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user5]",value,msg,mlen_max);
+ return get_stat("cpu[user15]", flags, result);
}
-int SYSTEM_CPU_USER15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user15]",value,msg,mlen_max);
+ return get_stat("cpu[system1]", flags, result);
}
-int SYSTEM_CPU_SYS1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system1]",value,msg,mlen_max);
+ return get_stat("cpu[system5]", flags, result);
}
-int SYSTEM_CPU_SYS5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system5]",value,msg,mlen_max);
+ return get_stat("cpu[system15]", flags, result);
}
-int SYSTEM_CPU_SYS15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+int OLD_CPU(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system15]",value,msg,mlen_max);
+ return get_stat(cmd, flags, result);
+}
+
+int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"idle", "avg1" , SYSTEM_CPU_IDLE1},
+ {"idle", "avg5" , SYSTEM_CPU_IDLE5},
+ {"idle", "avg15", SYSTEM_CPU_IDLE15},
+ {"nice", "avg1" , SYSTEM_CPU_NICE1},
+ {"nice", "avg5" , SYSTEM_CPU_NICE5},
+ {"nice", "avg15", SYSTEM_CPU_NICE15},
+ {"user", "avg1" , SYSTEM_CPU_USER1},
+ {"user", "avg5" , SYSTEM_CPU_USER5},
+ {"user", "avg15", SYSTEM_CPU_USER15},
+ {"system", "avg1" , SYSTEM_CPU_SYS1},
+ {"system", "avg5" , SYSTEM_CPU_SYS5},
+ {"system", "avg15", SYSTEM_CPU_SYS15},
+ {0, 0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "user");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+ }
+ return SYSINFO_RET_FAIL;
}
/* AIX CPU info */
@@ -232,14 +210,19 @@ static int getloadavg_kmem(double loadavg[], int nelem)
}
#endif
-int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[0];
return SYSINFO_RET_OK;
}
else
@@ -250,24 +233,33 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_1_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_1_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,1,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,1, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -278,20 +270,29 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return SYSINFO_RET_FAIL;
}
- *value=loadavg[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[0];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -300,14 +301,19 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
#endif
}
-int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[1];
return SYSINFO_RET_OK;
}
else
@@ -318,24 +324,33 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_5_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_5_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,2,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,2, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -346,20 +361,29 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[1];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -368,14 +392,19 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#endif
}
-int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[2];
return SYSINFO_RET_OK;
}
else
@@ -386,24 +415,33 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_15_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_15_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,3,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,3, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -414,20 +452,29 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[2];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -435,3 +482,69 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#endif
#endif
}
+
+int SYSTEM_CPU_LOAD(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"avg1" , SYSTEM_CPU_LOAD1},
+ {"avg5" , SYSTEM_CPU_LOAD5},
+ {"avg15", SYSTEM_CPU_LOAD15},
+ {0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/osx/diskio.c b/src/libs/zbxsysinfo/osx/diskio.c
index 11da801b..23d0c450 100644
--- a/src/libs/zbxsysinfo/osx/diskio.c
+++ b/src/libs/zbxsysinfo/osx/diskio.c
@@ -19,271 +19,358 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int DISKREADOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+
+ return get_stat(key, flags, result);
+}
+
+int VFS_DEV_WRITE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
- return get_stat(key,value,msg,mlen_max);
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKWRITEOPS1},
+ {"ops", "avg5" , DISKWRITEOPS5},
+ {"ops", "avg15", DISKWRITEOPS15},
+ {"bps", "avg1" , DISKWRITEBLKS1},
+ {"bps", "avg5" , DISKWRITEBLKS5},
+ {"bps", "avg15", DISKWRITEBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
}
-int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int VFS_DEV_READ(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKREADOPS1},
+ {"ops", "avg5" , DISKREADOPS5},
+ {"ops", "avg15", DISKREADOPS15},
+ {"bps", "avg1" , DISKREADBLKS1},
+ {"bps", "avg5" , DISKREADBLKS5},
+ {"bps", "avg15", DISKREADBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+static int DISK_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",2,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",2,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",3,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",3,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",4,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",4,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",5,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",5,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",6,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",6,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
+
+int OLD_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"disk_io") == 0)
+ {
+ ret = DISK_IO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rio") == 0)
+ {
+ ret = DISK_RIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wio") == 0)
+ {
+ ret = DISK_WIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rblk") == 0)
+ {
+ ret = DISK_RBLK(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wblk") == 0)
+ {
+ ret = DISK_WBLK(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/osx/diskspace.c b/src/libs/zbxsysinfo/osx/diskspace.c
index b0955ef6..e2120ac6 100644
--- a/src/libs/zbxsysinfo/osx/diskspace.c
+++ b/src/libs/zbxsysinfo/osx/diskspace.c
@@ -19,302 +19,227 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
+#include "common.h"
+#include "sysinfo.h"
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
+int get_fs_size_stat(char *fs, double *total, double *free, double *usage)
+{
+#ifdef HAVE_SYS_STATVFS_H
+ struct statvfs s;
+#else
+ struct statfs s;
#endif
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
+ assert(fs);
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
#endif
+ {
+ return SYSINFO_RET_FAIL;
+ }
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
+#ifdef HAVE_SYS_STATVFS_H
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_frsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bavail * (s.f_frsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bavail) * (s.f_frsize / 1024.0));
+#else
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_bsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bfree * (s.f_bsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0));
+#endif
+ return SYSINFO_RET_OK;
+}
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
+static int VFS_FS_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
+ assert(result);
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
+ clean_result(result);
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
-#include "common.h"
-#include "sysinfo.h"
+ return SYSINFO_RET_OK;
+}
-int VFS_FS_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return s.f_bavail * (s.f_bsize / 1024.0);*/
- *value=s.f_bavail * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_bavail * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- return SYSINFO_RET_FAIL;
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_USED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return (s.f_blocks-s.f_bavail) * (s.f_bsize / 1024.0);*/
- *value=(s.f_blocks-s.f_bavail) * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=blocks_used * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_size_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
- return SYSINFO_RET_FAIL;
-#endif
}
-int VFS_FS_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return s.f_blocks * (s.f_bsize / 1024.0);*/
- *value= s.f_blocks * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_blocks * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- return SYSINFO_RET_FAIL;
-#endif
+ if(get_fs_size_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double used;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_USED(cmd, mountPoint, &used, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
- if(total == 0)
- {
- return SYSINFO_RET_FAIL;
- }
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_size_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
- *value = 100*used/total;
- return SYSINFO_RET_OK;
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+int VFS_FS_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if(SYSINFO_RET_OK != VFS_FS_FREE(cmd, mountPoint, &free, msg, mlen_max))
+ FS_FNCLIST fl[] =
+ {
+ {"free" , VFS_FS_FREE},
+ {"total" , VFS_FS_TOTAL},
+ {"used", VFS_FS_USED},
+ {"pfree" , VFS_FS_PFREE},
+ {"pused" , VFS_FS_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
{
- return SYSINFO_RET_FAIL;
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if(total == 0)
+
+ for(i=0; fl[i].mode!=0; i++)
{
- return SYSINFO_RET_FAIL;
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+
+ return SYSINFO_RET_FAIL;
}
diff --git a/src/libs/zbxsysinfo/osx/inodes.c b/src/libs/zbxsysinfo/osx/inodes.c
index da92ca93..c8109f28 100644
--- a/src/libs/zbxsysinfo/osx/inodes.c
+++ b/src/libs/zbxsysinfo/osx/inodes.c
@@ -19,144 +19,226 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-
-/* FreeBSD/MacOS/OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int VFS_FS_INODE_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int get_fs_inodes_stat(char *fs, double *total, double *free, double *usage)
{
#ifdef HAVE_SYS_STATVFS_H
struct statvfs s;
-
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- *value=s.f_favail;
- return SYSINFO_RET_OK;
#else
struct statfs s;
- long blocks_used;
- long blocks_percent_used;
-
- if ( statfs( (char *)mountPoint, &s) != 0 )
+#endif
+
+ assert(fs);
+
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
+#endif
{
return SYSINFO_RET_FAIL;
}
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_ffree;
- return SYSINFO_RET_OK;
-
- }
- return SYSINFO_RET_FAIL;
+ if(total)
+ (*total) = (double)(s.f_files);
+#ifdef HAVE_SYS_STATVFS_H
+ if(free)
+ (*free) = (double)(s.f_favail);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_favail);
+#else
+ if(free)
+ (*free) = (double)(s.ffree);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_ffree);
#endif
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
return SYSINFO_RET_FAIL;
- }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- *value=s.f_files;
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+}
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_files;
- return SYSINFO_RET_OK;
+static int VFS_FS_INODE_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- }
- return SYSINFO_RET_FAIL;
-#endif
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_inodes_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
+
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_INODE_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+int VFS_FS_INODE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if(SYSINFO_RET_OK != VFS_FS_INODE_FREE(cmd, mountPoint, &free, msg, mlen_max))
+ FS_FNCLIST fl[] =
{
- return SYSINFO_RET_FAIL;
+ {"free" , VFS_FS_INODE_FREE},
+ {"total" , VFS_FS_INODE_TOTAL},
+ {"used", VFS_FS_INODE_USED},
+ {"pfree" , VFS_FS_INODE_PFREE},
+ {"pused" , VFS_FS_INODE_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if(total == 0)
+
+ for(i=0; fl[i].mode!=0; i++)
{
- return SYSINFO_RET_FAIL;
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+
+ return SYSINFO_RET_FAIL;
}
+
diff --git a/src/libs/zbxsysinfo/osx/memory.c b/src/libs/zbxsysinfo/osx/memory.c
index ae4e6b03..7dc0fcbe 100644
--- a/src/libs/zbxsysinfo/osx/memory.c
+++ b/src/libs/zbxsysinfo/osx/memory.c
@@ -19,123 +19,10 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
/* Get CACHED memory in bytes */
@@ -145,8 +32,12 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
FILE *f;
char *t;
char c[MAX_STRING_LEN];
- double result = SYSINFO_RET_FAIL;
+ double res = 0;
+ assert(result);
+
+ clean_result(result);
+
f=fopen("/proc/meminfo","r");
if(NULL == f)
{
@@ -158,30 +49,40 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
{
t=(char *)strtok(c," ");
t=(char *)strtok(NULL," ");
- sscanf(t, "%lf", &result );
+ sscanf(t, "%lf", &res );
break;
}
}
fclose(f);
- *value=result;
+ result->type |= AR_DOUBLE;
+ result->dbl=res;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_BUFFERS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_BUFFERRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.bufferram * (double)info.mem_unit;
+ result->dbl=(double)info.bufferram * (double)info.mem_unit;
#else
- *value=(double)info.bufferram;
+ result->dbl=(double)info.bufferram;
#endif
return SYSINFO_RET_OK;
}
@@ -190,21 +91,30 @@ int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, con
return SYSINFO_RET_FAIL;
}
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_SHARED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_SHAREDRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.sharedram * (double)info.mem_unit;
+ result->dbl=(double)info.sharedram * (double)info.mem_unit;
#else
- *value=(double)info.sharedram;
+ result->dbl=(double)info.sharedram;
#endif
return SYSINFO_RET_OK;
}
@@ -212,36 +122,47 @@ int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_armshr<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_armshr<<2);
return SYSINFO_RET_OK;
#else
return SYSINFO_RET_FAIL;
#endif
-#endif
}
-int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -251,19 +172,24 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
/* Get page size */
page = pst.page_size;
/* Total physical memory in bytes */
- *value=(double)page*pst.physical_memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)page*pst.physical_memory;
return SYSINFO_RET_OK;
}
-#else
-#ifdef HAVE_SYSINFO_TOTALRAM
+#elif defined(HAVE_SYSINFO_TOTALRAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalram * (double)info.mem_unit;
+ result->dbl=(double)info.totalram * (double)info.mem_unit;
#else
- *value=(double)info.totalram;
+ result->dbl=(double)info.totalram;
#endif
return SYSINFO_RET_OK;
}
@@ -271,31 +197,39 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_rm<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_rm<<2);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_SYSCTL_H
+#elif defined(HAVE_SYS_SYSCTL_H)
static int mib[] = { CTL_HW, HW_PHYSMEM };
size_t len;
unsigned int memory;
int ret;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(memory);
if(0==sysctl(mib,2,&memory,&len,NULL,0))
{
- *value=(double)memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)memory;
ret=SYSINFO_RET_OK;
}
else
@@ -304,26 +238,34 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
-#endif
-#endif
-#endif
-#endif
}
-int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
struct pst_dynamic dyn;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -352,20 +294,25 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
*/
/* Free memory in bytes */
- *value=(double)dyn.psd_free * page;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)dyn.psd_free * page;
return SYSINFO_RET_OK;
}
}
-#else
-#ifdef HAVE_SYSINFO_FREERAM
+#elif defined(HAVE_SYSINFO_FREERAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.freeram * (double)info.mem_unit;
+ result->dbl=(double)info.freeram * (double)info.mem_unit;
#else
- *value=(double)info.freeram;
+ result->dbl=(double)info.freeram;
#endif
return SYSINFO_RET_OK;
}
@@ -373,28 +320,35 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_free<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_free<<2);
return SYSINFO_RET_OK;
-#else
/* OS/X */
-#ifdef HAVE_MACH_HOST_INFO_H
+#elif defined(HAVE_MACH_HOST_INFO_H)
vm_statistics_data_t page_info;
vm_size_t pagesize;
mach_msg_type_number_t count;
kern_return_t kret;
int ret;
+ assert(result);
+
+ clean_result(result);
+
pagesize = 0;
kret = host_page_size (mach_host_self(), &pagesize);
@@ -412,7 +366,8 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
pu = pw+pa+pi;
- *value=(double)pf;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)pf;
ret = SYSINFO_RET_OK;
}
else
@@ -421,10 +376,63 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
-#endif
-#endif
-#endif
-#endif
}
+
+int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#define MEM_FNCLIST struct mem_fnclist_s
+MEM_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ MEM_FNCLIST fl[] =
+ {
+ {"free", VM_MEMORY_FREE},
+ {"shared", VM_MEMORY_SHARED},
+ {"total", VM_MEMORY_TOTAL},
+ {"buffers", VM_MEMORY_BUFFERS},
+ {"cached", VM_MEMORY_CACHED},
+ {0, 0}
+ };
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/osx/osx.c b/src/libs/zbxsysinfo/osx/osx.c
index 5a92ba6c..df66bf38 100644
--- a/src/libs/zbxsysinfo/osx/osx.c
+++ b/src/libs/zbxsysinfo/osx/osx.c
@@ -18,255 +18,179 @@
**/
#include "config.h"
+#include "common.h"
#include "sysinfo.h"
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_CPU_IDLE1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_IDLE5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_IDLE15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int VFS_FS_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_USED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_PUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-
-int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int VFS_FILE_ATIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_CKSUM(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_CTIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_MD5SUM(const char *cmd, const char *filename, char **value, const char *msg, int mlen_max);
-int VFS_FILE_MTIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_REGEXP(const char *cmd, const char *filename, char **value, const char *msg, int mlen_max);
-int VFS_FILE_REGMATCH(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_SIZE(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_EXISTS(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-
-int VFS_FS_INODE_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_INODE_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-
-
-int KERNEL_MAXFILES(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int KERNEL_MAXPROC(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int NET_IF_IBYTES1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_IBYTES5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_IBYTES15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int NET_IF_OBYTES1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_OBYTES5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_OBYTES15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int DISKREADOPS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADOPS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADOPS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int AGENT_PING(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int PROC_NUM(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int PROC_MEMORY(const char *cmd, const char *param, double *value, const char *msg, int mlen_max);
-
-
-int PROCCOUNT(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SENSOR_TEMP1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SENSOR_TEMP2(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SENSOR_TEMP3(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int TCP_LISTEN(const char *cmd, const char *porthex,double *value, const char *msg, int mlen_max);
-
-int EXECUTE(const char *cmd, const char *command,double *value, const char *msg, int mlen_max);
-int EXECUTE_STR(const char *cmd, const char *command, const char *parameter, char **value, const char *msg, int mlen_max);
-int AGENT_VERSION(const char *cmd, const char *command,char **value, const char *msg, int mlen_max);
-
-
-int CHECK_SERVICE(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-int CHECK_SERVICE_PERF(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-int CHECK_PORT(const char *cmd, const char *ip_and_port,double *value, const char *msg, int mlen_max);
-int CHECK_DNS(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-
ZBX_METRIC parameters_specific[]=
-/* KEY FUNCTION (if double) FUNCTION (if string) PARAM*/
+/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
/* Outdated */
-
- {"cksum[*]" ,VFS_FILE_CKSUM, 0, "/etc/services"},
- {"cpu[idle1]" ,SYSTEM_CPU_IDLE1, 0, 0},
- {"cpu[idle5]" ,SYSTEM_CPU_IDLE5, 0, 0},
- {"cpu[idle15]" ,SYSTEM_CPU_IDLE15, 0, 0},
- {"cpu[nice1]" ,SYSTEM_CPU_NICE1, 0, 0},
- {"cpu[nice5]" ,SYSTEM_CPU_NICE5, 0, 0},
- {"cpu[nice15]" ,SYSTEM_CPU_NICE15, 0, 0},
- {"cpu[system1]" ,SYSTEM_CPU_SYS1, 0, 0},
- {"cpu[system5]" ,SYSTEM_CPU_SYS5, 0, 0},
- {"cpu[system15]" ,SYSTEM_CPU_SYS15, 0, 0},
- {"cpu[user1]" ,SYSTEM_CPU_USER1, 0, 0},
- {"cpu[user5]" ,SYSTEM_CPU_USER5, 0, 0},
- {"cpu[user15]" ,SYSTEM_CPU_USER15, 0, 0},
- {"diskfree[*]" ,VFS_FS_FREE, 0, "/"},
- {"disktotal[*]" ,VFS_FS_TOTAL, 0, "/"},
- {"diskused[*]" ,VFS_FS_USED, 0, "/"},
- {"diskfree_perc[*]" ,VFS_FS_PFREE, 0, "/"},
- {"diskused_perc[*]" ,VFS_FS_PUSED, 0, "/"},
- {"file[*]" ,VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize[*]" ,VFS_FILE_SIZE, 0, "/etc/passwd"},
- {"inodefree[*]" ,VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal[*]" ,VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc[*]" ,VFS_FS_INODE_PFREE, 0, "/"},
- {"kern[maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kern[maxproc]" ,KERNEL_MAXPROC, 0, 0},
- {"md5sum[*]" ,0, VFS_FILE_MD5SUM, "/etc/services"},
- {"memory[buffers]" ,VM_MEMORY_BUFFERS, 0, 0},
- {"memory[cached]" ,VM_MEMORY_CACHED, 0, 0},
- {"memory[free]" ,VM_MEMORY_FREE, 0, 0},
- {"memory[shared]" ,VM_MEMORY_SHARED, 0, 0},
- {"memory[total]" ,VM_MEMORY_TOTAL, 0, 0},
- {"netloadin1[*]" ,NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5[*]" ,NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15[*]" ,NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1[*]" ,NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5[*]" ,NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15[*]" ,NET_IF_OBYTES15, 0, "lo"},
- {"ping" ,AGENT_PING, 0, 0},
- {"proc_cnt[*]" ,PROC_NUM, 0, "inetd"},
- {"swap[free]" ,SYSTEM_SWAP_FREE, 0, 0},
- {"swap[total]" ,SYSTEM_SWAP_TOTAL, 0, 0},
- {"system[procload]" ,SYSTEM_CPU_LOAD1, 0, 0},
- {"system[procload5]" ,SYSTEM_CPU_LOAD5, 0, 0},
- {"system[procload15]" ,SYSTEM_CPU_LOAD15, 0, 0},
- {"system[hostname]" ,0, EXECUTE_STR, "hostname"},
- {"system[uname]" ,0, EXECUTE_STR, "uname -a"},
- {"system[uptime]" ,SYSTEM_UPTIME, 0, 0},
- {"system[users]" ,EXECUTE, 0,"who|wc -l"},
- {"version[zabbix_agent]", 0, AGENT_VERSION, 0},
+/* incorrect OLD naming */
+ {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
+/*
+ {"cpu[idle1]", 0, 0, 0, 0},
+ {"cpu[idle5]", 0, 0, 0, 0},
+ {"cpu[idle15]", 0, 0, 0, 0},
+ {"cpu[nice1]", 0, 0, 0, 0},
+ {"cpu[nice5]", 0, 0, 0, 0},
+ {"cpu[nice15]", 0, 0, 0, 0},
+ {"cpu[system1]", 0, 0, 0, 0},
+ {"cpu[system5]", 0, 0, 0, 0},
+ {"cpu[system15]", 0, 0, 0, 0},
+ {"cpu[user1]", 0, 0, 0, 0},
+ {"cpu[user5]", 0, 0, 0, 0},
+ {"cpu[user15]", 0, 0, 0, 0},
+*/
+ {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
+/*
+ {"io[disk_io]", 0, 0, 0, 0},
+ {"io[disk_rio]", 0, 0, 0, 0},
+ {"io[disk_wio]", 0, 0, 0, 0},
+ {"io[disk_rblk]", 0, 0, 0, 0},
+ {"io[disk_wblk]", 0, 0, 0, 0},
+*/
+ {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
+/*
+ {"kern[maxfiles]", 0, 0, 0, 0},
+ {"kern[maxproc]", 0, 0, 0, 0},
+*/
+ {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
+/*
+ {"memory[buffers]", 0, 0, 0, 0},
+ {"memory[cached]", 0, 0, 0, 0},
+ {"memory[free]", 0, 0, 0, 0},
+ {"memory[shared]", 0, 0, 0, 0},
+ {"memory[total]", 0, 0, 0, 0},
+*/
+ {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
+/*
+ {"system[proccount]", 0, 0, 0, 0},
+
+ {"system[procload]", 0, 0, 0, 0},
+ {"system[procload5]", 0, 0, 0, 0},
+ {"system[procload15]", 0, 0, 0, 0},
+ {"system[hostname]", 0, 0, 0, 0},
+ {"system[uname]", 0, 0, 0, 0},
+ {"system[uptime]", 0, 0, 0, 0},
+ {"system[users]", 0, 0, 0, 0},
+
+ {"system[procrunning]", 0, 0, 0, 0},
+*/
+ {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
+/*
+ {"sensor[temp1]", 0, 0, 0, 0},
+ {"sensor[temp2]", 0, 0, 0, 0},
+ {"sensor[temp3]", 0, 0, 0, 0},
+*/
+ {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
+/*
+ {"swap[free]", 0, 0, 0, 0},
+ {"swap[total]", 0, 0, 0, 0},
+*/
+ {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
+/*
+ {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
+*/
+/* correct OLD naming */
+/*
+ {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
+*/
+/*
+ {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
+ {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
+ {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
+ {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
+ {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
+*/
+/*
+ {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+*/
+/*
+ {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
+ {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
+ {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
+*/
+/*
+ {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
+*/
+/*
+ {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
+ {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
+ {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
+ {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
+ {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
+ {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
+*/
+/*
+ {"ping", 0, AGENT_PING, 0, 0},
+*/
/* New naming */
-
- {"agent.ping" ,AGENT_PING, 0, 0},
- {"agent.version", 0, AGENT_VERSION, 0},
-
- {"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
-
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
- {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
-
- {"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers" ,VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached" ,VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free" ,VM_MEMORY_FREE, 0, 0},
-
- {"vfs.fs.free[*]" ,VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total[*]" ,VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used[*]" ,VFS_FS_USED, 0, "/"},
-
- {"vfs.fs.pfree[*]" ,VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused[*]" ,VFS_FS_PUSED, 0, "/"},
-
- {"vfs.fs.inode.free[*]" ,VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total[*]",VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree[*]",VFS_FS_INODE_PFREE, 0, "/"},
-
- {"vfs.file.atime[*]" ,VFS_FILE_ATIME, 0, "/etc/passwd"},
- {"vfs.file.cksum[*]" ,VFS_FILE_CKSUM, 0, "/etc/services"},
- {"vfs.file.ctime[*]" ,VFS_FILE_CTIME, 0, "/etc/passwd"},
- {"vfs.file.exists[*]" ,VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"vfs.file.md5sum[*]" ,0, VFS_FILE_MD5SUM, "/etc/services"},
- {"vfs.file.mtime[*]" ,VFS_FILE_MTIME, 0, "/etc/passwd"},
- {"vfs.file.regexp[*]" ,0, VFS_FILE_REGEXP, "/etc/passwd,root"},
- {"vfs.file.regmatch[*]" ,VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
- {"vfs.file.size[*]" ,VFS_FILE_SIZE, 0, "/etc/passwd"},
-
- {"system.cpu.idle1" ,SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5" ,SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15" ,SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1" ,SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5" ,SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15" ,SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1" ,SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5" ,SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15" ,SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1" ,SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5" ,SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15" ,SYSTEM_CPU_USER15, 0, 0},
-
- {"net.if.ibytes1[*]" ,NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5[*]" ,NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15[*]" ,NET_IF_IBYTES15, 0, "lo"},
- {"net.if.obytes1[*]" ,NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5[*]" ,NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15[*]" ,NET_IF_OBYTES15, 0, "lo"},
-
- {"disk_read_ops1[*]" ,DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5[*]" ,DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15[*]" ,DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1[*]" ,DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5[*]" ,DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15[*]" ,DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1[*]" ,DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5[*]" ,DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15[*]" ,DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1[*]" ,DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5[*]" ,DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15[*]" ,DISKWRITEBLKS15, 0, "hda"},
-
- {"sensor[temp1]" ,SENSOR_TEMP1, 0, 0},
- {"sensor[temp2]" ,SENSOR_TEMP2, 0, 0},
- {"sensor[temp3]" ,SENSOR_TEMP3, 0, 0},
-
- {"system.cpu.load1" ,SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5" ,SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15" ,SYSTEM_CPU_LOAD15, 0, 0},
-
- {"system.hostname" ,0, EXECUTE_STR, "hostname"},
-
- {"system.swap.free" ,SYSTEM_SWAP_FREE, 0, 0},
- {"system.swap.total" ,SYSTEM_SWAP_TOTAL, 0, 0},
-
- {"system.uname" ,0, EXECUTE_STR, "uname -a"},
- {"system.uptime" ,SYSTEM_UPTIME, 0, 0},
- {"system.users.num" ,EXECUTE, 0,"who|wc -l"},
+/*
+ {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
+ {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
+ {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
+ {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
+ {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
+ {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
+ {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
+ {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
+ {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
+ {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
+ {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
+ {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
+*/
+/*
+ {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
+ {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
+ {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
+ {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
+ {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
+*/
+/*
+ {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
+ {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
+ {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
+ {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
+ {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
+*/
+/*
+ {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
+ {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
+ {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
+*/
+/*
+ {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
+ {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
+ {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
+
+ {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
+ {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
+ {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
+*/
+/*
+ {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
+ {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
+ {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
+
+ {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
+ {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
+ {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
+
+ {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
+ {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
+ {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
+
+ {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
+ {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
+ {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
+*/
+/*
+ {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
+ {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
+ {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
+*/
/****************************************
All these perameters require more than 1 second to retrieve.
@@ -278,30 +202,66 @@ ZBX_METRIC parameters_specific[]=
{"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
***************************************/
- {"io[disk_io]" ,DISK_IO, 0, 0},
- {"io[disk_rio]" ,DISK_RIO, 0, 0},
- {"io[disk_wio]" ,DISK_WIO, 0, 0},
- {"io[disk_rblk]" ,DISK_RBLK, 0, 0},
- {"io[disk_wblk]" ,DISK_WBLK, 0, 0},
-
-
-
- {"system[proccount]" ,PROCCOUNT, 0, 0},
-
-#ifdef HAVE_PROC_LOADAVG
- {"system[procrunning]" ,EXECUTE, 0, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '"},
-#endif
-
/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-
- {"net[listen_23]" ,TCP_LISTEN, 0, "0017"},
- {"net[listen_80]" ,TCP_LISTEN, 0, "0050"},
-
- {"check_port[*]" ,CHECK_PORT, 0, "80"},
-
- {"check_service[*]" ,CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"dns[*]" ,CHECK_DNS, 0, "127.0.0.1,localhost"},
- {"check_service_perf[*]",CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+/*
+ {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
+ {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
+ {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+*/
+/*
+ {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+*/
+ {"agent.ping", 0, AGENT_PING, 0, 0},
+ {"agent.version", 0, AGENT_VERSION, 0, 0},
+
+ {"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
+ {"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+
+ {"vfs.file.atime", CF_USEUPARAM, VFS_FILE_ATIME, 0, "/etc/passwd"},
+ {"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
+ {"vfs.file.ctime", CF_USEUPARAM, VFS_FILE_CTIME, 0, "/etc/passwd"},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
+ {"vfs.file.mtime", CF_USEUPARAM, VFS_FILE_MTIME, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+
+/************************************
+ * NEW FUNCTIONS *
+ ************************************/
+
+ {"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+
+ {"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
+ {"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
+ {"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+
+ {"net.if.in", CF_USEUPARAM, NET_IF_IN, 0, "lo,bytes"},
+ {"net.if.out", CF_USEUPARAM, NET_IF_OUT, 0, "lo,bytes"},
+
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
+
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
+
+ {"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
+
+ {"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
+ {"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+
+ {"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
+
+ {"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
+
+ {"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
+
+ {"system.hostname", 0, SYSTEM_HOSTNAME, 0, 0},
+
+ {"system.uname", 0, SYSTEM_UNAME, 0, 0},
+ {"system.uptime", 0, SYSTEM_UPTIME, 0, 0},
+ {"system.users.num", 0, SYSTEM_UNUM, 0, 0},
{0}
};
diff --git a/src/libs/zbxsysinfo/osx/proc.c b/src/libs/zbxsysinfo/osx/proc.c
index 7f5c596b..d80dac13 100644
--- a/src/libs/zbxsysinfo/osx/proc.c
+++ b/src/libs/zbxsysinfo/osx/proc.c
@@ -19,32 +19,485 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
#include "common.h"
#include "sysinfo.h"
-/*
-#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
-#define SDI(m) FDI("%s", m) // string info
-#define IDI(i) FDI("%i", i) // integer info
-*/
-int PROC_MEMORY(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+#define DO_SUM 0
+#define DO_MAX 1
+#define DO_MIN 2
+#define DO_AVG 3
+
+int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- /* in this moment this function for this platform unsupported */
- return SYSINFO_RET_FAIL;
+#if defined(HAVE_PROC_1_STATUS)
+
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int do_task = DO_SUM;
+
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ FILE *f;
+
+ double memsize = -1;
+ int proccount = 0;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ strscpy(mode, "sum");
+ }
+
+ if(strcmp(mode,"avg") == 0)
+ {
+ do_task = DO_AVG;
+ }
+ else if(strcmp(mode,"max") == 0)
+ {
+ do_task = DO_MAX;
+ }
+ else if(strcmp(mode,"min") == 0)
+ {
+ do_task = DO_MIN;
+ }
+ else if(strcmp(mode,"sum") == 0)
+ {
+ do_task = DO_SUM;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ usr_ok = 0;
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ /* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+ /* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && usr_ok)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li %s\n", name1, &lvalue, name2) != 3)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"VmSize:") != 0)
+ {
+ continue;
+ }
+
+ proccount++;
+
+ if(strcasecmp(name2, "kB") == 0)
+ {
+ lvalue <<= 10;
+ }
+ else if(strcasecmp(name2, "mB") == 0)
+ {
+ lvalue <<= 20;
+ }
+ else if(strcasecmp(name2, "GB") == 0)
+ {
+ lvalue <<= 30;
+ }
+ else if(strcasecmp(name2, "TB") == 0)
+ {
+ lvalue <<= 40;
+ }
+
+ if(memsize < 0)
+ {
+ memsize = (double) lvalue;
+ }
+ else
+ {
+ if(do_task == DO_MAX)
+ {
+ memsize = MAX(memsize, (double) lvalue);
+ }
+ else if(do_task == DO_MIN)
+ {
+ memsize = MIN(memsize, (double) lvalue);
+ }
+ else
+ {
+ memsize += (double) lvalue;
+ }
+ }
+
+ break;
+ }
+ }
+
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ if(memsize < 0)
+ {
+ /* incorrect process name */
+ memsize = 0;
+ }
+
+ if(do_task == DO_AVG)
+ {
+ memsize /= (double)proccount;
+ }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = memsize;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
}
-int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- /* in this moment this function for this platform unsupported */
+#if defined(HAVE_PROC_1_STATUS)
+
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char procstat[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int stat_ok = 0;
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ FILE *f;
+
+ assert(result);
+
+ clean_result(result);
+
+ int proccount = 0;
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ {
+ procstat[0] = '\0';
+ }
+
+ if(procstat[0] == '\0')
+ {
+ strscpy(procstat, "all");
+ }
+
+ if(strcmp(procstat,"run") == 0)
+ {
+ strscpy(procstat,"R");
+ }
+ else if(strcmp(procstat,"sleep") == 0)
+ {
+ strscpy(procstat,"S");
+ }
+ else if(strcmp(procstat,"zomb") == 0)
+ {
+ strscpy(procstat,"Z");
+ }
+ else if(strcmp(procstat,"all") == 0)
+ {
+ procstat[0] = 0;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ stat_ok = 0;
+ usr_ok = 0;
+
+/* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+/* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(procstat[0] != 0)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%s\n", name1, name2) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"State:") != 0)
+ {
+ continue;
+ }
+
+ if(strcmp(name2, procstat))
+ {
+ stat_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ stat_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && stat_ok && usr_ok)
+ {
+ proccount++;
+ }
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (double) proccount;
+ return SYSINFO_RET_OK;
+#else
return SYSINFO_RET_FAIL;
+#endif
}
-
diff --git a/src/libs/zbxsysinfo/osx/sensors.c b/src/libs/zbxsysinfo/osx/sensors.c
index 32042922..956ca3d1 100644
--- a/src/libs/zbxsysinfo/osx/sensors.c
+++ b/src/libs/zbxsysinfo/osx/sensors.c
@@ -19,125 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -148,6 +35,10 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -173,7 +64,8 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -187,7 +79,7 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP2(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -198,6 +90,10 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -223,7 +119,8 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -237,7 +134,7 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP3(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -248,6 +145,10 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -273,7 +174,8 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -286,3 +188,43 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
closedir(dir);
return SYSINFO_RET_FAIL;
}
+
+int OLD_SENSOR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"temp1") == 0)
+ {
+ ret = SENSOR_TEMP1(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp2") == 0)
+ {
+ ret = SENSOR_TEMP2(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp3") == 0)
+ {
+ ret = SENSOR_TEMP3(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/osx/swap.c b/src/libs/zbxsysinfo/osx/swap.c
index db059f78..3d80fec9 100644
--- a/src/libs/zbxsysinfo/osx/swap.c
+++ b/src/libs/zbxsysinfo/osx/swap.c
@@ -19,124 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
+
/* Solaris. */
#ifndef HAVE_SYSINFO_FREESWAP
#ifdef HAVE_SYS_SWAP_SWAPTABLE
@@ -203,17 +91,22 @@ point them all to the same buffer */
#endif
#endif
-int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_FREESWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.freeswap * (double)info.mem_unit;
+ result->dbl = (double)info.freeswap * (double)info.mem_unit;
#else
- *value=(double)info.freeswap;
+ result->dbl = (double)info.freeswap;
#endif
return SYSINFO_RET_OK;
}
@@ -226,27 +119,41 @@ int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
+ assert(result);
+
+ clean_result(result);
+
get_swapinfo(&swaptotal,&swapfree);
- *value=swapfree;
+ result->type |= AR_DOUBLE;
+ result->dbl = swapfree;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
-int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_TOTALSWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalswap * (double)info.mem_unit;
+ result->dbl = (double)info.totalswap * (double)info.mem_unit;
#else
- *value=(double)info.totalswap;
+ result->dbl = (double)info.totalswap;
#endif
return SYSINFO_RET_OK;
}
@@ -259,12 +166,125 @@ int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
- get_swapinfo(&swaptotal,&swapfree);
+ assert(result);
+
+ clean_result(result);
- *value=(double)swaptotal;
+ get_swapinfo(&swaptotal,&swapfree);
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)swaptotal;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
+
+int SYSTEM_SWAP_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define SWP_FNCLIST struct swp_fnclist_s
+SWP_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ SWP_FNCLIST fl[] =
+ {
+ {"total", SYSTEM_SWAP_FREE},
+ {"free", SYSTEM_SWAP_TOTAL},
+ {0, 0}
+ };
+
+ char swapdev[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(swapdev[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(swapdev, "all");
+ }
+
+ if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "free");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+int OLD_SWAP(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"free") == 0)
+ {
+ ret = SYSTEM_SWAP_FREE(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"total") == 0)
+ {
+ ret = SYSTEM_SWAP_TOTAL(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/osx/uptime.c b/src/libs/zbxsysinfo/osx/uptime.c
index 88eee810..a38b2bd7 100644
--- a/src/libs/zbxsysinfo/osx/uptime.c
+++ b/src/libs/zbxsysinfo/osx/uptime.c
@@ -19,130 +19,22 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_UPTIME
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
- *value=(double)info.uptime;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)info.uptime;
return SYSINFO_RET_OK;
}
else
@@ -155,6 +47,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
struct timeval uptime;
int now;
+ assert(result);
+
+ clean_result(result);
+
mib[0]=CTL_KERN;
mib[1]=KERN_BOOTTIME;
@@ -167,8 +63,8 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
}
now=time(NULL);
-
- *value=(double)(now-uptime.tv_sec);
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)(now-uptime.tv_sec);
return SYSINFO_RET_OK;
#else
/* Solaris */
@@ -180,6 +76,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
long hz;
long secs;
+ assert(result);
+
+ clean_result(result);
+
hz = sysconf(_SC_CLK_TCK);
/* open kstat */
@@ -207,9 +107,14 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
/* close kstat */
kstat_close(kc);
- *value=(double)secs;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)secs;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
diff --git a/src/libs/zbxsysinfo/solaris/net.c b/src/libs/zbxsysinfo/solaris/net.c
index fccea695..ca9dff08 100644
--- a/src/libs/zbxsysinfo/solaris/net.c
+++ b/src/libs/zbxsysinfo/solaris/net.c
@@ -252,7 +252,7 @@ static int NET_IF_OUT_ERRORS(const char *cmd, const char *param, unsigned flags,
return ret;
}
-int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+static int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
kstat_named_t kn;
char interface[MAX_STRING_LEN];
@@ -283,7 +283,7 @@ int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_
return ret;
}
-int NET_TCP_LISTEN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+static int NET_TCP_LISTEN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char command[MAX_STRING_LEN];
@@ -298,7 +298,7 @@ int NET_TCP_LISTEN(const char *cmd, const char *param, unsigned flags, AGENT_RES
return EXECUTE(NULL, command, flags, result);
}
-int NET_IF_IN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+static int NET_IF_IN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#define NET_FNCLIST struct net_fnclist_s
diff --git a/src/libs/zbxsysinfo/unknown/cpu.c b/src/libs/zbxsysinfo/unknown/cpu.c
index f8e94125..4e7e1502 100644
--- a/src/libs/zbxsysinfo/unknown/cpu.c
+++ b/src/libs/zbxsysinfo/unknown/cpu.c
@@ -19,183 +19,161 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-/* AIX CPU */
-#ifdef HAVE_KNLIST_H
- #include <knlist.h>
-#endif
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_CPU_IDLE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle1]",value,msg,mlen_max);
+ return get_stat("cpu[idle1]", flags, result);
}
-int SYSTEM_CPU_IDLE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle5]",value,msg,mlen_max);
+ return get_stat("cpu[idle5]", flags, result);
}
-int SYSTEM_CPU_IDLE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_IDLE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[idle15]",value,msg,mlen_max);
+ return get_stat("cpu[idle15]", flags, result);
}
-int SYSTEM_CPU_NICE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice1]",value,msg,mlen_max);
+ return get_stat("cpu[nice1]", flags, result);
}
-int SYSTEM_CPU_NICE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_NICE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ return get_stat("cpu[nice5]", flags, result);
+}
+static int SYSTEM_CPU_NICE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice5]",value,msg,mlen_max);
+ return get_stat("cpu[nice15]", flags, result);
}
-int SYSTEM_CPU_NICE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+
+static int SYSTEM_CPU_USER1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice15]",value,msg,mlen_max);
+ return get_stat("cpu[user1]", flags, result);
}
-int SYSTEM_CPU_USER1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user1]",value,msg,mlen_max);
+ return get_stat("cpu[user5]", flags, result);
}
-int SYSTEM_CPU_USER5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user5]",value,msg,mlen_max);
+ return get_stat("cpu[user15]", flags, result);
}
-int SYSTEM_CPU_USER15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user15]",value,msg,mlen_max);
+ return get_stat("cpu[system1]", flags, result);
}
-int SYSTEM_CPU_SYS1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system1]",value,msg,mlen_max);
+ return get_stat("cpu[system5]", flags, result);
}
-int SYSTEM_CPU_SYS5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system5]",value,msg,mlen_max);
+ return get_stat("cpu[system15]", flags, result);
}
-int SYSTEM_CPU_SYS15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+int OLD_CPU(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system15]",value,msg,mlen_max);
+ return get_stat(cmd, flags, result);
+}
+
+int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"idle", "avg1" , SYSTEM_CPU_IDLE1},
+ {"idle", "avg5" , SYSTEM_CPU_IDLE5},
+ {"idle", "avg15", SYSTEM_CPU_IDLE15},
+ {"nice", "avg1" , SYSTEM_CPU_NICE1},
+ {"nice", "avg5" , SYSTEM_CPU_NICE5},
+ {"nice", "avg15", SYSTEM_CPU_NICE15},
+ {"user", "avg1" , SYSTEM_CPU_USER1},
+ {"user", "avg5" , SYSTEM_CPU_USER5},
+ {"user", "avg15", SYSTEM_CPU_USER15},
+ {"system", "avg1" , SYSTEM_CPU_SYS1},
+ {"system", "avg5" , SYSTEM_CPU_SYS5},
+ {"system", "avg15", SYSTEM_CPU_SYS15},
+ {0, 0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "user");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+ }
+ return SYSINFO_RET_FAIL;
}
/* AIX CPU info */
@@ -232,14 +210,19 @@ static int getloadavg_kmem(double loadavg[], int nelem)
}
#endif
-int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[0];
return SYSINFO_RET_OK;
}
else
@@ -250,24 +233,33 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_1_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_1_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,1,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,1, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -278,20 +270,29 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return SYSINFO_RET_FAIL;
}
- *value=loadavg[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[0];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -300,14 +301,19 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons
#endif
}
-int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[1];
return SYSINFO_RET_OK;
}
else
@@ -318,24 +324,33 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_5_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_5_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,2,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,2, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -346,20 +361,29 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[1];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -368,14 +392,19 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons
#endif
}
-int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_GETLOADAVG
double load[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[2];
return SYSINFO_RET_OK;
}
else
@@ -386,24 +415,33 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_PSTAT_H
struct pst_dynamic dyn;
+ assert(result);
+
+ clean_result(result);
+
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
return SYSINFO_RET_FAIL;
}
else
{
- *value=(double)dyn.psd_avg_15_min;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)dyn.psd_avg_15_min;
return SYSINFO_RET_OK;
}
#else
#ifdef HAVE_PROC_LOADAVG
- return getPROC("/proc/loadavg",1,3,value,msg,mlen_max);
+ return getPROC("/proc/loadavg",1,3, flags, result);
#else
#ifdef HAVE_KSTAT_H
static kstat_ctl_t *kc = NULL;
kstat_t *ks;
kstat_named_t *kn;
+ assert(result);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -414,20 +452,29 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
{
return SYSINFO_RET_FAIL;
}
- *value=(double)kn->value.ul/256.0;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)kn->value.ul/256.0;
return SYSINFO_RET_OK;
#else
#ifdef HAVE_KNLIST_H
double loadavg[3];
+ assert(result);
+
+ clean_result(result);
+
if(getloadavg_kmem(loadavg,3) == FAIL)
{
return STSINFO_RET_FAIL;
}
- *value=loadavg[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = loadavg[2];
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -435,3 +482,69 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#endif
#endif
}
+
+int SYSTEM_CPU_LOAD(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"avg1" , SYSTEM_CPU_LOAD1},
+ {"avg5" , SYSTEM_CPU_LOAD5},
+ {"avg15", SYSTEM_CPU_LOAD15},
+ {0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/unknown/diskio.c b/src/libs/zbxsysinfo/unknown/diskio.c
index 11da801b..23d0c450 100644
--- a/src/libs/zbxsysinfo/unknown/diskio.c
+++ b/src/libs/zbxsysinfo/unknown/diskio.c
@@ -19,271 +19,358 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int DISKREADOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKREADBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
- return get_stat(key,value,msg,mlen_max);
+ return get_stat(key, flags, result);
}
-int DISKWRITEBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max)
+static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",device);
+ snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+
+ return get_stat(key, flags, result);
+}
+
+int VFS_DEV_WRITE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
- return get_stat(key,value,msg,mlen_max);
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKWRITEOPS1},
+ {"ops", "avg5" , DISKWRITEOPS5},
+ {"ops", "avg15", DISKWRITEOPS15},
+ {"bps", "avg1" , DISKWRITEBLKS1},
+ {"bps", "avg5" , DISKWRITEBLKS5},
+ {"bps", "avg15", DISKWRITEBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
}
-int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int VFS_DEV_READ(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define DEV_FNCLIST struct dev_fnclist_s
+DEV_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ DEV_FNCLIST fl[] =
+ {
+ {"ops", "avg1" , DISKREADOPS1},
+ {"ops", "avg5" , DISKREADOPS5},
+ {"ops", "avg15", DISKREADOPS15},
+ {"bps", "avg1" , DISKREADBLKS1},
+ {"bps", "avg5" , DISKREADBLKS5},
+ {"bps", "avg15", DISKREADBLKS15},
+ {0, 0, 0}
+ };
+
+ char devname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(type, "bps");
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+
+ for(i=0; fl[i].type!=0; i++)
+ {
+ if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, devname, flags, result);
+ }
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+static int DISK_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",2,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",2,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",3,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",3,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",4,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",4,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_RBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",5,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",5,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
-int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int DISK_WBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- return getPROC("/proc/stat",6,2,value,msg,mlen_max);
+ return getPROC("/proc/stat",6,2, flags, result);
#else
return SYSINFO_RET_FAIL;
#endif
}
+
+int OLD_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"disk_io") == 0)
+ {
+ ret = DISK_IO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rio") == 0)
+ {
+ ret = DISK_RIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wio") == 0)
+ {
+ ret = DISK_WIO(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_rblk") == 0)
+ {
+ ret = DISK_RBLK(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"disk_wblk") == 0)
+ {
+ ret = DISK_WBLK(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/unknown/diskspace.c b/src/libs/zbxsysinfo/unknown/diskspace.c
index b0955ef6..e2120ac6 100644
--- a/src/libs/zbxsysinfo/unknown/diskspace.c
+++ b/src/libs/zbxsysinfo/unknown/diskspace.c
@@ -19,302 +19,227 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
+#include "common.h"
+#include "sysinfo.h"
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
+int get_fs_size_stat(char *fs, double *total, double *free, double *usage)
+{
+#ifdef HAVE_SYS_STATVFS_H
+ struct statvfs s;
+#else
+ struct statfs s;
#endif
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
+ assert(fs);
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
#endif
+ {
+ return SYSINFO_RET_FAIL;
+ }
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
+#ifdef HAVE_SYS_STATVFS_H
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_frsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bavail * (s.f_frsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bavail) * (s.f_frsize / 1024.0));
+#else
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_bsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bfree * (s.f_bsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0));
+#endif
+ return SYSINFO_RET_OK;
+}
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
+static int VFS_FS_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
+ assert(result);
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
+ clean_result(result);
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
-#include "common.h"
-#include "sysinfo.h"
+ return SYSINFO_RET_OK;
+}
-int VFS_FS_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return s.f_bavail * (s.f_bsize / 1024.0);*/
- *value=s.f_bavail * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_bavail * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- return SYSINFO_RET_FAIL;
-#endif
+ if(get_fs_size_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_USED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return (s.f_blocks-s.f_bavail) * (s.f_bsize / 1024.0);*/
- *value=(s.f_blocks-s.f_bavail) * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=blocks_used * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_size_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
- return SYSINFO_RET_FAIL;
-#endif
}
-int VFS_FS_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
-/* return s.f_blocks * (s.f_bsize / 1024.0);*/
- *value= s.f_blocks * (s.f_frsize / 1024.0);
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+ clean_result(result);
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_blocks * (s.f_bsize / 1024.0);
- return SYSINFO_RET_OK;
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- }
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
- return SYSINFO_RET_FAIL;
-#endif
+ if(get_fs_size_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double used;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_USED(cmd, mountPoint, &used, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
- if(total == 0)
- {
- return SYSINFO_RET_FAIL;
- }
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_size_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
- *value = 100*used/total;
- return SYSINFO_RET_OK;
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+int VFS_FS_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if(SYSINFO_RET_OK != VFS_FS_FREE(cmd, mountPoint, &free, msg, mlen_max))
+ FS_FNCLIST fl[] =
+ {
+ {"free" , VFS_FS_FREE},
+ {"total" , VFS_FS_TOTAL},
+ {"used", VFS_FS_USED},
+ {"pfree" , VFS_FS_PFREE},
+ {"pused" , VFS_FS_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
{
- return SYSINFO_RET_FAIL;
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if(total == 0)
+
+ for(i=0; fl[i].mode!=0; i++)
{
- return SYSINFO_RET_FAIL;
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+
+ return SYSINFO_RET_FAIL;
}
diff --git a/src/libs/zbxsysinfo/unknown/inodes.c b/src/libs/zbxsysinfo/unknown/inodes.c
index da92ca93..c8109f28 100644
--- a/src/libs/zbxsysinfo/unknown/inodes.c
+++ b/src/libs/zbxsysinfo/unknown/inodes.c
@@ -19,144 +19,226 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-
-/* FreeBSD/MacOS/OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int VFS_FS_INODE_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int get_fs_inodes_stat(char *fs, double *total, double *free, double *usage)
{
#ifdef HAVE_SYS_STATVFS_H
struct statvfs s;
-
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- *value=s.f_favail;
- return SYSINFO_RET_OK;
#else
struct statfs s;
- long blocks_used;
- long blocks_percent_used;
-
- if ( statfs( (char *)mountPoint, &s) != 0 )
+#endif
+
+ assert(fs);
+
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
+#endif
{
return SYSINFO_RET_FAIL;
}
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_ffree;
- return SYSINFO_RET_OK;
-
- }
- return SYSINFO_RET_FAIL;
+ if(total)
+ (*total) = (double)(s.f_files);
+#ifdef HAVE_SYS_STATVFS_H
+ if(free)
+ (*free) = (double)(s.f_favail);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_favail);
+#else
+ if(free)
+ (*free) = (double)(s.ffree);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_ffree);
#endif
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
return SYSINFO_RET_FAIL;
- }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- *value=s.f_files;
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
+}
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_files;
- return SYSINFO_RET_OK;
+static int VFS_FS_INODE_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
+
+ assert(result);
- }
- return SYSINFO_RET_FAIL;
-#endif
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_fs_inodes_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max)
+static int VFS_FS_INODE_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- double total;
- double free;
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
+
+ assert(result);
- if(SYSINFO_RET_OK != VFS_FS_INODE_TOTAL(cmd, mountPoint, &total, msg, mlen_max))
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+static int VFS_FS_INODE_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
+ return SYSINFO_RET_OK;
+}
+
+int VFS_FS_INODE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define FS_FNCLIST struct fs_fnclist_s
+FS_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
- if(SYSINFO_RET_OK != VFS_FS_INODE_FREE(cmd, mountPoint, &free, msg, mlen_max))
+ FS_FNCLIST fl[] =
{
- return SYSINFO_RET_FAIL;
+ {"free" , VFS_FS_INODE_FREE},
+ {"total" , VFS_FS_INODE_TOTAL},
+ {"used", VFS_FS_INODE_USED},
+ {"pfree" , VFS_FS_INODE_PFREE},
+ {"pused" , VFS_FS_INODE_PUSED},
+ {0, 0}
+ };
+
+ char fsname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
}
-
- if(total == 0)
+
+ for(i=0; fl[i].mode!=0; i++)
{
- return SYSINFO_RET_FAIL;
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, fsname, flags, result);
+ }
}
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
+
+ return SYSINFO_RET_FAIL;
}
+
diff --git a/src/libs/zbxsysinfo/unknown/memory.c b/src/libs/zbxsysinfo/unknown/memory.c
index ae4e6b03..7dc0fcbe 100644
--- a/src/libs/zbxsysinfo/unknown/memory.c
+++ b/src/libs/zbxsysinfo/unknown/memory.c
@@ -19,123 +19,10 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
/* Get CACHED memory in bytes */
@@ -145,8 +32,12 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
FILE *f;
char *t;
char c[MAX_STRING_LEN];
- double result = SYSINFO_RET_FAIL;
+ double res = 0;
+ assert(result);
+
+ clean_result(result);
+
f=fopen("/proc/meminfo","r");
if(NULL == f)
{
@@ -158,30 +49,40 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
{
t=(char *)strtok(c," ");
t=(char *)strtok(NULL," ");
- sscanf(t, "%lf", &result );
+ sscanf(t, "%lf", &res );
break;
}
}
fclose(f);
- *value=result;
+ result->type |= AR_DOUBLE;
+ result->dbl=res;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_BUFFERS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_BUFFERRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.bufferram * (double)info.mem_unit;
+ result->dbl=(double)info.bufferram * (double)info.mem_unit;
#else
- *value=(double)info.bufferram;
+ result->dbl=(double)info.bufferram;
#endif
return SYSINFO_RET_OK;
}
@@ -190,21 +91,30 @@ int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, con
return SYSINFO_RET_FAIL;
}
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_SHARED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_SHAREDRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.sharedram * (double)info.mem_unit;
+ result->dbl=(double)info.sharedram * (double)info.mem_unit;
#else
- *value=(double)info.sharedram;
+ result->dbl=(double)info.sharedram;
#endif
return SYSINFO_RET_OK;
}
@@ -212,36 +122,47 @@ int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_armshr<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_armshr<<2);
return SYSINFO_RET_OK;
#else
return SYSINFO_RET_FAIL;
#endif
-#endif
}
-int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -251,19 +172,24 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
/* Get page size */
page = pst.page_size;
/* Total physical memory in bytes */
- *value=(double)page*pst.physical_memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)page*pst.physical_memory;
return SYSINFO_RET_OK;
}
-#else
-#ifdef HAVE_SYSINFO_TOTALRAM
+#elif defined(HAVE_SYSINFO_TOTALRAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalram * (double)info.mem_unit;
+ result->dbl=(double)info.totalram * (double)info.mem_unit;
#else
- *value=(double)info.totalram;
+ result->dbl=(double)info.totalram;
#endif
return SYSINFO_RET_OK;
}
@@ -271,31 +197,39 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_rm<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_rm<<2);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_SYSCTL_H
+#elif defined(HAVE_SYS_SYSCTL_H)
static int mib[] = { CTL_HW, HW_PHYSMEM };
size_t len;
unsigned int memory;
int ret;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(memory);
if(0==sysctl(mib,2,&memory,&len,NULL,0))
{
- *value=(double)memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)memory;
ret=SYSINFO_RET_OK;
}
else
@@ -304,26 +238,34 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
-#endif
-#endif
-#endif
-#endif
}
-int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
struct pst_dynamic dyn;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -352,20 +294,25 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
*/
/* Free memory in bytes */
- *value=(double)dyn.psd_free * page;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)dyn.psd_free * page;
return SYSINFO_RET_OK;
}
}
-#else
-#ifdef HAVE_SYSINFO_FREERAM
+#elif defined(HAVE_SYSINFO_FREERAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.freeram * (double)info.mem_unit;
+ result->dbl=(double)info.freeram * (double)info.mem_unit;
#else
- *value=(double)info.freeram;
+ result->dbl=(double)info.freeram;
#endif
return SYSINFO_RET_OK;
}
@@ -373,28 +320,35 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
mib[1]=VM_METER;
sysctl(mib,2,&v,&len,NULL,0);
- *value=(double)(v.t_free<<2);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_free<<2);
return SYSINFO_RET_OK;
-#else
/* OS/X */
-#ifdef HAVE_MACH_HOST_INFO_H
+#elif defined(HAVE_MACH_HOST_INFO_H)
vm_statistics_data_t page_info;
vm_size_t pagesize;
mach_msg_type_number_t count;
kern_return_t kret;
int ret;
+ assert(result);
+
+ clean_result(result);
+
pagesize = 0;
kret = host_page_size (mach_host_self(), &pagesize);
@@ -412,7 +366,8 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
pu = pw+pa+pi;
- *value=(double)pf;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)pf;
ret = SYSINFO_RET_OK;
}
else
@@ -421,10 +376,63 @@ int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
-#endif
-#endif
-#endif
-#endif
}
+
+int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#define MEM_FNCLIST struct mem_fnclist_s
+MEM_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ MEM_FNCLIST fl[] =
+ {
+ {"free", VM_MEMORY_FREE},
+ {"shared", VM_MEMORY_SHARED},
+ {"total", VM_MEMORY_TOTAL},
+ {"buffers", VM_MEMORY_BUFFERS},
+ {"cached", VM_MEMORY_CACHED},
+ {0, 0}
+ };
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/unknown/proc.c b/src/libs/zbxsysinfo/unknown/proc.c
index 4d7cfe5d..d80dac13 100644
--- a/src/libs/zbxsysinfo/unknown/proc.c
+++ b/src/libs/zbxsysinfo/unknown/proc.c
@@ -19,172 +19,57 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#ifdef HAVE_PWD_H
-# include <pwd.h>
-#endif
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-
-#ifdef HAVE_SYS_PROC_H
-# include <sys/proc.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
+#include "common.h"
+#include "sysinfo.h"
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
+#define DO_SUM 0
+#define DO_MAX 1
+#define DO_MIN 2
+#define DO_AVG 3
+
+int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#if defined(HAVE_PROC_1_STATUS)
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int do_task = DO_SUM;
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-#include "common.h"
-#include "sysinfo.h"
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
-/*
-#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
-#define SDI(m) FDI("%s", m) // string info
-#define IDI(i) FDI("%i", i) // integer info
-*/
-int PROC_MEMORY(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
-{
- /* in this moment this function for this platform unsupported */
- return SYSINFO_RET_FAIL;
-}
+ FILE *f;
-int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
-{
-#if defined(HAVE_PROC_0_PSINFO)
- DIR *dir;
- struct dirent *entries;
- struct stat buf;
-
- char filename[MAX_STRING_LEN];
- char procname[MAX_STRING_LEN];
-
- int proc_ok = 0;
- int usr_ok = 0;
- int stat_ok = 0;
+ double memsize = -1;
+ int proccount = 0;
- char pr_state = 0;
-
- int fd;
-/* In the correct procfs.h, the structure name is psinfo_t */
- psinfo_t psinfo;
+ assert(result);
- int proccount=0;
-
+ clean_result(result);
+
if(num_param(param) > 3)
{
- return SYSINFO_RET_FAIL;
+ return SYSINFO_RET_FAIL;
}
-
+
if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
{
- return SYSINFO_RET_FAIL;
- }
+ return SYSINFO_RET_FAIL;
+ }
if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
{
@@ -192,130 +77,216 @@ int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg,
}
else
{
- if(usrname[0] != 0)
- {
- usrinfo = getpwnam(usrname);
- if(usrinfo == NULL)
- {
- /* incorrect user name */
- return SYSINFO_RET_FAIL;
- }
- }
- }
-
- if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ if(usrname[0] != 0)
{
- strscpy(procstat,"all");
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
}
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ strscpy(mode, "sum");
+ }
- if(strcmp(procstat,"run") == 0)
- {
- /* running */
- pr_state = SRUN;
- }
- else if(strcmp(procstat,"sleep") == 0)
- {
- /* awaiting an event */
- pr_state = SSLEEP;
- }
- else if(strcmp(procstat,"zomb") == 0)
- {
- pr_state = SZOMB;
- }
- else if(strcmp(procstat,"all") == 0)
- {
- procstat[0] = 0;
- }
- else
- {
+ if(strcmp(mode,"avg") == 0)
+ {
+ do_task = DO_AVG;
+ }
+ else if(strcmp(mode,"max") == 0)
+ {
+ do_task = DO_MAX;
+ }
+ else if(strcmp(mode,"min") == 0)
+ {
+ do_task = DO_MIN;
+ }
+ else if(strcmp(mode,"sum") == 0)
+ {
+ do_task = DO_SUM;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
return SYSINFO_RET_FAIL;
- }
-
- dir=opendir("/proc");
- if(NULL == dir)
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ usr_ok = 0;
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ /* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+ /* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
{
- return SYSINFO_RET_FAIL;
+ continue;
}
- while((entries=readdir(dir))!=NULL)
+ if(stat(filename,&buf)==0)
{
- proc_ok = 0;
- usr_ok = 0;
- stat_ok = 0;
-
- strscpy(filename,"/proc/");
- strncat(filename,entries->d_name,MAX_STRING_LEN);
- strncat(filename,"/psinfo",MAX_STRING_LEN);
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
- if(stat(filename,&buf)==0)
+ if(procname[0] != 0)
{
- fd = open (filename, O_RDONLY);
- if (fd != -1)
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
{
- if(read(fd, &psinfo, sizeof(psinfo)) == -1)
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && usr_ok)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li %s\n", name1, &lvalue, name2) != 3)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"VmSize:") != 0)
+ {
+ continue;
+ }
+
+ proccount++;
+
+ if(strcasecmp(name2, "kB") == 0)
+ {
+ lvalue <<= 10;
+ }
+ else if(strcasecmp(name2, "mB") == 0)
+ {
+ lvalue <<= 20;
+ }
+ else if(strcasecmp(name2, "GB") == 0)
+ {
+ lvalue <<= 30;
+ }
+ else if(strcasecmp(name2, "TB") == 0)
{
- close(fd);
- closedir(dir);
- return SYSINFO_RET_FAIL;
+ lvalue <<= 40;
+ }
+
+ if(memsize < 0)
+ {
+ memsize = (double) lvalue;
}
else
{
- if(procname[0] != 0)
+ if(do_task == DO_MAX)
{
- if(strcmp(procname, psinfo.pr_fname) == 0)
- {
- proc_ok = 1;
- }
+ memsize = MAX(memsize, (double) lvalue);
}
- else
+ else if(do_task == DO_MIN)
{
- proc_ok = 1;
- }
-
- if(usrinfo != NULL)
- {
- /* uid_t pr_uid; real user id */
- if(usrinfo->pw_uid == psinfo.pr_uid)
- {
- usr_ok = 1;
- }
- }
- else
- {
- usr_ok = 1;
- }
-
- if(procstat[0] != 0)
- {
- /* char pr_state; numeric lwp state */
- if(psinfo.pr_lwp.pr_state == pr_state)
- {
- state_ok = 1;
- }
+ memsize = MIN(memsize, (double) lvalue);
}
else
{
- usr_ok = 1;
- }
-
- if(proc_ok && usr_ok && state_ok)
- {
- proccount++;
+ memsize += (double) lvalue;
}
}
- close (fd);
- }
- else
- {
- continue;
+
+ break;
}
}
+
+
+ fclose(f);
}
- closedir(dir);
- *value=(double)proccount;
- return SYSINFO_RET_OK;
-
-#elif defined(HAVE_PROC_1_STATUS)
+ }
+ closedir(dir);
+
+ if(memsize < 0)
+ {
+ /* incorrect process name */
+ memsize = 0;
+ }
+
+ if(do_task == DO_AVG)
+ {
+ memsize /= (double)proccount;
+ }
+
+ result->type |= AR_DOUBLE;
+ result->dbl = memsize;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
+}
+
+int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#if defined(HAVE_PROC_1_STATUS)
DIR *dir;
struct dirent *entries;
@@ -339,6 +310,10 @@ int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg,
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
int proccount = 0;
if(num_param(param) > 3)
@@ -368,10 +343,15 @@ int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg,
}
}
- if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
- {
- strscpy(procstat,"all");
- }
+ if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ {
+ procstat[0] = '\0';
+ }
+
+ if(procstat[0] == '\0')
+ {
+ strscpy(procstat, "all");
+ }
if(strcmp(procstat,"run") == 0)
{
@@ -514,10 +494,10 @@ int PROC_NUM(const char *cmd, const char *param,double *value, const char *msg,
}
closedir(dir);
- *value = (double) proccount;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double) proccount;
return SYSINFO_RET_OK;
#else
return SYSINFO_RET_FAIL;
#endif
}
-
diff --git a/src/libs/zbxsysinfo/unknown/sensors.c b/src/libs/zbxsysinfo/unknown/sensors.c
index 32042922..956ca3d1 100644
--- a/src/libs/zbxsysinfo/unknown/sensors.c
+++ b/src/libs/zbxsysinfo/unknown/sensors.c
@@ -19,125 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
-int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -148,6 +35,10 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -173,7 +64,8 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -187,7 +79,7 @@ int SENSOR_TEMP1(const char *cmd, const char *param,double *value, const char *
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP2(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -198,6 +90,10 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -223,7 +119,8 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -237,7 +134,7 @@ int SENSOR_TEMP2(const char *cmd, const char *param,double *value, const char *
return SYSINFO_RET_FAIL;
}
-int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SENSOR_TEMP3(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
DIR *dir;
struct dirent *entries;
@@ -248,6 +145,10 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
FILE *f;
+ assert(result);
+
+ clean_result(result);
+
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
{
@@ -273,7 +174,8 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
closedir(dir);
- *value=d3;
+ result->type |= AR_DOUBLE;
+ result->dbl = d3;
return SYSINFO_RET_OK;
}
else
@@ -286,3 +188,43 @@ int SENSOR_TEMP3(const char *cmd, const char *param,double *value, const char *
closedir(dir);
return SYSINFO_RET_FAIL;
}
+
+int OLD_SENSOR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"temp1") == 0)
+ {
+ ret = SENSOR_TEMP1(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp2") == 0)
+ {
+ ret = SENSOR_TEMP2(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"temp3") == 0)
+ {
+ ret = SENSOR_TEMP3(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/unknown/swap.c b/src/libs/zbxsysinfo/unknown/swap.c
index db059f78..3d80fec9 100644
--- a/src/libs/zbxsysinfo/unknown/swap.c
+++ b/src/libs/zbxsysinfo/unknown/swap.c
@@ -19,124 +19,12 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
+
/* Solaris. */
#ifndef HAVE_SYSINFO_FREESWAP
#ifdef HAVE_SYS_SWAP_SWAPTABLE
@@ -203,17 +91,22 @@ point them all to the same buffer */
#endif
#endif
-int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_FREESWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.freeswap * (double)info.mem_unit;
+ result->dbl = (double)info.freeswap * (double)info.mem_unit;
#else
- *value=(double)info.freeswap;
+ result->dbl = (double)info.freeswap;
#endif
return SYSINFO_RET_OK;
}
@@ -226,27 +119,41 @@ int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, cons
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
+ assert(result);
+
+ clean_result(result);
+
get_swapinfo(&swaptotal,&swapfree);
- *value=swapfree;
+ result->type |= AR_DOUBLE;
+ result->dbl = swapfree;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
-int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int SYSTEM_SWAP_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_TOTALSWAP
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalswap * (double)info.mem_unit;
+ result->dbl = (double)info.totalswap * (double)info.mem_unit;
#else
- *value=(double)info.totalswap;
+ result->dbl = (double)info.totalswap;
#endif
return SYSINFO_RET_OK;
}
@@ -259,12 +166,125 @@ int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, con
#ifdef HAVE_SYS_SWAP_SWAPTABLE
double swaptotal,swapfree;
- get_swapinfo(&swaptotal,&swapfree);
+ assert(result);
+
+ clean_result(result);
- *value=(double)swaptotal;
+ get_swapinfo(&swaptotal,&swapfree);
+
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)swaptotal;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif
}
+
+int SYSTEM_SWAP_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define SWP_FNCLIST struct swp_fnclist_s
+SWP_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ SWP_FNCLIST fl[] =
+ {
+ {"total", SYSTEM_SWAP_FREE},
+ {"free", SYSTEM_SWAP_TOTAL},
+ {0, 0}
+ };
+
+ char swapdev[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(swapdev[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(swapdev, "all");
+ }
+
+ if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "free");
+ }
+
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+
+int OLD_SWAP(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char key[MAX_STRING_LEN];
+ int ret;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, key, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(key,"free") == 0)
+ {
+ ret = SYSTEM_SWAP_FREE(cmd, param, flags, result);
+ }
+ else if(strcmp(key,"total") == 0)
+ {
+ ret = SYSTEM_SWAP_TOTAL(cmd, param, flags, result);
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ return ret;
+}
+
diff --git a/src/libs/zbxsysinfo/unknown/unknown.c b/src/libs/zbxsysinfo/unknown/unknown.c
index e04ef0e7..df66bf38 100644
--- a/src/libs/zbxsysinfo/unknown/unknown.c
+++ b/src/libs/zbxsysinfo/unknown/unknown.c
@@ -18,254 +18,179 @@
**/
#include "config.h"
+#include "common.h"
#include "sysinfo.h"
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_CPU_IDLE1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_IDLE5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_IDLE15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_USER15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_NICE15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_SYS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int VFS_FS_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_USED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_PUSED(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-
-int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int VFS_FILE_ATIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_CKSUM(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_CTIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_MD5SUM(const char *cmd, const char *filename, char **value, const char *msg, int mlen_max);
-int VFS_FILE_MTIME(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_REGEXP(const char *cmd, const char *filename, char **value, const char *msg, int mlen_max);
-int VFS_FILE_REGMATCH(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_SIZE(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-int VFS_FILE_EXISTS(const char *cmd, const char *filename,double *value, const char *msg, int mlen_max);
-
-int VFS_FS_INODE_FREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_INODE_PFREE(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value, const char *msg, int mlen_max);
-
-
-int KERNEL_MAXFILES(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int KERNEL_MAXPROC(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int NET_IF_IBYTES1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_IBYTES5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_IBYTES15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int NET_IF_OBYTES1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_OBYTES5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int NET_IF_OBYTES15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int DISKREADOPS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADOPS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADOPS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKREADBLKS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEOPS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int AGENT_PING(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int PROC_NUM(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int PROC_MEMORY(const char *cmd, const char *param, double *value, const char *msg, int mlen_max);
-
-int PROCCOUNT(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SENSOR_TEMP1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SENSOR_TEMP2(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SENSOR_TEMP3(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max);
-
-int TCP_LISTEN(const char *cmd, const char *porthex,double *value, const char *msg, int mlen_max);
-
-int EXECUTE(const char *cmd, const char *command,double *value, const char *msg, int mlen_max);
-int EXECUTE_STR(const char *cmd, const char *command, const char *parameter, char **value, const char *msg, int mlen_max);
-int AGENT_VERSION(const char *cmd, const char *command,char **value, const char *msg, int mlen_max);
-
-
-int CHECK_SERVICE(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-int CHECK_SERVICE_PERF(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-int CHECK_PORT(const char *cmd, const char *ip_and_port,double *value, const char *msg, int mlen_max);
-int CHECK_DNS(const char *cmd, const char *service,double *value, const char *msg, int mlen_max);
-
ZBX_METRIC parameters_specific[]=
-/* KEY FUNCTION (if double) FUNCTION (if string) PARAM*/
+/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
/* Outdated */
-
- {"cksum[*]" ,VFS_FILE_CKSUM, 0, "/etc/services"},
- {"cpu[idle1]" ,SYSTEM_CPU_IDLE1, 0, 0},
- {"cpu[idle5]" ,SYSTEM_CPU_IDLE5, 0, 0},
- {"cpu[idle15]" ,SYSTEM_CPU_IDLE15, 0, 0},
- {"cpu[nice1]" ,SYSTEM_CPU_NICE1, 0, 0},
- {"cpu[nice5]" ,SYSTEM_CPU_NICE5, 0, 0},
- {"cpu[nice15]" ,SYSTEM_CPU_NICE15, 0, 0},
- {"cpu[system1]" ,SYSTEM_CPU_SYS1, 0, 0},
- {"cpu[system5]" ,SYSTEM_CPU_SYS5, 0, 0},
- {"cpu[system15]" ,SYSTEM_CPU_SYS15, 0, 0},
- {"cpu[user1]" ,SYSTEM_CPU_USER1, 0, 0},
- {"cpu[user5]" ,SYSTEM_CPU_USER5, 0, 0},
- {"cpu[user15]" ,SYSTEM_CPU_USER15, 0, 0},
- {"diskfree[*]" ,VFS_FS_FREE, 0, "/"},
- {"disktotal[*]" ,VFS_FS_TOTAL, 0, "/"},
- {"diskused[*]" ,VFS_FS_USED, 0, "/"},
- {"diskfree_perc[*]" ,VFS_FS_PFREE, 0, "/"},
- {"diskused_perc[*]" ,VFS_FS_PUSED, 0, "/"},
- {"file[*]" ,VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize[*]" ,VFS_FILE_SIZE, 0, "/etc/passwd"},
- {"inodefree[*]" ,VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal[*]" ,VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc[*]" ,VFS_FS_INODE_PFREE, 0, "/"},
- {"kern[maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kern[maxproc]" ,KERNEL_MAXPROC, 0, 0},
- {"md5sum[*]" ,0, VFS_FILE_MD5SUM, "/etc/services"},
- {"memory[buffers]" ,VM_MEMORY_BUFFERS, 0, 0},
- {"memory[cached]" ,VM_MEMORY_CACHED, 0, 0},
- {"memory[free]" ,VM_MEMORY_FREE, 0, 0},
- {"memory[shared]" ,VM_MEMORY_SHARED, 0, 0},
- {"memory[total]" ,VM_MEMORY_TOTAL, 0, 0},
- {"netloadin1[*]" ,NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5[*]" ,NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15[*]" ,NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1[*]" ,NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5[*]" ,NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15[*]" ,NET_IF_OBYTES15, 0, "lo"},
- {"ping" ,AGENT_PING, 0, 0},
- {"proc_cnt[*]" ,PROC_NUM, 0, "inetd"},
- {"swap[free]" ,SYSTEM_SWAP_FREE, 0, 0},
- {"swap[total]" ,SYSTEM_SWAP_TOTAL, 0, 0},
- {"system[procload]" ,SYSTEM_CPU_LOAD1, 0, 0},
- {"system[procload5]" ,SYSTEM_CPU_LOAD5, 0, 0},
- {"system[procload15]" ,SYSTEM_CPU_LOAD15, 0, 0},
- {"system[hostname]" ,0, EXECUTE_STR, "hostname"},
- {"system[uname]" ,0, EXECUTE_STR, "uname -a"},
- {"system[uptime]" ,SYSTEM_UPTIME, 0, 0},
- {"system[users]" ,EXECUTE, 0,"who|wc -l"},
- {"version[zabbix_agent]", 0, AGENT_VERSION, 0},
+/* incorrect OLD naming */
+ {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
+/*
+ {"cpu[idle1]", 0, 0, 0, 0},
+ {"cpu[idle5]", 0, 0, 0, 0},
+ {"cpu[idle15]", 0, 0, 0, 0},
+ {"cpu[nice1]", 0, 0, 0, 0},
+ {"cpu[nice5]", 0, 0, 0, 0},
+ {"cpu[nice15]", 0, 0, 0, 0},
+ {"cpu[system1]", 0, 0, 0, 0},
+ {"cpu[system5]", 0, 0, 0, 0},
+ {"cpu[system15]", 0, 0, 0, 0},
+ {"cpu[user1]", 0, 0, 0, 0},
+ {"cpu[user5]", 0, 0, 0, 0},
+ {"cpu[user15]", 0, 0, 0, 0},
+*/
+ {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
+/*
+ {"io[disk_io]", 0, 0, 0, 0},
+ {"io[disk_rio]", 0, 0, 0, 0},
+ {"io[disk_wio]", 0, 0, 0, 0},
+ {"io[disk_rblk]", 0, 0, 0, 0},
+ {"io[disk_wblk]", 0, 0, 0, 0},
+*/
+ {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
+/*
+ {"kern[maxfiles]", 0, 0, 0, 0},
+ {"kern[maxproc]", 0, 0, 0, 0},
+*/
+ {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
+/*
+ {"memory[buffers]", 0, 0, 0, 0},
+ {"memory[cached]", 0, 0, 0, 0},
+ {"memory[free]", 0, 0, 0, 0},
+ {"memory[shared]", 0, 0, 0, 0},
+ {"memory[total]", 0, 0, 0, 0},
+*/
+ {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
+/*
+ {"system[proccount]", 0, 0, 0, 0},
+
+ {"system[procload]", 0, 0, 0, 0},
+ {"system[procload5]", 0, 0, 0, 0},
+ {"system[procload15]", 0, 0, 0, 0},
+ {"system[hostname]", 0, 0, 0, 0},
+ {"system[uname]", 0, 0, 0, 0},
+ {"system[uptime]", 0, 0, 0, 0},
+ {"system[users]", 0, 0, 0, 0},
+
+ {"system[procrunning]", 0, 0, 0, 0},
+*/
+ {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
+/*
+ {"sensor[temp1]", 0, 0, 0, 0},
+ {"sensor[temp2]", 0, 0, 0, 0},
+ {"sensor[temp3]", 0, 0, 0, 0},
+*/
+ {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
+/*
+ {"swap[free]", 0, 0, 0, 0},
+ {"swap[total]", 0, 0, 0, 0},
+*/
+ {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
+/*
+ {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
+*/
+/* correct OLD naming */
+/*
+ {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
+*/
+/*
+ {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
+ {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
+ {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
+ {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
+ {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
+*/
+/*
+ {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+*/
+/*
+ {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
+ {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
+ {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
+*/
+/*
+ {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
+*/
+/*
+ {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
+ {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
+ {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
+ {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
+ {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
+ {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
+*/
+/*
+ {"ping", 0, AGENT_PING, 0, 0},
+*/
/* New naming */
-
- {"agent.ping" ,AGENT_PING, 0, 0},
- {"agent.version", 0, AGENT_VERSION, 0},
-
- {"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
-
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
- {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
-
- {"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers" ,VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached" ,VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free" ,VM_MEMORY_FREE, 0, 0},
-
- {"vfs.fs.free[*]" ,VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total[*]" ,VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used[*]" ,VFS_FS_USED, 0, "/"},
-
- {"vfs.fs.pfree[*]" ,VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused[*]" ,VFS_FS_PUSED, 0, "/"},
-
- {"vfs.fs.inode.free[*]" ,VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total[*]",VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree[*]",VFS_FS_INODE_PFREE, 0, "/"},
-
- {"vfs.file.atime[*]" ,VFS_FILE_ATIME, 0, "/etc/passwd"},
- {"vfs.file.cksum[*]" ,VFS_FILE_CKSUM, 0, "/etc/services"},
- {"vfs.file.ctime[*]" ,VFS_FILE_CTIME, 0, "/etc/passwd"},
- {"vfs.file.exists[*]" ,VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"vfs.file.md5sum[*]" ,0, VFS_FILE_MD5SUM, "/etc/services"},
- {"vfs.file.mtime[*]" ,VFS_FILE_MTIME, 0, "/etc/passwd"},
- {"vfs.file.regexp[*]" ,0, VFS_FILE_REGEXP, "/etc/passwd,root"},
- {"vfs.file.regmatch[*]" ,VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
- {"vfs.file.size[*]" ,VFS_FILE_SIZE, 0, "/etc/passwd"},
-
- {"system.cpu.idle1" ,SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5" ,SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15" ,SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1" ,SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5" ,SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15" ,SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1" ,SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5" ,SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15" ,SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1" ,SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5" ,SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15" ,SYSTEM_CPU_USER15, 0, 0},
-
- {"net.if.ibytes1[*]" ,NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5[*]" ,NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15[*]" ,NET_IF_IBYTES15, 0, "lo"},
- {"net.if.obytes1[*]" ,NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5[*]" ,NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15[*]" ,NET_IF_OBYTES15, 0, "lo"},
-
- {"disk_read_ops1[*]" ,DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5[*]" ,DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15[*]" ,DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1[*]" ,DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5[*]" ,DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15[*]" ,DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1[*]" ,DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5[*]" ,DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15[*]" ,DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1[*]" ,DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5[*]" ,DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15[*]" ,DISKWRITEBLKS15, 0, "hda"},
-
- {"sensor[temp1]" ,SENSOR_TEMP1, 0, 0},
- {"sensor[temp2]" ,SENSOR_TEMP2, 0, 0},
- {"sensor[temp3]" ,SENSOR_TEMP3, 0, 0},
-
- {"system.cpu.load1" ,SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5" ,SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15" ,SYSTEM_CPU_LOAD15, 0, 0},
-
- {"system.hostname" ,0, EXECUTE_STR, "hostname"},
-
- {"system.swap.free" ,SYSTEM_SWAP_FREE, 0, 0},
- {"system.swap.total" ,SYSTEM_SWAP_TOTAL, 0, 0},
-
- {"system.uname" ,0, EXECUTE_STR, "uname -a"},
- {"system.uptime" ,SYSTEM_UPTIME, 0, 0},
- {"system.users.num" ,EXECUTE, 0,"who|wc -l"},
+/*
+ {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
+ {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
+ {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
+ {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
+ {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
+ {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
+ {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
+ {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
+ {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
+ {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
+ {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
+ {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
+*/
+/*
+ {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
+ {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
+ {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
+ {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
+ {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
+*/
+/*
+ {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
+ {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
+ {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
+ {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
+ {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
+*/
+/*
+ {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
+ {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
+ {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
+*/
+/*
+ {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
+ {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
+ {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
+
+ {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
+ {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
+ {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
+*/
+/*
+ {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
+ {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
+ {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
+
+ {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
+ {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
+ {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
+
+ {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
+ {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
+ {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
+
+ {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
+ {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
+ {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
+*/
+/*
+ {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
+ {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
+ {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
+*/
/****************************************
All these perameters require more than 1 second to retrieve.
@@ -277,30 +202,66 @@ ZBX_METRIC parameters_specific[]=
{"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
***************************************/
- {"io[disk_io]" ,DISK_IO, 0, 0},
- {"io[disk_rio]" ,DISK_RIO, 0, 0},
- {"io[disk_wio]" ,DISK_WIO, 0, 0},
- {"io[disk_rblk]" ,DISK_RBLK, 0, 0},
- {"io[disk_wblk]" ,DISK_WBLK, 0, 0},
-
-
-
- {"system[proccount]" ,PROCCOUNT, 0, 0},
-
-#ifdef HAVE_PROC_LOADAVG
- {"system[procrunning]" ,EXECUTE, 0, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '"},
-#endif
-
/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-
- {"net[listen_23]" ,TCP_LISTEN, 0, "0017"},
- {"net[listen_80]" ,TCP_LISTEN, 0, "0050"},
-
- {"check_port[*]" ,CHECK_PORT, 0, "80"},
-
- {"check_service[*]" ,CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"dns[*]" ,CHECK_DNS, 0, "127.0.0.1,localhost"},
- {"check_service_perf[*]",CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+/*
+ {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
+ {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
+ {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+*/
+/*
+ {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+*/
+ {"agent.ping", 0, AGENT_PING, 0, 0},
+ {"agent.version", 0, AGENT_VERSION, 0, 0},
+
+ {"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
+ {"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+
+ {"vfs.file.atime", CF_USEUPARAM, VFS_FILE_ATIME, 0, "/etc/passwd"},
+ {"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
+ {"vfs.file.ctime", CF_USEUPARAM, VFS_FILE_CTIME, 0, "/etc/passwd"},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
+ {"vfs.file.mtime", CF_USEUPARAM, VFS_FILE_MTIME, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+
+/************************************
+ * NEW FUNCTIONS *
+ ************************************/
+
+ {"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+
+ {"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
+ {"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
+ {"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+
+ {"net.if.in", CF_USEUPARAM, NET_IF_IN, 0, "lo,bytes"},
+ {"net.if.out", CF_USEUPARAM, NET_IF_OUT, 0, "lo,bytes"},
+
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
+
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
+
+ {"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
+
+ {"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
+ {"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+
+ {"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
+
+ {"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
+
+ {"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
+
+ {"system.hostname", 0, SYSTEM_HOSTNAME, 0, 0},
+
+ {"system.uname", 0, SYSTEM_UNAME, 0, 0},
+ {"system.uptime", 0, SYSTEM_UPTIME, 0, 0},
+ {"system.users.num", 0, SYSTEM_UNUM, 0, 0},
{0}
};
diff --git a/src/libs/zbxsysinfo/unknown/uptime.c b/src/libs/zbxsysinfo/unknown/uptime.c
index 88eee810..a38b2bd7 100644
--- a/src/libs/zbxsysinfo/unknown/uptime.c
+++ b/src/libs/zbxsysinfo/unknown/uptime.c
@@ -19,130 +19,22 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_UPTIME
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
- *value=(double)info.uptime;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)info.uptime;
return SYSINFO_RET_OK;
}
else
@@ -155,6 +47,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
struct timeval uptime;
int now;
+ assert(result);
+
+ clean_result(result);
+
mib[0]=CTL_KERN;
mib[1]=KERN_BOOTTIME;
@@ -167,8 +63,8 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
}
now=time(NULL);
-
- *value=(double)(now-uptime.tv_sec);
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)(now-uptime.tv_sec);
return SYSINFO_RET_OK;
#else
/* Solaris */
@@ -180,6 +76,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
long hz;
long secs;
+ assert(result);
+
+ clean_result(result);
+
hz = sysconf(_SC_CLK_TCK);
/* open kstat */
@@ -207,9 +107,14 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
/* close kstat */
kstat_close(kc);
- *value=(double)secs;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)secs;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif