Regarding Debian Bug#708397:  nut: APC SNMP set value does not work (wrong mib type declarations)
 
Here are the patches that work for APC Smart-UPS with APC AP9617 / SNMP.
After applying the patches the UPS accepts and holds the values that are written to the UPS (string, int and tick values) via SNMP.
 
I would be happy if someone could review the changes and possibly incorporate them into nut.
 
-lutzn
 
 
--- apc-mib.c    2012-05-30 22:42:42.000000000 +0200
+++ apc-mib.c.new    2013-05-16 11:33:54.000000000 +0200
@@ -25,7 +25,7 @@
 
 #include "apc-mib.h"
 
-#define APCC_MIB_VERSION    "1.1"
+#define APCC_MIB_VERSION    "1.2"
 
 /* Other APC sysOID:
  *
@@ -166,12 +166,12 @@
     { "ups.temperature", 0, 1, ".1.3.6.1.4.1.318.1.1.1.2.2.2.0", "", SU_FLAG_OK, NULL },
     { "ups.load", 0, 1, ".1.3.6.1.4.1.318.1.1.1.4.2.3.0", "", SU_FLAG_OK, NULL },
     { "ups.firmware", ST_FLAG_STRING, 16, ".1.3.6.1.4.1.318.1.1.1.1.2.1.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL },
-    { "ups.delay.shutdown", ST_FLAG_STRING | ST_FLAG_RW, 3, ".1.3.6.1.4.1.318.1.1.1.5.2.10.0", "", SU_FLAG_OK, NULL },
-    { "ups.delay.start", ST_FLAG_STRING | ST_FLAG_RW, 3, ".1.3.6.1.4.1.318.1.1.1.5.2.9.0", "", SU_FLAG_OK, NULL },
+    { "ups.delay.shutdown", ST_FLAG_STRING | ST_FLAG_RW, 3, ".1.3.6.1.4.1.318.1.1.1.5.2.10.0", "", SU_TYPE_TIME | SU_FLAG_OK, NULL },
+    { "ups.delay.start", ST_FLAG_STRING | ST_FLAG_RW, 3, ".1.3.6.1.4.1.318.1.1.1.5.2.9.0", "", SU_TYPE_TIME | SU_FLAG_OK, NULL },
     { "battery.charge", 0, 1, ".1.3.6.1.4.1.318.1.1.1.2.2.1.0", "", SU_FLAG_OK, NULL },
     { "battery.charge.restart", ST_FLAG_STRING | ST_FLAG_RW, 3, ".1.3.6.1.4.1.318.1.1.1.5.2.6.0", "", SU_TYPE_INT | SU_FLAG_OK, NULL },
     { "battery.runtime", 0, 1, ".1.3.6.1.4.1.318.1.1.1.2.2.3.0", "", SU_FLAG_OK, NULL },
-    { "battery.runtime.low", ST_FLAG_STRING | ST_FLAG_RW, 3, ".1.3.6.1.4.1.318.1.1.1.5.2.8.0", "", SU_FLAG_OK, NULL },
+    { "battery.runtime.low", ST_FLAG_STRING | ST_FLAG_RW, 3, ".1.3.6.1.4.1.318.1.1.1.5.2.8.0", "", SU_TYPE_TIME | SU_FLAG_OK, NULL },
     { "battery.voltage", 0, 1, ".1.3.6.1.4.1.318.1.1.1.2.2.8.0", "", SU_FLAG_OK, NULL },
     { "battery.voltage.nominal", 0, 1, ".1.3.6.1.4.1.318.1.1.1.2.2.7.0", "", SU_FLAG_OK, NULL },
     { "battery.current", 0, 1, ".1.3.6.1.4.1.318.1.1.1.2.2.9.0", "", SU_FLAG_OK, NULL },
--- snmp-ups.c    2012-05-15 16:37:00.000000000 +0200
+++ snmp-ups.c.new    2013-05-16 11:32:28.000000000 +0200
@@ -91,7 +91,7 @@
 static void disable_transfer_oids(void);
 
 #define DRIVER_NAME    "Generic SNMP UPS driver"
-#define DRIVER_VERSION        "0.66"
+#define DRIVER_VERSION        "0.67"
 
 /* driver description structure */
 upsdrv_info_t    upsdrv_info = {
@@ -683,7 +683,7 @@
 {
     char buf[SU_BUFSIZE];
 
-    snprintf(buf, SU_BUFSIZE, "%ld", value * 100);
+    snprintf(buf, sizeof(buf), "%ld", value * 100);
     return nut_snmp_set(OID, 't', buf);
 }
 
@@ -1460,7 +1460,7 @@
     }
 
     /* set value into the device */
-    if (su_info_p->info_flags & ST_FLAG_STRING) {
+    if (SU_TYPE(su_info_p) == SU_TYPE_STRING) {
         status = nut_snmp_set_str(su_info_p->OID, val);
     } else {
         /* non string data may imply a value lookup */
@@ -1471,7 +1471,7 @@
             value = strtol(val, NULL, 0);
         }
         /* Actually apply the new value */
-        status = nut_snmp_set_int(su_info_p->OID, value);
+        status = (SU_TYPE(su_info_p) == SU_TYPE_TIME) ? nut_snmp_set_time(su_info_p->OID, value) : nut_snmp_set_int(su_info_p->OID, value);
     }
 
     if (status == FALSE)
 
 
 
Ok, now I saw that it is far from complete.  nut does only support snmp types 's' and 'i' when writing.  nut does not support type 't'.  So no timeticks such as delays can be set on an AP9617.  Maybe other cards do no type checking...
This means snmp-ups.c and apc-mib.c need to be changed.  And maybe other mib files, too.
So, is it by design that timeticks/delays cannot be set?
-lutzn
 
I changed one line only:
 
line 1463 in snmp-ups.c:
from:  if (su_info_p->info_flags & ST_FLAG_STRING) {
to:      if (su_info_p->flags & SU_TYPE_STRING) {
 
Can anyone please verify!
 
Because if it is true what I did then I believe that setting values might not have worked for any snmp ups.
And believe that this cannot be.  But with this change setting values now work with AP9617.  snmp-lib does not generate "" anymore.  Strange...
 
The other problem with the ups not shutting down is still open.
 
-lutzn
 
 
 
> I will post the changed apc-mib.c here. Ok? Or shall I send it to someone else?

This list is fine. Would you please post a unified diff (diff -u) instead of the whole file?

Thanks,

--
Charles Lepple
clepple@gmail


 
_______________________________________________
Nut-upsuser mailing list
Nut-upsuser@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser

Reply via email to