diff options
Diffstat (limited to 'usr.sbin/snmpd/mib.c')
-rw-r--r-- | usr.sbin/snmpd/mib.c | 99 |
1 files changed, 98 insertions, 1 deletions
diff --git a/usr.sbin/snmpd/mib.c b/usr.sbin/snmpd/mib.c index a24d916eea3..57d61b5ddcb 100644 --- a/usr.sbin/snmpd/mib.c +++ b/usr.sbin/snmpd/mib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mib.c,v 1.53 2012/05/26 14:45:55 joel Exp $ */ +/* $OpenBSD: mib.c,v 1.54 2012/06/14 17:31:32 matthew Exp $ */ /* * Copyright (c) 2012 Joel Knight <joel@openbsd.org> @@ -32,6 +32,7 @@ #include <sys/socket.h> #include <sys/mount.h> #include <sys/ioctl.h> +#include <sys/disk.h> #include <net/if.h> #include <net/if_types.h> @@ -3363,6 +3364,99 @@ mib_ipfroute(struct oid *oid, struct ber_oid *o, struct ber_element **elm) } /* + * Defined in UCD-DISKIO-MIB.txt. + */ + +int mib_diskio(struct oid *oid, struct ber_oid *o, struct ber_element **elm); + +static struct oid diskio_mib[] = { + { MIB(ucdDiskIOMIB), OID_MIB }, + { MIB(diskIOIndex), OID_TRD, mib_diskio }, + { MIB(diskIODevice), OID_TRD, mib_diskio }, + { MIB(diskIONRead), OID_TRD, mib_diskio }, + { MIB(diskIONWritten), OID_TRD, mib_diskio }, + { MIB(diskIOReads), OID_TRD, mib_diskio }, + { MIB(diskIOWrites), OID_TRD, mib_diskio }, + { MIB(diskIONReadX), OID_TRD, mib_diskio }, + { MIB(diskIONWrittenX), OID_TRD, mib_diskio }, + { MIBEND } +}; + +int +mib_diskio(struct oid *oid, struct ber_oid *o, struct ber_element **elm) +{ + struct ber_element *ber = *elm; + u_int32_t idx; + int mib[] = { CTL_HW, 0 }; + unsigned int diskcount; + struct diskstats *stats; + size_t len; + + len = sizeof(diskcount); + mib[1] = HW_DISKCOUNT; + if (sysctl(mib, sizeofa(mib), &diskcount, &len, NULL, 0) == -1) + return (-1); + + /* Get and verify the current row index */ + idx = o->bo_id[OIDIDX_diskIOEntry]; + if (idx > diskcount) + return (1); + + /* Tables need to prepend the OID on their own */ + o->bo_id[OIDIDX_diskIOEntry] = idx; + ber = ber_add_oid(ber, o); + + len = diskcount * sizeof(*stats); + stats = malloc(len); + if (stats == NULL) + return (-1); + mib[1] = HW_DISKSTATS; + if (sysctl(mib, sizeofa(mib), stats, &len, NULL, 0) == -1) { + free(stats); + return (-1); + } + + switch (o->bo_id[OIDIDX_diskIO]) { + case 1: /* diskIOIndex */ + ber = ber_add_integer(ber, idx); + break; + case 2: /* diskIODevice */ + ber = ber_add_string(ber, stats[idx - 1].ds_name); + break; + case 3: /* diskIONRead */ + ber = ber_add_integer(ber, (u_int32_t)stats[idx - 1].ds_rbytes); + ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER32); + break; + case 4: /* diskIONWritten */ + ber = ber_add_integer(ber, (u_int32_t)stats[idx - 1].ds_wbytes); + ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER32); + break; + case 5: /* diskIOReads */ + ber = ber_add_integer(ber, (u_int32_t)stats[idx - 1].ds_rxfer); + ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER32); + break; + case 6: /* diskIOWrites */ + ber = ber_add_integer(ber, (u_int32_t)stats[idx - 1].ds_wxfer); + ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER32); + break; + case 12: /* diskIONReadX */ + ber = ber_add_integer(ber, stats[idx - 1].ds_rbytes); + ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER64); + break; + case 13: /* diskIONWrittenX */ + ber = ber_add_integer(ber, stats[idx - 1].ds_wbytes); + ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER64); + break; + default: + free(stats); + return (-1); + } + + free(stats); + return (0); +} + +/* * Defined in BRIDGE-MIB.txt (rfc1493) * * This MIB is required by some NMS to accept the device because @@ -3453,6 +3547,9 @@ mib_init(void) /* BRIDGE-MIB */ smi_mibtree(bridge_mib); + /* UCD-DISKIO-MIB */ + smi_mibtree(diskio_mib); + /* OPENBSD-MIB */ smi_mibtree(openbsd_mib); } |