# HG changeset patch
# User Denis Chapligin <chol...@satgate.net>
# Date 1252489058 -10800
# Node ID 5d4dbc751c2141930af33adf6e5654282e339fa6
# Parent  3bd40c1bfba54a2d573ca2760c5bb784ce7bc3ef
Added support for different version of the MPC MIBs
Added README documentation
Outlet oids renamed to groups
Retrieval of number of groups is better documented now

diff -r 3bd40c1bfba5 -r 5d4dbc751c21 lib/plugins/stonith/README.wti_mpc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/plugins/stonith/README.wti_mpc        Wed Sep 09 12:37:38 2009 +0300
@@ -0,0 +1,85 @@
+STONITH module for WTI MPC
+--------------------------
+
+
+****Introduction.
+
+wti_mpc module uses snmp for controlling the MPC power distribution unit. It 
has
+been tested with MPC-8H and MPC-18H and should be compatible with the whole
+MPC series:
+    * MPC-20*
+    * MPC-16*
+    * MPC-18*
+    * MPC-8*
+    
+****Unit configuration.
+    
+wti_mpc STONITH modules uses SNMP v1, therefore it should be configured on the 
+device side. To do so, you should login to device, go to "Network 
+configuration" (/N), select "SNMP access" (25) and turn it on (enable/1). At 
the
+SNMP access screnn set "Version" (2) to "V1/V2 Only", set "Read only" (3) to
+"No and set any "Community" (10) you want. You may also set other options as
+you need. You may check your setup by ussuing the following command:
+
+    snmpwalk -v1 -c <community> <host> .1.3.6.1.2.1.1.1.0
+
+and result should be something like this:
+
+    SNMPv2-MIB::sysDescr.0 = STRING: Linux 85.195.135.236 2.4.18_mvl30-cllf 
#1991 Sun Mar 16 14:39:29 PST 2008 ppc
+    
+
+****Plugin configuration.
+
+    Plugin declares the following configuration variables:
+    
+    *ipaddr -     ip address or hostname of a MPC unit.
+    *port   -     ip port, should be 161, as MPC listens for incoming SNMP 
+                  packets on that port. It is made for future use actually.
+    *community -   Community that you've specified on previous step.
+    *mib_version - Should be 3 for MPC devices with firmware version 1.62
+                   and later. 1 is for firmware version 1.44 and below.
+                   2 is unused right now, if you have device, with mib V2 
+                   feel free to contact me and i'll add it.
+                   
+****MIB version issue
+
+    WTI guys have several time changed OIDs, used by MPC devices. I own two
+types of the devices:
+       *With firmware v 1.44 which is compatible with MIB version 1
+       *With firmware v 1.62 which is compatible with MIB version 3
+       
+I suppose there are exist MIB v2, but i cannot find it and i'm not able 
+to test it.
+Anyway, this plugin supports both V1 and V3 versions, and the correct version 
+is selected by the "mib-version" configuration parameter. Default value is "1",
+so if you do not specify this parameter or assign a unsupported value to it,
+it will fall back to mib version 1.
+
+****Outlets and groups
+
+    MPC devices forces uniqie names of the outlets. This is a big problem 
+for STONITH plugin, cause it uses nodes unames as outlet names, so in case
+you have a node with several power plugs, you should have set the node uname
+as name of all the plugs. The MPC device simply doesn't allows this. 
+    So, this plugin works with a GROUPS instead of a PLUGS. You may give
+any unique names for your physical outlets on the MPC, but you MUST create
+a plug group, name it using node's uname and include plugs, corresponding to
+that particular node to this group. It should be done even for node with
+single power supply. Some example:
+
+    Let's pretend you have a node "atest", with two power cords, connected
+to plugs A1 and B1. You have to create a group ("Plug grouping parameters" (/G)
+-> Add Plug Group to directory (2)), name it "atest" ("Plug Group Name (1)) and
+assugn plugs A1 and B1 to that group ("Plug access" (2)). Now save your
+configuration and try to retrieve host list:
+
+     stonith -t wti_mpc ipaddr=<host> port=161 community=<community>  
mib-version=<version> -l
+
+result should be: 
+    
+    atest
+    
+
+------------------
+(C) Denis Chapligin <chol...@satgate.net>, SatGate, 2009
+
diff -r 3bd40c1bfba5 -r 5d4dbc751c21 lib/plugins/stonith/wti_mpc.c
--- a/lib/plugins/stonith/wti_mpc.c     Tue Sep 08 12:26:49 2009 +0200
+++ b/lib/plugins/stonith/wti_mpc.c     Wed Sep 09 12:37:38 2009 +0300
@@ -1,5 +1,5 @@
 /*
- * Stonith module for APC Masterswitch (SNMP)
+ * Stonith module for WTI MPC (SNMP)
  * Copyright (c) 2001 Andreas Piesk <a.pi...@gmx.net>
  * Mangled by Sun Jiang Dong <su...@cn.ibm.com>, IBM, 2005
  * 
@@ -139,9 +139,12 @@
 
 /* oids */
 #define OID_IDENT                      ".1.3.6.1.2.1.1.5.0"
-#define OID_NUM_OUTLETS                        ".1.3.6.1.4.1.2634.3.1.3.1.2.%u"
-#define OID_OUTLET_NAMES               ".1.3.6.1.4.1.2634.3.1.3.1.2.%u"
-#define OID_OUTLET_STATE               ".1.3.6.1.4.1.2634.3.1.3.1.3.%i"
+
+#define OID_GROUP_NAMES_V1             ".1.3.6.1.4.1.2634.3.1.3.1.2.%u"
+#define OID_GROUP_STATE_V1             ".1.3.6.1.4.1.2634.3.1.3.1.3.%i"
+
+#define OID_GROUP_NAMES_V3             ".1.3.6.1.4.1.2634.3.100.300.1.2.%u"
+#define OID_GROUP_STATE_V3             ".1.3.6.1.4.1.2634.3.100.300.1.3.%i"
 
 #define MAX_OUTLETS 128
 
@@ -157,6 +160,7 @@
 /* own defines */
 #define MAX_STRING             128
 #define ST_PORT                        "port"
+#define ST_MIBVERSION          "mib-version"
 
 /* structur of stonith object */
 struct pluginDevice {
@@ -167,6 +171,7 @@
        char *                  hostname;       /* masterswitch's hostname  */
                                                /* or  ip addr          */
        int                     port;           /* snmp port            */
+       int                     mib_version;    /* mib version to use   */
        char *                  community;      /* snmp community (r/w) */
        int                     num_outlets;    /* number of outlets    */
 };
@@ -193,11 +198,28 @@
          XML_PORT_LONGDESC \
        XML_PARAMETER_END
 
+#define XML_MIBVERSION_SHORTDESC \
+       XML_PARM_SHORTDESC_BEGIN("en") \
+       ST_MIBVERSION \
+       XML_PARM_SHORTDESC_END
+
+#define XML_MIBVERSION_LONGDESC \
+       XML_MIBVERSION_LONGDESC_BEGIN("en") \
+       "Version number of MPC MIB that we should use. Valid values are 1 (for 
1.44 firmware) and 3 (for 1.62 firmware and later)" \
+       XML_PARM_LONGDESC_END
+
+#define XML_MIBVERSION_PARM \
+       XML_PARAMETER_BEGIN(ST_MIBVERSION, "string", "1") \
+         XML_PORT_SHORTDESC \
+         XML_PORT_LONGDESC \
+       XML_PARAMETER_END
+
 static const char *apcmastersnmpXML = 
   XML_PARAMETERS_BEGIN
     XML_IPADDR_PARM
     XML_PORT_PARM
     XML_COMMUNITY_PARM
+    XML_MIBVERSION_PARM
   XML_PARAMETERS_END;
 
 /*
@@ -444,7 +466,18 @@
     for (j = 0; j < ad->num_outlets; ++j) {
 
        /* prepare objname */
-       snprintf(objname, MAX_STRING, OID_OUTLET_NAMES, j + 1);
+       switch (ad->mib_version) {
+           case 3:
+                snprintf(objname,MAX_STRING,OID_GROUP_NAMES_V3,j+1);
+                break;
+            case 1:
+            default:
+                snprintf(objname,MAX_STRING,OID_GROUP_NAMES_V1,j+1);
+               break;
+       }
+       if (Debug) {
+           LOG(PIL_DEBUG, "%s: using %s as group names oid", __FUNCTION__, 
objname);
+       }
 
        /* read outlet name */
        if ((outlet_name = MPC_read(ad->sptr, objname, ASN_OCTET_STR)) ==
@@ -514,7 +547,15 @@
     for (outlet = 1; outlet <= ad->num_outlets; outlet++) {
 
        /* prepare objname */
-       snprintf(objname, MAX_STRING, OID_OUTLET_NAMES, outlet);
+       switch (ad->mib_version) {
+           case 3:
+                snprintf(objname,MAX_STRING,OID_GROUP_NAMES_V3,outlet);
+                break;
+            case 1:
+            default:
+                snprintf(objname,MAX_STRING,OID_GROUP_NAMES_V1,outlet);
+               break;
+       }
 
        /* read outlet name */
        if ((outlet_name = MPC_read(ad->sptr, objname, ASN_OCTET_STR))
@@ -567,7 +608,17 @@
     /* Turn them all off */
    
            /* prepare objnames */
-           snprintf(objname, MAX_STRING, OID_OUTLET_STATE, found_outlet);
+
+       switch (ad->mib_version) {
+           case 3:
+                snprintf(objname,MAX_STRING,OID_GROUP_STATE_V3,found_outlet);
+                break;
+            case 1:
+            default:
+                snprintf(objname,MAX_STRING,OID_GROUP_STATE_V1,found_outlet);
+               break;
+       }
+
            snprintf(value, MAX_STRING, "%i", req_oid);
 
            /* send reboot cmd */
@@ -588,7 +639,7 @@
 static const char **
 wti_mpc_get_confignames(StonithPlugin * s)
 {
-       static const char * ret[] = {ST_IPADDR, ST_PORT, ST_COMMUNITY, NULL};
+       static const char * ret[] = {ST_IPADDR, ST_PORT, ST_COMMUNITY, 
ST_MIBVERSION, NULL};
        return ret;
 }
 
@@ -608,6 +659,7 @@
        {       {ST_IPADDR,     NULL}
        ,       {ST_PORT,       NULL}
        ,       {ST_COMMUNITY,  NULL}
+       ,       {ST_MIBVERSION, NULL}
        ,       {NULL,          NULL}
        };
 
@@ -624,6 +676,8 @@
        sd->port = atoi(namestocopy[1].s_value);
        PluginImports->mfree(namestocopy[1].s_value);
        sd->community = namestocopy[2].s_value;
+       sd->mib_version = atoi(namestocopy[3].s_value);
+       PluginImports->mfree(namestocopy[3].s_value);
 
         /* try to resolve the hostname/ip-address */
        if (gethostbyname(sd->hostname) != NULL) {
@@ -633,11 +687,27 @@
                /* now try to get a snmp session */
                if ((sd->sptr = MPC_open(sd->hostname, sd->port, 
sd->community)) != NULL) {
 
-                       /* ok, get the number of outlets from the mpc */
+           /* ok, get the number of groups from the mpc */
             sd->num_outlets=0;
-            /* We scan goup name from 1 to MAX_OUTLETS */
+            /* We scan goup names table starting from 1 to MAX_OUTLETS */
+            /* and increase num_outlet counter on every group entry with name 
*/
+            /* first entry without name is the mark of the end of the group 
table */
             for (mo=1;mo<MAX_OUTLETS;mo++) {
-                snprintf(objname,MAX_STRING,OID_NUM_OUTLETS,mo);
+               switch (sd->mib_version) {
+                   case 3:
+                       snprintf(objname,MAX_STRING,OID_GROUP_NAMES_V3,mo);
+                       break;
+                   case 1:
+                   default:
+                       snprintf(objname,MAX_STRING,OID_GROUP_NAMES_V1,mo);
+                       break;
+               }
+
+               if (Debug) {
+                   LOG(PIL_DEBUG, "%s: used for groupTable retrieval: %s."
+                   ,   __FUNCTION__, objname);
+               }
+
                 if ((i = MPC_read(sd->sptr, objname, ASN_OCTET_STR)) == NULL) {
                     LOG(PIL_CRIT
                     , "%s: cannot read number of outlets."
@@ -777,6 +847,7 @@
        ad->sptr = NULL;
        ad->hostname = NULL;
        ad->community = NULL;
+       ad->mib_version=1;
        ad->idinfo = DEVICE;
        ad->sp.s_ops = &wti_mpcOps;
 
_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to