summaryrefslogtreecommitdiffstats
path: root/src/libs/zbxsysinfo/unknown/swap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/zbxsysinfo/unknown/swap.c')
-rw-r--r--src/libs/zbxsysinfo/unknown/swap.c264
1 files changed, 142 insertions, 122 deletions
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;
+}
+