def check_sensor_oper_status(index, sensor_name): global args, status, statusstr, oid_sensor_operstatus oper_status = my_snmp_get(args, oid_sensor_operstatus.format(index)) if oper_status.value == u'1': # Ok return elif oper_status.value == u'2': # Unavailable status, statusstr = trigger_not_ok( status, statusstr, STATE_WARN, '{} sensor status: Unavailable'.format(sensor_name)) elif oper_status.value == u'3': # Non-operational status, statusstr = trigger_not_ok( status, statusstr, STATE_WARN, '{} sensor status: Non-operational'.format(sensor_name))
def check_entity_state(index, entity_name): global args, status, statusstr, oid_state_oper global oid_state_usage, oid_state_alarm, oid_state_standby standby_status = my_snmp_get_int(args, oid_state_standby.format(index)) if standby_status in [2, 3]: # Entity is standby unit return oper_status = my_snmp_get_int(args, oid_state_oper.format(index)) if oper_status == 2: # disabled status, statusstr = trigger_not_ok( status, statusstr, STATE_CRIT, 'Entity {} is in a disabled state'.format(entity_name)) usage_status = my_snmp_get_int(args, oid_state_usage.format(index)) if usage_status == 4: # busy status, statusstr = trigger_not_ok( status, statusstr, STATE_CRIT, 'Entity {} is fully utilized, no capacity left'.format( entity_name)) alarm_status = my_snmp_get( args, oid_state_alarm.format(index)).value.encode('latin1') alarm_bit = unpack("B", alarm_status)[0] if alarm_bit == 0: # unknown, but also ok return elif alarm_bit == 1: # underRepair status, statusstr = trigger_not_ok( status, statusstr, STATE_WARN, 'Entity {} is undergoing repair'.format(entity_name)) elif alarm_bit == 2: # Critical status, statusstr = trigger_not_ok( status, statusstr, STATE_CRIT, 'Entity {} is in critical state'.format(entity_name)) elif alarm_bit == 3: # Major status, statusstr = trigger_not_ok( status, statusstr, STATE_CRIT, 'Entity {} is in major alarm state'.format(entity_name)) elif alarm_bit == 4: # Minor status, statusstr = trigger_not_ok( status, statusstr, STATE_WARN, 'Entity {} is in minor alarm state'.format(entity_name)) elif alarm_bit == 5: # Warning status, statusstr = trigger_not_ok( status, statusstr, STATE_WARN, 'Entity {} is in warning state'.format(entity_name)) elif alarm_bit == 6: # Indeterminate status, statusstr = trigger_not_ok( status, statusstr, STATE_WARN, 'Entity {} is in an indeterminative state'.format(entity_name))
from lib.cnh_nm import STATE_OK, STATE_WARN, STATE_CRIT from lib.cnh_nm import my_snmp_get, snmpresult_to_dict, my_snmp_walk, snmp_oid_decode_ip from lib.cnh_nm import trigger_not_ok, check_if_ok # Argument parsing parser = argparse.ArgumentParser(description='Check iBGP session status') parser.add_argument('-C', metavar='<community>', required=True, help='SNMP Community') parser.add_argument('-H', metavar='<host>', required=True, help='Host to check') args = parser.parse_args() # Get local AS number local_as = my_snmp_get(args, 'BGP4-MIB::bgpLocalAs.0').value # Get all BGP peers oids = [ 'CISCO-BGP4-MIB::cbgpPeer2RemoteAs', 'CISCO-BGP4-MIB::cbgpPeer2AdminStatus', 'CISCO-BGP4-MIB::cbgpPeer2LastErrorTxt', 'CISCO-BGP4-MIB::cbgpPeer2State' ] rawdata = my_snmp_walk(args, oids) data = snmpresult_to_dict(rawdata) # Now loop over data, and for _iBGP_ check the states status = STATE_OK
rawdata = my_snmp_walk(args, bulk_oids) policy_maps = dict() # policy-map index -> policy-map name class_maps = dict() # class-map index -> class-map name qos_interfaces = list() # qos ifIndex -> IF-MIB ifIndex cmstats = dict() # <interface>: {<qos_ifindex>: {<statsname>: <value>} } qos_config_index_mapping = dict() # Parse the first bulkwalk into the above datastructures for snmpobj in rawdata: if snmpobj.oid == 'cbQosCMName': class_maps[snmpobj.oid_index] = snmpobj.value elif snmpobj.oid == 'cbQosPolicyMapName': policy_maps[snmpobj.oid_index] = snmpobj.value elif snmpobj.oid == 'cbQosIfIndex': iftype = my_snmp_get(args, "{}.{}".format(QOS_IFTYPE_OID, snmpobj.oid_index)) if iftype.value != '5': # control-plane auto-copp policy_map_id = my_snmp_get(args, "{}.{}.{}".format(QOS_CONFIG_INDEX_OID, snmpobj.oid_index, snmpobj.oid_index)) qos_interfaces.append({ 'qos_ifindex': snmpobj.oid_index, 'ifmib_ifindex': snmpobj.value, 'policy_map_id': policy_map_id.value }) config_indexes = my_snmp_walk(args, "{}.{}".format(QOS_CONFIG_INDEX_OID, snmpobj.oid_index)) for ci in config_indexes: index_parts = ci.oid_index.split(".") if index_parts[0] not in qos_config_index_mapping: qos_config_index_mapping[index_parts[0]] = dict() qos_config_index_mapping[index_parts[0]][index_parts[1]] = ci.value elif snmpobj.oid.startswith('cbQosCM') and snmpobj.oid != 'cbQosCMName': index_parts = snmpobj.oid_index.split(".")
from lib.cnh_nm import trigger_not_ok, check_if_ok, ftos_get_peer_ip # Argument parsing parser = argparse.ArgumentParser(description='Check iBGP session status') parser.add_argument('-C', metavar='<community>', required=True, help='SNMP Community') parser.add_argument('-H', metavar='<host>', required=True, help='Host to check') args = parser.parse_args() # Get local AS number local_as = my_snmp_get( args, 'DELL-NETWORKING-BGP4-V2-MIB::dellNetBgpM2LocalAs.0').value # Get all BGP peers oids = [ 'DELL-NETWORKING-BGP4-V2-MIB::dellNetBgpM2PeerIdentifier', 'DELL-NETWORKING-BGP4-V2-MIB::dellNetBgpM2PeerState', 'DELL-NETWORKING-BGP4-V2-MIB::dellNetBgpM2PeerStatus', 'DELL-NETWORKING-BGP4-V2-MIB::dellNetBgpM2PeerRemoteAddrType', 'DELL-NETWORKING-BGP4-V2-MIB::dellNetBgpM2PeerRemoteAddr', 'DELL-NETWORKING-BGP4-V2-MIB::dellNetBgpM2PeerRemoteAs' ] rawdata = my_snmp_walk(args, oids) data = snmpresult_to_dict(rawdata) # Now loop over data, and for _iBGP_ check the states status = STATE_OK
# Get all VSS info and check whether the device is actually capable of VSS and have it enabled oids_chassis = [ 'CISCO-VIRTUAL-SWITCH-MIB::cvsChassisRole', # 1=standalone, 2=active, 3=standby 'CISCO-VIRTUAL-SWITCH-MIB::cvsChassisUpTime' ] oids_VSL = [ 'CISCO-VIRTUAL-SWITCH-MIB::cvsVSLConnectOperStatus', # 1=up, 2=down 'CISCO-VIRTUAL-SWITCH-MIB::cvsVSLLastConnectionStateChange', 'CISCO-VIRTUAL-SWITCH-MIB::cvsVSLConfiguredPortCount', 'CISCO-VIRTUAL-SWITCH-MIB::cvsVSLOperationalPortCount' ] oids_switch = [ 'CISCO-VIRTUAL-SWITCH-MIB::cvsSwitchCapability.0', # 0=standalone, 1=core(part of vss cluster) 'CISCO-VIRTUAL-SWITCH-MIB::cvsSwitchMode.0' # 1=standalone, 2=multiNode(VSS) ] cvsSwitchCapability = my_snmp_get(args, oids_switch[0]) cvsSwitchMode = my_snmp_get(args, oids_switch[1]) if cvsSwitchCapability.value != u'\xc0' and cvsSwitchCapability.value != u'\x80': print "UNKNOWN: Switch is not VSS capable!" sys.exit(STATE_UNKNOWN) if cvsSwitchMode.value != u'2': print "OK: Switch is VSS capable, but isn't running in VSS mode" sys.exit(STATE_OK) rawdata_chassis = my_snmp_walk(args, oids_chassis) rawdata_VSL = my_snmp_walk(args, oids_VSL) # Sort the walked data into a nicer format chassis = snmpresult_to_dict(rawdata_chassis) VSL = snmpresult_to_dict(rawdata_VSL) # A valid and healthy VSS cluster is always 2 members
# Oids for devices with older firmware f10_oid_stack_num_units = 'F10-S-SERIES-CHASSIS-MIB::chNumStackUnits.0' f10_oids_stack_status = [ 'F10-S-SERIES-CHASSIS-MIB::chStackUnitNumber', 'F10-S-SERIES-CHASSIS-MIB::chStackUnitStatus', 'F10-S-SERIES-CHASSIS-MIB::chStackUnitUpTime' ] f10_oid_mgmt_status = 'F10-S-SERIES-CHASSIS-MIB::chStackUnitMgmtStatus.{}' f10_oid_num_psus = 'F10-S-SERIES-CHASSIS-MIB::chStackUnitNumPowerSupplies.{}' f10_oid_num_fans = 'F10-S-SERIES-CHASSIS-MIB::chStackUnitNumFanTrays.{}' f10_oid_psu_oper = 'F10-S-SERIES-CHASSIS-MIB::chSysPowerSupplyOperStatus.{}.{}' f10_oid_fans_oper = 'F10-S-SERIES-CHASSIS-MIB::chSysFanTrayOperStatus.{}.{}' # Checking system firmware type device_type = my_snmp_get(args, oid_device_type) if device_type.value == u'NOSUCHOBJECT' or device_type.value == u'NOSUCHINSTANCE': f10 = True oid_stack_num_units = f10_oid_stack_num_units oids_stack_status = f10_oids_stack_status oid_num_psus = f10_oid_num_psus oid_num_fans = f10_oid_num_fans oid_psu_oper = f10_oid_psu_oper oid_fans_oper = f10_oid_fans_oper oid_mgmt_status = f10_oid_mgmt_status else: f10 = False num_stackunits = my_snmp_get(args, oid_stack_num_units) raw_stackunit_status = my_snmp_walk(args, oids_stack_status)
status, statusstr = trigger_not_ok( status, statusstr, STATE_CRIT, 'VPC Domain {} Peer-Link MsgRcvrStatus failure'.format(vpc_domain)) # Check VPC HostLink status rawdata = my_snmp_walk(args, oids_host_link_status) regex = re.compile(r"^[0-9]+\.") temp = [] for rd in rawdata: # Filter out the VPC Domain, doesn't matter here rd.oid_index = regex.sub('', rd.oid_index) temp.append(rd) data = snmpresult_to_dict(rawdata) for host_link in data: hl_data = data[host_link] snmp_ifname = my_snmp_get( args, oid_t_ifmib_ifname.format(hl_data['cVpcStatusHostLinkIfIndex'].value)) # 1 = down, 2 = downStar (forwarding via VPC host-link), 3 = up hl_status = int(hl_data['cVpcStatusHostLinkStatus'].value) if hl_status == 1: status, statusstr = trigger_not_ok( status, statusstr, STATE_CRIT, 'Host-link {} down'.format(snmp_ifname.value)) if hl_status == 2: status, statusstr = trigger_not_ok( status, statusstr, STATE_WARN, 'Host-link {} down but forwarding via VPC peer-link'.format( snmp_ifname.value)) # 1 = success, 2 = failed, 3 = notApplicable
rawdata = my_snmp_walk(args, 'ENTITY-MIB::entPhysicalTable') data = snmpresult_to_dict(rawdata) # Now we loop over the data and perform poweradmin/poweroper/sensorstatus checks status = STATE_OK statusstr = '' for index in data: descr = data[index]['entPhysicalDescr'].value # First off we'll try getting some Power status for those that support it # 1/on - Admin power on # 2/off - Admin power off # 3/inlineAuto,4/inlineOn,5/powerCycle - PoE stuff, irrelevant for us so not much caring here # cefcFRUPowerAdminStatus - 1=on, 2=off, 3=inlineAuto, 4=inlineOn, 5=powerCycle pwr_adminstatus = my_snmp_get( args, "CISCO-ENTITY-FRU-CONTROL-MIB::cefcFRUPowerAdminStatus.{0}".format( index)) if 'NOSUCHINSTANCE' not in pwr_adminstatus.value: pwr_adminstatus.value = int(str(pwr_adminstatus.value)) if pwr_adminstatus.value == 1: pass # ok elif pwr_adminstatus == 2: status, statusstr = trigger_not_ok( status, statusstr, STATE_WARN, "PowerAdminStatus Off for {0}".format(descr)) elif pwr_adminstatus == 3: pass # ok - PoE stuff elif pwr_adminstatus == 4: pass # ok - PoE stuff elif pwr_adminstatus == 5: pass # ok - PoE stuff
# Argument parsing parser = argparse.ArgumentParser(description='Check a OSPF sessions status') parser.add_argument('-C', metavar='<community>', required=True, help='SNMP Community') parser.add_argument('-H', metavar='<host>', required=True, help='Host to check') parser.add_argument('-p', metavar='<peer>', required=True, help='IPv4 of peer to check') args = parser.parse_args() # Get all interfaces, and then get OSPF data for that interface rawdata = my_snmp_get(args, 'OSPF-MIB::ospfNbrState.{}.0'.format(args.p)) if not rawdata or 'NOSUCH' in rawdata.value: print "CRITICAL: No OSPF session detected for peer {}".format(args.p) sys.exit(STATE_CRIT) nei_state = int(str(rawdata.value)) if nei_state not in ospf_ok_states: print "CRITICAL: OSPF session for peer {} down".format(args.p) sys.exit(STATE_CRIT) print "OK: OSPF session for {} is up".format(args.p) sys.exit(STATE_OK)
parser.add_argument('-C', metavar='<community>', required=True, help='SNMP Community') parser.add_argument('-H', metavar='<host>', required=True, help='Host to check') args = parser.parse_args() # Get data oids = [ 'CISCO-CONFIG-MAN-MIB::ccmHistoryRunningLastChanged', 'CISCO-CONFIG-MAN-MIB::ccmHistoryStartupLastChanged', 'CISCO-CONFIG-MAN-MIB::ccmCTIDWhoChanged' ] rawdata = my_snmp_walk(args, oids) data = snmpresult_to_dict(rawdata)['0'] uptime = my_snmp_get(args, 'SNMPv2-MIB::sysUpTime.0') # Check the data status = STATE_OK statusstr = '' try: culprit = data['ccmCTIDWhoChanged'].value except KeyError: culprit = 'unknown' # IOS-XR if float(data['ccmHistoryStartupLastChanged'].value) < float(data['ccmHistoryRunningLastChanged'].value): status = STATE_WARN statusstr = "Either {} is still doing changes or {} just forgot to save the config.".format(culprit, culprit) if ((float(uptime.value) - float(data['ccmHistoryRunningLastChanged'].value)) / 100) > (3600 * 3): status = STATE_CRIT statusstr = "Okay, {} has definately forgotten to save the configuration!".format(culprit)
# Get all LAG ports oids = [ 'DELL-NETWORKING-LINK-AGGREGATION-MIB::dot3aAggCfgNumPorts', 'DELL-NETWORKING-LINK-AGGREGATION-MIB::dot3aAggCfgOperStatus', 'DELL-NETWORKING-LINK-AGGREGATION-MIB::dot3aAggCfgIfIndex', 'DELL-NETWORKING-LINK-AGGREGATION-MIB::dot3aAggCfgPortListString' ] rawdata = my_snmp_walk(args, oids) data = snmpresult_to_dict(rawdata) # Loop through them and check num ports vs num active ports and operational status status = STATE_OK statusstr = "" for index, lag in data.iteritems(): lag_name = my_snmp_get(args, 'IF-MIB::ifDescr.{}'.format(lag['dot3aAggCfgIfIndex'].value)).value num_ports = int(str(lag['dot3aAggCfgNumPorts'].value)) if num_ports < 1: status, statusstr = trigger_not_ok( status, statusstr, STATE_WARN, '{} has no configured members'.format(lag_name)) continue active_ports = ftos_parse_lag_active_ports(lag['dot3aAggCfgPortListString'].value) if active_ports < num_ports and active_ports > 1: status, statusstr = trigger_not_ok( status, statusstr,