[Nut-upsdev] [PATCH 11/36] Fix sysOID matching to work properly, and fix "apcc" MIB.

Greg A. Woods woods at planix.com
Thu Mar 8 23:21:22 UTC 2012


From: "Greg A. Woods" <woods at planix.com>

The APC POWERNET MIB will match all valid sysOIDs with a partial match
at the "products.system" level.  Update the "apcc" MIB to reflect this
and fix the sysOID comparison code in the driver to match any given
sysOID against the tree rooted at the sysOID given in the MIB info.
---
 drivers/apc-mib.c  |   22 ++++++++++++----------
 drivers/snmp-ups.c |    4 ++--
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/apc-mib.c b/drivers/apc-mib.c
index 6b44fd6..30a0ebb 100644
--- a/drivers/apc-mib.c
+++ b/drivers/apc-mib.c
@@ -27,16 +27,17 @@
 
 #define APCC_MIB_VERSION	"1.1"
 
-/* Other APC sysOID:
- * 
- * examples found on the Net and other sources:
- *   'enterprises.apc.products.system.smartUPS.smartUPS700'
- *   '.1.3.6.1.4.1.318.1.3.4.5': ApcRPDU,
- *   '.1.3.6.1.4.1.318.1.3.4.4': ApcMSP
- */
+/* enterprises.apc */
+/* APC PowerNet-MIB */
+#define APCC_MIB_BASE_OID	".1.3.6.1.4.1.318"
+
+/* enterprises.apc.products.system */
+/* PowerNet-MIB, root of "products.system" OID tree */
+#define APCC_MIB_sysOID		APCC_MIB_BASE_OID ".1.3"
 
-/* TODO: find the right sysOID for this MIB 
- * Ie ".1.3.6.1.4.1.318.1.1.1" or ".1.3.6.1.4.1.318" or? */
+/* enterprises.apc.products.hardware.ups.upsIdent.upsBasicIdent.upsBasicIdentModel.0 */
+/* PowerNet-MIB::upsBasicIdentModel.0 */
+#define APCC_OID_MODEL_NAME	APCC_MIB_BASE_OID ".1.1.1.1.1.1.0"
 
 /* info elements */
 
@@ -249,7 +250,8 @@ static snmp_info_t apcc_mib[] = {
 	{ NULL, 0, 0, NULL, NULL, 0, NULL }
 };
 
-mib2nut_info_t	apc = { "apcc", APCC_MIB_VERSION, APCC_OID_POWER_STATUS, ".1.3.6.1.4.1.318.1.1.1.1.1.1.0", apcc_mib };
+/* XXX perhaps the name should be "apc-powernet" or something like that which is closer to the proper name of the MIB */
+mib2nut_info_t	apc = { "apcc", APCC_MIB_VERSION, APCC_OID_POWER_STATUS, APCC_OID_MODEL_NAME, apcc_mib, APCC_MIB_sysOID };
 
 /*
 vim:ts=4:sw=4:et:
diff --git a/drivers/snmp-ups.c b/drivers/snmp-ups.c
index 12eff77..a68c1c5 100644
--- a/drivers/snmp-ups.c
+++ b/drivers/snmp-ups.c
@@ -485,7 +485,7 @@ struct snmp_pdu *nut_snmp_get(const char *OID)
 	size_t name_len = MAX_OID_LEN;
 	static unsigned int numerr = 0;
 
-	upsdebugx(3, "nut_snmp_get(%s)", OID);
+	upsdebugx(3, "nut_snmp_get(\"%s\")", OID);
 
 	/* create and send request. */
 	if (!snmp_parse_oid(OID, name, &name_len)) {
@@ -862,7 +862,7 @@ mib2nut_info_t *match_sysoid()
 			}
 			/* Now compare these */
 			upsdebugx(1, "match_sysoid: comparing %s with %s", sysOID_buf, mib2nut[i]->sysOID);
-			if (!netsnmp_oid_equals(device_sysOID, device_sysOID_len, mib2nut_sysOID, mib2nut_sysOID_len))
+			if (!netsnmp_oid_is_subtree(mib2nut_sysOID, mib2nut_sysOID_len, device_sysOID, device_sysOID_len))
 			{
 				upsdebugx(2, "match_sysoid: sysOID matches MIB '%s'!", mib2nut[i]->mib_name);
 				return mib2nut[i];
-- 
1.7.9.2




More information about the Nut-upsdev mailing list