Procházet zdrojové kódy

1、完善SNMP协议电源超限及传感器超限报警信息接口。

liyuezong před 1 rokem
rodič
revize
baed0cc6a1
2 změnil soubory, kde provedl 334 přidání a 0 odebrání
  1. 313 0
      pro/src/pduMIB_form.c
  2. 21 0
      pro/src/pduMIB_form.h

+ 313 - 0
pro/src/pduMIB_form.c

@@ -488,6 +488,104 @@ initialize_table_pduSensorLimitTable(void)
                             table_set, NULL);
 }
 
+
+void
+initialize_table_pduPowerAlarmTable(void)
+{
+    const oid pduPowerAlarmTable_oid[] = {1,3,6,1,4,1,2024,1,6,2};
+    netsnmp_table_data_set *table_set;
+
+    /* create the table structure itself */
+    table_set = netsnmp_create_table_data_set("pduPowerAlarmTable");
+
+    /* comment this out or delete if you don't support creation of new rows */
+    table_set->allow_creation = 1;
+
+    /***************************************************
+     * Adding indexes
+     */
+    DEBUGMSGTL(("initialize_table_pduPowerAlarmTable",
+                "adding indexes to table pduPowerAlarmTable\n"));
+    netsnmp_table_set_add_indexes(table_set,
+                           ASN_INTEGER,  /* index:  pduChannelPowerAlarmID */
+                           0);
+
+    DEBUGMSGTL(("initialize_table_pduPowerAlarmTable",
+                "adding column types to table pduPowerAlarmTable\n"));		 
+    netsnmp_table_set_multi_add_default_row(table_set,
+                                            COLUMN_PDUCHANNELPOWERALARMID, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELPOWERALARMVOLTAGEUP, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELPOWERALARMVOLTAGEDOWN, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELPOWERALARMCURRENTUP, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELPOWERALARMPOWERUP, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUCHANNELPOWERALARMCONSUMPTIONUP, 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 pduPowerAlarmTable_handler to "NULL" */
+    netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduPowerAlarmTable", pduPowerAlarmTable_handler,
+                                                       pduPowerAlarmTable_oid,
+                                                        OID_LENGTH(pduPowerAlarmTable_oid),
+                                                        HANDLER_CAN_RWRITE),
+                            table_set, NULL);
+}
+/** Initialize the pduSensorLimitTable table by defining its contents and how it's structured */
+void
+initialize_table_pduSensorAlarmTable(void)
+{
+    const oid pduSensorAlarmTable_oid[] = {1,3,6,1,4,1,2024,1,6,3};
+    netsnmp_table_data_set *table_set;
+
+    /* create the table structure itself */
+    table_set = netsnmp_create_table_data_set("pduSensorAlarmTable");
+
+    /* comment this out or delete if you don't support creation of new rows */
+    table_set->allow_creation = 1;
+
+    /***************************************************
+     * Adding indexes
+     */
+    DEBUGMSGTL(("initialize_table_pduSensorAlarmTable",
+                "adding indexes to table pduSensorAlarmTable\n"));
+    netsnmp_table_set_add_indexes(table_set,
+                           ASN_INTEGER,  /* index:  pduSensorAlarmID */
+                           0);
+
+    DEBUGMSGTL(("initialize_table_pduSensorAlarmTable",
+                "adding column types to table pduSensorAlarmTable\n"));
+    netsnmp_table_set_multi_add_default_row(table_set,
+                                            COLUMN_PDUSENSORALARMID, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORALARMVALUE1UP, ASN_OCTET_STR, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORALARMVALUE1DOWN, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORALARMVALUE2UP, ASN_INTEGER, 1,
+                                            NULL, 0,
+                                            COLUMN_PDUSENSORALARMVALUE2DOWN, 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 pduSensorAlarmTable_handler to "NULL" */
+    netsnmp_register_table_data_set(netsnmp_create_handler_registration("pduSensorAlarmTable", pduSensorAlarmTable_handler,
+                                                        pduSensorAlarmTable_oid,
+                                                        OID_LENGTH(pduSensorAlarmTable_oid),
+                                                        HANDLER_CAN_RWRITE),
+                            table_set, NULL);
+}
+
+
+
+
 /** Initializes the pduMIB module */
 void
 init_pduMIB_form(void)
@@ -504,6 +602,8 @@ init_pduMIB_form(void)
     initialize_table_pduAlarmHistoryTable();
     initialize_table_pduChannelLimitTable();
     initialize_table_pduSensorLimitTable();
+    initialize_table_pduPowerAlarmTable();
+    initialize_table_pduSensorAlarmTable();
 }
 
 /** handles requests for the pduChannelTable table, if anything else needs to be done */
@@ -1562,3 +1662,216 @@ pduSensorLimitTable_handler(
 
     return SNMP_ERR_NOERROR;
 }
+
+
+int
+pduPowerAlarmTable_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. */
+
+    netsnmp_request_info *request;
+    netsnmp_table_request_info *table_info;
+    GlobalPowerManger *iterator = NULL;   
+    //
+    char buffer[16];
+    oid begin_next_oid[] = {1,3,6,1,4,1,2024,1,6,2,1,1,1};
+    int max_clonum = 6;
+    switch (reqinfo->mode)
+    {
+    case MODE_GET:
+   case MODE_GETNEXT:
+       for (request = requests; request; request = request->next)
+       {
+          table_info = netsnmp_extract_table_info(request);
+          if (reqinfo->mode == MODE_GETNEXT)
+          {
+             if (table_info->index_oid[0] == 0)
+             {
+                table_info->index_oid[0] = 1;
+                table_info->colnum = 1;
+                snmp_set_var_objid(requests->requestvb, begin_next_oid, OID_LENGTH(begin_next_oid));
+             }
+             else
+             {
+                if (table_info->colnum > max_clonum)
+                {
+                   table_info->index_oid[0] += 1;
+                   table_info->colnum = 1;
+                }
+                oid next_oid[] = {1, 3, 6, 1, 4, 1, 2024, 1, 6, 2, 1,table_info->colnum, table_info->index_oid[0]};
+                snmp_set_var_objid(requests->requestvb, next_oid, OID_LENGTH(next_oid));
+             }
+          }
+          int nIndex = 1;
+
+          list_for_each_entry(iterator, &__globalDeviceManage._globalPowerManger.list, list)
+          {
+             if (nIndex < table_info->index_oid[0])
+             {
+                nIndex++;
+                continue;
+             }
+             if (!iterator)
+             {
+                break;
+             }
+
+             memset(buffer, 0, sizeof(buffer));
+             switch (table_info->colnum)
+             {
+             case COLUMN_PDUCHANNELPOWERALARMID:
+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->product_ch_id);
+                break;
+             case COLUMN_PDUCHANNELPOWERALARMVOLTAGEUP:
+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->_PowerWarninginfo.w_voltage_up);
+                break;
+             case COLUMN_PDUCHANNELPOWERALARMVOLTAGEDOWN:
+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->_PowerWarninginfo.w_voltage_down);
+                break;
+             case COLUMN_PDUCHANNELPOWERALARMCURRENTUP:
+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->_PowerWarninginfo.w_current);
+                break;
+             case COLUMN_PDUCHANNELPOWERALARMPOWERUP:
+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->_PowerWarninginfo.w_power);
+                break;
+             case COLUMN_PDUCHANNELPOWERALARMCONSUMPTIONUP:
+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->_PowerWarninginfo.w_consumption);
+                break;
+             default:
+                netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
+                break;
+             }
+             //}
+             break;
+          }
+       }
+       break;
+    case MODE_SET_RESERVE1:
+       break;
+    case MODE_SET_RESERVE2:
+       break;
+    case MODE_SET_FREE:
+       break;
+    case MODE_SET_ACTION:
+       break;
+    case MODE_SET_UNDO:
+       break;
+    case MODE_SET_COMMIT:
+       break;
+    default:
+       /* we should never get here, so this is a really bad error */
+       snmp_log(LOG_ERR, "unknown mode (%d) in handle_pduType\n", reqinfo->mode);
+       return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+
+int
+pduSensorAlarmTable_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. */
+    netsnmp_request_info *request;
+    netsnmp_table_request_info *table_info;
+    GlobalSensorManger *iterator = NULL;
+    //
+    char buffer[16];
+    oid begin_next_oid[] = {1,3,6,1,4,1,2024,1,6,3,1,1,1};
+    int max_clonum = 5;
+    switch (reqinfo->mode)
+    {
+    case MODE_GET:
+    case MODE_GETNEXT:
+       for (request = requests; request; request = request->next)
+       {
+          table_info = netsnmp_extract_table_info(request);
+
+          if (reqinfo->mode == MODE_GETNEXT)
+          {
+             if (table_info->index_oid[0] == 0)
+             {
+                table_info->index_oid[0] = 1;
+                table_info->colnum = 1;
+                snmp_set_var_objid(requests->requestvb, begin_next_oid, OID_LENGTH(begin_next_oid));
+             }
+             else
+             {
+                if (table_info->colnum > max_clonum)
+                {
+                   table_info->index_oid[0] += 1;
+                   table_info->colnum = 1;
+                }
+                oid next_oid[] = {1, 3, 6, 1, 4, 1, 2024, 1, 6, 3, 1, table_info->colnum, table_info->index_oid[0]};
+                snmp_set_var_objid(requests->requestvb, next_oid, OID_LENGTH(next_oid));
+             }
+          }
+
+          int nIndex = table_info->index_oid[0];
+
+          list_for_each_entry(iterator, &__globalDeviceManage._globalSensorManger.list, list)
+          {
+             if (!iterator || nIndex != iterator->sensor_id)
+             {
+                continue;
+             }
+
+             memset(buffer, 0, sizeof(buffer));
+             switch (table_info->colnum)
+             {
+             case COLUMN_PDUSENSORALARMID:
+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->sensor_id);
+                break;
+             case COLUMN_PDUSENSORALARMVALUE1UP:
+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->warning_status.sensor_val1_upper);
+                break;
+             case COLUMN_PDUSENSORALARMVALUE1DOWN:
+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,iterator->warning_status.sensor_val1_lower);
+                break;
+             case COLUMN_PDUSENSORALARMVALUE2UP:
+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, iterator->warning_status.sensor_val2_upper);
+                break;
+             case COLUMN_PDUSENSORALARMVALUE2DOWN:
+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,iterator->warning_status.sensor_val2_lower);
+                break;
+             default:
+                netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
+                break;
+             }
+             //}
+             break;
+          }
+
+       }
+       break;
+    case MODE_SET_RESERVE1:
+       break;
+    case MODE_SET_RESERVE2:
+       break;
+    case MODE_SET_FREE:
+       break;
+    case MODE_SET_ACTION:
+       break;
+    case MODE_SET_UNDO:
+       break;
+    case MODE_SET_COMMIT:
+       break;
+    default:
+       /* we should never get here, so this is a really bad error */
+       snmp_log(LOG_ERR, "unknown mode (%d) in handle_pduType\n", reqinfo->mode);
+       return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}

+ 21 - 0
pro/src/pduMIB_form.h

@@ -27,6 +27,10 @@ void initialize_table_pduChannelLimitTable(void);
 Netsnmp_Node_Handler pduChannelLimitTable_handler;
 void initialize_table_pduSensorLimitTable(void);
 Netsnmp_Node_Handler pduSensorLimitTable_handler;
+void initialize_table_pduPowerAlarmTable(void);
+Netsnmp_Node_Handler pduPowerAlarmTable_handler;
+void initialize_table_pduSensorAlarmTable(void);
+Netsnmp_Node_Handler  pduSensorAlarmTable_handler;
 
 /* column number definitions for table pduChannelTable */
        #define COLUMN_PDUCHANNELID		1
@@ -105,4 +109,21 @@ Netsnmp_Node_Handler pduSensorLimitTable_handler;
        #define COLUMN_PDUSENSORLIMITVALUE2UP		4
        #define COLUMN_PDUSENSORLIMITVALUE1DOWN		5
        #define COLUMN_PDUSENSORLIMITVALUE2DOWN		6
+
+/* column number definitions for table pduPowerAlarmTable */
+       #define COLUMN_PDUCHANNELPOWERALARMID		1    
+       #define COLUMN_PDUCHANNELPOWERALARMVOLTAGEUP		2    
+       #define COLUMN_PDUCHANNELPOWERALARMVOLTAGEDOWN		3    
+       #define COLUMN_PDUCHANNELPOWERALARMCURRENTUP		4     
+       #define COLUMN_PDUCHANNELPOWERALARMPOWERUP		5    
+       #define COLUMN_PDUCHANNELPOWERALARMCONSUMPTIONUP		6  
+
+
+/* column number definitions for table  pduSensorAlarmTable */
+       #define COLUMN_PDUSENSORALARMID		1    
+       #define COLUMN_PDUSENSORALARMVALUE1UP		2    
+       #define COLUMN_PDUSENSORALARMVALUE1DOWN		3    
+       #define COLUMN_PDUSENSORALARMVALUE2UP		4     
+       #define COLUMN_PDUSENSORALARMVALUE2DOWN		5    
+
 #endif /* PDUMIB_FORM_H */