ソースを参照

1、完善了SNMP协议MIB库,增加了分组信息;
2、依据MIB库,重新生成了.c和.h开发文件(分为三类文件:标量、表格和Trap);
3、编写完成浪潮直流PDU的py接口调用文件。

liyuezong 2 年 前
親
コミット
899c4478c3

File diff suppressed because it is too large
+ 401 - 1
Liyuezong/SNMP协议设计/Gowone-SmartPDU-mib-V2c/GOWONE-SMARTPDU-MIB.mib


BIN
Liyuezong/SNMP协议设计/Gowone-SmartPDU-mib-V2c/GOWONE-SMARTPDU-MIB.smidb


+ 117 - 0
Liyuezong/SNMP协议设计/Gowone-SmartPDU-mib-V2c/agent代理开发的.c及.h文件/Trap调用代码/pduMIB.c

@@ -0,0 +1,117 @@
+/*
+ * Note: this file originally auto-generated by mib2c
+ * using mib2c.notify.conf
+ */
+
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/net-snmp-includes.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include "pduMIB.h"
+
+extern const oid snmptrap_oid[];
+extern const size_t snmptrap_oid_len;
+
+int
+send_pduAlarmAdded_trap( void )
+{
+    netsnmp_variable_list  *var_list = NULL;
+    const oid pduAlarmAdded_oid[] = { 1,3,6,1,4,1,2024,2,1 };
+    const oid pduAlarmType_oid[] = { 1,3,6,1,4,1,2024,1,6,1,1,2, /* insert index here */ };
+    const oid pduAlarmContext_oid[] = { 1,3,6,1,4,1,2024,1,6,1,1,3, /* insert index here */ };
+    const oid pduAlarmAction_oid[] = { 1,3,6,1,4,1,2024,1,6,1,1,4, /* insert index here */ };
+    const oid pduAlarmActionPara_oid[] = { 1,3,6,1,4,1,2024,1,6,1,1,5, /* insert index here */ };
+    const oid pduAlarmDate_oid[] = { 1,3,6,1,4,1,2024,1,6,1,1,6, /* insert index here */ };
+    const oid pduAlarmTime_oid[] = { 1,3,6,1,4,1,2024,1,6,1,1,7, /* insert index here */ };
+
+    /*
+     * Set the snmpTrapOid.0 value
+     */
+    snmp_varlist_add_variable(&var_list,
+        snmptrap_oid, snmptrap_oid_len,
+        ASN_OBJECT_ID,
+        pduAlarmAdded_oid, sizeof(pduAlarmAdded_oid));
+    
+    /*
+     * Add any objects from the trap definition
+     */
+    snmp_varlist_add_variable(&var_list,
+        pduAlarmType_oid, OID_LENGTH(pduAlarmType_oid),
+        ASN_INTEGER,
+        /* Set an appropriate value for pduAlarmType */
+        NULL, 0);
+    snmp_varlist_add_variable(&var_list,
+        pduAlarmContext_oid, OID_LENGTH(pduAlarmContext_oid),
+        ASN_OCTET_STR,
+        /* Set an appropriate value for pduAlarmContext */
+        NULL, 0);
+    snmp_varlist_add_variable(&var_list,
+        pduAlarmAction_oid, OID_LENGTH(pduAlarmAction_oid),
+        ASN_INTEGER,
+        /* Set an appropriate value for pduAlarmAction */
+        NULL, 0);
+    snmp_varlist_add_variable(&var_list,
+        pduAlarmActionPara_oid, OID_LENGTH(pduAlarmActionPara_oid),
+        ASN_INTEGER,
+        /* Set an appropriate value for pduAlarmActionPara */
+        NULL, 0);
+    snmp_varlist_add_variable(&var_list,
+        pduAlarmDate_oid, OID_LENGTH(pduAlarmDate_oid),
+        ASN_OCTET_STR,
+        /* Set an appropriate value for pduAlarmDate */
+        NULL, 0);
+    snmp_varlist_add_variable(&var_list,
+        pduAlarmTime_oid, OID_LENGTH(pduAlarmTime_oid),
+        ASN_OCTET_STR,
+        /* Set an appropriate value for pduAlarmTime */
+        NULL, 0);
+
+    /*
+     * Add any extra (optional) objects here
+     */
+
+    /*
+     * Send the trap to the list of configured destinations
+     *  and clean up
+     */
+    send_v2trap( var_list );
+    snmp_free_varbind( var_list );
+
+    return SNMP_ERR_NOERROR;
+}
+int
+send_pduAlarmRemoved_trap( void )
+{
+    netsnmp_variable_list  *var_list = NULL;
+    const oid pduAlarmRemoved_oid[] = { 1,3,6,1,4,1,2024,2,2 };
+    const oid pduAlarmContext_oid[] = { 1,3,6,1,4,1,2024,1,6,1,1,3, /* insert index here */ };
+
+    /*
+     * Set the snmpTrapOid.0 value
+     */
+    snmp_varlist_add_variable(&var_list,
+        snmptrap_oid, snmptrap_oid_len,
+        ASN_OBJECT_ID,
+        pduAlarmRemoved_oid, sizeof(pduAlarmRemoved_oid));
+    
+    /*
+     * Add any objects from the trap definition
+     */
+    snmp_varlist_add_variable(&var_list,
+        pduAlarmContext_oid, OID_LENGTH(pduAlarmContext_oid),
+        ASN_OCTET_STR,
+        /* Set an appropriate value for pduAlarmContext */
+        NULL, 0);
+
+    /*
+     * Add any extra (optional) objects here
+     */
+
+    /*
+     * Send the trap to the list of configured destinations
+     *  and clean up
+     */
+    send_v2trap( var_list );
+    snmp_free_varbind( var_list );
+
+    return SNMP_ERR_NOERROR;
+}

+ 12 - 0
Liyuezong/SNMP协议设计/Gowone-SmartPDU-mib-V2c/agent代理开发的.c及.h文件/Trap调用代码/pduMIB.h

@@ -0,0 +1,12 @@
+/*
+ * Note: this file originally auto-generated by mib2c
+ * using mib2c.notify.conf
+ */
+#ifndef PDUMIB_H
+#define PDUMIB_H
+
+/* function declarations */
+int send_pduAlarmAdded_trap(void);
+int send_pduAlarmRemoved_trap(void);
+
+#endif /* PDUMIB_H */

File diff suppressed because it is too large
+ 5194 - 0
Liyuezong/SNMP协议设计/Gowone-SmartPDU-mib-V2c/agent代理开发的.c及.h文件/标量+表格调用代码(旧方法)/pduMIB.c


+ 92 - 0
Liyuezong/SNMP协议设计/Gowone-SmartPDU-mib-V2c/agent代理开发的.c及.h文件/标量+表格调用代码(旧方法)/pduMIB.h

@@ -0,0 +1,92 @@
+/*
+ * Note: this file originally auto-generated by mib2c
+ * using mib2c.old-api.conf
+ */
+#ifndef PDUMIB_H
+#define PDUMIB_H
+
+/* function declarations */
+void init_pduMIB(void);
+FindVarMethod var_pduMIB;
+FindVarMethod var_pduChannelTable;
+FindVarMethod var_pduGroupTable;
+FindVarMethod var_pduSensorTable;
+FindVarMethod var_pduSMTPRecMailTable;
+FindVarMethod var_pduMessageNumTable;
+FindVarMethod var_pduMQTTBrokerTable;
+FindVarMethod var_pduCloudServerTable;
+FindVarMethod var_pduAlarmHistoryTable;
+FindVarMethod var_pduChannelLimitTable;
+FindVarMethod var_pduSensorLimitTable;
+    WriteMethod write_pduLanIpv4Address;
+    WriteMethod write_pduLanIpv4Mask;
+    WriteMethod write_pduLanIpv6Address;
+    WriteMethod write_pduLanIpv6SubnetLength;
+    WriteMethod write_pduWifiEnable;
+    WriteMethod write_pduWifiIpv4Link;
+    WriteMethod write_pduWifiIpv4Address;
+    WriteMethod write_pduWifiIpv4Mask;
+    WriteMethod write_pduWifiIpv6Address;
+    WriteMethod write_pduWifiIpv6SubnetLength;
+    WriteMethod write_pduModbusAddress;
+    WriteMethod write_pduModbusBaud;
+    WriteMethod write_pduModbusMode;
+    WriteMethod write_pduVpnEnable;
+    WriteMethod write_pduPowerFactor;
+    WriteMethod write_pduPowerStatus;
+    WriteMethod write_pduTelnetEnable;
+    WriteMethod write_pduTelnetUserName;
+    WriteMethod write_pduTelnetUserPW;
+    WriteMethod write_pduSMTPEnable;
+    WriteMethod write_pduSMTPServer;
+    WriteMethod write_pduSMTPPort;
+    WriteMethod write_pduSNMPEnable;
+    WriteMethod write_pduSNMPTrapEnable;
+    WriteMethod write_pduSNMPProtocolVersion;
+    WriteMethod write_pduMessageEnable;
+    WriteMethod write_pduMQTTEnable;
+    WriteMethod write_pduCloudEnable;
+    WriteMethod write_pduNTPEnable;
+    WriteMethod write_pduNTPTimeZone;
+    WriteMethod write_pduNTPDate;
+    WriteMethod write_pduNTPServerName;
+    WriteMethod write_pduNTPServerIPorDomain;
+    WriteMethod write_pduNTPServerPort;
+    WriteMethod write_pduCurrentLimitUp;
+    WriteMethod write_pduVoltageLimitUp;
+    WriteMethod write_pduVoltageLimitDown;
+    WriteMethod write_pduPowerLimitUp;
+    WriteMethod write_pduConsumptionLimitUp;
+    WriteMethod write_pduRestart;
+    WriteMethod write_pduReset;
+    WriteMethod write_pduChannelStatus;
+    WriteMethod write_pduGroupName;
+    WriteMethod write_pduGroupList;
+    WriteMethod write_pduGroupStatus;
+    WriteMethod write_pduSensorStatus;
+    WriteMethod write_pduSMTPRecMail;
+    WriteMethod write_pduMessageRecNum;
+    WriteMethod write_pduMQTTBrokerName;
+    WriteMethod write_pduMQTTBrokerEnable;
+    WriteMethod write_pduMQTTBrokerIPorDomain;
+    WriteMethod write_pduMQTTBrokerPort;
+    WriteMethod write_pduMQTTBrokerUserName;
+    WriteMethod write_pduMQTTBrokerUserPW;
+    WriteMethod write_pduCloudServerName;
+    WriteMethod write_pduCloudServerEnable;
+    WriteMethod write_pduCloudServerIPorDomain;
+    WriteMethod write_pduCloudServerPort;
+    WriteMethod write_pduCloudServerUserName;
+    WriteMethod write_pduCloudServerUserPW;
+    WriteMethod write_pduChannelLimitName;
+    WriteMethod write_pduChannelCurrentLimitUp;
+    WriteMethod write_pduChannelVoltageLimitUp;
+    WriteMethod write_pduChannelVoltageLimitDown;
+    WriteMethod write_pduChannelPowerLimitUp;
+    WriteMethod write_pduChannelConsumptionLimitUp;
+    WriteMethod write_pduSensorLimitID;
+    WriteMethod write_pduSensorLimitName;
+    WriteMethod write_pduSensorLimitValue1;
+    WriteMethod write_pduSensorLimitValue2;
+
+#endif /* PDUMIB_H */

Liyuezong/SNMP协议设计/Gowone-SmartPDU-mib-V2c/agent代理开发的.c及.h文件/pduMIB.c → Liyuezong/SNMP协议设计/Gowone-SmartPDU-mib-V2c/agent代理开发的.c及.h文件/标量调用代码/pduMIB.c


Liyuezong/SNMP协议设计/Gowone-SmartPDU-mib-V2c/agent代理开发的.c及.h文件/pduMIB.h → Liyuezong/SNMP协议设计/Gowone-SmartPDU-mib-V2c/agent代理开发的.c及.h文件/标量调用代码/pduMIB.h


+ 640 - 0
Liyuezong/SNMP协议设计/Gowone-SmartPDU-mib-V2c/agent代理开发的.c及.h文件/表格调用代码/pduMIB.c

@@ -0,0 +1,640 @@
+/*
+ * Note: this file originally auto-generated by mib2c
+ * using mib2c.create-dataset.conf
+ */
+
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/net-snmp-includes.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include "pduMIB.h"
+
+/** Initialize the pduChannelTable table by defining its contents and how it's structured */
+void
+initialize_table_pduChannelTable(void)
+{
+    const oid pduChannelTable_oid[] = {1,3,6,1,4,1,2024,1,3,9};
+    netsnmp_table_data_set *table_set;
+
+    /* create the table structure itself */
+    table_set = netsnmp_create_table_data_set("pduChannelTable");
+
+    /* comment this out or delete if you don't support creation of new rows */
+    table_set->allow_creation = 1;
+
+    /***************************************************
+     * Adding indexes
+     */
+    DEBUGMSGTL(("initialize_table_pduChannelTable",
+                "adding indexes to table pduChannelTable\n"));
+    netsnmp_table_set_add_indexes(table_set,
+                           ASN_INTEGER,  /* index: pduChannelID */
+                           0);
+
+    DEBUGMSGTL(("initialize_table_pduChannelTable",
+                "adding column types to table pduChannelTable\n"));		 
+    netsnmp_table_set_multi_add_default_row(table_set,
+                                            COLUMN_PDUCHANNELID, ASN_INTEGER, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELNAME, ASN_OCTET_STR, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELSTATUS, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELVOLTAGE, ASN_OCTET_STR, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELCURRENT, ASN_OCTET_STR, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELFREQUENCY, ASN_INTEGER, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELCONSUMPTION, ASN_OCTET_STR, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELPOWERFACTOR, ASN_OCTET_STR, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELPACTIVEPOWER, ASN_OCTET_STR, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELREACTIVEPOWER, ASN_OCTET_STR, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELAPPARENTPOWER, ASN_OCTET_STR, 0,
+                                            NULL, 0,
+                              0);
+    
+    /* registering the table with the master agent */
+    /* note: if you don't need a subhandler to deal with any aspects
+       of the request, change pduChannelTable_handler to "NULL" */
+    netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduChannelTable", pduChannelTable_handler,
+                                                        pduChannelTable_oid,
+                                                        OID_LENGTH(pduChannelTable_oid),
+                                                        HANDLER_CAN_RWRITE),
+                            table_set, NULL);
+}
+/** Initialize the pduGroupTable table by defining its contents and how it's structured */
+void
+initialize_table_pduGroupTable(void)
+{
+    const oid pduGroupTable_oid[] = {1,3,6,1,4,1,2024,1,3,10};
+    netsnmp_table_data_set *table_set;
+
+    /* create the table structure itself */
+    table_set = netsnmp_create_table_data_set("pduGroupTable");
+
+    /* comment this out or delete if you don't support creation of new rows */
+    table_set->allow_creation = 1;
+
+    /***************************************************
+     * Adding indexes
+     */
+    DEBUGMSGTL(("initialize_table_pduGroupTable",
+                "adding indexes to table pduGroupTable\n"));
+    netsnmp_table_set_add_indexes(table_set,
+                           ASN_INTEGER,  /* index: pduGroupID */
+                           0);
+
+    DEBUGMSGTL(("initialize_table_pduGroupTable",
+                "adding column types to table pduGroupTable\n"));		 
+    netsnmp_table_set_multi_add_default_row(table_set,
+                                            COLUMN_PDUGROUPID, ASN_INTEGER, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUGROUPNAME, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUGROUPLIST, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUGROUPSTATUS, ASN_INTEGER, 1,
+                                            NULL, 0,
+                              0);
+    
+    /* registering the table with the master agent */
+    /* note: if you don't need a subhandler to deal with any aspects
+       of the request, change pduGroupTable_handler to "NULL" */
+    netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduGroupTable", pduGroupTable_handler,
+                                                        pduGroupTable_oid,
+                                                        OID_LENGTH(pduGroupTable_oid),
+                                                        HANDLER_CAN_RWRITE),
+                            table_set, NULL);
+}
+/** Initialize the pduSensorTable table by defining its contents and how it's structured */
+void
+initialize_table_pduSensorTable(void)
+{
+    const oid pduSensorTable_oid[] = {1,3,6,1,4,1,2024,1,4,1};
+    netsnmp_table_data_set *table_set;
+
+    /* create the table structure itself */
+    table_set = netsnmp_create_table_data_set("pduSensorTable");
+
+    /* comment this out or delete if you don't support creation of new rows */
+    table_set->allow_creation = 1;
+
+    /***************************************************
+     * Adding indexes
+     */
+    DEBUGMSGTL(("initialize_table_pduSensorTable",
+                "adding indexes to table pduSensorTable\n"));
+    netsnmp_table_set_add_indexes(table_set,
+                           ASN_INTEGER,  /* index: pduSensorID */
+                           0);
+
+    DEBUGMSGTL(("initialize_table_pduSensorTable",
+                "adding column types to table pduSensorTable\n"));		 
+    netsnmp_table_set_multi_add_default_row(table_set,
+                                            COLUMN_PDUSENSORID, ASN_INTEGER, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORNAME, ASN_OCTET_STR, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORTYPE, ASN_INTEGER, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORDATACHENNEL, ASN_OCTET_STR, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORMODBUSADDRESS, ASN_INTEGER, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORSTATUS, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORVALUENUM, ASN_INTEGER, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORVALUE1, ASN_INTEGER, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORVALUE2, ASN_INTEGER, 0,
+                                            NULL, 0,
+                              0);
+    
+    /* registering the table with the master agent */
+    /* note: if you don't need a subhandler to deal with any aspects
+       of the request, change pduSensorTable_handler to "NULL" */
+    netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduSensorTable", pduSensorTable_handler,
+                                                        pduSensorTable_oid,
+                                                        OID_LENGTH(pduSensorTable_oid),
+                                                        HANDLER_CAN_RWRITE),
+                            table_set, NULL);
+}
+/** Initialize the pduSMTPRecMailTable table by defining its contents and how it's structured */
+void
+initialize_table_pduSMTPRecMailTable(void)
+{
+    const oid pduSMTPRecMailTable_oid[] = {1,3,6,1,4,1,2024,1,5,3,4};
+    netsnmp_table_data_set *table_set;
+
+    /* create the table structure itself */
+    table_set = netsnmp_create_table_data_set("pduSMTPRecMailTable");
+
+    /* comment this out or delete if you don't support creation of new rows */
+    table_set->allow_creation = 1;
+
+    /***************************************************
+     * Adding indexes
+     */
+    DEBUGMSGTL(("initialize_table_pduSMTPRecMailTable",
+                "adding indexes to table pduSMTPRecMailTable\n"));
+    netsnmp_table_set_add_indexes(table_set,
+                           ASN_OCTET_STR,  /* index: pduSMTPRecMail */
+                           0);
+
+    DEBUGMSGTL(("initialize_table_pduSMTPRecMailTable",
+                "adding column types to table pduSMTPRecMailTable\n"));		 
+    netsnmp_table_set_multi_add_default_row(table_set,
+                                            COLUMN_PDUSMTPRECMAIL, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                              0);
+    
+    /* registering the table with the master agent */
+    /* note: if you don't need a subhandler to deal with any aspects
+       of the request, change pduSMTPRecMailTable_handler to "NULL" */
+    netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduSMTPRecMailTable", pduSMTPRecMailTable_handler,
+                                                        pduSMTPRecMailTable_oid,
+                                                        OID_LENGTH(pduSMTPRecMailTable_oid),
+                                                        HANDLER_CAN_RWRITE),
+                            table_set, NULL);
+}
+/** Initialize the pduMessageNumTable table by defining its contents and how it's structured */
+void
+initialize_table_pduMessageNumTable(void)
+{
+    const oid pduMessageNumTable_oid[] = {1,3,6,1,4,1,2024,1,5,5,2};
+    netsnmp_table_data_set *table_set;
+
+    /* create the table structure itself */
+    table_set = netsnmp_create_table_data_set("pduMessageNumTable");
+
+    /* comment this out or delete if you don't support creation of new rows */
+    table_set->allow_creation = 1;
+
+    /***************************************************
+     * Adding indexes
+     */
+    DEBUGMSGTL(("initialize_table_pduMessageNumTable",
+                "adding indexes to table pduMessageNumTable\n"));
+    netsnmp_table_set_add_indexes(table_set,
+                           ASN_OCTET_STR,  /* index: pduMessageRecNum */
+                           0);
+
+    DEBUGMSGTL(("initialize_table_pduMessageNumTable",
+                "adding column types to table pduMessageNumTable\n"));		 
+    netsnmp_table_set_multi_add_default_row(table_set,
+                                            COLUMN_PDUMESSAGERECNUM, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                              0);
+    
+    /* registering the table with the master agent */
+    /* note: if you don't need a subhandler to deal with any aspects
+       of the request, change pduMessageNumTable_handler to "NULL" */
+    netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduMessageNumTable", pduMessageNumTable_handler,
+                                                        pduMessageNumTable_oid,
+                                                        OID_LENGTH(pduMessageNumTable_oid),
+                                                        HANDLER_CAN_RWRITE),
+                            table_set, NULL);
+}
+/** Initialize the pduMQTTBrokerTable table by defining its contents and how it's structured */
+void
+initialize_table_pduMQTTBrokerTable(void)
+{
+    const oid pduMQTTBrokerTable_oid[] = {1,3,6,1,4,1,2024,1,5,6,3};
+    netsnmp_table_data_set *table_set;
+
+    /* create the table structure itself */
+    table_set = netsnmp_create_table_data_set("pduMQTTBrokerTable");
+
+    /* comment this out or delete if you don't support creation of new rows */
+    table_set->allow_creation = 1;
+
+    /***************************************************
+     * Adding indexes
+     */
+    DEBUGMSGTL(("initialize_table_pduMQTTBrokerTable",
+                "adding indexes to table pduMQTTBrokerTable\n"));
+    netsnmp_table_set_add_indexes(table_set,
+                           ASN_OCTET_STR,  /* index: pduMQTTBrokerName */
+                           0);
+
+    DEBUGMSGTL(("initialize_table_pduMQTTBrokerTable",
+                "adding column types to table pduMQTTBrokerTable\n"));		 
+    netsnmp_table_set_multi_add_default_row(table_set,
+                                            COLUMN_PDUMQTTBROKERNAME, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUMQTTBROKERENABLE, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUMQTTBROKERIPORDOMAIN, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUMQTTBROKERPORT, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUMQTTBROKERUSERNAME, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUMQTTBROKERUSERPW, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                              0);
+    
+    /* registering the table with the master agent */
+    /* note: if you don't need a subhandler to deal with any aspects
+       of the request, change pduMQTTBrokerTable_handler to "NULL" */
+    netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduMQTTBrokerTable", pduMQTTBrokerTable_handler,
+                                                        pduMQTTBrokerTable_oid,
+                                                        OID_LENGTH(pduMQTTBrokerTable_oid),
+                                                        HANDLER_CAN_RWRITE),
+                            table_set, NULL);
+}
+/** Initialize the pduCloudServerTable table by defining its contents and how it's structured */
+void
+initialize_table_pduCloudServerTable(void)
+{
+    const oid pduCloudServerTable_oid[] = {1,3,6,1,4,1,2024,1,5,7,3};
+    netsnmp_table_data_set *table_set;
+
+    /* create the table structure itself */
+    table_set = netsnmp_create_table_data_set("pduCloudServerTable");
+
+    /* comment this out or delete if you don't support creation of new rows */
+    table_set->allow_creation = 1;
+
+    /***************************************************
+     * Adding indexes
+     */
+    DEBUGMSGTL(("initialize_table_pduCloudServerTable",
+                "adding indexes to table pduCloudServerTable\n"));
+    netsnmp_table_set_add_indexes(table_set,
+                           ASN_OCTET_STR,  /* index: pduCloudServerName */
+                           0);
+
+    DEBUGMSGTL(("initialize_table_pduCloudServerTable",
+                "adding column types to table pduCloudServerTable\n"));		 
+    netsnmp_table_set_multi_add_default_row(table_set,
+                                            COLUMN_PDUCLOUDSERVERNAME, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCLOUDSERVERENABLE, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCLOUDSERVERIPORDOMAIN, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCLOUDSERVERPORT, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCLOUDSERVERUSERNAME, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCLOUDSERVERUSERPW, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                              0);
+    
+    /* registering the table with the master agent */
+    /* note: if you don't need a subhandler to deal with any aspects
+       of the request, change pduCloudServerTable_handler to "NULL" */
+    netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduCloudServerTable", pduCloudServerTable_handler,
+                                                        pduCloudServerTable_oid,
+                                                        OID_LENGTH(pduCloudServerTable_oid),
+                                                        HANDLER_CAN_RWRITE),
+                            table_set, NULL);
+}
+/** Initialize the pduAlarmHistoryTable table by defining its contents and how it's structured */
+void
+initialize_table_pduAlarmHistoryTable(void)
+{
+    const oid pduAlarmHistoryTable_oid[] = {1,3,6,1,4,1,2024,1,6,1};
+    netsnmp_table_data_set *table_set;
+
+    /* create the table structure itself */
+    table_set = netsnmp_create_table_data_set("pduAlarmHistoryTable");
+
+    /* comment this out or delete if you don't support creation of new rows */
+    table_set->allow_creation = 1;
+
+    /***************************************************
+     * Adding indexes
+     */
+    DEBUGMSGTL(("initialize_table_pduAlarmHistoryTable",
+                "adding indexes to table pduAlarmHistoryTable\n"));
+    netsnmp_table_set_add_indexes(table_set,
+                           ASN_INTEGER,  /* index: pduAlarmID */
+                           0);
+
+    DEBUGMSGTL(("initialize_table_pduAlarmHistoryTable",
+                "adding column types to table pduAlarmHistoryTable\n"));		 
+    netsnmp_table_set_multi_add_default_row(table_set,
+                                            COLUMN_PDUALARMID, ASN_INTEGER, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUALARMTYPE, ASN_INTEGER, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUALARMCONTEXT, ASN_OCTET_STR, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUALARMACTION, ASN_INTEGER, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUALARMACTIONPARA, ASN_INTEGER, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUALARMDATE, ASN_OCTET_STR, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUALARMTIME, ASN_OCTET_STR, 0,
+                                            NULL, 0,
+                              0);
+    
+    /* registering the table with the master agent */
+    /* note: if you don't need a subhandler to deal with any aspects
+       of the request, change pduAlarmHistoryTable_handler to "NULL" */
+    netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduAlarmHistoryTable", pduAlarmHistoryTable_handler,
+                                                        pduAlarmHistoryTable_oid,
+                                                        OID_LENGTH(pduAlarmHistoryTable_oid),
+                                                        HANDLER_CAN_RWRITE),
+                            table_set, NULL);
+}
+/** Initialize the pduChannelLimitTable table by defining its contents and how it's structured */
+void
+initialize_table_pduChannelLimitTable(void)
+{
+    const oid pduChannelLimitTable_oid[] = {1,3,6,1,4,1,2024,1,7,2,6};
+    netsnmp_table_data_set *table_set;
+
+    /* create the table structure itself */
+    table_set = netsnmp_create_table_data_set("pduChannelLimitTable");
+
+    /* comment this out or delete if you don't support creation of new rows */
+    table_set->allow_creation = 1;
+
+    /***************************************************
+     * Adding indexes
+     */
+    DEBUGMSGTL(("initialize_table_pduChannelLimitTable",
+                "adding indexes to table pduChannelLimitTable\n"));
+    netsnmp_table_set_add_indexes(table_set,
+                           ASN_INTEGER,  /* index: pduChannelLimitID */
+                           0);
+
+    DEBUGMSGTL(("initialize_table_pduChannelLimitTable",
+                "adding column types to table pduChannelLimitTable\n"));		 
+    netsnmp_table_set_multi_add_default_row(table_set,
+                                            COLUMN_PDUCHANNELLIMITID, ASN_INTEGER, 0,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELLIMITNAME, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELCURRENTLIMITUP, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELVOLTAGELIMITUP, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELVOLTAGELIMITDOWN, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELPOWERLIMITUP, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELCONSUMPTIONLIMITUP, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                              0);
+    
+    /* registering the table with the master agent */
+    /* note: if you don't need a subhandler to deal with any aspects
+       of the request, change pduChannelLimitTable_handler to "NULL" */
+    netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduChannelLimitTable", pduChannelLimitTable_handler,
+                                                        pduChannelLimitTable_oid,
+                                                        OID_LENGTH(pduChannelLimitTable_oid),
+                                                        HANDLER_CAN_RWRITE),
+                            table_set, NULL);
+}
+/** Initialize the pduSensorLimitTable table by defining its contents and how it's structured */
+void
+initialize_table_pduSensorLimitTable(void)
+{
+    const oid pduSensorLimitTable_oid[] = {1,3,6,1,4,1,2024,1,7,3,1};
+    netsnmp_table_data_set *table_set;
+
+    /* create the table structure itself */
+    table_set = netsnmp_create_table_data_set("pduSensorLimitTable");
+
+    /* comment this out or delete if you don't support creation of new rows */
+    table_set->allow_creation = 1;
+
+    /***************************************************
+     * Adding indexes
+     */
+    DEBUGMSGTL(("initialize_table_pduSensorLimitTable",
+                "adding indexes to table pduSensorLimitTable\n"));
+    netsnmp_table_set_add_indexes(table_set,
+                           ASN_INTEGER,  /* index: pduSensorLimitID */
+                           0);
+
+    DEBUGMSGTL(("initialize_table_pduSensorLimitTable",
+                "adding column types to table pduSensorLimitTable\n"));		 
+    netsnmp_table_set_multi_add_default_row(table_set,
+                                            COLUMN_PDUSENSORLIMITID, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORLIMITNAME, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORLIMITVALUE1, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORLIMITVALUE2, ASN_INTEGER, 1,
+                                            NULL, 0,
+                              0);
+    
+    /* registering the table with the master agent */
+    /* note: if you don't need a subhandler to deal with any aspects
+       of the request, change pduSensorLimitTable_handler to "NULL" */
+    netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduSensorLimitTable", pduSensorLimitTable_handler,
+                                                        pduSensorLimitTable_oid,
+                                                        OID_LENGTH(pduSensorLimitTable_oid),
+                                                        HANDLER_CAN_RWRITE),
+                            table_set, NULL);
+}
+
+/** Initializes the pduMIB module */
+void
+init_pduMIB(void)
+{
+
+  /* here we initialize all the tables we're planning on supporting */
+    initialize_table_pduChannelTable();
+    initialize_table_pduGroupTable();
+    initialize_table_pduSensorTable();
+    initialize_table_pduSMTPRecMailTable();
+    initialize_table_pduMessageNumTable();
+    initialize_table_pduMQTTBrokerTable();
+    initialize_table_pduCloudServerTable();
+    initialize_table_pduAlarmHistoryTable();
+    initialize_table_pduChannelLimitTable();
+    initialize_table_pduSensorLimitTable();
+}
+
+/** handles requests for the pduChannelTable table, if anything else needs to be done */
+int
+pduChannelTable_handler(
+    netsnmp_mib_handler               *handler,
+    netsnmp_handler_registration      *reginfo,
+    netsnmp_agent_request_info        *reqinfo,
+    netsnmp_request_info              *requests) {
+    /* perform anything here that you need to do.  The requests have
+       already been processed by the master table_dataset handler, but
+       this gives you chance to act on the request in some other way
+       if need be. */
+    return SNMP_ERR_NOERROR;
+}
+
+/** handles requests for the pduGroupTable table, if anything else needs to be done */
+int
+pduGroupTable_handler(
+    netsnmp_mib_handler               *handler,
+    netsnmp_handler_registration      *reginfo,
+    netsnmp_agent_request_info        *reqinfo,
+    netsnmp_request_info              *requests) {
+    /* perform anything here that you need to do.  The requests have
+       already been processed by the master table_dataset handler, but
+       this gives you chance to act on the request in some other way
+       if need be. */
+    return SNMP_ERR_NOERROR;
+}
+
+/** handles requests for the pduSensorTable table, if anything else needs to be done */
+int
+pduSensorTable_handler(
+    netsnmp_mib_handler               *handler,
+    netsnmp_handler_registration      *reginfo,
+    netsnmp_agent_request_info        *reqinfo,
+    netsnmp_request_info              *requests) {
+    /* perform anything here that you need to do.  The requests have
+       already been processed by the master table_dataset handler, but
+       this gives you chance to act on the request in some other way
+       if need be. */
+    return SNMP_ERR_NOERROR;
+}
+
+/** handles requests for the pduSMTPRecMailTable table, if anything else needs to be done */
+int
+pduSMTPRecMailTable_handler(
+    netsnmp_mib_handler               *handler,
+    netsnmp_handler_registration      *reginfo,
+    netsnmp_agent_request_info        *reqinfo,
+    netsnmp_request_info              *requests) {
+    /* perform anything here that you need to do.  The requests have
+       already been processed by the master table_dataset handler, but
+       this gives you chance to act on the request in some other way
+       if need be. */
+    return SNMP_ERR_NOERROR;
+}
+
+/** handles requests for the pduMessageNumTable table, if anything else needs to be done */
+int
+pduMessageNumTable_handler(
+    netsnmp_mib_handler               *handler,
+    netsnmp_handler_registration      *reginfo,
+    netsnmp_agent_request_info        *reqinfo,
+    netsnmp_request_info              *requests) {
+    /* perform anything here that you need to do.  The requests have
+       already been processed by the master table_dataset handler, but
+       this gives you chance to act on the request in some other way
+       if need be. */
+    return SNMP_ERR_NOERROR;
+}
+
+/** handles requests for the pduMQTTBrokerTable table, if anything else needs to be done */
+int
+pduMQTTBrokerTable_handler(
+    netsnmp_mib_handler               *handler,
+    netsnmp_handler_registration      *reginfo,
+    netsnmp_agent_request_info        *reqinfo,
+    netsnmp_request_info              *requests) {
+    /* perform anything here that you need to do.  The requests have
+       already been processed by the master table_dataset handler, but
+       this gives you chance to act on the request in some other way
+       if need be. */
+    return SNMP_ERR_NOERROR;
+}
+
+/** handles requests for the pduCloudServerTable table, if anything else needs to be done */
+int
+pduCloudServerTable_handler(
+    netsnmp_mib_handler               *handler,
+    netsnmp_handler_registration      *reginfo,
+    netsnmp_agent_request_info        *reqinfo,
+    netsnmp_request_info              *requests) {
+    /* perform anything here that you need to do.  The requests have
+       already been processed by the master table_dataset handler, but
+       this gives you chance to act on the request in some other way
+       if need be. */
+    return SNMP_ERR_NOERROR;
+}
+
+/** handles requests for the pduAlarmHistoryTable table, if anything else needs to be done */
+int
+pduAlarmHistoryTable_handler(
+    netsnmp_mib_handler               *handler,
+    netsnmp_handler_registration      *reginfo,
+    netsnmp_agent_request_info        *reqinfo,
+    netsnmp_request_info              *requests) {
+    /* perform anything here that you need to do.  The requests have
+       already been processed by the master table_dataset handler, but
+       this gives you chance to act on the request in some other way
+       if need be. */
+    return SNMP_ERR_NOERROR;
+}
+
+/** handles requests for the pduChannelLimitTable table, if anything else needs to be done */
+int
+pduChannelLimitTable_handler(
+    netsnmp_mib_handler               *handler,
+    netsnmp_handler_registration      *reginfo,
+    netsnmp_agent_request_info        *reqinfo,
+    netsnmp_request_info              *requests) {
+    /* perform anything here that you need to do.  The requests have
+       already been processed by the master table_dataset handler, but
+       this gives you chance to act on the request in some other way
+       if need be. */
+    return SNMP_ERR_NOERROR;
+}
+
+/** handles requests for the pduSensorLimitTable table, if anything else needs to be done */
+int
+pduSensorLimitTable_handler(
+    netsnmp_mib_handler               *handler,
+    netsnmp_handler_registration      *reginfo,
+    netsnmp_agent_request_info        *reqinfo,
+    netsnmp_request_info              *requests) {
+    /* perform anything here that you need to do.  The requests have
+       already been processed by the master table_dataset handler, but
+       this gives you chance to act on the request in some other way
+       if need be. */
+    return SNMP_ERR_NOERROR;
+}

+ 106 - 0
Liyuezong/SNMP协议设计/Gowone-SmartPDU-mib-V2c/agent代理开发的.c及.h文件/表格调用代码/pduMIB.h

@@ -0,0 +1,106 @@
+/*
+ * Note: this file originally auto-generated by mib2c
+ * using mib2c.create-dataset.conf
+ */
+#ifndef PDUMIB_H
+#define PDUMIB_H
+
+/* function declarations */
+void init_pduMIB(void);
+void initialize_table_pduChannelTable(void);
+Netsnmp_Node_Handler pduChannelTable_handler;
+void initialize_table_pduGroupTable(void);
+Netsnmp_Node_Handler pduGroupTable_handler;
+void initialize_table_pduSensorTable(void);
+Netsnmp_Node_Handler pduSensorTable_handler;
+void initialize_table_pduSMTPRecMailTable(void);
+Netsnmp_Node_Handler pduSMTPRecMailTable_handler;
+void initialize_table_pduMessageNumTable(void);
+Netsnmp_Node_Handler pduMessageNumTable_handler;
+void initialize_table_pduMQTTBrokerTable(void);
+Netsnmp_Node_Handler pduMQTTBrokerTable_handler;
+void initialize_table_pduCloudServerTable(void);
+Netsnmp_Node_Handler pduCloudServerTable_handler;
+void initialize_table_pduAlarmHistoryTable(void);
+Netsnmp_Node_Handler pduAlarmHistoryTable_handler;
+void initialize_table_pduChannelLimitTable(void);
+Netsnmp_Node_Handler pduChannelLimitTable_handler;
+void initialize_table_pduSensorLimitTable(void);
+Netsnmp_Node_Handler pduSensorLimitTable_handler;
+
+/* column number definitions for table pduChannelTable */
+       #define COLUMN_PDUCHANNELID		1
+       #define COLUMN_PDUCHANNELNAME		2
+       #define COLUMN_PDUCHANNELSTATUS		3
+       #define COLUMN_PDUCHANNELVOLTAGE		4
+       #define COLUMN_PDUCHANNELCURRENT		5
+       #define COLUMN_PDUCHANNELFREQUENCY		6
+       #define COLUMN_PDUCHANNELCONSUMPTION		7
+       #define COLUMN_PDUCHANNELPOWERFACTOR		8
+       #define COLUMN_PDUCHANNELPACTIVEPOWER		9
+       #define COLUMN_PDUCHANNELREACTIVEPOWER		10
+       #define COLUMN_PDUCHANNELAPPARENTPOWER		11
+
+/* column number definitions for table pduGroupTable */
+       #define COLUMN_PDUGROUPID		1
+       #define COLUMN_PDUGROUPNAME		2
+       #define COLUMN_PDUGROUPLIST		3
+       #define COLUMN_PDUGROUPSTATUS		4
+
+/* column number definitions for table pduSensorTable */
+       #define COLUMN_PDUSENSORID		1
+       #define COLUMN_PDUSENSORNAME		2
+       #define COLUMN_PDUSENSORTYPE		3
+       #define COLUMN_PDUSENSORDATACHENNEL		4
+       #define COLUMN_PDUSENSORMODBUSADDRESS		5
+       #define COLUMN_PDUSENSORSTATUS		7
+       #define COLUMN_PDUSENSORVALUENUM		8
+       #define COLUMN_PDUSENSORVALUE1		9
+       #define COLUMN_PDUSENSORVALUE2		10
+
+/* column number definitions for table pduSMTPRecMailTable */
+       #define COLUMN_PDUSMTPRECMAIL		1
+
+/* column number definitions for table pduMessageNumTable */
+       #define COLUMN_PDUMESSAGERECNUM		1
+
+/* column number definitions for table pduMQTTBrokerTable */
+       #define COLUMN_PDUMQTTBROKERNAME		1
+       #define COLUMN_PDUMQTTBROKERENABLE		2
+       #define COLUMN_PDUMQTTBROKERIPORDOMAIN		3
+       #define COLUMN_PDUMQTTBROKERPORT		4
+       #define COLUMN_PDUMQTTBROKERUSERNAME		5
+       #define COLUMN_PDUMQTTBROKERUSERPW		6
+
+/* column number definitions for table pduCloudServerTable */
+       #define COLUMN_PDUCLOUDSERVERNAME		1
+       #define COLUMN_PDUCLOUDSERVERENABLE		2
+       #define COLUMN_PDUCLOUDSERVERIPORDOMAIN		3
+       #define COLUMN_PDUCLOUDSERVERPORT		4
+       #define COLUMN_PDUCLOUDSERVERUSERNAME		5
+       #define COLUMN_PDUCLOUDSERVERUSERPW		6
+
+/* column number definitions for table pduAlarmHistoryTable */
+       #define COLUMN_PDUALARMID		1
+       #define COLUMN_PDUALARMTYPE		2
+       #define COLUMN_PDUALARMCONTEXT		3
+       #define COLUMN_PDUALARMACTION		4
+       #define COLUMN_PDUALARMACTIONPARA		5
+       #define COLUMN_PDUALARMDATE		6
+       #define COLUMN_PDUALARMTIME		7
+
+/* column number definitions for table pduChannelLimitTable */
+       #define COLUMN_PDUCHANNELLIMITID		1
+       #define COLUMN_PDUCHANNELLIMITNAME		2
+       #define COLUMN_PDUCHANNELCURRENTLIMITUP		3
+       #define COLUMN_PDUCHANNELVOLTAGELIMITUP		4
+       #define COLUMN_PDUCHANNELVOLTAGELIMITDOWN		5
+       #define COLUMN_PDUCHANNELPOWERLIMITUP		6
+       #define COLUMN_PDUCHANNELCONSUMPTIONLIMITUP		7
+
+/* column number definitions for table pduSensorLimitTable */
+       #define COLUMN_PDUSENSORLIMITID		1
+       #define COLUMN_PDUSENSORLIMITNAME		2
+       #define COLUMN_PDUSENSORLIMITVALUE1		3
+       #define COLUMN_PDUSENSORLIMITVALUE2		4
+#endif /* PDUMIB_H */

+ 189 - 0
Liyuezong/SNMP协议设计/浪潮python API/pdusnmp_24.py

@@ -0,0 +1,189 @@
+# _*_ coding:utf-8 _*_
+#依赖pysnmp 请自行安装(可以使用命令 pip install pysnmp)
+from pysnmp.hlapi import *
+
+def validate_ip(ip_str: str) -> bool:
+    return True
+
+
+def validate_Sock(nSock: int) -> bool:
+    if nSock > 100 or nSock <= 0:
+        return False
+    else:
+        return True
+
+def validate_Group(nGroup: int) -> bool:
+    if nGroup > 100 or nGroup <= 0:
+        return False
+    else:
+        return True
+
+def get_value(devip:str, soid:str) -> str:
+    # 实现snmpget
+    g = getCmd(SnmpEngine(),  # 创建SNMP引擎
+               CommunityData('public'),  # 团体属性
+               # userData,交换机没有配认证,这里就不需要
+               UdpTransportTarget((devip, 161), timeout=1, retries=0),  # 创建被管理设备信息 包含IP和端口号 超时1秒 不重试
+               ContextData(),  # 创建SNMP上下文信息
+               ObjectType(ObjectIdentity(soid))  # 创建MIB节点对象 #要跟参数 否则会报错
+               )
+    errorIndication, errorStatus, errorIndex, varBinds = next(g)  # 发送Get请求,获取sysName
+    for i in varBinds:
+        print(i.prettyPrint())
+        return i
+
+
+def set_value(devip:str, soid:str, varvalue:str) -> bool:
+    # 实现snmpset
+    # SNMP SET请求
+    errorIndication, errorStatus, errorIndex, varBinds = next(
+        setCmd(SnmpEngine(),
+               CommunityData('public'),
+               UdpTransportTarget((devip, 161)),
+               ContextData(),
+               ObjectType(ObjectIdentity(soid), varvalue)
+               )
+    )
+    # 检查错误
+    if errorIndication:
+        print(errorIndication)
+        return False
+    elif errorStatus:
+        print('%s at %s' % (errorStatus.prettyPrint(),
+                             errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+        return False
+    else:
+        for varBind in varBinds:
+            print(' = '.join([x.prettyPrint() for x in varBind]))
+        return True
+
+
+#获取设备名称
+def GetDeviceName(sDevIp: str) -> str:
+    if validate_ip(sDevIp) == False:
+        print('invalid ip address!')
+        return 'Invalid Name'
+    sOId = '1.3.6.1.4.1.2024.1.1.2.0'
+    value = get_value(sDevIp, sOId)
+    if value is None:
+        print('invalid value!')
+        return 'Invalid Name'
+    rt_value = str(value)
+    return rt_value
+
+
+#打开或关闭指定插口
+def TurnOnOff(sDevIp:str, nSock:int, onoff:bool) -> bool:
+    if validate_ip(sDevIp) == False:
+        print('invalid ip address!')
+        return False
+    if validate_Sock(nSock) == False:
+        print('invalid sock!')
+        return False
+    sOId = '1.3.6.1.4.1.2024.1.3.9.1.3.%d.0' % (nSock)
+    if onoff == True:
+        state = '1'
+    else:
+        state = '0'
+
+    return set_value(sDevIp, sOId, state)
+
+
+#打开或关闭制定分组/端口
+def TurnOnOffGroup(sDevIp:str, nGroup:int, onoff:bool) -> bool:
+    if validate_ip(sDevIp) == False:
+        print('invalid ip address!')
+        return False
+    if validate_Group(nGroup) == False:
+        print('invalid Group!')
+        return False
+    sOId = '1.3.6.1.4.1.2024.1.3.10.1.4.%d.0' % (nGroup)
+    if onoff == True:
+        state = '1'
+    else:
+        state = '0'
+
+    return set_value(sDevIp, sOId, state)
+
+
+#获取分组状态 0-关闭 1-开启
+def GetStatusGroup(sDevIp:str, nGroup:int) -> int:
+    if validate_ip(sDevIp) == False:
+        print('invalid ip address!')
+        return 0
+    if validate_Group(nGroup) == False:
+        print('invalid Group!')
+        return 0
+    sOId = '1.3.6.1.4.1.2024.1.3.10.1.4.%d.0' % (nGroup)
+    value = get_value(sDevIp, sOId)
+    if value is None:
+        return 0
+    rt_value = int(value)
+    return rt_value
+
+
+
+#获取插口状态 0-关闭 1-开
+def GetStatus(sDevIp:str, nSock:bool) -> int:
+    if validate_ip(sDevIp) == False:
+        print('invalid ip address!')
+        return 0
+    if validate_Sock(nsock) == False:
+        print('invalid sock!')
+        return 0
+    sOId = '1.3.6.1.4.1.2024.1.3.9.1.3.%d.0' % (nSock)
+    value = get_value(sDevIp, sOId)
+    if value is None:
+        return 0
+    rt_value = int(value)
+    return rt_value
+
+
+#获取指定插口电流 A
+def GetCurrent(sDevIp:str, nSock:int) -> float:
+    if validate_ip(sDevIp) == False:
+        print('invalid ip address!')
+        return 0
+    if validate_Sock(nsock) == False:
+        print('invalid sock!')
+        return 0
+    sOId = '1.3.6.1.4.1.2024.1.3.9.1.5.%d.0' % (nSock)
+    value = get_value(sDevIp, sOId)
+    if value is None:
+        return 0
+    rt_value = float(value)
+    return rt_value
+
+
+#获取指定插口电能 kWh
+def GetEnergy(sDevIp:str, nSock:int) -> float:
+    if validate_ip(sDevIp) == False:
+        print('invalid ip address!')
+        return 0
+    if validate_Sock(nsock) == False:
+        print('invalid sock!')
+        return 0
+    sOId = '1.3.6.1.4.1.2024.1.3.9.1.7.%d.0' % (nsock)
+    value = get_value(sDevIp, sOId)
+    if value is None:
+        return 0
+    rt_value = float(value)
+    return rt_value
+
+
+#获取指定插口名称
+def GetSockName(sDevIp:str, nSock:int) -> str:
+    if validate_ip(sDevIp) == False:
+        print('invalid ip address!')
+        return ''
+    sOId = '1.3.6.1.4.1.2024.1.3.9.1.2.0'
+    value = get_value(sDevIp, sOId)
+    if value is None:
+        print('invalid value!')
+        return ''
+    rt_value = str(value)
+    return rt_value
+
+#Test
+#get_value('127.0.0.1', '.1.3.6.1.2.1.1.3.0')
+#set_value('127.0.0.1', '.1.3.6.1.2.1.1.4.0', 'lyz')