ソースを参照

1、添加SNMP总体电源信息超限报警

liyuezong 1 年間 前
親
コミット
f11267f23a
共有2 個のファイルを変更した、430 個の追加 と 0 個の削除を含む
  1. 425 0
      pro/src/pduMIB_scalar.c
  2. 5 0
      pro/src/pduMIB_scalar.h

+ 425 - 0
pro/src/pduMIB_scalar.c

@@ -63,6 +63,11 @@ void init_pduMIB_scalar(void)
     const oid pduNTPServerName_oid[] = {1, 3, 6, 1, 4, 1, 2024, 1, 5, 8, 4};
     const oid pduNTPServerIPorDomain_oid[] = {1, 3, 6, 1, 4, 1, 2024, 1, 5, 8, 5};
     const oid pduNTPServerPort_oid[] = {1, 3, 6, 1, 4, 1, 2024, 1, 5, 8, 6};
+    const oid pduTotalPowerAlarmVoltageUp_oid[] = {1, 3, 6, 1, 4, 1, 2024, 1, 6, 4};
+    const oid pduTotalPowerAlarmVoltageDown_oid[] = {1, 3, 6, 1, 4, 1, 2024, 1, 6, 5};
+    const oid pduTotalPowerAlarmCurrentUp_oid[] = {1, 3, 6, 1, 4, 1, 2024, 1, 6, 6};
+    const oid pduTotalPowerAlarmPowerUp_oid[] = {1, 3, 6, 1, 4, 1, 2024, 1, 6, 7};
+    const oid pduTotalPowerAlarmConsumptionUp_oid[] = {1, 3, 6, 1, 4, 1, 2024, 1, 6, 8};
     const oid pduCurrentLimitUp_oid[] = {1, 3, 6, 1, 4, 1, 2024, 1, 7, 2, 1};
     const oid pduVoltageLimitUp_oid[] = {1, 3, 6, 1, 4, 1, 2024, 1, 7, 2, 2};
     const oid pduVoltageLimitDown_oid[] = {1, 3, 6, 1, 4, 1, 2024, 1, 7, 2, 3};
@@ -269,6 +274,26 @@ void init_pduMIB_scalar(void)
         netsnmp_create_handler_registration("pduNTPServerPort", handle_pduNTPServerPort,
                                             pduNTPServerPort_oid, OID_LENGTH(pduNTPServerPort_oid),
                                             HANDLER_CAN_RWRITE));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("pduTotalPowerAlarmVoltageUp", handle_pduTotalPowerAlarmVoltageUp,
+                                            pduTotalPowerAlarmVoltageUp_oid, OID_LENGTH(pduTotalPowerAlarmVoltageUp_oid),
+                                            HANDLER_CAN_RONLY));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("pduTotalPowerAlarmVoltageDown", handle_pduTotalPowerAlarmVoltageDown,
+                                            pduTotalPowerAlarmVoltageDown_oid, OID_LENGTH(pduTotalPowerAlarmVoltageDown_oid),
+                                            HANDLER_CAN_RONLY));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("pduTotalPowerAlarmCurrentUp", handle_pduTotalPowerAlarmCurrentUp,
+                                            pduTotalPowerAlarmCurrentUp_oid, OID_LENGTH(pduTotalPowerAlarmCurrentUp_oid),
+                                            HANDLER_CAN_RONLY));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("pduTotalPowerAlarmPowerUp", handle_pduTotalPowerAlarmPowerUp,
+                                            pduTotalPowerAlarmPowerUp_oid, OID_LENGTH(pduTotalPowerAlarmPowerUp_oid),
+                                            HANDLER_CAN_RONLY));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("pduTotalPowerAlarmConsumptionUp", handle_pduTotalPowerAlarmConsumptionUp,
+                                            pduTotalPowerAlarmConsumptionUp_oid, OID_LENGTH(pduTotalPowerAlarmConsumptionUp_oid),
+                                            HANDLER_CAN_RONLY));
     netsnmp_register_scalar(
         netsnmp_create_handler_registration("pduCurrentLimitUp", handle_pduCurrentLimitUp,
                                             pduCurrentLimitUp_oid, OID_LENGTH(pduCurrentLimitUp_oid),
@@ -3912,6 +3937,406 @@ int handle_pduConsumptionLimitUp(netsnmp_mib_handler *handler,
 
     return SNMP_ERR_NOERROR;
 }
+
+
+
+int handle_pduTotalPowerAlarmVoltageUp(netsnmp_mib_handler *handler,
+                                 netsnmp_handler_registration *reginfo,
+                                 netsnmp_agent_request_info *reqinfo,
+                                 netsnmp_request_info *requests)
+{
+    int ret;
+    /* We are never called for a GETNEXT if it's registered as a
+       "instance", as it's "magically" handled for us.  */
+
+    /* a instance handler also only hands us one request at a time, so
+       we don't need to loop over a list of requests; we'll only get one. */
+    bool AlarmFlag = false;
+    switch (reqinfo->mode)
+    {
+    case MODE_GET:
+        AlarmFlag = __globalDeviceManage._globalPowerManger._PowerWarninginfo.w_voltage_up;
+        snmp_set_var_typed_integer(requests->requestvb, ASN_INTEGER, AlarmFlag);
+        break;
+
+    /*
+     * SET REQUEST
+     *
+     * multiple states in the transaction.  See:
+     * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
+     */
+    case MODE_SET_RESERVE1:
+        /* or you could use netsnmp_check_vb_type_and_size instead */
+        ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
+        if (ret != SNMP_ERR_NOERROR)
+        {
+            netsnmp_set_request_error(reqinfo, requests, ret);
+        }
+        break;
+
+    case MODE_SET_RESERVE2:
+        /* XXX malloc "undo" storage buffer */
+        // if (/* XXX if malloc, or whatever, failed: */) {
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
+        // }
+        break;
+
+    case MODE_SET_FREE:
+        /* XXX: free resources allocated in RESERVE1 and/or
+           RESERVE2.  Something failed somewhere, and the states
+           below won't be called. */
+        break;
+
+    case MODE_SET_ACTION:
+        /* XXX: perform the value change here */
+        // if (/* XXX: error? */) {
+        //     netsnmp_set_request_error(reqinfo, requests, /* some error */);
+        // }
+        break;
+
+    case MODE_SET_COMMIT:
+        /* XXX: delete temporary storage */
+        // if (/* XXX: error? */) {
+        //     /* try _really_really_ hard to never get to this point */
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
+        // }
+        break;
+
+    case MODE_SET_UNDO:
+        /* XXX: UNDO and return to previous value for the object */
+        // if (/* XXX: error? */) {
+        //     /* try _really_really_ hard to never get to this point */
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
+        // }
+        break;
+
+    default:
+        /* we should never get here, so this is a really bad error */
+        snmp_log(LOG_ERR, "unknown mode (%d) in handle_pduTotalPowerAlarmVoltageUp\n", reqinfo->mode);
+        return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+
+int handle_pduTotalPowerAlarmVoltageDown(netsnmp_mib_handler *handler,
+                                 netsnmp_handler_registration *reginfo,
+                                 netsnmp_agent_request_info *reqinfo,
+                                 netsnmp_request_info *requests)
+{
+    int ret;
+    /* We are never called for a GETNEXT if it's registered as a
+       "instance", as it's "magically" handled for us.  */
+
+    /* a instance handler also only hands us one request at a time, so
+       we don't need to loop over a list of requests; we'll only get one. */
+    bool AlarmFlag = false;
+    switch (reqinfo->mode)
+    {
+    case MODE_GET:
+        AlarmFlag = __globalDeviceManage._globalPowerManger._PowerWarninginfo.w_voltage_down;
+         snmp_set_var_typed_integer(requests->requestvb, ASN_INTEGER, AlarmFlag);
+        break;
+
+    /*
+     * SET REQUEST
+     *
+     * multiple states in the transaction.  See:
+     * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
+     */
+    case MODE_SET_RESERVE1:
+        /* or you could use netsnmp_check_vb_type_and_size instead */
+        ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
+        if (ret != SNMP_ERR_NOERROR)
+        {
+            netsnmp_set_request_error(reqinfo, requests, ret);
+        }
+        break;
+
+    case MODE_SET_RESERVE2:
+        /* XXX malloc "undo" storage buffer */
+        // if (/* XXX if malloc, or whatever, failed: */) {
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
+        // }
+        break;
+
+    case MODE_SET_FREE:
+        /* XXX: free resources allocated in RESERVE1 and/or
+           RESERVE2.  Something failed somewhere, and the states
+           below won't be called. */
+        break;
+
+    case MODE_SET_ACTION:
+        /* XXX: perform the value change here */
+        // if (/* XXX: error? */) {
+        //     netsnmp_set_request_error(reqinfo, requests, /* some error */);
+        // }
+        break;
+
+    case MODE_SET_COMMIT:
+        /* XXX: delete temporary storage */
+        // if (/* XXX: error? */) {
+        //     /* try _really_really_ hard to never get to this point */
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
+        // }
+        break;
+
+    case MODE_SET_UNDO:
+        /* XXX: UNDO and return to previous value for the object */
+        // if (/* XXX: error? */) {
+        //     /* try _really_really_ hard to never get to this point */
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
+        // }
+        break;
+
+    default:
+        /* we should never get here, so this is a really bad error */
+        snmp_log(LOG_ERR, "unknown mode (%d) in handle_pduTotalPowerAlarmVoltageDown\n", reqinfo->mode);
+        return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+
+
+int handle_pduTotalPowerAlarmCurrentUp(netsnmp_mib_handler *handler,
+                                 netsnmp_handler_registration *reginfo,
+                                 netsnmp_agent_request_info *reqinfo,
+                                 netsnmp_request_info *requests)
+{
+    int ret;
+    /* We are never called for a GETNEXT if it's registered as a
+       "instance", as it's "magically" handled for us.  */
+
+    /* a instance handler also only hands us one request at a time, so
+       we don't need to loop over a list of requests; we'll only get one. */
+    bool AlarmFlag = false;
+    switch (reqinfo->mode)
+    {
+    case MODE_GET:
+        AlarmFlag = __globalDeviceManage._globalPowerManger._PowerWarninginfo.w_current;
+        snmp_set_var_typed_integer(requests->requestvb, ASN_INTEGER, AlarmFlag);
+        break;
+
+    /*
+     * SET REQUEST
+     *
+     * multiple states in the transaction.  See:
+     * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
+     */
+    case MODE_SET_RESERVE1:
+        /* or you could use netsnmp_check_vb_type_and_size instead */
+        ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
+        if (ret != SNMP_ERR_NOERROR)
+        {
+            netsnmp_set_request_error(reqinfo, requests, ret);
+        }
+        break;
+
+    case MODE_SET_RESERVE2:
+        /* XXX malloc "undo" storage buffer */
+        // if (/* XXX if malloc, or whatever, failed: */) {
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
+        // }
+        break;
+
+    case MODE_SET_FREE:
+        /* XXX: free resources allocated in RESERVE1 and/or
+           RESERVE2.  Something failed somewhere, and the states
+           below won't be called. */
+        break;
+
+    case MODE_SET_ACTION:
+        /* XXX: perform the value change here */
+        // if (/* XXX: error? */) {
+        //     netsnmp_set_request_error(reqinfo, requests, /* some error */);
+        // }
+        break;
+
+    case MODE_SET_COMMIT:
+        /* XXX: delete temporary storage */
+        // if (/* XXX: error? */) {
+        //     /* try _really_really_ hard to never get to this point */
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
+        // }
+        break;
+
+    case MODE_SET_UNDO:
+        /* XXX: UNDO and return to previous value for the object */
+        // if (/* XXX: error? */) {
+        //     /* try _really_really_ hard to never get to this point */
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
+        // }
+        break;
+
+    default:
+        /* we should never get here, so this is a really bad error */
+        snmp_log(LOG_ERR, "unknown mode (%d) in handle_pduTotalPowerAlarmCurrentUp\n", reqinfo->mode);
+        return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+
+int handle_pduTotalPowerAlarmPowerUp(netsnmp_mib_handler *handler,
+                                 netsnmp_handler_registration *reginfo,
+                                 netsnmp_agent_request_info *reqinfo,
+                                 netsnmp_request_info *requests)
+{
+    int ret;
+    /* We are never called for a GETNEXT if it's registered as a
+       "instance", as it's "magically" handled for us.  */
+
+    /* a instance handler also only hands us one request at a time, so
+       we don't need to loop over a list of requests; we'll only get one. */
+    bool AlarmFlag = false;
+    switch (reqinfo->mode)
+    {
+    case MODE_GET:
+        AlarmFlag = __globalDeviceManage._globalPowerManger._PowerWarninginfo.w_power;
+        snmp_set_var_typed_integer(requests->requestvb, ASN_INTEGER, AlarmFlag);
+        break;
+
+    /*
+     * SET REQUEST
+     *
+     * multiple states in the transaction.  See:
+     * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
+     */
+    case MODE_SET_RESERVE1:
+        /* or you could use netsnmp_check_vb_type_and_size instead */
+        ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
+        if (ret != SNMP_ERR_NOERROR)
+        {
+            netsnmp_set_request_error(reqinfo, requests, ret);
+        }
+        break;
+
+    case MODE_SET_RESERVE2:
+        /* XXX malloc "undo" storage buffer */
+        // if (/* XXX if malloc, or whatever, failed: */) {
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
+        // }
+        break;
+
+    case MODE_SET_FREE:
+        /* XXX: free resources allocated in RESERVE1 and/or
+           RESERVE2.  Something failed somewhere, and the states
+           below won't be called. */
+        break;
+
+    case MODE_SET_ACTION:
+        /* XXX: perform the value change here */
+        // if (/* XXX: error? */) {
+        //     netsnmp_set_request_error(reqinfo, requests, /* some error */);
+        // }
+        break;
+
+    case MODE_SET_COMMIT:
+        /* XXX: delete temporary storage */
+        // if (/* XXX: error? */) {
+        //     /* try _really_really_ hard to never get to this point */
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
+        // }
+        break;
+
+    case MODE_SET_UNDO:
+        /* XXX: UNDO and return to previous value for the object */
+        // if (/* XXX: error? */) {
+        //     /* try _really_really_ hard to never get to this point */
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
+        // }
+        break;
+
+    default:
+        /* we should never get here, so this is a really bad error */
+        snmp_log(LOG_ERR, "unknown mode (%d) in handle_pduTotalPowerAlarmPowerUp\n", reqinfo->mode);
+        return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+
+int handle_pduTotalPowerAlarmConsumptionUp(netsnmp_mib_handler *handler,
+                                 netsnmp_handler_registration *reginfo,
+                                 netsnmp_agent_request_info *reqinfo,
+                                 netsnmp_request_info *requests)
+{
+    int ret;
+    /* We are never called for a GETNEXT if it's registered as a
+       "instance", as it's "magically" handled for us.  */
+
+    /* a instance handler also only hands us one request at a time, so
+       we don't need to loop over a list of requests; we'll only get one. */
+    bool AlarmFlag = false;
+    switch (reqinfo->mode)
+    {
+    case MODE_GET:
+        AlarmFlag = __globalDeviceManage._globalPowerManger._PowerWarninginfo.w_consumption;
+         snmp_set_var_typed_integer(requests->requestvb, ASN_INTEGER, AlarmFlag);
+        break;
+
+    /*
+     * SET REQUEST
+     *
+     * multiple states in the transaction.  See:
+     * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
+     */
+    case MODE_SET_RESERVE1:
+        /* or you could use netsnmp_check_vb_type_and_size instead */
+        ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
+        if (ret != SNMP_ERR_NOERROR)
+        {
+            netsnmp_set_request_error(reqinfo, requests, ret);
+        }
+        break;
+
+    case MODE_SET_RESERVE2:
+        /* XXX malloc "undo" storage buffer */
+        // if (/* XXX if malloc, or whatever, failed: */) {
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
+        // }
+        break;
+
+    case MODE_SET_FREE:
+        /* XXX: free resources allocated in RESERVE1 and/or
+           RESERVE2.  Something failed somewhere, and the states
+           below won't be called. */
+        break;
+
+    case MODE_SET_ACTION:
+        /* XXX: perform the value change here */
+        // if (/* XXX: error? */) {
+        //     netsnmp_set_request_error(reqinfo, requests, /* some error */);
+        // }
+        break;
+
+    case MODE_SET_COMMIT:
+        /* XXX: delete temporary storage */
+        // if (/* XXX: error? */) {
+        //     /* try _really_really_ hard to never get to this point */
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
+        // }
+        break;
+
+    case MODE_SET_UNDO:
+        /* XXX: UNDO and return to previous value for the object */
+        // if (/* XXX: error? */) {
+        //     /* try _really_really_ hard to never get to this point */
+        //     netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
+        // }
+        break;
+
+    default:
+        /* we should never get here, so this is a really bad error */
+        snmp_log(LOG_ERR, "unknown mode (%d) in handle_pduTotalPowerAlarmConsumptionUp\n", reqinfo->mode);
+        return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+
+
 int handle_pduRestart(netsnmp_mib_handler *handler,
                       netsnmp_handler_registration *reginfo,
                       netsnmp_agent_request_info *reqinfo,

+ 5 - 0
pro/src/pduMIB_scalar.h

@@ -56,6 +56,11 @@ Netsnmp_Node_Handler handle_pduNTPDate;
 Netsnmp_Node_Handler handle_pduNTPServerName;
 Netsnmp_Node_Handler handle_pduNTPServerIPorDomain;
 Netsnmp_Node_Handler handle_pduNTPServerPort;
+Netsnmp_Node_Handler handle_pduTotalPowerAlarmVoltageUp;
+Netsnmp_Node_Handler handle_pduTotalPowerAlarmVoltageDown;
+Netsnmp_Node_Handler handle_pduTotalPowerAlarmCurrentUp;
+Netsnmp_Node_Handler handle_pduTotalPowerAlarmPowerUp;
+Netsnmp_Node_Handler handle_pduTotalPowerAlarmConsumptionUp;
 Netsnmp_Node_Handler handle_pduCurrentLimitUp;
 Netsnmp_Node_Handler handle_pduVoltageLimitUp;
 Netsnmp_Node_Handler handle_pduVoltageLimitDown;