SNMP Publisher / Agent
-
Hi,
Can Mango publish data as a SNMP agent? Can Mango send SNMP traps as an Event Handler type?
BR,
Ricardo -
Hi @ricardo
Mango only has 4 publishers: BACnet, Modbus, Mango PTCP and an HTTP publisher
-
Hi Ricardo,
No, Mango does not currently have an SNMP publisher.
Can Mango send SNMP traps as an Event Handler type?
Yes, but it isn't really set up to make such a thing easy. I think we'd best to have a running SNMP data source and use some reflection, something like this, in a Set Point Event Handler,
//untested var snmpDataSourceId = com.serotonin.m2m2.db.dao.DataPointDao.instance.getIdByXid("DS_XID_HERE"); var snmpDataSourceRT = com.serotonin.m2m2.Common.runtimeManager.getRunningDataSource( snmpDataSourceId ); if( snmpDataSourceRT !== null ) { var field = snmpDataSourceRT.getClass().getDeclearedField("snmp"); field.setAccessible( true ); var snmp = field.get( snmpDataSourceRT ); //get the SNMP version information field = snmpDataSourceRT.getClass().getDeclearedField("writeVersion"); field.setAccessible( true ); var writeVersion = field.get( snmpDataSourceRT ); //get the target to send it to var target = writeVersion.getTarget( "192.168.0.123", 162, 1, 5000 ); //host, port, retries, timeout //construct the PDU var pdu = writeVersion.createPDU(); if( target.getVersion === org.snmp4j.mp.SnmpConstants.version1 ) { pdu.setType( org.snmp4j.PDU.V1TRAP ); pdu.setEnterprise( new org.snmp4j.smi.OID( "1.1.1.1.1.1.1") ); //probably a clever way to get the OID from the event pdu.setGenericTrap( org.snmp4j.PDUv1.ENTERPRISE_SPECIFIC ); pdu.setSpecificTrap( 1 ); //looks like this may need to cycle in value 1-5 pdu.setAgentAddress( new org.snmp4j.smi.IpAddress( "127.0.0.1" )); //Mango's IP on the network here snmp.send( pdu, target ); } else if ( target.getVersion === org.snmp4j.mp.SnmpConstants.version2c ) { throw "not yet implemented!"; } else if ( target.getVersion === org.snmp4j.mp.SnmpConstants.version3 ) { throw "not yet implemented!"; } else throw "unknown snmp version!"; } else { throw "Data source not found to send trap for event: " + event; } return UNCHANGED; //don't set from the set point handler
I would be somewhat surprised if this works, but it shouldn't be too far from the way to do it. I consulted this site for the V1 implementation, and there is also a v2c example: https://www.jitendrazaa.com/blog/java/snmp/generating-trap-in-snmp-using-snmp4j/
So, possible, but will probably take some trial and error to figure out.
-
@craigweb said in SNMP Publisher / Agent:
Hi @ricardo
Mango only has 4 publishers: BACnet, Modbus, Mango PTCP and an HTTP publisher
Also Twilio and Pachube.