Search in sources :

Example 1 with UnsignedInteger32

use of org.snmp4j.smi.UnsignedInteger32 in project cloudstack by apache.

the class SnmpHelper method createPDU.

private PDU createPDU(SnmpTrapInfo snmpTrapInfo) {
    PDU trap = new PDU();
    trap.setType(PDU.TRAP);
    int alertType = snmpTrapInfo.getAlertType() + 1;
    if (alertType > 0) {
        trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, getOID(CsSnmpConstants.TRAPS_PREFIX + alertType)));
        if (snmpTrapInfo.getDataCenterId() != 0) {
            trap.add(new VariableBinding(getOID(CsSnmpConstants.DATA_CENTER_ID), new UnsignedInteger32(snmpTrapInfo.getDataCenterId())));
        }
        if (snmpTrapInfo.getPodId() != 0) {
            trap.add(new VariableBinding(getOID(CsSnmpConstants.POD_ID), new UnsignedInteger32(snmpTrapInfo.getPodId())));
        }
        if (snmpTrapInfo.getClusterId() != 0) {
            trap.add(new VariableBinding(getOID(CsSnmpConstants.CLUSTER_ID), new UnsignedInteger32(snmpTrapInfo.getClusterId())));
        }
        if (snmpTrapInfo.getMessage() != null) {
            trap.add(new VariableBinding(getOID(CsSnmpConstants.MESSAGE), new OctetString(snmpTrapInfo.getMessage())));
        } else {
            throw new CloudRuntimeException(" What is the use of alert without message ");
        }
        if (snmpTrapInfo.getGenerationTime() != null) {
            trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME), new OctetString(snmpTrapInfo.getGenerationTime().toString())));
        } else {
            trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME)));
        }
    } else {
        throw new CloudRuntimeException(" Invalid alert Type ");
    }
    return trap;
}
Also used : PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsignedInteger32(org.snmp4j.smi.UnsignedInteger32) VariableBinding(org.snmp4j.smi.VariableBinding)

Aggregations

CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 PDU (org.snmp4j.PDU)1 OctetString (org.snmp4j.smi.OctetString)1 UnsignedInteger32 (org.snmp4j.smi.UnsignedInteger32)1 VariableBinding (org.snmp4j.smi.VariableBinding)1