def _parseMixedIPFromIndex(rawIndexValue): rawIndexValue = rawIndexValue.split('.') #split it to array rawIndexValue = ".".join(rawIndexValue[2:]) #the first two elements are irrelevant, ignore them rawIndexValue = OctetString.fromString(rawIndexValue, '.', 10).getValue() ipAddr = None try: ipAddr = InetAddress.getByAddress(rawIndexValue).getHostAddress() except: pass return ipAddr
def parseIPFromIpNetToPhysicalTableIndex(rawIndexValue): realValue = None try: rawIndexValue = rawIndexValue.split('.') #split it to array rawIndexValue = ".".join(rawIndexValue[3:]) #the first three elements are irrelevant, ignore them rawIndexValue = OctetString.fromString(rawIndexValue, '.', 10).getValue() inetAddress = InetAddress.getByAddress(rawIndexValue) realValue = inetAddress.getHostAddress() except: pass return realValue
def parseIPv6FromIPv6NetToMediaTableIndex(rawIndexValue): realValue = None try: rawIndexValue = rawIndexValue.split('.') #split it to array rawIndexValue = ".".join(rawIndexValue[2:]) #the first two elements are irrelevant, ignore them rawIndexValue = OctetString.fromString(rawIndexValue, '.', 10).getValue() ipv6Address = InetAddress.getByAddress(rawIndexValue) realValue = ipv6Address.getHostAddress() except: pass return realValue
def main(): if param_disabled or not param_ipAddress: console.warn('Disabled or IP address not specified; nothing to do') return # complete the init of the target _target.setAddress( UdpAddress('%s/%s' % (param_ipAddress, param_port or DEFAULT_PORT))) _target.setCommunity(OctetString(param_community or DEFAULT_COMMUNITY)) # kick-off timer to poll the outlet status Timer( lambda: lookup_local_action('snmpLookupOID').call( { 'oid': OUTLETSTATUS_OID, 'signal': 'rawOutletStatus' }), 30, 2) # and trap the feedback local_event_rawOutletStatus.addEmitHandler(handleOutletStatusResult)
def local_action_snmpSetOID(arg): '''{'group': 'SNMP', 'order': 100, 'schema': {'type': 'object', 'properties': { 'oid': {'type': 'string', 'order': 1}, 'value': {'type': 'string', 'order': 2}, 'signal': {'type': 'string', 'order': 3} }}}''' pdu = PDU() pdu.add(VariableBinding(OID(arg['oid']), OctetString(arg['value']))) pdu.setType(PDU.SET) respEvent = NodelSnmp.shared().set(pdu, _target) if respEvent == None: console.warn('timeout') return respPDU = respEvent.getResponse() if respPDU == None: console.warn('response PDU was empty') return errStatus = respPDU.getErrorStatus() if errStatus != PDU.noError: errIndex = respPDU.getErrorIndex() errText = respPDU.getErrorStatusText() console.warn('an error occurred - status:%s, index:%s, text:[%s]' % (errStatus, errIndex, errText)) return result = str(respPDU.getVariableBindings()[0].getVariable()) signal = lookup_local_event(arg['signal']).emit(result)
'type': 'integer', 'hint': '%s (default)' % DEFAULT_PORT }}) DEFAULT_COMMUNITY = 'public' param_community = Parameter( {'schema': { 'type': 'string', 'hint': '%s (default)' % DEFAULT_COMMUNITY }}) # --> # the community target _target = CommunityTarget() _target.setCommunity(OctetString('public')) _target.setVersion(SnmpConstants.version1) _target.setRetries(2) _target.setTimeout(1000) def main(): if param_disabled or not param_ipAddress: console.warn('Disabled or IP address not specified; nothing to do') return # complete the init of the target _target.setAddress( UdpAddress('%s/%s' % (param_ipAddress, param_port or DEFAULT_PORT))) _target.setCommunity(OctetString(param_community or DEFAULT_COMMUNITY))