summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2008-03-10 11:02:33 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2008-03-10 11:02:33 +0000
commitfae6e9a4a1f4db2d450d1b938106490fb9acd722 (patch)
tree20aecc46c09bf00b4caba9bfe505650661de0603
parent47f9c2b05a540bc4501484482d1302df8d99cb90 (diff)
provide a partial implementation of the HOST-RESOURCES-MIB. this implements
the hrStorage part, which is enough to see how much space is used on your filesystems. makes my nms happy. ok reyk@
-rw-r--r--usr.sbin/snmpd/mib.c99
-rw-r--r--usr.sbin/snmpd/mib.h63
2 files changed, 160 insertions, 2 deletions
diff --git a/usr.sbin/snmpd/mib.c b/usr.sbin/snmpd/mib.c
index 4ec263a119a..fe48ae3aae0 100644
--- a/usr.sbin/snmpd/mib.c
+++ b/usr.sbin/snmpd/mib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mib.c,v 1.19 2008/01/30 10:12:45 reyk Exp $ */
+/* $OpenBSD: mib.c,v 1.20 2008/03/10 11:02:32 dlg Exp $ */
/*
* Copyright (c) 2007, 2008 Reyk Floeter <reyk@vantronix.net>
@@ -26,6 +26,7 @@
#include <sys/utsname.h>
#include <sys/sysctl.h>
#include <sys/sensors.h>
+#include <sys/mount.h>
#include <net/if.h>
#include <net/if_types.h>
@@ -319,6 +320,99 @@ mib_setsnmp(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
}
/*
+ * Defined in HOST-RESOURCES-MIB.txt (RFC 2790)
+ */
+
+int mib_hrmemory(struct oid *, struct ber_oid *, struct ber_element **);
+int mib_hrstorage(struct oid *, struct ber_oid *, struct ber_element **);
+
+static struct oid hr_mib[] = {
+ { MIB(host), OID_MIB },
+ { MIB(hrStorage), OID_MIB },
+ { MIB(hrMemorySize), OID_RD, mib_hrmemory },
+ { MIB(hrStorageIndex), OID_TRD, mib_hrstorage },
+ { MIB(hrStorageType), OID_TRD, mib_hrstorage },
+ { MIB(hrStorageDescr), OID_TRD, mib_hrstorage },
+ { MIB(hrStorageAllocationUnits), OID_TRD, mib_hrstorage },
+ { MIB(hrStorageSize), OID_TRD, mib_hrstorage },
+ { MIB(hrStorageUsed), OID_TRD, mib_hrstorage },
+ { MIB(hrStorageAllocationFailures), OID_TRD, mib_hrstorage },
+ { MIBEND }
+};
+
+int
+mib_hrmemory(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
+{
+ struct ber_element *ber = *elm;
+ int mib[] = { CTL_HW, HW_PHYSMEM64 };
+ size_t miblen = sizeof(mib) / sizeof(mib[0]);
+ u_int64_t physmem;
+ size_t len = sizeof(physmem);
+
+ if (sysctl(mib, miblen, &physmem, &len, NULL, 0) == -1)
+ return (-1);
+
+ ber = ber_add_integer(ber, physmem / 1024);
+
+ return (0);
+}
+
+int
+mib_hrstorage(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
+{
+ struct ber_element *ber = *elm;
+ static struct ber_oid so = { { MIB_hrStorageFixedDisk } };
+ u_int32_t idx;
+ struct statfs *mntbuf, *mnt;
+ int mntsize;
+
+ mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
+ if (mntsize == 0)
+ return (-1);
+
+ /* Get and verify the current row index */
+ idx = o->bo_id[OIDIDX_hrStorageEntry];
+ if ((int)idx > mntsize)
+ return (1);
+
+ /* Tables need to prepend the OID on their own */
+ o->bo_id[OIDIDX_hrStorageEntry] = idx;
+ ber = ber_add_oid(ber, o);
+
+ mnt = &mntbuf[idx - 1];
+
+ switch (o->bo_id[OIDIDX_hrStorage]) {
+ case 1: /* hrStorageIndex */
+ ber = ber_add_integer(ber, idx);
+ break;
+ case 2: /* hrStorageType */
+ smi_oidlen(&so);
+ ber = ber_add_oid(ber, &so);
+ break;
+ case 3: /* hrStorageDescr */
+ ber = ber_add_string(ber, mnt->f_mntonname);
+ break;
+ case 4: /* hrStorageAllocationUnits */
+ ber = ber_add_integer(ber, mnt->f_bsize);
+ break;
+ case 5: /* hrStorageSize */
+ ber = ber_add_integer(ber, mnt->f_blocks);
+ break;
+ case 6: /* hrStorageUsed */
+ ber = ber_add_integer(ber, mnt->f_blocks - mnt->f_bfree);
+ break;
+ case 7: /* hrStorageAllocationFailures */
+ ber = ber_add_integer(ber, 0);
+ ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER32);
+ break;
+ default:
+ return (-1);
+ }
+
+ return (0);
+}
+
+/*
* Defined in IF-MIB.txt (RFCs 1229, 1573, 2233, 2863)
*/
@@ -1343,6 +1437,9 @@ mib_init(void)
/* SNMPv2-MIB */
smi_mibtree(base_mib);
+ /* HOST-RESOURCES-MIB */
+ smi_mibtree(hr_mib);
+
/* IF-MIB */
smi_mibtree(if_mib);
diff --git a/usr.sbin/snmpd/mib.h b/usr.sbin/snmpd/mib.h
index 1639b6bff5f..c258be10b21 100644
--- a/usr.sbin/snmpd/mib.h
+++ b/usr.sbin/snmpd/mib.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mib.h,v 1.13 2008/01/21 23:56:39 reyk Exp $ */
+/* $OpenBSD: mib.h,v 1.14 2008/03/10 11:02:32 dlg Exp $ */
/*
* Copyright (c) 2007, 2008 Reyk Floeter <reyk@vantronix.net>
@@ -106,6 +106,45 @@
#define MIB_authenticationFailure MIB_snmpTraps, 5
#define MIB_egpNeighborLoss MIB_snmpTraps, 6
+/* HOST-RESOURCES-MIB */
+#define MIB_host MIB_mib_2, 25
+#define MIB_hrSystem MIB_host, 1
+#define MIB_hrSystemUptime MIB_hrSystem, 1
+#define MIB_hrSystemDate MIB_hrSystem, 2
+#define MIB_hrSystemInitialLoadDevice MIB_hrSystem, 3
+#define MIB_hrSystemInitialLoadParameters MIB_hrSystem, 4
+#define MIB_hrSystemNumUsers MIB_hrSystem, 5
+#define MIB_hrSystemProcesses MIB_hrSystem, 6
+#define MIB_hrSystemMaxProcesses MIB_hrSystem, 7
+#define MIB_hrStorage MIB_host, 2
+#define MIB_hrStorageTypes MIB_hrStorage, 1
+#define MIB_hrStorageOther MIB_hrStorageTypes, 1
+#define MIB_hrStorageRam MIB_hrStorageTypes, 2
+#define MIB_hrStorageVirtualMemory MIB_hrStorageTypes, 3
+#define MIB_hrStorageFixedDisk MIB_hrStorageTypes, 4
+#define MIB_hrStorageRemovableDisk MIB_hrStorageTypes, 5
+#define MIB_hrStorageFloppyDisk MIB_hrStorageTypes, 6
+#define MIB_hrStorageCompactDisc MIB_hrStorageTypes, 7
+#define MIB_hrStorageRamDisk MIB_hrStorageTypes, 8
+#define MIB_hrStorageFlashMemory MIB_hrStorageTypes, 9
+#define MIB_hrStorageNetworkDisk MIB_hrStorageTypes, 10
+#define MIB_hrMemorySize MIB_hrStorage, 2
+#define MIB_hrStorageTable MIB_hrStorage, 3
+#define MIB_hrStorageEntry MIB_hrStorageTable, 1
+#define OIDIDX_hrStorage 10
+#define OIDIDX_hrStorageEntry 11
+#define MIB_hrStorageIndex MIB_hrStorageEntry, 1
+#define MIB_hrStorageType MIB_hrStorageEntry, 2
+#define MIB_hrStorageDescr MIB_hrStorageEntry, 3
+#define MIB_hrStorageAllocationUnits MIB_hrStorageEntry, 4
+#define MIB_hrStorageSize MIB_hrStorageEntry, 5
+#define MIB_hrStorageUsed MIB_hrStorageEntry, 6
+#define MIB_hrStorageAllocationFailures MIB_hrStorageEntry, 7
+#define MIB_hrSWRun MIB_host, 4
+#define MIB_hrSWRunPerf MIB_host, 5
+#define MIB_hrSWInstalled MIB_host, 6
+#define MIB_hrMIBAdminInfo MIB_host, 7
+
/* IF-MIB */
#define MIB_ifMIB MIB_mib_2, 31
#define MIB_ifMIBObjects MIB_ifMIB, 1
@@ -373,6 +412,28 @@
{ MIBDECL(authenticationFailure) }, \
{ MIBDECL(egpNeighborLoss) }, \
\
+ { MIBDECL(host) }, \
+ { MIBDECL(hrSystem) }, \
+ { MIBDECL(hrSystemUptime) }, \
+ { MIBDECL(hrSystemDate) }, \
+ { MIBDECL(hrSystemInitialLoadDevice) }, \
+ { MIBDECL(hrSystemInitialLoadParameters) }, \
+ { MIBDECL(hrSystemNumUsers) }, \
+ { MIBDECL(hrSystemProcesses) }, \
+ { MIBDECL(hrSystemMaxProcesses) }, \
+ { MIBDECL(hrStorage) }, \
+ { MIBDECL(hrStorageTypes) }, \
+ { MIBDECL(hrMemorySize) }, \
+ { MIBDECL(hrStorageTable) }, \
+ { MIBDECL(hrStorageEntry) }, \
+ { MIBDECL(hrStorageIndex) }, \
+ { MIBDECL(hrStorageType) }, \
+ { MIBDECL(hrStorageDescr) }, \
+ { MIBDECL(hrStorageAllocationUnits) }, \
+ { MIBDECL(hrStorageSize) }, \
+ { MIBDECL(hrStorageUsed) }, \
+ { MIBDECL(hrStorageAllocationFailures) }, \
+ \
{ MIBDECL(ifMIB) }, \
{ MIBDECL(ifMIBObjects) }, \
{ MIBDECL(ifXTable) }, \