From 8e45bd5b89c972e9b4b1baf8571813309cc64447 Mon Sep 17 00:00:00 2001 From: Packit Date: Sep 10 2020 11:07:37 +0000 Subject: Apply patch net-snmp-5.8-autofs-skip.patch patch_name: net-snmp-5.8-autofs-skip.patch present_in_specfile: true --- diff --git a/agent/mibgroup/hardware/fsys/fsys_mntctl.c b/agent/mibgroup/hardware/fsys/fsys_mntctl.c index e7d9a1c..3364dc5 100644 --- a/agent/mibgroup/hardware/fsys/fsys_mntctl.c +++ b/agent/mibgroup/hardware/fsys/fsys_mntctl.c @@ -43,8 +43,9 @@ _fsys_type( int type) case MNT_NFS: case MNT_NFS3: - case MNT_AUTOFS: return NETSNMP_FS_TYPE_NFS; + case MNT_AUTOFS: + return NETSNMP_FS_TYPE_AUTOFS; /* * The following code covers selected filesystems @@ -156,10 +157,12 @@ netsnmp_fsys_arch_load( void ) /* * Optionally skip retrieving statistics for remote mounts + * AUTOFS is skipped by default */ - if ( (entry->flags & NETSNMP_FS_FLAG_REMOTE) && + if ( ((entry->flags & NETSNMP_FS_FLAG_REMOTE) && netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, - NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES)) + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES)) || + entry->type == (NETSNMP_FS_TYPE_AUTOFS)) continue; if ( statfs( entry->path, &stat_buf ) < 0 ) { diff --git a/agent/mibgroup/hardware/fsys/fsys_mntctl.c.autofs-skip b/agent/mibgroup/hardware/fsys/fsys_mntctl.c.autofs-skip new file mode 100644 index 0000000..e7d9a1c --- /dev/null +++ b/agent/mibgroup/hardware/fsys/fsys_mntctl.c.autofs-skip @@ -0,0 +1,182 @@ +#include +#include +#include +#include + +#include +#if HAVE_SYS_MNTCTL_H +#include +#endif +#if HAVE_SYS_VMOUNT_H +#include +#endif +#if HAVE_SYS_STATFS_H +#include +#endif +#if HAVE_SYS_STATVFS_H +#include +#endif + + +static int +_fsys_remote( char *device, int type, char *host ) +{ + if (( type == NETSNMP_FS_TYPE_NFS) || + ( type == NETSNMP_FS_TYPE_AFS)) + return 1; + else + return 0; +} + +static int +_fsys_type( int type) +{ + DEBUGMSGTL(("fsys:type", "Classifying %d\n", type)); + + switch ( type ) { + case MNT_AIX: + case MNT_JFS: + return NETSNMP_FS_TYPE_BERKELEY; + + case MNT_CDROM: + return NETSNMP_FS_TYPE_ISO9660; + + case MNT_NFS: + case MNT_NFS3: + case MNT_AUTOFS: + return NETSNMP_FS_TYPE_NFS; + + /* + * The following code covers selected filesystems + * which are not covered by the HR-TYPES enumerations, + * but should still be monitored. + * These are all mapped into type "other" + * + */ +#ifdef MNT_NAMEFS + case MNT_NAMEFS: +#endif +#ifdef MNT_PROCFS + case MNT_PROCFS: +#endif +#ifdef MNT_ACFS + case MNT_ACFS: +#endif + case MNT_SFS: + case MNT_CACHEFS: + return NETSNMP_FS_TYPE_OTHER; + + /* + * All other types are silently skipped + */ + default: + return NETSNMP_FS_TYPE_IGNORE; + } + return NETSNMP_FS_TYPE_IGNORE; /* Not reached */ +} + +void +netsnmp_fsys_arch_init( void ) +{ + return; +} + +void +netsnmp_fsys_arch_load( void ) +{ + int ret = 0, i = 0; + uint size = 0; + + struct vmount *aixmnt, *aixcurr; + char *path; + struct statfs stat_buf; + netsnmp_fsys_info *entry; + char tmpbuf[1024]; + + /* + * Retrieve information about the currently mounted filesystems... + */ + ret = mntctl(MCTL_QUERY, sizeof(uint), (void *) &size); + if ( ret != 0 || size<=0 ) { + snmp_log_perror( "initial mntctl failed" ); + return; + } + + aixmnt = (struct vmount *)malloc( size ); + if ( aixmnt == NULL ) { + snmp_log_perror( "cannot allocate memory for mntctl data" ); + return; + } + + ret = mntctl(MCTL_QUERY, size, (void *) aixmnt); + if ( ret <= 0 ) { + free(aixmnt); + snmp_log_perror( "main mntctl failed" ); + return; + } + aixcurr = aixmnt; + + + /* + * ... and insert this into the filesystem container. + */ + + for (i = 0; + i < ret; + i++, aixcurr = (struct vmount *) ((char*)aixcurr + aixcurr->vmt_length) ) { + + path = vmt2dataptr( aixcurr, VMT_STUB ); + entry = netsnmp_fsys_by_path( path, NETSNMP_FS_FIND_CREATE ); + if (!entry) { + continue; + } + + strlcpy(entry->path, path, sizeof(entry->path)); + strlcpy(entry->device, vmt2dataptr(aixcurr, VMT_OBJECT), + sizeof(entry->device)); + entry->type = _fsys_type( aixcurr->vmt_gfstype ); + + if (!(entry->type & _NETSNMP_FS_TYPE_SKIP_BIT)) + entry->flags |= NETSNMP_FS_FLAG_ACTIVE; + + if ( _fsys_remote( entry->device, entry->type, vmt2dataptr( aixcurr, VMT_HOST) )) + entry->flags |= NETSNMP_FS_FLAG_REMOTE; + if ( aixcurr->vmt_flags & MNT_READONLY ) + entry->flags |= NETSNMP_FS_FLAG_RONLY; + /* + * The root device is presumably bootable. + * Other partitions probably aren't! + */ + if ((entry->path[0] == '/') && (entry->path[1] == '\0')) + entry->flags |= NETSNMP_FS_FLAG_BOOTABLE; + + /* + * XXX - identify removeable disks + */ + + /* + * Optionally skip retrieving statistics for remote mounts + */ + if ( (entry->flags & NETSNMP_FS_FLAG_REMOTE) && + netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES)) + continue; + + if ( statfs( entry->path, &stat_buf ) < 0 ) { + snprintf( tmpbuf, sizeof(tmpbuf), "Cannot statfs %s", entry->path ); + snmp_log_perror( tmpbuf ); + continue; + } + entry->units = stat_buf.f_bsize; + entry->size = stat_buf.f_blocks; + entry->used = (stat_buf.f_blocks - stat_buf.f_bfree); + entry->avail = stat_buf.f_bavail; + entry->inums_total = stat_buf.f_files; + entry->inums_avail = stat_buf.f_ffree; + netsnmp_fsys_calculate32(entry); + } + free(aixmnt); + aixmnt = NULL; + aixcurr = NULL; +} + diff --git a/agent/mibgroup/hardware/fsys/fsys_mntent.c b/agent/mibgroup/hardware/fsys/fsys_mntent.c index 3cdcea1..93e405d 100644 --- a/agent/mibgroup/hardware/fsys/fsys_mntent.c +++ b/agent/mibgroup/hardware/fsys/fsys_mntent.c @@ -150,6 +150,13 @@ _fsys_type( char *typename ) !strcmp(typename, MNTTYPE_LOFS)) return NETSNMP_FS_TYPE_OTHER; + /* Detection of AUTOFS. + * This file system will be ignored by default + */ + else if ( !strcmp(typename, MNTTYPE_AUTOFS)) + return NETSNMP_FS_TYPE_AUTOFS; + + /* * All other types are silently skipped */ @@ -239,6 +246,10 @@ netsnmp_fsys_arch_load( void ) NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES)) continue; + /* Skip AUTOFS enteries */ + if ( entry->type == (NETSNMP_FS_TYPE_AUTOFS)) + continue; + #ifdef irix6 if ( NSFS_STATFS( entry->path, &stat_buf, sizeof(struct statfs), 0) < 0 ) #else diff --git a/agent/mibgroup/hardware/fsys/fsys_mntent.c.autofs-skip b/agent/mibgroup/hardware/fsys/fsys_mntent.c.autofs-skip new file mode 100644 index 0000000..3cdcea1 --- /dev/null +++ b/agent/mibgroup/hardware/fsys/fsys_mntent.c.autofs-skip @@ -0,0 +1,277 @@ +#include +#include +#include +#include +#include "hw_fsys.h" +#include "hardware/fsys/hw_fsys_private.h" + +#include +#if HAVE_MNTENT_H +#include +#endif +#if HAVE_SYS_MNTTAB_H +#include +#endif +#if HAVE_SYS_VFS_H +#include +#endif +#if HAVE_SYS_PARAM_H +#include +#endif +#if HAVE_SYS_MOUNT_H +#include +#endif +#if HAVE_SYS_STATFS_H +#include +#endif +#if HAVE_SYS_STATVFS_H +#include +#endif + +#ifdef solaris2 +#define _NETSNMP_GETMNTENT_TWO_ARGS 1 +#else +#undef _NETSNMP_GETMNTENT_TWO_ARGS +#endif + + /* + * Handle naming differences between getmntent() APIs + */ +#ifdef _NETSNMP_GETMNTENT_TWO_ARGS + /* Two-argument form (Solaris) */ +#define NSFS_MNTENT struct mnttab +#define NSFS_PATH mnt_mountp +#define NSFS_DEV mnt_special +#define NSFS_TYPE mnt_fstype + +#define NSFS_STATFS statvfs +#define NSFS_SIZE f_frsize + +#else + /* One-argument form (everything else?) */ +#define NSFS_MNTENT struct mntent +#define NSFS_PATH mnt_dir +#define NSFS_DEV mnt_fsname +#define NSFS_TYPE mnt_type + +#define NSFS_STATFS statfs +#define NSFS_SIZE f_bsize + +#endif + +static int +_fsys_remote( char *device, int type ) +{ + if (( type == NETSNMP_FS_TYPE_NFS) || + ( type == NETSNMP_FS_TYPE_AFS)) + return 1; + else + return 0; +} + +static int +_fsys_type( char *typename ) +{ + DEBUGMSGTL(("fsys:type", "Classifying %s\n", typename)); + + if ( !typename || *typename=='\0' ) + return NETSNMP_FS_TYPE_UNKNOWN; + +#include "mnttypes.h" + + else if ( !strcmp(typename, MNTTYPE_FFS) ) + return NETSNMP_FS_TYPE_BERKELEY; + else if ( !strcmp(typename, MNTTYPE_UFS) ) + return _NETSNMP_FS_TYPE_UFS; /* either N_FS_TYPE_BERKELEY or N_FS_TYPE_SYSV */ + else if ( !strcmp(typename, MNTTYPE_SYSV) ) + return NETSNMP_FS_TYPE_SYSV; + else if ( !strcmp(typename, MNTTYPE_PC) || + !strcmp(typename, MNTTYPE_MSDOS) ) + return NETSNMP_FS_TYPE_FAT; + else if ( !strcmp(typename, MNTTYPE_HFS) ) + return NETSNMP_FS_TYPE_HFS; + else if ( !strcmp(typename, MNTTYPE_MFS) ) + return NETSNMP_FS_TYPE_MFS; + else if ( !strcmp(typename, MNTTYPE_NTFS) ) + return NETSNMP_FS_TYPE_NTFS; + else if ( !strcmp(typename, MNTTYPE_ISO9660) || + !strcmp(typename, MNTTYPE_CD9660) ) + return NETSNMP_FS_TYPE_ISO9660; + else if ( !strcmp(typename, MNTTYPE_CDFS) ) + return _NETSNMP_FS_TYPE_CDFS; /* either N_FS_TYPE_ISO9660 or N_FS_TYPE_ROCKRIDGE */ + else if ( !strcmp(typename, MNTTYPE_HSFS) ) + return NETSNMP_FS_TYPE_ROCKRIDGE; + else if ( !strcmp(typename, MNTTYPE_NFS) || + !strcmp(typename, MNTTYPE_NFS3) || + !strcmp(typename, MNTTYPE_NFS4) || + !strcmp(typename, MNTTYPE_CIFS) || /* i.e. SMB - ?? */ + !strcmp(typename, MNTTYPE_SMBFS) || /* ?? */ + /* mvfs (IBM ClearCase) is nfs-like in nature */ + !strcmp(typename, MNTTYPE_MVFS)) + return NETSNMP_FS_TYPE_NFS; + else if ( !strcmp(typename, MNTTYPE_NCPFS) ) + return NETSNMP_FS_TYPE_NETWARE; + else if ( !strcmp(typename, MNTTYPE_AFS) ) + return NETSNMP_FS_TYPE_AFS; + else if ( !strcmp(typename, MNTTYPE_EXT2) || + !strcmp(typename, MNTTYPE_EXT3) || + !strcmp(typename, MNTTYPE_EXT4) || + !strcmp(typename, MNTTYPE_EXT2FS) || + !strcmp(typename, MNTTYPE_EXT3FS) || + !strcmp(typename, MNTTYPE_EXT4FS) ) + return NETSNMP_FS_TYPE_EXT2; + else if ( !strcmp(typename, MNTTYPE_FAT32) || + !strcmp(typename, MNTTYPE_VFAT) ) + return NETSNMP_FS_TYPE_FAT32; + + /* + * The following code covers selected filesystems + * which are not covered by the HR-TYPES enumerations, + * but should still be monitored. + * These are all mapped into type "other" + * + * (The systems listed are not fixed in stone, + * but are simply here to illustrate the principle!) + */ + else if ( !strcmp(typename, MNTTYPE_TMPFS) || + !strcmp(typename, MNTTYPE_GFS) || + !strcmp(typename, MNTTYPE_GFS2) || + !strcmp(typename, MNTTYPE_XFS) || + !strcmp(typename, MNTTYPE_JFS) || + !strcmp(typename, MNTTYPE_VXFS) || + !strcmp(typename, MNTTYPE_REISERFS) || + !strcmp(typename, MNTTYPE_OCFS2) || + !strcmp(typename, MNTTYPE_CVFS) || + !strcmp(typename, MNTTYPE_SIMFS) || + !strcmp(typename, MNTTYPE_BTRFS) || + !strcmp(typename, MNTTYPE_ZFS) || + !strcmp(typename, MNTTYPE_NVMFS) || + !strcmp(typename, MNTTYPE_ACFS) || + !strcmp(typename, MNTTYPE_LOFS)) + return NETSNMP_FS_TYPE_OTHER; + + /* + * All other types are silently skipped + */ + else + return NETSNMP_FS_TYPE_IGNORE; +} + +void +netsnmp_fsys_arch_init( void ) +{ + return; +} + +void +netsnmp_fsys_arch_load( void ) +{ + FILE *fp=NULL; +#ifdef _NETSNMP_GETMNTENT_TWO_ARGS + struct mnttab mtmp; + struct mnttab *m = &mtmp; +#else + struct mntent *m; +#endif + struct NSFS_STATFS stat_buf; + netsnmp_fsys_info *entry; + char *tmpbuf = NULL; + + /* + * Retrieve information about the currently mounted filesystems... + */ + fp = fopen( ETC_MNTTAB, "r" ); /* OR setmntent()?? */ + if ( !fp ) { + if (asprintf(&tmpbuf, "Cannot open %s", ETC_MNTTAB) >= 0) + snmp_log_perror(tmpbuf); + free(tmpbuf); + return; + } + + /* + * ... and insert this into the filesystem container. + */ + while +#ifdef _NETSNMP_GETMNTENT_TWO_ARGS + ((getmntent(fp, m)) == 0 ) +#else + ((m = getmntent(fp)) != NULL ) +#endif + { + entry = netsnmp_fsys_by_path( m->NSFS_PATH, NETSNMP_FS_FIND_CREATE ); + if (!entry) { + continue; + } + + strlcpy(entry->path, m->NSFS_PATH, sizeof(entry->path)); + strlcpy(entry->device, m->NSFS_DEV, sizeof(entry->device)); + entry->type = _fsys_type(m->NSFS_TYPE); + if (!(entry->type & _NETSNMP_FS_TYPE_SKIP_BIT)) + entry->flags |= NETSNMP_FS_FLAG_ACTIVE; + + if ( _fsys_remote( entry->device, entry->type )) + entry->flags |= NETSNMP_FS_FLAG_REMOTE; +#if HAVE_HASMNTOPT + if (hasmntopt( m, "ro" )) + entry->flags |= NETSNMP_FS_FLAG_RONLY; + else + entry->flags &= ~NETSNMP_FS_FLAG_RONLY; +#endif + /* + * The root device is presumably bootable. + * Other partitions probably aren't! + * + * XXX - what about /boot ?? + */ + if ((entry->path[0] == '/') && + (entry->path[1] == '\0')) + entry->flags |= NETSNMP_FS_FLAG_BOOTABLE; + + /* + * XXX - identify removeable disks + */ + + /* + * Optionally skip retrieving statistics for remote mounts + */ + if ( (entry->flags & NETSNMP_FS_FLAG_REMOTE) && + netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES)) + continue; + +#ifdef irix6 + if ( NSFS_STATFS( entry->path, &stat_buf, sizeof(struct statfs), 0) < 0 ) +#else + if ( NSFS_STATFS( entry->path, &stat_buf ) < 0 ) +#endif + { + tmpbuf = NULL; + if (asprintf(&tmpbuf, "Cannot statfs %s", entry->path) >= 0) + snmp_log_perror(tmpbuf); + free(tmpbuf); + entry->units = stat_buf.NSFS_SIZE; + entry->size = 0; + entry->used = 0; + entry->avail = 0; + entry->inums_total = stat_buf.f_files; + entry->inums_avail = stat_buf.f_ffree; + netsnmp_fsys_calculate32(entry); + continue; + } + entry->units = stat_buf.NSFS_SIZE; + entry->size = stat_buf.f_blocks; + entry->used = (stat_buf.f_blocks - stat_buf.f_bfree); + /* entry->avail is currently unsigned, so protect against negative + * values! + * This should be changed to a signed field. + */ + if (stat_buf.f_bavail < 0) + entry->avail = 0; + else + entry->avail = stat_buf.f_bavail; + entry->inums_total = stat_buf.f_files; + entry->inums_avail = stat_buf.f_ffree; + netsnmp_fsys_calculate32(entry); + } + fclose( fp ); +} diff --git a/agent/mibgroup/hardware/fsys/mnttypes.h b/agent/mibgroup/hardware/fsys/mnttypes.h index bb1b401..53f1cc8 100644 --- a/agent/mibgroup/hardware/fsys/mnttypes.h +++ b/agent/mibgroup/hardware/fsys/mnttypes.h @@ -165,6 +165,9 @@ #ifndef MNTTYPE_APP #define MNTTYPE_APP "app" #endif +#ifndef MNTTYPE_AUTOFS +#define MNTTYPE_AUTOFS "autofs" +#endif #ifndef MNTTYPE_DEVPTS #define MNTTYPE_DEVPTS "devpts" #endif diff --git a/agent/mibgroup/hardware/fsys/mnttypes.h.autofs-skip b/agent/mibgroup/hardware/fsys/mnttypes.h.autofs-skip new file mode 100644 index 0000000..bb1b401 --- /dev/null +++ b/agent/mibgroup/hardware/fsys/mnttypes.h.autofs-skip @@ -0,0 +1,190 @@ +#ifndef _NETSNMP_FSYS_MNTTYPES_H +#define _NETSNMP_FSYS_MNTTYPES_H +/* + * Some mounts can map to one of two hrFS types + * (depending on other characteristics of the system) + * Note which should be used *before* defining any + * type tokens which may be missing. + */ + +#if (defined(BerkelyFS) && !defined(MNTTYPE_HFS)) || defined(solaris2) +#define _NETSNMP_FS_TYPE_UFS NETSNMP_FS_TYPE_BERKELEY +#else +#define _NETSNMP_FS_TYPE_UFS NETSNMP_FS_TYPE_SYSV +#endif + +#ifdef RockRidge +#define _NETSNMP_FS_TYPE_CDFS NETSNMP_FS_TYPE_ROCKRIDGE +#else +#define _NETSNMP_FS_TYPE_CDFS NETSNMP_FS_TYPE_ISO9660 +#endif + + +/* + * Ensure all recognised filesystem mount type tokens are + * available (even on systems where they're not used) + */ +#ifndef MNTTYPE_AFS +#define MNTTYPE_AFS "afs" +#endif +#ifndef MNTTYPE_CDFS +#define MNTTYPE_CDFS "cdfs" +#endif +#ifndef MNTTYPE_CD9660 +#define MNTTYPE_CD9660 "cd9660" +#endif +#ifndef MNTTYPE_EXT2 +#define MNTTYPE_EXT2 "ext2" +#endif +#ifndef MNTTYPE_EXT3 +#define MNTTYPE_EXT3 "ext3" +#endif +#ifndef MNTTYPE_EXT4 +#define MNTTYPE_EXT4 "ext4" +#endif +#ifndef MNTTYPE_EXT2FS +#define MNTTYPE_EXT2FS "ext2fs" +#endif +#ifndef MNTTYPE_EXT3FS +#define MNTTYPE_EXT3FS "ext3fs" +#endif +#ifndef MNTTYPE_EXT4FS +#define MNTTYPE_EXT4FS "ext4fs" +#endif +#ifndef MNTTYPE_FAT32 +#define MNTTYPE_FAT32 "fat32" +#endif +#ifndef MNTTYPE_FFS +#define MNTTYPE_FFS "ffs" +#endif +#ifndef MNTTYPE_HFS +#define MNTTYPE_HFS "hfs" +#endif +#ifndef MNTTYPE_HSFS +#define MNTTYPE_HSFS "hsfs" +#endif +#ifndef MNTTYPE_ISO9660 +#define MNTTYPE_ISO9660 "iso9660" +#endif +#ifndef MNTTYPE_MFS +#define MNTTYPE_MFS "mfs" +#endif +#ifndef MNTTYPE_MSDOS +#define MNTTYPE_MSDOS "msdos" +#endif +#ifndef MNTTYPE_NCPFS +#define MNTTYPE_NCPFS "ncpfs" +#endif +#ifndef MNTTYPE_NFS +#define MNTTYPE_NFS "nfs" +#endif +#ifndef MNTTYPE_NFS3 +#define MNTTYPE_NFS3 "nfs3" +#endif +#ifndef MNTTYPE_NFS4 +#define MNTTYPE_NFS4 "nfs4" +#endif +#ifndef MNTTYPE_NTFS +#define MNTTYPE_NTFS "ntfs" +#endif +#ifndef MNTTYPE_PC +#define MNTTYPE_PC "pc" +#endif +#ifndef MNTTYPE_SMBFS +#define MNTTYPE_SMBFS "smbfs" +#endif +#ifndef MNTTYPE_CIFS +#define MNTTYPE_CIFS "cifs" +#endif +#ifndef MNTTYPE_SYSV +#define MNTTYPE_SYSV "sysv" +#endif +#ifndef MNTTYPE_UFS +#define MNTTYPE_UFS "ufs" +#endif +#ifndef MNTTYPE_VFAT +#define MNTTYPE_VFAT "vfat" +#endif + +/* + * File systems to monitor, but not covered by HR-TYPES enumerations + */ +#ifndef MNTTYPE_MVFS +#define MNTTYPE_MVFS "mvfs" +#endif +#ifndef MNTTYPE_TMPFS +#define MNTTYPE_TMPFS "tmpfs" +#endif +#ifndef MNTTYPE_GFS +#define MNTTYPE_GFS "gfs" +#endif +#ifndef MNTTYPE_GFS2 +#define MNTTYPE_GFS2 "gfs2" +#endif +#ifndef MNTTYPE_XFS +#define MNTTYPE_XFS "xfs" +#endif +#ifndef MNTTYPE_JFS +#define MNTTYPE_JFS "jfs" +#endif +#ifndef MNTTYPE_VXFS +#define MNTTYPE_VXFS "vxfs" +#endif +#ifndef MNTTYPE_REISERFS +#define MNTTYPE_REISERFS "reiserfs" +#endif +#ifndef MNTTYPE_LOFS +#define MNTTYPE_LOFS "lofs" +#endif +#ifndef MNTTYPE_OCFS2 +#define MNTTYPE_OCFS2 "ocfs2" +#endif +#ifndef MNTTYPE_CVFS +#define MNTTYPE_CVFS "cvfs" +#endif +#ifndef MNTTYPE_SIMFS +#define MNTTYPE_SIMFS "simfs" +#endif +#ifndef MNTTYPE_BTRFS +#define MNTTYPE_BTRFS "btrfs" +#endif +#ifndef MNTTYPE_ZFS +#define MNTTYPE_ZFS "zfs" +#endif +#ifndef MNTTYPE_NVMFS +#define MNTTYPE_NVMFS "nvmfs" +#endif +#ifndef MNTTYPE_ACFS +#define MNTTYPE_ACFS "acfs" +#endif + +/* + * File systems to skip + * (Probably not strictly needed) + */ +#ifndef MNTTYPE_APP +#define MNTTYPE_APP "app" +#endif +#ifndef MNTTYPE_DEVPTS +#define MNTTYPE_DEVPTS "devpts" +#endif +#ifndef MNTTYPE_IGNORE +#define MNTTYPE_IGNORE "ignore" +#endif +#ifndef MNTTYPE_PROC +#define MNTTYPE_PROC "proc" +#endif +#ifndef MNTTYPE_SYSFS +#define MNTTYPE_SYSFS "sysfs" +#endif +#ifndef MNTTYPE_USBFS +#define MNTTYPE_USBFS "usbfs" +#endif +#ifndef MNTTYPE_BINFMT +#define MNTTYPE_BINFMT "binfmt_misc" +#endif +#ifndef MNTTYPE_RPCPIPE +#define MNTTYPE_RPCPIPE "rpc_pipefs" +#endif + +#endif /* _NETSNMP_FSYS_MNTTYPES_H */ diff --git a/agent/mibgroup/host/hr_filesys.c b/agent/mibgroup/host/hr_filesys.c index 56c8b20..bc11123 100644 --- a/agent/mibgroup/host/hr_filesys.c +++ b/agent/mibgroup/host/hr_filesys.c @@ -834,6 +834,27 @@ Check_HR_FileSys_NFS (void) return 0; /* no NFS file system */ } +/* This function checks whether current file system is an AutoFs + * HRFS_entry must be valid prior to calling this function + * return 1 if AutoFs, 0 otherwise + */ +int +Check_HR_FileSys_AutoFs (void) +{ +#if HAVE_GETFSSTAT + if ( HRFS_entry->HRFS_type != NULL && +#if defined(MNTTYPE_AUTOFS) + !strcmp( HRFS_entry->HRFS_type, MNTTYPE_AUTOFS) +#else + !strcmp( HRFS_entry->HRFS_type, "autofs") +#endif + ) +#endif /* HAVE_GETFSSTAT */ + return 1; /* AUTOFS */ + + return 0; /* no AUTOFS */ +} + void End_HR_FileSys(void) { diff --git a/agent/mibgroup/host/hr_filesys.c.autofs-skip b/agent/mibgroup/host/hr_filesys.c.autofs-skip new file mode 100644 index 0000000..56c8b20 --- /dev/null +++ b/agent/mibgroup/host/hr_filesys.c.autofs-skip @@ -0,0 +1,1004 @@ +/* + * Host Resources MIB - File System device group implementation - hr_filesys.c + * + */ +/* Portions of this file are subject to the following copyright(s). See + * the Net-SNMP's COPYING file for more details and other copyrights + * that may apply: + */ +/* + * Portions of this file are copyrighted by: + * Copyright (C) 2007 Apple, Inc. All rights reserved. + * Use is subject to license terms specified in the COPYING file + * distributed with the Net-SNMP package. + */ + +#include +#include +#include +#include +#include +#include "host_res.h" +#include "hr_filesys.h" +#include "hr_storage.h" +#include "hr_disk.h" +#include + +#if HAVE_MNTENT_H +#include +#endif +#if HAVE_SYS_MNTENT_H +#include +#endif +#if HAVE_SYS_MNTTAB_H +#include +#endif +#if HAVE_SYS_STATVFS_H +#include +#endif +#if HAVE_SYS_VFS_H +#include +#endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef HAVE_SYS_MOUNT_H +#include +#endif + +#include +#if HAVE_STRING_H +#include +#endif +#if HAVE_STDLIB_H +#include +#endif + +#if HAVE_NBUTIL_H +#include +#endif + +#if defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7) +#include +#include +#include +#endif + +netsnmp_feature_require(se_find_free_value_in_slist) +netsnmp_feature_require(date_n_time) +netsnmp_feature_require(ctime_to_timet) + +#if defined(bsdi4) || defined(freebsd3) || defined(freebsd4) || defined(freebsd5) || defined(darwin) +#if HAVE_GETFSSTAT && defined(MFSNAMELEN) +#define MOUNT_NFS "nfs" +#define MNTTYPE_UFS "ufs" +#define BerkelyFS +#define MNTTYPE_FFS "ffs" +#define MNTTYPE_NFS "nfs" +#define MNTTYPE_NFS3 "nfs" +#define MNTTYPE_HFS "hfs" +#define MNTTYPE_MFS "mfs" +#define MNTTYPE_MSDOS "msdos" +#define MNTTYPE_LFS "lfs" +#define MNTTYPE_FDESC "fdesc" +#define MNTTYPE_PORTAL "portal" +#define MNTTYPE_NULL "null" +#define MNTTYPE_UMAP "umap" +#define MNTTYPE_KERNFS "kernfs" +#define MNTTYPE_PROCFS "procfs" +#define MNTTYPE_AFS "afs" +#define MNTTYPE_CD9660 "cd9660" +#define MNTTYPE_UNION "union" +#define MNTTYPE_ADOSFS "adosfs" +#define MNTTYPE_EXT2FS "ext2fs" +#define MNTTYPE_CFS "coda" +#define MNTTYPE_NTFS "ntfs" +#endif +#endif /* freebsd3 */ + +#define HRFS_MONOTONICALLY_INCREASING + + /********************* + * + * Kernel & interface information, + * and internal forward declarations + * + *********************/ + +#ifdef solaris2 + +struct mnttab HRFS_entry_struct; +struct mnttab *HRFS_entry = &HRFS_entry_struct; +#define HRFS_name mnt_special +#define HRFS_mount mnt_mountp +#define HRFS_type mnt_fstype +#define HRFS_statfs statvfs + +#elif defined(HAVE_STATVFS) && defined(__NetBSD__) + +#if !defined(MFSNAMELEN) && defined(_VFS_NAMELEN) +#define MFSNAMELEN _VFS_NAMELEN +#endif + +#define getfsstat getvfsstat + +static struct statvfs *fsstats = NULL; +struct statvfs *HRFS_entry; +static int fscount; +#define HRFS_mount f_mntonname +#define HRFS_name f_mntfromname +#define HRFS_statfs statvfs +#define HRFS_type f_fstypename +#elif defined(HAVE_GETFSSTAT) && !defined(HAVE_STATFS) && defined(HAVE_STATVFS) + +static struct statfs *fsstats = NULL; +struct statfs *HRFS_entry; +static int fscount; +#define HRFS_mount f_mntonname +#define HRFS_name f_mntfromname +#define HRFS_statfs statvfs +#define HRFS_type f_fstypename + +#elif defined(HAVE_GETFSSTAT) +static struct statfs *fsstats = 0; +static int fscount; +struct statfs *HRFS_entry; +#define HRFS_statfs statfs +#ifdef MFSNAMELEN +#define HRFS_type f_fstypename +#else +#define HRFS_type f_type +#endif +#define HRFS_mount f_mntonname +#define HRFS_name f_mntfromname + +#elif defined(dynix) +struct mntent *HRFS_entry; +#define HRFS_name mnt_fsname +#define HRFS_mount mnt_dir +#define HRFS_type mnt_type +#define HRFS_statfs statvfs + +#elif defined(WIN32) +struct win_statfs *HRFS_entry; +static int fscount; +#define HRFS_mount f_driveletter +#define HRFS_name f_fsid +#define HRFS_statfs win_statfs +#define HRFS_type f_type + +#elif defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7) + +struct vmount *aixmnt, *aixcurr; +struct HRFS_entry { + char *HRFS_name; + char *HRFS_mount; + int HRFS_type; + int HRFS_flags; +} *HRFS_entry; +#define HRFS_statfs statfs + +#else +struct mntent *HRFS_entry; +#define HRFS_name mnt_fsname +#define HRFS_mount mnt_dir +#define HRFS_type mnt_type +#define HRFS_statfs statfs + +#ifdef linux +#define MNTTYPE_CD9660 "iso9660" +#define MNTTYPE_EXT2FS "ext2" +#define MNTTYPE_EXT3FS "ext3" +#define MNTTYPE_SMBFS "smbfs" +#define MNTTYPE_MSDOS "msdos" +#define MNTTYPE_FAT32 "vfat" +#define MNTTYPE_NTFS "ntfs" +#define MNTTYPE_NFS4 "nfs4" +#endif /* linux */ + +#endif + +#define FULL_DUMP 0 +#define PART_DUMP 1 + +static u_char *when_dumped(char *filesys, int level, size_t * length); + + /********************* + * + * Initialisation & common implementation functions + * + *********************/ + +#define HRFSYS_INDEX 1 +#define HRFSYS_MOUNT 2 +#define HRFSYS_RMOUNT 3 +#define HRFSYS_TYPE 4 +#define HRFSYS_ACCESS 5 +#define HRFSYS_BOOT 6 +#define HRFSYS_STOREIDX 7 +#define HRFSYS_FULLDUMP 8 +#define HRFSYS_PARTDUMP 9 + +struct variable4 hrfsys_variables[] = { + {HRFSYS_INDEX, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrfilesys, 2, {1, 1}}, + {HRFSYS_MOUNT, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, + var_hrfilesys, 2, {1, 2}}, + {HRFSYS_RMOUNT, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, + var_hrfilesys, 2, {1, 3}}, + {HRFSYS_TYPE, ASN_OBJECT_ID, NETSNMP_OLDAPI_RONLY, + var_hrfilesys, 2, {1, 4}}, + {HRFSYS_ACCESS, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrfilesys, 2, {1, 5}}, + {HRFSYS_BOOT, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrfilesys, 2, {1, 6}}, + {HRFSYS_STOREIDX, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrfilesys, 2, {1, 7}}, + {HRFSYS_FULLDUMP, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, + var_hrfilesys, 2, {1, 8}}, + {HRFSYS_PARTDUMP, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, + var_hrfilesys, 2, {1, 9}}, +}; +oid hrfsys_variables_oid[] = { 1, 3, 6, 1, 2, 1, 25, 3, 8 }; + +void +init_hr_filesys(void) +{ + REGISTER_MIB("host/hr_filesys", hrfsys_variables, variable4, + hrfsys_variables_oid); +#if defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7) + /* something leaks, make it idiot-safe */ + aixmnt = NULL; + aixcurr = NULL; +#endif +} + +/* + * header_hrfilesys(... + * 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 + * + */ + +int +header_hrfilesys(struct variable *vp, + oid * name, + size_t * length, + int exact, size_t * var_len, WriteMethod ** write_method) +{ +#define HRFSYS_ENTRY_NAME_LENGTH 11 + oid newname[MAX_OID_LEN]; + int fsys_idx, LowIndex = -1; + int result; + + DEBUGMSGTL(("host/hr_filesys", "var_hrfilesys: ")); + DEBUGMSGOID(("host/hr_filesys", name, *length)); + DEBUGMSG(("host/hr_filesys", " %d\n", exact)); + + memcpy((char *) newname, (char *) vp->name, vp->namelen * sizeof(oid)); + /* + * Find "next" file system entry + */ + + Init_HR_FileSys(); + for (;;) { + fsys_idx = Get_Next_HR_FileSys(); + if (fsys_idx == -1) + break; + newname[HRFSYS_ENTRY_NAME_LENGTH] = fsys_idx; + result = snmp_oid_compare(name, *length, newname, vp->namelen + 1); + if (exact && (result == 0)) { + LowIndex = fsys_idx; + break; + } + if ((!exact && (result < 0)) && + (LowIndex == -1 || fsys_idx < LowIndex)) { + LowIndex = fsys_idx; +#ifdef HRFS_MONOTONICALLY_INCREASING + break; +#endif + } + } + + if (LowIndex == -1) { + DEBUGMSGTL(("host/hr_filesys", "... index out of range\n")); + return (MATCH_FAILED); + } + + memcpy((char *) name, (char *) newname, + (vp->namelen + 1) * sizeof(oid)); + *length = vp->namelen + 1; + *write_method = (WriteMethod*)0; + *var_len = sizeof(long); /* default to 'long' results */ + + DEBUGMSGTL(("host/hr_filesys", "... get filesys stats ")); + DEBUGMSGOID(("host/hr_filesys", name, *length)); + DEBUGMSG(("host/hr_filesys", "\n")); + + return LowIndex; +} + + +oid fsys_type_id[] = { 1, 3, 6, 1, 2, 1, 25, 3, 9, 1 }; /* hrFSOther */ +int fsys_type_len = + sizeof(fsys_type_id) / sizeof(fsys_type_id[0]); + + /********************* + * + * System specific implementation functions + * + *********************/ + + +u_char * +var_hrfilesys(struct variable *vp, + oid * name, + size_t * length, + int exact, size_t * var_len, WriteMethod ** write_method) +{ + int fsys_idx; + static char string[1024]; + char *mnt_type; + + fsys_idx = + header_hrfilesys(vp, name, length, exact, var_len, write_method); + if (fsys_idx == MATCH_FAILED) + return NULL; + + + switch (vp->magic) { + case HRFSYS_INDEX: + long_return = fsys_idx; + return (u_char *) & long_return; + case HRFSYS_MOUNT: + strlcpy(string, HRFS_entry->HRFS_mount, sizeof(string)); + *var_len = strlen(string); + return (u_char *) string; + case HRFSYS_RMOUNT: + if (Check_HR_FileSys_NFS()) + strlcpy(string, HRFS_entry->HRFS_name, sizeof(string)); + else + string[0] = '\0'; + *var_len = strlen(string); + return (u_char *) string; + + case HRFSYS_TYPE: + if (Check_HR_FileSys_NFS()) + fsys_type_id[fsys_type_len - 1] = 14; + else { + /* + * Not sufficient to identity the file + * type precisely, but it's a start. + */ +#if HAVE_GETFSSTAT && !defined(MFSNAMELEN) + switch (HRFS_entry->HRFS_type) { + case MOUNT_UFS: + fsys_type_id[fsys_type_len - 1] = 3; + break; + case MOUNT_NFS: + fsys_type_id[fsys_type_len - 1] = 14; + break; + case MOUNT_HFS: + fsys_type_id[fsys_type_len - 1] = 7; + break; + case MOUNT_MFS: + fsys_type_id[fsys_type_len - 1] = 8; + break; + case MOUNT_MSDOS: + fsys_type_id[fsys_type_len - 1] = 5; + break; + case MOUNT_LFS: + fsys_type_id[fsys_type_len - 1] = 1; + break; + case MOUNT_LOFS: + fsys_type_id[fsys_type_len - 1] = 1; + break; + case MOUNT_FDESC: + fsys_type_id[fsys_type_len - 1] = 1; + break; + case MOUNT_PORTAL: + fsys_type_id[fsys_type_len - 1] = 1; + break; + case MOUNT_NULL: + fsys_type_id[fsys_type_len - 1] = 1; + break; + case MOUNT_UMAP: + fsys_type_id[fsys_type_len - 1] = 1; + break; + case MOUNT_KERNFS: + fsys_type_id[fsys_type_len - 1] = 1; + break; + case MOUNT_PROCFS: + fsys_type_id[fsys_type_len - 1] = 1; + break; + case MOUNT_AFS: + fsys_type_id[fsys_type_len - 1] = 16; + break; + case MOUNT_CD9660: + fsys_type_id[fsys_type_len - 1] = 12; + break; + case MOUNT_UNION: + fsys_type_id[fsys_type_len - 1] = 1; + break; + case MOUNT_DEVFS: + fsys_type_id[fsys_type_len - 1] = 1; + break; +#ifdef MOUNT_EXT2FS + case MOUNT_EXT2FS: + fsys_type_id[fsys_type_len - 1] = 23; + break; +#endif +#ifdef MOUNT_TFS + case MOUNT_TFS: + fsys_type_id[fsys_type_len - 1] = 15; + break; +#endif + } +#elif defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7) + switch (HRFS_entry->HRFS_type) { + case MNT_AIX: + case MNT_JFS: + fsys_type_id[fsys_type_len - 1] = 3; + break; + case MNT_CDROM: + fsys_type_id[fsys_type_len - 1] = 12; + break; +#ifdef MNT_NAMEFS + case MNT_NAMEFS: +#endif +#ifdef MNT_PROCFS + case MNT_PROCFS: +#endif + case MNT_SFS: + case MNT_CACHEFS: + fsys_type_id[fsys_type_len - 1] = 1; + break; + case MNT_NFS: + case MNT_NFS3: + case MNT_AUTOFS: + fsys_type_id[fsys_type_len - 1] = 14; + break; + } +#else + mnt_type = HRFS_entry->HRFS_type; + if (mnt_type == NULL) + fsys_type_id[fsys_type_len - 1] = 2; /* unknown */ +#ifdef MNTTYPE_HFS + else if (!strcmp(mnt_type, MNTTYPE_HFS)) + fsys_type_id[fsys_type_len - 1] = 7; +#endif +#ifdef MNTTYPE_UFS + else if (!strcmp(mnt_type, MNTTYPE_UFS)) +#if (defined(BerkelyFS) && !defined(MNTTYPE_HFS)) || defined(solaris2) + fsys_type_id[fsys_type_len - 1] = 3; +#else /* SysV */ + fsys_type_id[fsys_type_len - 1] = 4; /* or 3? XXX */ +#endif +#endif +#ifdef MNTTYPE_SYSV + else if (!strcmp(mnt_type, MNTTYPE_SYSV)) + fsys_type_id[fsys_type_len - 1] = 4; +#endif +#ifdef MNTTYPE_PC + else if (!strcmp(mnt_type, MNTTYPE_PC)) + fsys_type_id[fsys_type_len - 1] = 5; +#endif +#ifdef MNTTYPE_MSDOS + else if (!strcmp(mnt_type, MNTTYPE_MSDOS)) + fsys_type_id[fsys_type_len - 1] = 5; +#endif +#ifdef MNTTYPE_FAT32 + else if (!strcmp(mnt_type, MNTTYPE_FAT32)) + fsys_type_id[fsys_type_len - 1] = 22; +#endif +#ifdef MNTTYPE_CDFS + else if (!strcmp(mnt_type, MNTTYPE_CDFS)) +#ifdef RockRidge + fsys_type_id[fsys_type_len - 1] = 13; +#else /* ISO 9660 */ + fsys_type_id[fsys_type_len - 1] = 12; +#endif +#endif +#ifdef MNTTYPE_HSFS + else if (!strcmp(mnt_type, MNTTYPE_HSFS)) + fsys_type_id[fsys_type_len - 1] = 13; +#endif +#ifdef MNTTYPE_ISO9660 + else if (!strcmp(mnt_type, MNTTYPE_ISO9660)) + fsys_type_id[fsys_type_len - 1] = 12; +#endif +#ifdef MNTTYPE_CD9660 + else if (!strcmp(mnt_type, MNTTYPE_CD9660)) + fsys_type_id[fsys_type_len - 1] = 12; +#endif +#ifdef MNTTYPE_SMBFS + else if (!strcmp(mnt_type, MNTTYPE_SMBFS)) + fsys_type_id[fsys_type_len - 1] = 14; +#endif +#ifdef MNTTYPE_NFS + else if (!strcmp(mnt_type, MNTTYPE_NFS)) + fsys_type_id[fsys_type_len - 1] = 14; +#endif +#ifdef MNTTYPE_NFS3 + else if (!strcmp(mnt_type, MNTTYPE_NFS3)) + fsys_type_id[fsys_type_len - 1] = 14; +#endif +#ifdef MNTTYPE_NFS4 + else if (!strcmp(mnt_type, MNTTYPE_NFS4)) + fsys_type_id[fsys_type_len - 1] = 14; +#endif +#ifdef MNTTYPE_MFS + else if (!strcmp(mnt_type, MNTTYPE_MFS)) + fsys_type_id[fsys_type_len - 1] = 8; +#endif +#ifdef MNTTYPE_EXT2FS + else if (!strcmp(mnt_type, MNTTYPE_EXT2FS)) + fsys_type_id[fsys_type_len - 1] = 23; +#endif +#ifdef MNTTYPE_EXT3FS + else if (!strcmp(mnt_type, MNTTYPE_EXT3FS)) + fsys_type_id[fsys_type_len - 1] = 23; +#endif +#ifdef MNTTYPE_NTFS + else if (!strcmp(mnt_type, MNTTYPE_NTFS)) + fsys_type_id[fsys_type_len - 1] = 9; +#endif + else + fsys_type_id[fsys_type_len - 1] = 1; /* Other */ +#endif /* HAVE_GETFSSTAT */ + } + + *var_len = sizeof(fsys_type_id); + return (u_char *) fsys_type_id; + + case HRFSYS_ACCESS: +#if defined(HAVE_STATVFS) && defined(__NetBSD__) + long_return = HRFS_entry->f_flag & MNT_RDONLY ? 2 : 1; +#elif defined(HAVE_GETFSSTAT) +#if HAVE_STRUCT_STATFS_F_FLAGS + long_return = HRFS_entry->f_flags & MNT_RDONLY ? 2 : 1; +#else + long_return = HRFS_entry->f_flag & MNT_RDONLY ? 2 : 1; +#endif +#elif defined(cygwin) + long_return = 1; +#elif defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7) + long_return = (HRFS_entry->HRFS_flags & MNT_READONLY) == 0 ? 1 : 2; +#else +#if HAVE_HASMNTOPT + if (hasmntopt(HRFS_entry, "ro") != NULL) + long_return = 2; /* Read Only */ + else +#endif + long_return = 1; /* Read-Write */ +#endif + return (u_char *) & long_return; + case HRFSYS_BOOT: + if (HRFS_entry->HRFS_mount[0] == '/' && + HRFS_entry->HRFS_mount[1] == 0) + long_return = 1; /* root is probably bootable! */ + else + long_return = 2; /* others probably aren't */ + return (u_char *) & long_return; + case HRFSYS_STOREIDX: + long_return = fsys_idx + NETSNMP_MEM_TYPE_MAX; + return (u_char *) & long_return; + case HRFSYS_FULLDUMP: + return when_dumped(HRFS_entry->HRFS_name, FULL_DUMP, var_len); + case HRFSYS_PARTDUMP: + return when_dumped(HRFS_entry->HRFS_name, PART_DUMP, var_len); + default: + DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_hrfilesys\n", + vp->magic)); + } + return NULL; +} + + + /********************* + * + * Internal implementation functions + * + *********************/ + +static int HRFS_index; +#ifndef HAVE_GETFSSTAT +static FILE *fp; +#endif + +void +Init_HR_FileSys(void) +{ +#if HAVE_GETFSSTAT +#if defined(HAVE_STATVFS) && defined(__NetBSD__) + fscount = getvfsstat(NULL, 0, ST_NOWAIT); +#else + fscount = getfsstat(NULL, 0, MNT_NOWAIT); +#endif + if (fsstats) + free((char *) fsstats); + fsstats = NULL; + fsstats = malloc(fscount * sizeof(*fsstats)); +#if defined(HAVE_STATVFS) && defined(__NetBSD__) + getvfsstat(fsstats, fscount * sizeof(*fsstats), ST_NOWAIT); +#else + getfsstat(fsstats, fscount * sizeof(*fsstats), MNT_NOWAIT); +#endif + HRFS_index = 0; +#elif defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7) + int ret; + uint size; + ret = 0; + size = 0; + if(aixmnt != NULL) free(aixmnt); /* something leaks, make it idiot-safe */ + aixmnt = NULL; + aixcurr = NULL; + HRFS_index = 0; + ret = mntctl(MCTL_QUERY, sizeof(uint), &size); + if(ret == 0 && size > 0) { + aixmnt = malloc(size + sizeof(struct HRFS_entry)); + if(aixmnt != NULL) { + HRFS_entry = (char *) aixmnt + size; + ret = mntctl(MCTL_QUERY, size, aixmnt); + HRFS_index = 1; + if(ret <= 0) { + free(aixmnt); + aixmnt = NULL; + HRFS_entry = NULL; + } else aixcurr = aixmnt; + } + } +#else + HRFS_index = 1; + if (fp != NULL) + fclose(fp); + fp = fopen(ETC_MNTTAB, "r"); + if (!fp) { + netsnmp_config_error("Can't open mnttab %s\n", ETC_MNTTAB); + } +#endif +} + +const char *HRFS_ignores[] = { +#ifdef MNTTYPE_IGNORE + MNTTYPE_IGNORE, +#endif +#ifdef MNTTYPE_SWAP + MNTTYPE_SWAP, +#endif +#ifdef MNTTYPE_PROC + MNTTYPE_PROC, +#endif +#ifdef MNTTYPE_PROCFS + MNTTYPE_PROCFS, +#endif +#ifdef MNTTYPE_AUTOFS + MNTTYPE_AUTOFS, +#else + "autofs", +#endif +#ifdef linux + "autofs", + "bdev", + "binfmt_misc", + "cpuset", + "debugfs", + "devfs", + "devpts", + "eventpollfs", + "futexfs", + "hugetlbfs", + "inotifyfs", + "mqueue", + "nfsd", + "pipefs", + "proc", + "ramfs", + "rootfs", + "rpc_pipefs", + "securityfs", + "shm", + "sockfs", + "sysfs", + "tmpfs", + "usbdevfs", + "usbfs", +#endif +#ifdef solaris2 + "mntfs", + "proc", + "fd", +#endif + NULL +}; + +int +Get_Next_HR_FileSys(void) +{ +#if HAVE_GETFSSTAT + if (HRFS_index >= fscount) + return -1; + HRFS_entry = fsstats + HRFS_index; + return ++HRFS_index; +#elif defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7) + if(aixcurr == NULL) { + if(aixmnt != NULL) free(aixmnt); + aixmnt = NULL; + HRFS_entry = NULL; + return -1; + } + HRFS_entry->HRFS_name = vmt2dataptr(aixcurr, VMT_OBJECT); + HRFS_entry->HRFS_mount = vmt2dataptr(aixcurr, VMT_STUB); + HRFS_entry->HRFS_type = aixcurr->vmt_gfstype; + HRFS_entry->HRFS_flags = aixcurr->vmt_flags; + aixcurr = (char *) aixcurr + aixcurr->vmt_length; + if((char *) aixcurr >= (char *) HRFS_entry) aixcurr = NULL; + switch(HRFS_entry->HRFS_type) { +#ifdef MNT_NAMEFS + case MNT_NAMEFS: +#endif +#ifdef MNT_PROCFS + case MNT_PROCFS: +#endif + case MNT_SFS: + return Get_Next_HR_FileSys(); + break; + } + return HRFS_index++; +#else + const char **cpp; + + if (fp == NULL) + return -1; + +#ifdef solaris2 + if (getmntent(fp, HRFS_entry) != 0) + return -1; +#else + HRFS_entry = getmntent(fp); + if (HRFS_entry == NULL) + return -1; +#endif /* solaris2 */ + + for (cpp = HRFS_ignores; *cpp != NULL; ++cpp) + if (!strcmp(HRFS_entry->HRFS_type, *cpp)) + return Get_Next_HR_FileSys(); + + /* + * Try and ensure that index values are persistent + * at least within a single run of the agent + */ + HRFS_index = se_find_value_in_slist("filesys", HRFS_entry->HRFS_name ); + if (HRFS_index == SE_DNE) { + HRFS_index = se_find_free_value_in_slist("filesys"); + if (HRFS_index == SE_DNE) { HRFS_index = 1; } + se_add_pair_to_slist( "filesys", + strdup( HRFS_entry->HRFS_name ), HRFS_index); + } + + return HRFS_index++; +#endif /* HAVE_GETFSSTAT */ +} + +/* + * this function checks whether the current file system (info can be found + * in HRFS_entry) is a NFS file system + * HRFS_entry must be valid prior to calling this function + * returns 1 if NFS file system, 0 otherwise + */ +int +Check_HR_FileSys_NFS (void) +{ +#if HAVE_GETFSSTAT && !defined(MFSNAMELEN) + if ((HRFS_entry->HRFS_type == MOUNT_NFS) || + (HRFS_entry->HRFS_type == MOUNT_AFS)) +#elif defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7) + if(HRFS_entry->HRFS_type == MNT_NFS || HRFS_entry->HRFS_type == MNT_NFS3) +#else /* HAVE_GETFSSTAT */ + if ( HRFS_entry->HRFS_type != NULL && ( +#if defined(MNTTYPE_NFS) + !strcmp( HRFS_entry->HRFS_type, MNTTYPE_NFS) || +#else + !strcmp( HRFS_entry->HRFS_type, "nfs") || +#endif +#if defined(MNTTYPE_NFS3) + !strcmp( HRFS_entry->HRFS_type, MNTTYPE_NFS3) || +#endif +#if defined(MNTTYPE_NFS4) + !strcmp( HRFS_entry->HRFS_type, MNTTYPE_NFS4) || +#endif +#if defined(MNTTYPE_SMBFS) + !strcmp( HRFS_entry->HRFS_type, MNTTYPE_SMBFS) || +#endif +#if defined(MNTTYPE_LOFS) + !strcmp( HRFS_entry->HRFS_type, MNTTYPE_LOFS) || +#endif +#if defined(MNTTYPE_AFP) + !strcmp( HRFS_entry->HRFS_type, MNTTYPE_AFP) || +#endif + !strcmp( HRFS_entry->HRFS_type, "cifs") || + /* + * MVFS is Rational ClearCase's view file system + * it is similiar to NFS file systems in that it is mounted + * locally or remotely from the ClearCase server + */ + !strcmp( HRFS_entry->HRFS_type, "mvfs"))) +#endif /* HAVE_GETFSSTAT */ + return 1; /* NFS file system */ + + return 0; /* no NFS file system */ +} + +void +End_HR_FileSys(void) +{ +#ifdef HAVE_GETFSSTAT + if (fsstats) + free((char *) fsstats); + fsstats = NULL; +#elif defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7) + if(aixmnt != NULL) { + free(aixmnt); + aixmnt = NULL; + aixcurr = NULL; + HRFS_entry = NULL; + } +#else + if (fp != NULL) + fclose(fp); + fp = NULL; +#endif +} + + +static u_char * +when_dumped(char *filesys, int level, size_t * length) +{ + time_t dumpdate = 0, tmp; + FILE *dump_fp; + char line[1024]; + char *cp1, *cp2, *cp3; + + /* + * Look for the relevent entries in /etc/dumpdates + * + * This is complicated by the fact that disks are + * mounted using block devices, but dumps are + * done via the raw character devices. + * Thus the device names in /etc/dumpdates and + * /etc/mnttab don't match. + * These comparisons are therefore made using the + * final portion of the device name only. + */ + + if (*filesys == '\0') /* No filesystem name? */ + return date_n_time(NULL, length); + cp1 = strrchr(filesys, '/'); /* Find the last element of the current FS */ + + if (cp1 == NULL) + cp1 = filesys; + + if ((dump_fp = fopen("/etc/dumpdates", "r")) == NULL) + return date_n_time(NULL, length); + + while (fgets(line, sizeof(line), dump_fp) != NULL) { + cp2 = strchr(line, ' '); /* Start by looking at the device name only */ + if (cp2 != NULL) { + *cp2 = '\0'; + cp3 = strrchr(line, '/'); /* and find the last element */ + if (cp3 == NULL) + cp3 = line; + + if (strcmp(cp1, cp3) != 0) /* Wrong FS */ + continue; + + ++cp2; + while (isspace(*cp2 & 0xFF)) + ++cp2; /* Now find the dump level */ + + if (level == FULL_DUMP) { + if (*(cp2++) != '0') + continue; /* Not interested in partial dumps */ + while (isspace(*cp2 & 0xFF)) + ++cp2; + + dumpdate = ctime_to_timet(cp2); + fclose(dump_fp); + return date_n_time(&dumpdate, length); + } else { /* Partial Dump */ + if (*(cp2++) == '0') + continue; /* Not interested in full dumps */ + while (isspace(*cp2 & 0xFF)) + ++cp2; + + tmp = ctime_to_timet(cp2); + if (tmp > dumpdate) + dumpdate = tmp; /* Remember the 'latest' partial dump */ + } + } + } + + fclose(dump_fp); + + return date_n_time(&dumpdate, length); +} + + +#define RAW_DEVICE_PREFIX "/dev/rdsk" +#define COOKED_DEVICE_PREFIX "/dev/dsk" + +char * +cook_device(char *dev) +{ + static char cooked_dev[SNMP_MAXPATH+1]; + + if (!strncmp(dev, RAW_DEVICE_PREFIX, strlen(RAW_DEVICE_PREFIX))) { + strlcpy(cooked_dev, COOKED_DEVICE_PREFIX, sizeof(cooked_dev)); + strlcat(cooked_dev, dev + strlen(RAW_DEVICE_PREFIX), + sizeof(cooked_dev)); + } else { + strlcpy(cooked_dev, dev, sizeof(cooked_dev)); + } + + return cooked_dev; +} + + +int +Get_FSIndex(char *dev) +{ + int iindex; + + Init_HR_FileSys(); + + while ((iindex = Get_Next_HR_FileSys()) != -1) + if (!strcmp(HRFS_entry->HRFS_name, cook_device(dev))) { + End_HR_FileSys(); + return iindex; + } + + End_HR_FileSys(); + return 0; +} + +long +Get_FSSize(char *dev) +{ + struct HRFS_statfs statfs_buf; + + Init_HR_FileSys(); + + while (Get_Next_HR_FileSys() != -1) + if (!strcmp(HRFS_entry->HRFS_name, cook_device(dev))) { + End_HR_FileSys(); + + if (HRFS_statfs(HRFS_entry->HRFS_mount, &statfs_buf) != -1) + /* + * with large file systems the following calculation produces + * an overflow: + * (statfs_buf.f_blocks*statfs_buf.f_bsize)/1024 + * + * assumption: f_bsize is either 512 or a multiple of 1024 + * in case of 512 (f_blocks/2) is returned + * otherwise (f_blocks*(f_bsize/1024)) is returned + */ +#if defined(solaris2) && defined(HAVE_STRUCT_STATVFS_F_FRSIZE) + return (statfs_buf.f_blocks*(statfs_buf.f_frsize/1024)); +#else + if (statfs_buf.f_bsize == 512) + return (statfs_buf.f_blocks/2); + else + return (statfs_buf.f_blocks*(statfs_buf.f_bsize/1024)); +#endif + else + return -1; + } + + End_HR_FileSys(); + return 0; +} diff --git a/agent/mibgroup/host/hr_filesys.h b/agent/mibgroup/host/hr_filesys.h index 2f00355..36cd7dd 100644 --- a/agent/mibgroup/host/hr_filesys.h +++ b/agent/mibgroup/host/hr_filesys.h @@ -10,6 +10,7 @@ extern void Init_HR_FileSys(void); extern FindVarMethod var_hrfilesys; extern int Get_Next_HR_FileSys(void); extern int Check_HR_FileSys_NFS(void); +extern int Check_HR_FileSys_AutoFs(void); extern int Get_FSIndex(char *); extern long Get_FSSize(char *); /* Temporary */ diff --git a/agent/mibgroup/host/hr_filesys.h.autofs-skip b/agent/mibgroup/host/hr_filesys.h.autofs-skip new file mode 100644 index 0000000..2f00355 --- /dev/null +++ b/agent/mibgroup/host/hr_filesys.h.autofs-skip @@ -0,0 +1,18 @@ +/* + * Host Resources MIB - file system device group interface - hr_filesys.h + * + */ +#ifndef _MIBGROUP_HRFSYS_H +#define _MIBGROUP_HRFSYS_H + +extern void init_hr_filesys(void); +extern void Init_HR_FileSys(void); +extern FindVarMethod var_hrfilesys; +extern int Get_Next_HR_FileSys(void); +extern int Check_HR_FileSys_NFS(void); + +extern int Get_FSIndex(char *); +extern long Get_FSSize(char *); /* Temporary */ + + +#endif /* _MIBGROUP_HRFSYS_H */ diff --git a/agent/mibgroup/host/hr_storage.c b/agent/mibgroup/host/hr_storage.c index a868984..b7c23fd 100644 --- a/agent/mibgroup/host/hr_storage.c +++ b/agent/mibgroup/host/hr_storage.c @@ -540,9 +540,10 @@ really_try_next: store_idx = name[ HRSTORE_ENTRY_NAME_LENGTH ]; if (store_idx > NETSNMP_MEM_TYPE_MAX ) { - if ( netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + if ( (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) && - Check_HR_FileSys_NFS()) + Check_HR_FileSys_NFS()) || + Check_HR_FileSys_AutoFs()) return NULL; /* or goto try_next; */ if (HRFS_statfs(HRFS_entry->HRFS_mount, &stat_buf) < 0) { snmp_log_perror(HRFS_entry->HRFS_mount); @@ -683,7 +684,8 @@ Get_Next_HR_Store(void) if (HRS_index >= 0) { if (!(netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) && - Check_HR_FileSys_NFS())) { + Check_HR_FileSys_NFS()) && + !Check_HR_FileSys_AutoFs()) { return HRS_index + NETSNMP_MEM_TYPE_MAX; } } else { diff --git a/agent/mibgroup/host/hr_storage.c.autofs-skip b/agent/mibgroup/host/hr_storage.c.autofs-skip new file mode 100644 index 0000000..a868984 --- /dev/null +++ b/agent/mibgroup/host/hr_storage.c.autofs-skip @@ -0,0 +1,788 @@ +/* + * Host Resources MIB - storage group implementation - hr_storage.c + * + */ + +#include + +#if defined(freebsd5) +/* undefine these in order to use getfsstat */ +#undef HAVE_STATVFS +#undef HAVE_STRUCT_STATVFS_F_FRSIZE +#endif + +#include +#if HAVE_SYS_PARAM_H +#include +#endif +#if HAVE_UNISTD_H +#include +#endif +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + +#if (!defined(mingw32) && !defined(WIN32)) +#if HAVE_UTMPX_H +#include +#else +#include +#endif +#endif /* mingw32 */ +#ifndef dynix +#if HAVE_SYS_VM_H +#include +#if (!defined(KERNEL) || defined(MACH_USER_API)) && defined(HAVE_SYS_VMMETER_H) /*OS X does not #include if (defined(KERNEL) && !defined(MACH_USER_API)) */ +#include +#endif +#else +#if HAVE_VM_VM_H +#include +#if HAVE_MACHINE_TYPES_H +#include +#endif +#if HAVE_SYS_VMMETER_H +#include +#endif +#if HAVE_VM_VM_PARAM_H +#include +#endif +#else +#if HAVE_SYS_VMPARAM_H +#include +#endif +#if HAVE_SYS_VMMAC_H +#include +#endif +#if HAVE_SYS_VMMETER_H +#include +#endif +#if HAVE_SYS_VMSYSTM_H +#include +#endif +#endif /* vm/vm.h */ +#endif /* sys/vm.h */ +#if defined(HAVE_UVM_UVM_PARAM_H) && defined(HAVE_UVM_UVM_EXTERN_H) +#include +#include +#elif defined(HAVE_VM_VM_PARAM_H) && defined(HAVE_VM_VM_EXTERN_H) +#include +#include +#endif +#if HAVE_KVM_H +#include +#endif +#if HAVE_FCNTL_H +#include +#endif +#if HAVE_SYS_POOL_H +#if defined(MBPOOL_SYMBOL) && defined(MCLPOOL_SYMBOL) +#define __POOL_EXPOSE +#include +#else +#undef HAVE_SYS_POOL_H +#endif +#endif +#if HAVE_SYS_MBUF_H +#include +#endif +#if HAVE_SYS_SYSCTL_H +#include +#if defined(CTL_HW) && defined(HW_PAGESIZE) +#define USE_SYSCTL +#endif +#if USE_MACH_HOST_STATISTICS +#include +#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) || defined(aix6) || defined(aix7)) && HAVE_LIBPERFSTAT_H +#ifdef HAVE_SYS_PROTOSW_H +#include +#endif +#include +#endif + + +#include "host_res.h" +#include "hr_storage.h" +#include "hr_filesys.h" +#include + +#if HAVE_MNTENT_H +#include +#endif +#if HAVE_SYS_MNTTAB_H +#include +#endif +#if HAVE_SYS_STATVFS_H +#include +#endif +#if HAVE_SYS_VFS_H +#include +#endif +#if HAVE_SYS_MOUNT_H +#ifdef __osf__ +#undef m_next +#undef m_data +#endif +#include +#endif +#ifdef HAVE_MACHINE_PARAM_H +#include +#endif +#include + +#if defined(hpux10) || defined(hpux11) +#include +#endif +#if defined(solaris2) +#if HAVE_SYS_SWAP_H +#include +#endif +#endif + +#if HAVE_STRING_H +#include +#else +#include +#endif +#if HAVE_NBUTIL_H +#include +#endif + +#include +#include + +#include +#include + +#ifdef solaris2 +#include "kernel_sunos5.h" +#endif + +#include +#include + +#define HRSTORE_MONOTONICALLY_INCREASING + + /********************* + * + * Kernel & interface information, + * and internal forward declarations + * + *********************/ + + +#ifdef solaris2 + +extern struct mnttab *HRFS_entry; +#define HRFS_mount mnt_mountp +#define HRFS_statfs statvfs +#define HRFS_HAS_FRSIZE HAVE_STRUCT_STATVFS_F_FRSIZE + +#elif defined(WIN32) +/* fake block size */ +#define FAKED_BLOCK_SIZE 512 + +extern 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 HAVE_STRUCT_STATVFS_F_FRSIZE + +#elif defined(HAVE_STATVFS) && defined(HAVE_STRUCT_STATVFS_MNT_DIR) + +extern struct mntent *HRFS_entry; +extern int fscount; +#define HRFS_statfs statvfs +#define HRFS_mount mnt_dir +#define HRFS_HAS_FRSIZE HAVE_STRUCT_STATVFS_F_FRSIZE + +#elif defined(HAVE_GETFSSTAT) && !defined(HAVE_STATFS) && defined(HAVE_STATVFS) + +extern struct statfs *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_GETFSSTAT) + +extern struct statfs *HRFS_entry; +extern int fscount; +#define HRFS_statfs statfs +#define HRFS_mount f_mntonname +#define HRFS_HAS_FRSIZE HAVE_STRUCT_STATFS_F_FRSIZE + +#else + +extern struct mntent *HRFS_entry; +#define HRFS_mount mnt_dir +#define HRFS_statfs statfs +#define HRFS_HAS_FRSIZE HAVE_STRUCT_STATFS_F_FRSIZE + +#endif + +#if defined(USE_MACH_HOST_STATISTICS) +mach_port_t myHost; +#endif + +static 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 **); +Netsnmp_Node_Handler handle_memsize; + +#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 8 + +struct variable2 hrstore_variables[] = { + {HRSTORE_INDEX, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {1}}, + {HRSTORE_TYPE, ASN_OBJECT_ID, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {2}}, + {HRSTORE_DESCR, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {3}}, + {HRSTORE_UNITS, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {4}}, + {HRSTORE_SIZE, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {5}}, + {HRSTORE_USED, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {6}}, + {HRSTORE_FAILS, ASN_COUNTER, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {7}} +}; +oid hrMemorySize_oid[] = { 1, 3, 6, 1, 2, 1, 25, 2, 2 }; +oid hrStorageTable_oid[] = { 1, 3, 6, 1, 2, 1, 25, 2, 3, 1 }; + + +void +init_hr_storage(void) +{ + char *appname; + + netsnmp_register_scalar( + netsnmp_create_handler_registration("host/hrMemorySize", handle_memsize, + hrMemorySize_oid, OID_LENGTH(hrMemorySize_oid), + HANDLER_CAN_RONLY)); + REGISTER_MIB("host/hr_storage", hrstore_variables, variable2, + hrStorageTable_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 void +parse_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_hrstoreEntry(... + * 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 + * + */ + +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 + * should use the first row. + */ + if ( exact ) + return NULL; + netsnmp_memory_load(); + mem = netsnmp_memory_get_first( 0 ); + } + else { + /* + * Otherwise, retrieve the requested + * (or following) row as appropriate. + */ + if ( exact && *length > HRSTORE_ENTRY_NAME_LENGTH+1 ) + return NULL; /* Too long for a valid instance */ + idx = name[ HRSTORE_ENTRY_NAME_LENGTH ]; + if ( idx < NETSNMP_MEM_TYPE_MAX ) { + netsnmp_memory_load(); + mem = ( exact ? netsnmp_memory_get_byIdx( idx, 0 ) : + netsnmp_memory_get_next_byIdx( idx, 0 )); + } + } + + /* + * If this matched a memory-based entry, then + * update the OID parameter(s) for GETNEXT requests. + */ + if ( mem ) { + if ( !exact ) { + newname[ HRSTORE_ENTRY_NAME_LENGTH ] = mem->idx; + memcpy((char *) name, (char *) newname, + ((int) vp->namelen + 1) * sizeof(oid)); + *length = vp->namelen + 1; + } + } + /* + * If this didn't match a memory-based entry, + * then consider the disk-based storage. + */ + else { + Init_HR_Store(); + for (;;) { + storage_idx = Get_Next_HR_Store(); + DEBUGMSG(("host/hr_storage", "(index %d ....", storage_idx)); + if (storage_idx == -1) + break; + newname[HRSTORE_ENTRY_NAME_LENGTH] = storage_idx; + DEBUGMSGOID(("host/hr_storage", newname, *length)); + DEBUGMSG(("host/hr_storage", "\n")); + result = snmp_oid_compare(name, *length, newname, vp->namelen + 1); + if (exact && (result == 0)) { + LowIndex = storage_idx; + /* + * Save storage status information + */ + break; + } + if ((!exact && (result < 0)) && + (LowIndex == -1 || storage_idx < LowIndex)) { + LowIndex = storage_idx; + /* + * Save storage status information + */ +#ifdef HRSTORE_MONOTONICALLY_INCREASING + break; +#endif + } + } + if ( LowIndex != -1 ) { + if ( !exact ) { + newname[ HRSTORE_ENTRY_NAME_LENGTH ] = LowIndex; + memcpy((char *) name, (char *) newname, + ((int) vp->namelen + 1) * sizeof(oid)); + *length = vp->namelen + 1; + } + mem = (netsnmp_memory_info*)0xffffffff; /* To indicate 'success' */ + } + } + + *write_method = (WriteMethod*)0; + *var_len = sizeof(long); /* default to 'long' results */ + + /* + * ... and return the appropriate row + */ + DEBUGMSGTL(("host/hr_storage", "var_hrstoreEntry: process ")); + DEBUGMSGOID(("host/hr_storage", name, *length)); + DEBUGMSG(("host/hr_storage", " (%p)\n", mem)); + return (void*)mem; +} + +oid storage_type_id[] = { 1, 3, 6, 1, 2, 1, 25, 2, 1, 1 }; /* hrStorageOther */ +int storage_type_len = + sizeof(storage_type_id) / sizeof(storage_type_id[0]); + + /********************* + * + * System specific implementation functions + * + *********************/ + +int +handle_memsize(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, + netsnmp_request_info *requests) +{ + netsnmp_memory_info *mem_info; + int val; + + /* + * We just need to handle valid GET requests, as invalid instances + * are rejected automatically, and (valid) GETNEXT requests are + * converted into the appropriate GET request. + * + * We also only ever receive one request at a time. + */ + switch (reqinfo->mode) { + case MODE_GET: + netsnmp_memory_load(); + mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_PHYSMEM, 0 ); + if ( !mem_info || mem_info->size == -1 || mem_info->units == -1 ) + netsnmp_set_request_error( reqinfo, requests, SNMP_NOSUCHOBJECT ); + else { + val = mem_info->size; /* memtotal */ + val *= (mem_info->units/1024); + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&val, sizeof(val)); + } + return SNMP_ERR_NOERROR; + + default: + /* + * we should never get here, so this is a really bad error + */ + snmp_log(LOG_ERR, "unknown mode (%d) in handle_memsize\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; +} + + +u_char * +var_hrstore(struct variable *vp, + oid * name, + size_t * length, + int exact, size_t * var_len, WriteMethod ** write_method) +{ + int store_idx = 0; + static char string[1024]; + struct HRFS_statfs stat_buf; + void *ptr; + netsnmp_memory_info *mem = NULL; + +really_try_next: + ptr = header_hrstoreEntry(vp, name, length, exact, var_len, + write_method); + if (ptr == NULL) + return NULL; + + store_idx = name[ HRSTORE_ENTRY_NAME_LENGTH ]; + if (store_idx > NETSNMP_MEM_TYPE_MAX ) { + if ( netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) && + Check_HR_FileSys_NFS()) + return NULL; /* or goto try_next; */ + if (HRFS_statfs(HRFS_entry->HRFS_mount, &stat_buf) < 0) { + snmp_log_perror(HRFS_entry->HRFS_mount); + goto try_next; + } + } else { + mem = (netsnmp_memory_info*)ptr; + } + + + + switch (vp->magic) { + case HRSTORE_INDEX: + long_return = store_idx; + return (u_char *) & long_return; + case HRSTORE_TYPE: + if (store_idx > NETSNMP_MEM_TYPE_MAX) + if (storageUseNFS && Check_HR_FileSys_NFS()) + storage_type_id[storage_type_len - 1] = 10; /* Network Disk */ +#if HAVE_HASMNTOPT && !(defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7)) + /* + * hasmntopt takes "const struct mntent*", but HRFS_entry has been + * defined differently for AIX, so skip this for AIX + */ + else if (hasmntopt(HRFS_entry, "loop") != NULL) + storage_type_id[storage_type_len - 1] = 5; /* Removable Disk */ +#endif + else + storage_type_id[storage_type_len - 1] = 4; /* Assume fixed */ + else + switch (store_idx) { + case NETSNMP_MEM_TYPE_PHYSMEM: + case NETSNMP_MEM_TYPE_USERMEM: + storage_type_id[storage_type_len - 1] = 2; /* RAM */ + break; + case NETSNMP_MEM_TYPE_VIRTMEM: + case NETSNMP_MEM_TYPE_SWAP: + storage_type_id[storage_type_len - 1] = 3; /* Virtual Mem */ + break; + default: + storage_type_id[storage_type_len - 1] = 1; /* Other */ + break; + } + *var_len = sizeof(storage_type_id); + return (u_char *) storage_type_id; + case HRSTORE_DESCR: + if (store_idx > NETSNMP_MEM_TYPE_MAX) { + strlcpy(string, HRFS_entry->HRFS_mount, sizeof(string)); + *var_len = strlen(string); + return (u_char *) string; + } else { + if ( !mem || !mem->descr ) + goto try_next; + *var_len = strlen(mem->descr); + return (u_char *) mem->descr; + } + case HRSTORE_UNITS: + if (store_idx > NETSNMP_MEM_TYPE_MAX) +#if HRFS_HAS_FRSIZE + long_return = stat_buf.f_frsize; +#else + long_return = stat_buf.f_bsize; +#endif + else { + if ( !mem || mem->units == -1 ) + goto try_next; + long_return = mem->units; + } + return (u_char *) & long_return; + case HRSTORE_SIZE: + if (store_idx > NETSNMP_MEM_TYPE_MAX) + long_return = stat_buf.f_blocks; + else { + if ( !mem || mem->size == -1 ) + goto try_next; + long_return = mem->size; + } + return (u_char *) & long_return; + case HRSTORE_USED: + if (store_idx > NETSNMP_MEM_TYPE_MAX) + long_return = (stat_buf.f_blocks - stat_buf.f_bfree); + else { + if ( !mem || mem->size == -1 || mem->free == -1 ) + goto try_next; + long_return = mem->size - mem->free; + } + return (u_char *) & long_return; + case HRSTORE_FAILS: + if (store_idx > NETSNMP_MEM_TYPE_MAX) +#if NETSNMP_NO_DUMMY_VALUES + goto try_next; +#else + long_return = 0; +#endif + else { + if ( !mem || mem->other == -1 ) + goto try_next; + long_return = mem->other; + } + return (u_char *) & long_return; + default: + DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_hrstore\n", + vp->magic)); + } + return NULL; + + try_next: + if (!exact) + goto really_try_next; + + return NULL; +} + + + /********************* + * + * Internal implementation functions + * + *********************/ + +static int HRS_index; + +void +Init_HR_Store(void) +{ + HRS_index = 0; + Init_HR_FileSys(); +} + +int +Get_Next_HR_Store(void) +{ + /* + * File-based storage + */ + for (;;) { + HRS_index = Get_Next_HR_FileSys(); + if (HRS_index >= 0) { + if (!(netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) && + Check_HR_FileSys_NFS())) { + return HRS_index + NETSNMP_MEM_TYPE_MAX; + } + } else { + return -1; + } + } +} + +#if 0 +void +sol_get_swapinfo(int *totalP, int *usedP) +{ + struct anoninfo ainfo; + + if (swapctl(SC_AINFO, &ainfo) < 0) { + *totalP = *usedP = 0; + return; + } + + *totalP = ainfo.ani_max; + *usedP = ainfo.ani_resv; +} +#endif /* solaris2 */ + +#ifdef WIN32 +char *win_realpath(const char *file_name, char *resolved_name) +{ + char szFile[_MAX_PATH + 1]; + char *pszRet; + + pszRet = _fullpath(szFile, resolved_name, MAX_PATH); + + return pszRet; +} + +static int win_statfs (const char *path, struct win_statfs *buf) +{ + HINSTANCE h; + FARPROC f; + int retval = 0; + char tmp [MAX_PATH], resolved_path [MAX_PATH]; + GetFullPathName(path, MAX_PATH, resolved_path, NULL); + /* TODO - Fix this! The realpath macro needs defined + * or rewritten into the function. + */ + + win_realpath(path, resolved_path); + + if (!resolved_path) + retval = - 1; + else { + /* check whether GetDiskFreeSpaceExA is supported */ + h = LoadLibraryA ("kernel32.dll"); + if (h) + f = GetProcAddress (h, "GetDiskFreeSpaceExA"); + else + f = NULL; + + if (f) { + ULARGE_INTEGER bytes_free, bytes_total, bytes_free2; + if (!f (resolved_path, &bytes_free2, &bytes_total, &bytes_free)) { + errno = ENOENT; + retval = - 1; + } else { + buf -> f_bsize = FAKED_BLOCK_SIZE; + buf -> f_bfree = (bytes_free.QuadPart) / FAKED_BLOCK_SIZE; + buf -> f_files = buf -> f_blocks = (bytes_total.QuadPart) / FAKED_BLOCK_SIZE; + buf -> f_ffree = buf -> f_bavail = (bytes_free2.QuadPart) / FAKED_BLOCK_SIZE; + } + } else { + DWORD sectors_per_cluster, bytes_per_sector; + if (h) FreeLibrary (h); + if (!GetDiskFreeSpaceA (resolved_path, §ors_per_cluster, + &bytes_per_sector, &buf -> f_bavail, &buf -> f_blocks)) { + errno = ENOENT; + retval = - 1; + } else { + buf -> f_bsize = sectors_per_cluster * bytes_per_sector; + buf -> f_files = buf -> f_blocks; + buf -> f_ffree = buf -> f_bavail; + buf -> f_bfree = buf -> f_bavail; + } + } + if (h) FreeLibrary (h); + } + + /* get the FS volume information */ + if (strspn (":", resolved_path) > 0) resolved_path [3] = '\0'; /* we want only the root */ + if (GetVolumeInformation (resolved_path, NULL, 0, &buf -> f_fsid, &buf -> f_namelen, + NULL, tmp, MAX_PATH)) { + if (strcasecmp ("NTFS", tmp) == 0) { + buf -> f_type = NTFS_SUPER_MAGIC; + } else { + buf -> f_type = MSDOS_SUPER_MAGIC; + } + } else { + errno = ENOENT; + retval = - 1; + } + return retval; +} +#endif /* WIN32 */ diff --git a/agent/mibgroup/host/hrh_filesys.c b/agent/mibgroup/host/hrh_filesys.c index 5ad82b2..5bdf02b 100644 --- a/agent/mibgroup/host/hrh_filesys.c +++ b/agent/mibgroup/host/hrh_filesys.c @@ -429,3 +429,9 @@ Check_HR_FileSys_NFS (void) { return (HRFS_entry->flags & NETSNMP_FS_FLAG_REMOTE) ? 1 : 0; } + +int +Check_HR_FileSys_AutoFs (void) +{ + return (HRFS_entry->type == (NETSNMP_FS_TYPE_AUTOFS)) ? 1 : 0; +} diff --git a/agent/mibgroup/host/hrh_filesys.c.autofs-skip b/agent/mibgroup/host/hrh_filesys.c.autofs-skip new file mode 100644 index 0000000..5ad82b2 --- /dev/null +++ b/agent/mibgroup/host/hrh_filesys.c.autofs-skip @@ -0,0 +1,431 @@ +/* + * Host Resources MIB - File System device group implementation (HAL rewrite) - hrh_filesys.c + * + */ +/* Portions of this file are subject to the following copyright(s). See + * the Net-SNMP's COPYING file for more details and other copyrights + * that may apply: + */ +/* + * Portions of this file are copyrighted by: + * Copyright (C) 2007 Apple, Inc. All rights reserved. + * Use is subject to license terms specified in the COPYING file + * distributed with the Net-SNMP package. + */ + +#include +#include +#include +#include +#include +#include +#include "host_res.h" +#include "hrh_filesys.h" +#include "hrh_storage.h" +#include "hr_disk.h" +#include "hr_filesys.h" +#include + +#if HAVE_MNTENT_H +#include +#endif +#if HAVE_SYS_MNTENT_H +#include +#endif +#if HAVE_SYS_MNTTAB_H +#include +#endif +#if HAVE_SYS_STATVFS_H +#include +#endif +#if HAVE_SYS_VFS_H +#include +#endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef HAVE_SYS_MOUNT_H +#include +#endif + +#include +#if HAVE_STRING_H +#include +#endif +#if HAVE_STDLIB_H +#include +#endif + +#if defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7) +#include +#include +#include +#endif + +netsnmp_feature_require(date_n_time) +netsnmp_feature_require(ctime_to_timet) + +#define HRFS_MONOTONICALLY_INCREASING + + /********************* + * + * Kernel & interface information, + * and internal forward declarations + * + *********************/ +netsnmp_fsys_info *HRFS_entry; + +#define FULL_DUMP 0 +#define PART_DUMP 1 + +static u_char *when_dumped(char *filesys, int level, size_t * length); +int header_hrhfilesys(struct variable *, oid *, size_t *, int, + size_t *, WriteMethod **); + + /********************* + * + * Initialisation & common implementation functions + * + *********************/ + +#define HRFSYS_INDEX 1 +#define HRFSYS_MOUNT 2 +#define HRFSYS_RMOUNT 3 +#define HRFSYS_TYPE 4 +#define HRFSYS_ACCESS 5 +#define HRFSYS_BOOT 6 +#define HRFSYS_STOREIDX 7 +#define HRFSYS_FULLDUMP 8 +#define HRFSYS_PARTDUMP 9 + +struct variable4 hrfsys_variables[] = { + {HRFSYS_INDEX, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrhfilesys, 2, {1, 1}}, + {HRFSYS_MOUNT, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, + var_hrhfilesys, 2, {1, 2}}, + {HRFSYS_RMOUNT, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, + var_hrhfilesys, 2, {1, 3}}, + {HRFSYS_TYPE, ASN_OBJECT_ID, NETSNMP_OLDAPI_RONLY, + var_hrhfilesys, 2, {1, 4}}, + {HRFSYS_ACCESS, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrhfilesys, 2, {1, 5}}, + {HRFSYS_BOOT, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrhfilesys, 2, {1, 6}}, + {HRFSYS_STOREIDX, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrhfilesys, 2, {1, 7}}, + {HRFSYS_FULLDUMP, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, + var_hrhfilesys, 2, {1, 8}}, + {HRFSYS_PARTDUMP, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, + var_hrhfilesys, 2, {1, 9}}, +}; +oid hrfsys_variables_oid[] = { 1, 3, 6, 1, 2, 1, 25, 3, 8 }; + +void +init_hrh_filesys(void) +{ + REGISTER_MIB("host/hr_filesys", hrfsys_variables, variable4, + hrfsys_variables_oid); +} + +/* + * header_hrhfilesys(... + * 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 + * + */ + +int +header_hrhfilesys(struct variable *vp, + oid * name, + size_t * length, + int exact, size_t * var_len, WriteMethod ** write_method) +{ +#define HRFSYS_ENTRY_NAME_LENGTH 11 + oid newname[MAX_OID_LEN]; + int fsys_idx, LowIndex = -1; + int result; + + DEBUGMSGTL(("host/hr_filesys", "var_hrhfilesys: ")); + DEBUGMSGOID(("host/hr_filesys", name, *length)); + DEBUGMSG(("host/hr_filesys", " %d\n", exact)); + + memcpy((char *) newname, (char *) vp->name, vp->namelen * sizeof(oid)); + /* + * Find "next" file system entry + */ + + Init_HR_FileSys(); + for (;;) { + fsys_idx = Get_Next_HR_FileSys(); + if (fsys_idx == -1) + break; + newname[HRFSYS_ENTRY_NAME_LENGTH] = fsys_idx; + result = snmp_oid_compare(name, *length, newname, vp->namelen + 1); + if (exact && (result == 0)) { + LowIndex = fsys_idx; + break; + } + if ((!exact && (result < 0)) && + (LowIndex == -1 || fsys_idx < LowIndex)) { + LowIndex = fsys_idx; +#ifdef HRFS_MONOTONICALLY_INCREASING + break; +#endif + } + } + + if (LowIndex == -1) { + DEBUGMSGTL(("host/hr_filesys", "... index out of range\n")); + return (MATCH_FAILED); + } + + memcpy((char *) name, (char *) newname, + (vp->namelen + 1) * sizeof(oid)); + *length = vp->namelen + 1; + *write_method = NULL; + *var_len = sizeof(long); /* default to 'long' results */ + + DEBUGMSGTL(("host/hr_filesys", "... get filesys stats ")); + DEBUGMSGOID(("host/hr_filesys", name, *length)); + DEBUGMSG(("host/hr_filesys", "\n")); + + return LowIndex; +} + + +oid fsys_type_id[] = { 1, 3, 6, 1, 2, 1, 25, 3, 9, 1 }; /* hrFSOther */ +int fsys_type_len = + sizeof(fsys_type_id) / sizeof(fsys_type_id[0]); + + + + /********************* + * + * System specific implementation functions + * + *********************/ + + +u_char * +var_hrhfilesys(struct variable *vp, + oid * name, + size_t * length, + int exact, size_t * var_len, WriteMethod ** write_method) +{ + int fsys_idx; + static char *string; + + fsys_idx = + header_hrhfilesys(vp, name, length, exact, var_len, write_method); + if (fsys_idx == MATCH_FAILED) + return NULL; + + switch (vp->magic) { + case HRFSYS_INDEX: + long_return = fsys_idx; + return (u_char *) & long_return; + case HRFSYS_MOUNT: + free(string); + string = NULL; + *var_len = 0; + if (asprintf(&string, "%s", HRFS_entry->path) >= 0) + *var_len = strlen(string); + return (u_char *) string; + case HRFSYS_RMOUNT: + free(string); + if (HRFS_entry->flags & NETSNMP_FS_FLAG_REMOTE) { + if (asprintf(&string, "%s", HRFS_entry->device) < 0) + string = NULL; + } else { + string = strdup(""); + } + *var_len = string ? strlen(string) : 0; + return (u_char *) string; + + case HRFSYS_TYPE: + fsys_type_id[fsys_type_len - 1] = + (HRFS_entry->type > _NETSNMP_FS_TYPE_LOCAL ? + NETSNMP_FS_TYPE_OTHER : HRFS_entry->type); + *var_len = sizeof(fsys_type_id); + return (u_char *) fsys_type_id; + + case HRFSYS_ACCESS: + long_return = HRFS_entry->flags & NETSNMP_FS_FLAG_RONLY ? 2 : 1; + return (u_char *) & long_return; + case HRFSYS_BOOT: + long_return = HRFS_entry->flags & NETSNMP_FS_FLAG_BOOTABLE ? 1 : 2; + return (u_char *) & long_return; + case HRFSYS_STOREIDX: + long_return = fsys_idx + NETSNMP_MEM_TYPE_MAX; + return (u_char *) & long_return; + case HRFSYS_FULLDUMP: + return when_dumped(HRFS_entry->path, FULL_DUMP, var_len); + case HRFSYS_PARTDUMP: + return when_dumped(HRFS_entry->path, PART_DUMP, var_len); + default: + DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_hrhfilesys\n", + vp->magic)); + } + return NULL; +} + + + /********************* + * + * Internal implementation functions + * + *********************/ +static int HRFS_index; + +void +Init_HR_FileSys(void) +{ + netsnmp_cache *c = netsnmp_fsys_get_cache(); + netsnmp_cache_check_and_reload( c ); + + HRFS_entry = NULL; + HRFS_index = 0; +} + +int +Get_Next_HR_FileSys(void) +{ + if ( HRFS_entry ) { + HRFS_entry = netsnmp_fsys_get_next( HRFS_entry ); + } else { + HRFS_entry = netsnmp_fsys_get_first(); + } + /* Skip "inactive" entries */ + while ( HRFS_entry && !(HRFS_entry->flags & NETSNMP_FS_FLAG_ACTIVE)) + HRFS_entry = netsnmp_fsys_get_next( HRFS_entry ); + + HRFS_index = (HRFS_entry ? HRFS_entry->idx.oids[0] : -1 ); + return HRFS_index; +} + + + +static u_char * +when_dumped(char *filesys, int level, size_t * length) +{ + time_t dumpdate = 0, tmp; + FILE *dump_fp; + char line[1024]; + char *cp1, *cp2, *cp3; + + /* + * Look for the relevent entries in /etc/dumpdates + * + * This is complicated by the fact that disks are + * mounted using block devices, but dumps are + * done via the raw character devices. + * Thus the device names in /etc/dumpdates and + * /etc/mnttab don't match. + * These comparisons are therefore made using the + * final portion of the device name only. + */ + + if (*filesys == '\0') /* No filesystem name? */ + return date_n_time(NULL, length); + cp1 = strrchr(filesys, '/'); /* Find the last element of the current FS */ + + if (cp1 == NULL) + cp1 = filesys; + + if ((dump_fp = fopen("/etc/dumpdates", "r")) == NULL) + return date_n_time(NULL, length); + + while (fgets(line, sizeof(line), dump_fp) != NULL) { + cp2 = strchr(line, ' '); /* Start by looking at the device name only */ + if (cp2 != NULL) { + *cp2 = '\0'; + cp3 = strrchr(line, '/'); /* and find the last element */ + if (cp3 == NULL) + cp3 = line; + + if (strcmp(cp1, cp3) != 0) /* Wrong FS */ + continue; + + ++cp2; + while (isspace(0xFF & *cp2)) + ++cp2; /* Now find the dump level */ + + if (level == FULL_DUMP) { + if (*(cp2++) != '0') + continue; /* Not interested in partial dumps */ + while (isspace(0xFF & *cp2)) + ++cp2; + + dumpdate = ctime_to_timet(cp2); + fclose(dump_fp); + return date_n_time(&dumpdate, length); + } else { /* Partial Dump */ + if (*(cp2++) == '0') + continue; /* Not interested in full dumps */ + while (isspace(0xFF & *cp2)) + ++cp2; + + tmp = ctime_to_timet(cp2); + if (tmp > dumpdate) + dumpdate = tmp; /* Remember the 'latest' partial dump */ + } + } + } + + fclose(dump_fp); + + return date_n_time(&dumpdate, length); +} + + +#define RAW_DEVICE_PREFIX "/dev/rdsk" +#define COOKED_DEVICE_PREFIX "/dev/dsk" + +char * +cook_device(char *dev) +{ + static char cooked_dev[SNMP_MAXPATH+1]; + + if (!strncmp(dev, RAW_DEVICE_PREFIX, strlen(RAW_DEVICE_PREFIX))) { + strlcpy(cooked_dev, COOKED_DEVICE_PREFIX, sizeof(cooked_dev)); + strlcat(cooked_dev, dev + strlen(RAW_DEVICE_PREFIX), + sizeof(cooked_dev)); + } else { + strlcpy(cooked_dev, dev, sizeof(cooked_dev)); + } + + return cooked_dev; +} + + +int +Get_FSIndex(char *dev) +{ + netsnmp_fsys_info *fsys; + + fsys = netsnmp_fsys_by_device( dev, NETSNMP_FS_FIND_EXIST ); + return (fsys ? fsys->idx.oids[0] : -1 ); +} + +long +Get_FSSize(char *dev) +{ + netsnmp_fsys_info *fsys; + + fsys = netsnmp_fsys_by_device( dev, NETSNMP_FS_FIND_EXIST ); + if ( fsys ) + return netsnmp_fsys_size( fsys ); + else + return -1; +} + +int +Check_HR_FileSys_NFS (void) +{ + return (HRFS_entry->flags & NETSNMP_FS_FLAG_REMOTE) ? 1 : 0; +} diff --git a/agent/mibgroup/host/hrh_filesys.h b/agent/mibgroup/host/hrh_filesys.h index 568917e..c0f5d6e 100644 --- a/agent/mibgroup/host/hrh_filesys.h +++ b/agent/mibgroup/host/hrh_filesys.h @@ -10,6 +10,7 @@ extern void Init_HR_FileSys(void); extern FindVarMethod var_hrhfilesys; extern int Get_Next_HR_FileSys(void); extern int Check_HR_FileSys_NFS(void); +extern int Check_HR_FileSys_AutoFs(void); extern int Get_FSIndex(char *); extern long Get_FSSize(char *); /* Temporary */ diff --git a/agent/mibgroup/host/hrh_filesys.h.autofs-skip b/agent/mibgroup/host/hrh_filesys.h.autofs-skip new file mode 100644 index 0000000..568917e --- /dev/null +++ b/agent/mibgroup/host/hrh_filesys.h.autofs-skip @@ -0,0 +1,19 @@ +/* + * Host Resources MIB - file system device group interface (HAL rewrite) - hrh_filesys.h + * + */ +#ifndef _MIBGROUP_HRFSYS_H +#define _MIBGROUP_HRFSYS_H + +extern void init_hrh_filesys(void); +extern void Init_HR_FileSys(void); +extern FindVarMethod var_hrhfilesys; +extern int Get_Next_HR_FileSys(void); +extern int Check_HR_FileSys_NFS(void); + +extern int Get_FSIndex(char *); +extern long Get_FSSize(char *); /* Temporary */ + +config_exclude( host/hr_filesys ) + +#endif /* _MIBGROUP_HRFSYS_H */ diff --git a/agent/mibgroup/host/hrh_storage.c b/agent/mibgroup/host/hrh_storage.c index 8107669..490ae90 100644 --- a/agent/mibgroup/host/hrh_storage.c +++ b/agent/mibgroup/host/hrh_storage.c @@ -367,9 +367,10 @@ really_try_next: store_idx = name[ HRSTORE_ENTRY_NAME_LENGTH ]; if (HRFS_entry && store_idx > NETSNMP_MEM_TYPE_MAX && - netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + ((netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) && - Check_HR_FileSys_NFS()) + Check_HR_FileSys_NFS()) || + Check_HR_FileSys_AutoFs())) return NULL; if (store_idx <= NETSNMP_MEM_TYPE_MAX ) { mem = (netsnmp_memory_info*)ptr; @@ -508,7 +509,8 @@ Get_Next_HR_Store(void) if (HRS_index >= 0) { if (!(netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) && - Check_HR_FileSys_NFS())) { + Check_HR_FileSys_NFS()) && + !Check_HR_FileSys_AutoFs()) { return HRS_index + NETSNMP_MEM_TYPE_MAX; } } else { diff --git a/agent/mibgroup/host/hrh_storage.c.autofs-skip b/agent/mibgroup/host/hrh_storage.c.autofs-skip new file mode 100644 index 0000000..8107669 --- /dev/null +++ b/agent/mibgroup/host/hrh_storage.c.autofs-skip @@ -0,0 +1,519 @@ +/* + * Host Resources MIB - storage group implementation - hrh_storage.c + * + */ + +#include +#include +#include +#include +#include +#include "host_res.h" +#include "hrh_filesys.h" +#include "hrh_storage.h" +#include "hr_disk.h" +#include "hr_filesys.h" +#include + + +#include +#if HAVE_SYS_PARAM_H +#include +#endif +#if HAVE_UNISTD_H +#include +#endif +#if TIME_WITH_SYS_TIME +# ifdef WIN32 +# include +# include +# include +# else +# include +# endif +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + +#if HAVE_FCNTL_H +#include +#endif + +#if HAVE_STRING_H +#include +#else +#include +#endif + +#include + +#include +#include + +#define HRSTORE_MONOTONICALLY_INCREASING + + /********************* + * + * Kernel & interface information, + * and internal forward declarations + * + *********************/ + + +extern netsnmp_fsys_info *HRFS_entry; + +static void parse_storage_config(const char *, char *); + + /********************* + * + * Initialisation & common implementation functions + * + *********************/ +int Get_Next_HR_Store(void); +void Init_HR_Store(void); +void* header_hrstoreEntry(struct variable *, oid *, size_t *, + int, size_t *, WriteMethod **); +Netsnmp_Node_Handler handle_memsize; + + +#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 8 + +struct variable2 hrstore_variables[] = { + {HRSTORE_INDEX, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {1}}, + {HRSTORE_TYPE, ASN_OBJECT_ID, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {2}}, + {HRSTORE_DESCR, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {3}}, + {HRSTORE_UNITS, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {4}}, + {HRSTORE_SIZE, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {5}}, + {HRSTORE_USED, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {6}}, + {HRSTORE_FAILS, ASN_COUNTER, NETSNMP_OLDAPI_RONLY, + var_hrstore, 1, {7}} +}; +oid hrstore_variables_oid[] = { 1, 3, 6, 1, 2, 1, 25, 2 }; +oid hrMemorySize_oid[] = { 1, 3, 6, 1, 2, 1, 25, 2, 2 }; +oid hrStorageTable_oid[] = { 1, 3, 6, 1, 2, 1, 25, 2, 3, 1 }; + + +void +init_hrh_storage(void) +{ + char *appname; + + netsnmp_register_scalar( + netsnmp_create_handler_registration("host/hrMemorySize", handle_memsize, + hrMemorySize_oid, OID_LENGTH(hrMemorySize_oid), + HANDLER_CAN_RONLY)); + REGISTER_MIB("host/hr_storage", hrstore_variables, variable2, + hrStorageTable_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); + + netsnmp_ds_register_config(ASN_BOOLEAN, appname, "realStorageUnits", + NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_REALSTORAGEUNITS); + + 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 void +parse_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_hrstoreEntry(... + * 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 + * + */ + +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 + * should use the first row. + */ + if ( exact ) + return NULL; + netsnmp_memory_load(); + mem = netsnmp_memory_get_first( 0 ); + } + else { + /* + * Otherwise, retrieve the requested + * (or following) row as appropriate. + */ + if ( exact && *length > HRSTORE_ENTRY_NAME_LENGTH+1 ) + return NULL; /* Too long for a valid instance */ + idx = name[ HRSTORE_ENTRY_NAME_LENGTH ]; + if ( idx < NETSNMP_MEM_TYPE_MAX ) { + netsnmp_memory_load(); + mem = ( exact ? netsnmp_memory_get_byIdx( idx, 0 ) : + netsnmp_memory_get_next_byIdx( idx, 0 )); + } + } + + /* + * If this matched a memory-based entry, then + * update the OID parameter(s) for GETNEXT requests. + */ + if ( mem ) { + if ( !exact ) { + newname[ HRSTORE_ENTRY_NAME_LENGTH ] = mem->idx; + memcpy((char *) name, (char *) newname, + ((int) vp->namelen + 1) * sizeof(oid)); + *length = vp->namelen + 1; + } + } + /* + * If this didn't match a memory-based entry, + * then consider the disk-based storage. + */ + else { + Init_HR_Store(); + for (;;) { + storage_idx = Get_Next_HR_Store(); + DEBUGMSG(("host/hr_storage", "(index %d ....", storage_idx)); + if (storage_idx == -1) + break; + newname[HRSTORE_ENTRY_NAME_LENGTH] = storage_idx; + DEBUGMSGOID(("host/hr_storage", newname, *length)); + DEBUGMSG(("host/hr_storage", "\n")); + result = snmp_oid_compare(name, *length, newname, vp->namelen + 1); + if (exact && (result == 0)) { + LowIndex = storage_idx; + /* + * Save storage status information + */ + break; + } + if ((!exact && (result < 0)) && + (LowIndex == -1 || storage_idx < LowIndex)) { + LowIndex = storage_idx; + /* + * Save storage status information + */ +#ifdef HRSTORE_MONOTONICALLY_INCREASING + break; +#endif + } + } + if ( LowIndex != -1 ) { + if ( !exact ) { + newname[ HRSTORE_ENTRY_NAME_LENGTH ] = LowIndex; + memcpy((char *) name, (char *) newname, + ((int) vp->namelen + 1) * sizeof(oid)); + *length = vp->namelen + 1; + } + mem = (netsnmp_memory_info*)0xffffffff; /* To indicate 'success' */ + } + } + + *write_method = (WriteMethod*)0; + *var_len = sizeof(long); /* default to 'long' results */ + + /* + * ... and return the appropriate row + */ + DEBUGMSGTL(("host/hr_storage", "var_hrstoreEntry: process ")); + DEBUGMSGOID(("host/hr_storage", name, *length)); + DEBUGMSG(("host/hr_storage", " (%p)\n", mem)); + return (void*)mem; +} + +oid storage_type_id[] = { 1, 3, 6, 1, 2, 1, 25, 2, 1, 1 }; /* hrStorageOther */ +int storage_type_len = + sizeof(storage_type_id) / sizeof(storage_type_id[0]); + + /********************* + * + * System specific implementation functions + * + *********************/ + +int +handle_memsize(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, + netsnmp_request_info *requests) +{ + netsnmp_memory_info *mem_info; + int val; + + /* + * We just need to handle valid GET requests, as invalid instances + * are rejected automatically, and (valid) GETNEXT requests are + * converted into the appropriate GET request. + * + * We also only ever receive one request at a time. + */ + switch (reqinfo->mode) { + case MODE_GET: + netsnmp_memory_load(); + mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_PHYSMEM, 0 ); + if ( !mem_info || mem_info->size == -1 || mem_info->units == -1 ) + netsnmp_set_request_error( reqinfo, requests, SNMP_NOSUCHOBJECT ); + else { + val = mem_info->size; /* memtotal */ + val *= (mem_info->units/1024); + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&val, sizeof(val)); + } + return SNMP_ERR_NOERROR; + + default: + /* + * we should never get here, so this is a really bad error + */ + snmp_log(LOG_ERR, "unknown mode (%d) in handle_memsize\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; +} + + +u_char * +var_hrstore(struct variable *vp, + oid * name, + size_t * length, + int exact, size_t * var_len, WriteMethod ** write_method) +{ + int store_idx = 0; + static char string[1024]; + void *ptr; + netsnmp_memory_info *mem = NULL; + +really_try_next: + ptr = header_hrstoreEntry(vp, name, length, exact, var_len, + write_method); + if (ptr == NULL) + return NULL; + + store_idx = name[ HRSTORE_ENTRY_NAME_LENGTH ]; + if (HRFS_entry && + store_idx > NETSNMP_MEM_TYPE_MAX && + netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) && + Check_HR_FileSys_NFS()) + return NULL; + if (store_idx <= NETSNMP_MEM_TYPE_MAX ) { + mem = (netsnmp_memory_info*)ptr; + } + + + + switch (vp->magic) { + case HRSTORE_INDEX: + long_return = store_idx; + return (u_char *) & long_return; + case HRSTORE_TYPE: + if (store_idx > NETSNMP_MEM_TYPE_MAX) + if (HRFS_entry->flags & NETSNMP_FS_FLAG_REMOTE && storageUseNFS) + storage_type_id[storage_type_len - 1] = 10; /* Network Disk */ + else if (HRFS_entry->flags & NETSNMP_FS_FLAG_REMOVE ) + storage_type_id[storage_type_len - 1] = 5; /* Removable Disk */ + else + storage_type_id[storage_type_len - 1] = 4; /* Assume fixed */ + else + switch (store_idx) { + case NETSNMP_MEM_TYPE_PHYSMEM: + case NETSNMP_MEM_TYPE_USERMEM: + storage_type_id[storage_type_len - 1] = 2; /* RAM */ + break; + case NETSNMP_MEM_TYPE_VIRTMEM: + case NETSNMP_MEM_TYPE_SWAP: + storage_type_id[storage_type_len - 1] = 3; /* Virtual Mem */ + break; + default: + storage_type_id[storage_type_len - 1] = 1; /* Other */ + break; + } + *var_len = sizeof(storage_type_id); + return (u_char *) storage_type_id; + case HRSTORE_DESCR: + if (store_idx > NETSNMP_MEM_TYPE_MAX) { + strlcpy(string, HRFS_entry->path, sizeof(string)); + *var_len = strlen(string); + return (u_char *) string; + } else { + if ( !mem || !mem->descr ) + goto try_next; + *var_len = strlen(mem->descr); + return (u_char *) mem->descr; + } + case HRSTORE_UNITS: + if (store_idx > NETSNMP_MEM_TYPE_MAX) { + if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_REALSTORAGEUNITS)) + long_return = HRFS_entry->units & 0x7fffffff; + else + long_return = HRFS_entry->units_32; + } else { + if ( !mem || mem->units == -1 ) + goto try_next; + long_return = mem->units & 0x7fffffff; + } + return (u_char *) & long_return; + case HRSTORE_SIZE: + if (store_idx > NETSNMP_MEM_TYPE_MAX) { + if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_REALSTORAGEUNITS)) + long_return = HRFS_entry->size & 0x7fffffff; + else + long_return = HRFS_entry->size_32; + } else { + if ( !mem || mem->size == -1 ) + goto try_next; + long_return = mem->size & 0x7fffffff; + } + return (u_char *) & long_return; + case HRSTORE_USED: + if (store_idx > NETSNMP_MEM_TYPE_MAX) { + if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_REALSTORAGEUNITS)) + long_return = HRFS_entry->used & 0x7fffffff; + else + long_return = HRFS_entry->used_32; + } else { + if ( !mem || mem->size == -1 || mem->free == -1 ) + goto try_next; + long_return = (mem->size - mem->free) & 0x7fffffff; + } + return (u_char *) & long_return; + case HRSTORE_FAILS: + if (store_idx > NETSNMP_MEM_TYPE_MAX) +#if NETSNMP_NO_DUMMY_VALUES + goto try_next; +#else + long_return = 0; +#endif + else { + if ( !mem || mem->other == -1 ) + goto try_next; + long_return = mem->other; + } + return (u_char *) & long_return; + default: + DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_hrstore\n", + vp->magic)); + } + return NULL; + + try_next: + if (!exact) + goto really_try_next; + + return NULL; +} + + + /********************* + * + * Internal implementation functions + * + *********************/ + +static int HRS_index; + +void +Init_HR_Store(void) +{ + HRS_index = 0; + Init_HR_FileSys(); +} + +int +Get_Next_HR_Store(void) +{ + /* + * File-based storage + */ + for (;;) { + HRS_index = Get_Next_HR_FileSys(); + if (HRS_index >= 0) { + if (!(netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) && + Check_HR_FileSys_NFS())) { + return HRS_index + NETSNMP_MEM_TYPE_MAX; + } + } else { + return -1; + } + } +} + diff --git a/include/net-snmp/agent/hardware/fsys.h b/include/net-snmp/agent/hardware/fsys.h index 3f2b284..21235c0 100644 --- a/include/net-snmp/agent/hardware/fsys.h +++ b/include/net-snmp/agent/hardware/fsys.h @@ -41,6 +41,7 @@ typedef struct netsnmp_fsys_info_s netsnmp_fsys_info; #define NETSNMP_FS_TYPE_SYSFS (4 | _NETSNMP_FS_TYPE_LOCAL | _NETSNMP_FS_TYPE_SKIP_BIT) #define NETSNMP_FS_TYPE_TMPFS (5 | _NETSNMP_FS_TYPE_LOCAL) #define NETSNMP_FS_TYPE_USBFS (6 | _NETSNMP_FS_TYPE_LOCAL) +#define NETSNMP_FS_TYPE_AUTOFS (7 | _NETSNMP_FS_TYPE_LOCAL | _NETSNMP_FS_TYPE_SKIP_BIT) #define NETSNMP_FS_FLAG_ACTIVE 0x01 #define NETSNMP_FS_FLAG_REMOTE 0x02 diff --git a/include/net-snmp/agent/hardware/fsys.h.autofs-skip b/include/net-snmp/agent/hardware/fsys.h.autofs-skip new file mode 100644 index 0000000..3f2b284 --- /dev/null +++ b/include/net-snmp/agent/hardware/fsys.h.autofs-skip @@ -0,0 +1,109 @@ +typedef struct netsnmp_fsys_info_s netsnmp_fsys_info; + +#define _NETSNMP_FS_TYPE_SKIP_BIT 0x2000 +#define _NETSNMP_FS_TYPE_LOCAL 0x1000 + + /* + * Enumeration from HOST-RESOURCES-TYPES mib + */ +#define NETSNMP_FS_TYPE_OTHER 1 +#define NETSNMP_FS_TYPE_UNKNOWN 2 +#define NETSNMP_FS_TYPE_BERKELEY 3 +#define NETSNMP_FS_TYPE_SYSV 4 +#define NETSNMP_FS_TYPE_FAT 5 +#define NETSNMP_FS_TYPE_HPFS 6 +#define NETSNMP_FS_TYPE_HFS 7 +#define NETSNMP_FS_TYPE_MFS 8 +#define NETSNMP_FS_TYPE_NTFS 9 +#define NETSNMP_FS_TYPE_VNODE 10 +#define NETSNMP_FS_TYPE_JFS 11 +#define NETSNMP_FS_TYPE_ISO9660 12 +#define NETSNMP_FS_TYPE_ROCKRIDGE 13 +#define NETSNMP_FS_TYPE_NFS 14 +#define NETSNMP_FS_TYPE_NETWARE 15 +#define NETSNMP_FS_TYPE_AFS 16 +#define NETSNMP_FS_TYPE_DFS 17 +#define NETSNMP_FS_TYPE_APPLESHARE 18 +#define NETSNMP_FS_TYPE_RFS 19 +#define NETSNMP_FS_TYPE_DGCS 20 +#define NETSNMP_FS_TYPE_BOOTFS 21 +#define NETSNMP_FS_TYPE_FAT32 22 +#define NETSNMP_FS_TYPE_EXT2 23 + + /* + * Additional enumerationis - not listed in that MIB + */ +#define NETSNMP_FS_TYPE_IGNORE (1 | _NETSNMP_FS_TYPE_LOCAL | _NETSNMP_FS_TYPE_SKIP_BIT) + +#define NETSNMP_FS_TYPE_PROC (2 | _NETSNMP_FS_TYPE_LOCAL | _NETSNMP_FS_TYPE_SKIP_BIT) + +#define NETSNMP_FS_TYPE_DEVPTS (3 | _NETSNMP_FS_TYPE_LOCAL | _NETSNMP_FS_TYPE_SKIP_BIT) +#define NETSNMP_FS_TYPE_SYSFS (4 | _NETSNMP_FS_TYPE_LOCAL | _NETSNMP_FS_TYPE_SKIP_BIT) +#define NETSNMP_FS_TYPE_TMPFS (5 | _NETSNMP_FS_TYPE_LOCAL) +#define NETSNMP_FS_TYPE_USBFS (6 | _NETSNMP_FS_TYPE_LOCAL) + +#define NETSNMP_FS_FLAG_ACTIVE 0x01 +#define NETSNMP_FS_FLAG_REMOTE 0x02 +#define NETSNMP_FS_FLAG_RONLY 0x04 +#define NETSNMP_FS_FLAG_BOOTABLE 0x08 +#define NETSNMP_FS_FLAG_REMOVE 0x10 +#define NETSNMP_FS_FLAG_UCD 0x20 + +#define NETSNMP_FS_FIND_CREATE 1 /* or use one of the type values */ +#define NETSNMP_FS_FIND_EXIST 0 + +struct netsnmp_fsys_info_s { + netsnmp_index idx; + /* int idx; */ + + char path[ SNMP_MAXPATH+1]; + char device[SNMP_MAXPATH+1]; + int type; + + unsigned long long size; + unsigned long long used; + unsigned long long avail; + unsigned long long units; + + /* artificially computed values, both 'size_32' and 'units_32' fit INT32 */ + unsigned long size_32; + unsigned long used_32; + unsigned long avail_32; + unsigned long units_32; + + unsigned long long inums_total; + unsigned long long inums_avail; + + int minspace; + int minpercent; + + long flags; + + netsnmp_fsys_info *next; +}; + + + /* + * Possibly not all needed ?? + */ +netsnmp_fsys_info *netsnmp_fsys_get_first( void ); +netsnmp_fsys_info *netsnmp_fsys_get_next( netsnmp_fsys_info* ); +netsnmp_fsys_info *netsnmp_fsys_get_byIdx( int, int ); +netsnmp_fsys_info *netsnmp_fsys_get_next_byIdx(int,int ); + +netsnmp_fsys_info *netsnmp_fsys_by_device( char*, int ); +netsnmp_fsys_info *netsnmp_fsys_by_path( char*, int ); + +netsnmp_cache *netsnmp_fsys_get_cache( void ); +int netsnmp_fsys_load( netsnmp_cache *cache, void *data ); +void netsnmp_fsys_free( netsnmp_cache *cache, void *data ); + +int netsnmp_fsys_size( netsnmp_fsys_info* ); +int netsnmp_fsys_used( netsnmp_fsys_info* ); +int netsnmp_fsys_avail(netsnmp_fsys_info* ); + +unsigned long long netsnmp_fsys_size_ull( netsnmp_fsys_info* ); +unsigned long long netsnmp_fsys_used_ull( netsnmp_fsys_info* ); +unsigned long long netsnmp_fsys_avail_ull(netsnmp_fsys_info* ); + +void netsnmp_fsys_calculate32( netsnmp_fsys_info *f);