📄 hr_storage.c
字号:
/* * Host Resources MIB - storage group implementation - hr_storage.c * */#include <net-snmp/net-snmp-config.h>#if defined(freebsd5)/* undefine these in order to use getfsstat */#undef HAVE_STATVFS#undef STRUCT_STATVFS_HAS_F_FRSIZE#endif#include <sys/types.h>#if HAVE_SYS_PARAM_H#include <sys/param.h>#endif#if HAVE_UNISTD_H#include <unistd.h>#endif#if TIME_WITH_SYS_TIME# ifdef WIN32# include <windows.h># include <errno.h># include <sys/timeb.h># else# include <sys/time.h># endif# include <time.h>#else# if HAVE_SYS_TIME_H# include <sys/time.h># else# include <time.h># endif#endif#if (!defined(mingw32) && !defined(WIN32))#if HAVE_UTMPX_H#include <utmpx.h>#else#include <utmp.h>#endif#endif /* mingw32 */#ifndef dynix#if HAVE_SYS_VM_H#include <sys/vm.h>#if (!defined(KERNEL) || defined(MACH_USER_API)) && defined(HAVE_SYS_VMMETER_H) /*OS X does not #include <sys/vmmeter.h> if (defined(KERNEL) && !defined(MACH_USER_API)) */#include <sys/vmmeter.h>#endif#else#if HAVE_VM_VM_H#include <vm/vm.h>#if HAVE_MACHINE_TYPES_H#include <machine/types.h>#endif#if HAVE_SYS_VMMETER_H#include <sys/vmmeter.h>#endif#if HAVE_VM_VM_PARAM_H#include <vm/vm_param.h>#endif#else#if HAVE_SYS_VMPARAM_H#include <sys/vmparam.h>#endif#if HAVE_SYS_VMMAC_H#include <sys/vmmac.h>#endif#if HAVE_SYS_VMMETER_H#include <sys/vmmeter.h>#endif#if HAVE_SYS_VMSYSTM_H#include <sys/vmsystm.h>#endif#endif /* vm/vm.h */#endif /* sys/vm.h */#if defined(HAVE_UVM_UVM_PARAM_H) && defined(HAVE_UVM_UVM_EXTERN_H)#include <uvm/uvm_param.h>#include <uvm/uvm_extern.h>#elif defined(HAVE_VM_VM_PARAM_H) && defined(HAVE_VM_VM_EXTERN_H)#include <vm/vm_param.h>#include <vm/vm_extern.h>#endif#if HAVE_KVM_H#include <kvm.h>#endif#if HAVE_FCNTL_H#include <fcntl.h>#endif#if HAVE_SYS_POOL_H#if defined(MBPOOL_SYMBOL) && defined(MCLPOOL_SYMBOL)#define __POOL_EXPOSE#include <sys/pool.h>#else#undef HAVE_SYS_POOL_H#endif#endif#if HAVE_SYS_MBUF_H#include <sys/mbuf.h>#endif#if HAVE_SYS_SYSCTL_H#include <sys/sysctl.h>#if defined(CTL_HW) && defined(HW_PAGESIZE)#define USE_SYSCTL#endif#if USE_MACH_HOST_STATISTICS#include <mach/mach.h>#elif defined(CTL_VM) && (defined(VM_METER) || defined(VM_UVMEXP))#define USE_SYSCTL_VM#endif#endif /* if HAVE_SYS_SYSCTL_H */#endif /* ifndef dynix */#if (defined(aix4) || defined(aix5)) && HAVE_LIBPERFSTAT_H#include <libperfstat.h>#endif#include "host_res.h"#include "hr_storage.h"#include "hr_filesys.h"#include <net-snmp/agent/auto_nlist.h>#if HAVE_MNTENT_H#include <mntent.h>#endif#if HAVE_SYS_MNTTAB_H#include <sys/mnttab.h>#endif#if HAVE_SYS_STATVFS_H#include <sys/statvfs.h>#endif#if HAVE_SYS_VFS_H#include <sys/vfs.h>#endif#if HAVE_SYS_MOUNT_H#ifdef __osf__#undef m_next#undef m_data#endif#include <sys/mount.h>#endif#ifdef HAVE_MACHINE_PARAM_H#include <machine/param.h>#endif#include <sys/stat.h>#if defined(hpux10) || defined(hpux11)#include <sys/pstat.h>#endif#if defined(solaris2)#if HAVE_SYS_SWAP_H#include <sys/swap.h>#endif#endif#if HAVE_STRING_H#include <string.h>#else#include <strings.h>#endif#include <net-snmp/utilities.h>#include <net-snmp/output_api.h>#include <net-snmp/agent/net-snmp-agent-includes.h>#include <net-snmp/agent/hardware/memory.h>#ifdef solaris2#include "kernel_sunos5.h"#endif#include <net-snmp/agent/agent_read_config.h>#include <net-snmp/library/read_config.h>#define HRSTORE_MONOTONICALLY_INCREASING /********************* * * Kernel & interface information, * and internal forward declarations * *********************/#ifdef solaris2extern struct mnttab *HRFS_entry;#define HRFS_mount mnt_mountp#define HRFS_statfs statvfs#define HRFS_HAS_FRSIZE STRUCT_STATVFS_HAS_F_FRSIZE#elif defined(WIN32)/* fake block size */#define FAKED_BLOCK_SIZE 512extern struct win_statfs *HRFS_entry;#define HRFS_statfs win_statfs#define HRFS_mount f_driveletter#elif defined(HAVE_STATVFS) && defined(__NetBSD__)extern struct statvfs *HRFS_entry;extern int fscount;#define HRFS_statfs statvfs#define HRFS_mount f_mntonname#define HRFS_HAS_FRSIZE STRUCT_STATVFS_HAS_F_FRSIZE#elif defined(HAVE_STATVFS) && defined(STRUCT_STATVFS_HAS_MNT_DIR)extern struct mntent *HRFS_entry;extern int fscount;#define HRFS_statfs statvfs#define HRFS_mount mnt_dir#define HRFS_HAS_FRSIZE STRUCT_STATVFS_HAS_F_FRSIZE#elif defined(HAVE_GETFSSTAT)extern struct statfs *HRFS_entry;extern int fscount;#define HRFS_statfs statfs#define HRFS_mount f_mntonname#define HRFS_HAS_FRSIZE STRUCT_STATFS_HAS_F_FRSIZE#elseextern struct mntent *HRFS_entry;#define HRFS_mount mnt_dir#define HRFS_statfs statfs#define HRFS_HAS_FRSIZE STRUCT_STATFS_HAS_F_FRSIZE#endif #if defined(USE_MACH_HOST_STATISTICS)mach_port_t myHost;#endifstatic void parse_storage_config(const char *, char *); /********************* * * Initialisation & common implementation functions * *********************/int Get_Next_HR_Store(void);void Init_HR_Store(void);int header_hrstore(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **);void* header_hrstoreEntry(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **);#ifdef solaris2void sol_get_swapinfo(int *, int *);#endif#define HRSTORE_MEMSIZE 1#define HRSTORE_INDEX 2#define HRSTORE_TYPE 3#define HRSTORE_DESCR 4#define HRSTORE_UNITS 5#define HRSTORE_SIZE 6#define HRSTORE_USED 7#define HRSTORE_FAILS 8struct variable4 hrstore_variables[] = { {HRSTORE_MEMSIZE, ASN_INTEGER, RONLY, var_hrstore, 1, {2}}, {HRSTORE_INDEX, ASN_INTEGER, RONLY, var_hrstore, 3, {3, 1, 1}}, {HRSTORE_TYPE, ASN_OBJECT_ID, RONLY, var_hrstore, 3, {3, 1, 2}}, {HRSTORE_DESCR, ASN_OCTET_STR, RONLY, var_hrstore, 3, {3, 1, 3}}, {HRSTORE_UNITS, ASN_INTEGER, RONLY, var_hrstore, 3, {3, 1, 4}}, {HRSTORE_SIZE, ASN_INTEGER, RONLY, var_hrstore, 3, {3, 1, 5}}, {HRSTORE_USED, ASN_INTEGER, RONLY, var_hrstore, 3, {3, 1, 6}}, {HRSTORE_FAILS, ASN_COUNTER, RONLY, var_hrstore, 3, {3, 1, 7}}};oid hrstore_variables_oid[] = { 1, 3, 6, 1, 2, 1, 25, 2 };voidinit_hr_storage(void){ char *appname; REGISTER_MIB("host/hr_storage", hrstore_variables, variable4, hrstore_variables_oid); appname = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPTYPE); netsnmp_ds_register_config(ASN_BOOLEAN, appname, "skipNFSInHostResources", NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES); snmpd_register_config_handler("storageUseNFS", parse_storage_config, NULL, "1 | 2\t\t(1 = enable, 2 = disable)");}static int storageUseNFS = 1; /* Default to reporting NFS mounts as NetworkDisk */static voidparse_storage_config(const char *token, char *cptr){ char *val; int ival; char *st; val = strtok_r(cptr, " \t", &st); if (!val) { config_perror("Missing FLAG parameter in storageUseNFS"); return; } ival = atoi(val); if (ival < 1 || ival > 2) { config_perror("storageUseNFS must be 1 or 2"); return; } storageUseNFS = (ival == 1) ? 1 : 0;}/* * header_hrstore(... * Arguments: * vp IN - pointer to variable entry that points here * name IN/OUT - IN/name requested, OUT/name found * length IN/OUT - length of IN/OUT oid's * exact IN - TRUE if an exact match was requested * var_len OUT - length of variable or 0 if function returned * write_method * */intheader_hrstore(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method){#define HRSTORE_NAME_LENGTH 9 oid newname[MAX_OID_LEN]; int result; DEBUGMSGTL(("host/hr_storage", "var_hrstore: ")); DEBUGMSGOID(("host/hr_storage", name, *length)); DEBUGMSG(("host/hr_storage", " %d\n", exact)); memcpy((char *) newname, (char *) vp->name, vp->namelen * sizeof(oid)); newname[HRSTORE_NAME_LENGTH] = 0; result = snmp_oid_compare(name, *length, newname, vp->namelen + 1); if ((exact && (result != 0)) || (!exact && (result >= 0))) return (MATCH_FAILED); memcpy((char *) name, (char *) newname, (vp->namelen + 1) * sizeof(oid)); *length = vp->namelen + 1; *write_method = 0; *var_len = sizeof(long); /* default to 'long' results */ return (MATCH_SUCCEEDED);}void *header_hrstoreEntry(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method){#define HRSTORE_ENTRY_NAME_LENGTH 11 oid newname[MAX_OID_LEN]; int storage_idx, LowIndex = -1; int result; int idx = -1; netsnmp_memory_info *mem = NULL; DEBUGMSGTL(("host/hr_storage", "var_hrstoreEntry: request ")); DEBUGMSGOID(("host/hr_storage", name, *length)); DEBUGMSG(("host/hr_storage", " exact=%d\n", exact)); memcpy((char *) newname, (char *) vp->name, (int) vp->namelen * sizeof(oid)); result = snmp_oid_compare(name, *length, vp->name, vp->namelen); DEBUGMSGTL(("host/hr_storage", "var_hrstoreEntry: compare ")); DEBUGMSGOID(("host/hr_storage", vp->name, vp->namelen)); DEBUGMSG(("host/hr_storage", " => %d\n", result)); if (result < 0 || *length <= HRSTORE_ENTRY_NAME_LENGTH ) { /* * Requested OID too early or too short to refer * to a valid row (for the current column object). * GET requests should fail, GETNEXT requests
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -