def _parse_mibs_cisco_config(self, oid, val): """ Parse Cisco specific ConfigMan MIBs for running-config info This gets added to the Information tab! """ sub_oid = oid_in_branch(ccmHistoryRunningLastChanged, oid) if sub_oid: # ticks in 1/100th of a second ago = str(datetime.timedelta(seconds=(int(val) / 100))) self.add_vendor_data("Configuration", "Running Last Modified", ago) return True sub_oid = oid_in_branch(ccmHistoryRunningLastSaved, oid) if sub_oid: # ticks in 1/100th of a second ago = str(datetime.timedelta(seconds=(int(val) / 100))) self.add_vendor_data("Configuration", "Running Last Saved", ago) return True sub_oid = oid_in_branch(ccmHistoryStartupLastChanged, oid) if sub_oid: # ticks in 1/100th of a second ago = str(datetime.timedelta(seconds=(int(val) / 100))) self.add_vendor_data("Configuration", "Startup Last Changed", ago) return True return False
def _parse_mibs_cisco_poe(self, oid, val): """ Parse Cisco POE Extension MIB database """ # the actual consumed power, shown in 'show power inline <name> detail' pe_index = oid_in_branch(cpeExtPsePortPwrConsumption, oid) if pe_index: if pe_index in self.poe_port_entries.keys(): self.poe_port_entries[ pe_index].power_consumption_supported = True self.poe_port_entries[pe_index].power_consumed = int(val) return True # this is what is shown via 'show power inline interface X' command: pe_index = oid_in_branch(cpeExtPsePortPwrAvailable, oid) if pe_index: if pe_index in self.poe_port_entries.keys(): self.poe_port_entries[ pe_index].power_consumption_supported = True self.poe_port_entries[pe_index].power_available = int(val) return True pe_index = oid_in_branch(cpeExtPsePortMaxPwrDrawn, oid) if pe_index: if pe_index in self.poe_port_entries.keys(): self.poe_port_entries[ pe_index].power_consumption_supported = True self.poe_port_entries[pe_index].max_power_consumed = int(val) return True return False
def _parse_mibs_procurve_config(self, oid, val): """ Parse Procurve specific ConfigMan MIBs for running-config info This gets added to the Information tab! """ sub_oid = oid_in_branch(hpnicfCfgRunModifiedLast, oid) if sub_oid: ago = str(datetime.timedelta(seconds=int(val) / 100)) self.add_vendor_data("Configuration", "Running Last Modified", ago) return True sub_oid = oid_in_branch(hpnicfCfgRunSavedLast, oid) if sub_oid: ago = str(datetime.timedelta(seconds=int(val) / 100)) self.add_vendor_data("Configuration", "Running Last Saved", ago) return True return False
def _parse_mibs_comware_configfile(self, oid, val): """ Parse Comware specific ConfigMan MIB """ dprint("_parse_mibs_comware_configfile(Comware)") sub_oid = oid_in_branch(hh3cCfgOperateRowStatus, oid) if sub_oid: if int(sub_oid) > self.active_config_rows: self.active_config_rows = int(sub_oid) return True
def _parse_mibs_comware_if_linkmode(self, oid, val): """ Parse Comware specific Interface Extension MIB for link mode, PoE info """ if_index = int(oid_in_branch(hh3cIfLinkMode, oid)) if if_index: dprint(f"Comware LinkMode if_index {if_index} link_mode {val}") if if_index in self.interfaces.keys(): if int(val) == HH3C_ROUTE_MODE: self.interfaces[if_index].is_routed = True return True return False
def _parse_mibs_comware_vlan(self, oid, val): """ Parse Comware specific VLAN MIB """ vlan_id = int(oid_in_branch(hh3cdot1qVlanName, oid)) if vlan_id > 0: if vlan_id in self.vlans.keys(): # some Comware switches only report "VLAN xxxx", skip that! if not val.startswith('VLAN '): self.vlans[vlan_id].name = val return True return False
def _parse_oid(self, oid, val): """ Parse a single OID with data returned from a switch through some "get" function THIS NEEDS WORK TO IMPROVE PERFORMANCE !!! Returns True if we parse the OID and we should cache it! """ dprint(f"CISCO Parsing OID {oid}") if_index = int(oid_in_branch(vmVoiceVlanId, oid)) if if_index: voiceVlanId = int(val) if if_index in self.interfaces.keys( ) and voiceVlanId in self.vlans.keys(): self.interfaces[if_index].voice_vlan = voiceVlanId return True """ Stack-MIB PortId to ifIndex mapping """ stack_port_id = oid_in_branch(portIfIndex, oid) if stack_port_id: self.stack_port_to_if_index[stack_port_id] = int(val) return True if self._parse_mibs_cisco_vtp(oid, val): return True if self._parse_mibs_cisco_poe(oid, val): return True if self._parse_mibs_cisco_config(oid, val): return True if self._parse_mibs_cisco_if_opermode(oid, val): return True if self._parse_mibs_cisco_syslog_msg(oid, val): return True # if not Cisco specific, call the generic parser return super()._parse_oid(oid, val)
def _parse_mibs_comware_if_type(self, oid, val): """ Parse Comware specific Interface Type MIB """ if_index = int(oid_in_branch(hh3cifVLANType, oid)) if if_index: # dprint(f"Comware if_index{if_index} if_type {val}" if if_index in self.interfaces.keys(): self.interfaces[if_index].if_vlan_mode = int(val) if int(val) == HH3C_IF_MODE_TRUNK: self.interfaces[if_index].is_tagged = True return True return False
def _parse_mibs_comware_poe(self, oid, val): """ Parse the Comware extended HH3C-POWER-ETH MIB, power usage extension """ dprint(f"_parse_mibs_comware_poe() {oid}, len = {val}, type = {type(val)}") pe_index = oid_in_branch(hh3cPsePortCurrentPower, oid) if pe_index: if pe_index in self.poe_port_entries.keys(): self.poe_port_entries[pe_index].power_consumption_supported = True self.poe_port_entries[pe_index].power_consumed = int(val) return True return False
def _parse_mibs_hp_poe(self, oid, val): """ Parse HP specific Power Extention MIBs """ dprint("_parse_mibs_hp_poe()") pe_index = oid_in_branch(hpicfPoePethPsePortPower, oid) if pe_index: if pe_index in self.poe_port_entries.keys(): self.poe_port_entries[ pe_index].power_consumption_supported = True self.poe_port_entries[pe_index].power_consumed = int(val) return True pe_index = oid_in_branch(hpEntPowerCurrentPowerUsage, oid) if pe_index: if pe_index in self.poe_port_entries.keys(): self.poe_port_entries[ pe_index].power_consumption_supported = True self.poe_port_entries[pe_index].power_consumed = int(val) return True return False
def _parse_mibs_cisco_if_opermode(self, oid, val): """ Parse Cisco specific Interface Config MIB for operational mode """ if_index = int(oid_in_branch(cL2L3IfModeOper, oid)) if if_index: dprint( f"Cisco Interface Operation mode if_index {if_index} mode {val}" ) if if_index in self.interfaces.keys(): if int(val) == CISCO_ROUTE_MODE: self.interfaces[if_index].is_routed = True return True return False
def _parse_mibs_comware_config(self, oid, val): """ Parse Comware specific ConfigMan MIB Mostly entries under 'hh3cCfgLog' """ sub_oid = oid_in_branch(hh3cCfgRunModifiedLast, oid) if sub_oid: ago = str(datetime.timedelta(seconds=(int(val) / 100))) self.add_vendor_data("Configuration", "Running Last Modified", ago) return True sub_oid = oid_in_branch(hh3cCfgRunSavedLast, oid) if sub_oid: ago = str(datetime.timedelta(seconds=(int(val) / 100))) self.add_vendor_data("Configuration", "Running Last Saved", ago) return True sub_oid = oid_in_branch(hh3cCfgStartModifiedLast, oid) if sub_oid: ago = str(datetime.timedelta(seconds=(int(val) / 100))) self.add_vendor_data("Configuration", "Startup Last Saved", ago) return True return False
def _parse_mibs_cisco_syslog_msg(self, oid, val): """ Parse Cisco specific Syslog MIB to read syslog messages stored. """ sub_oid = oid_in_branch(clogHistTableMaxLength, oid) if sub_oid: # this is the max number of syslog messages stored. self.syslog_max_msgs = int(val) return True sub_oid = oid_in_branch(clogHistIndex, oid) if sub_oid: # this is the index, create a new object. # note that not all implementation return this value, as it is implied in the other entries! index = int(sub_oid) self.syslog_msgs[index] = SyslogMsg(index) return True sub_oid = oid_in_branch(clogHistFacility, oid) if sub_oid: # verify we have an object for this index index = int(sub_oid) if index in self.syslog_msgs.keys(): self.syslog_msgs[index].facility = val else: msg = SyslogMsg(index) msg.facility = val self.syslog_msgs[index] = msg return True # from this point on we "should" have the object created! sub_oid = oid_in_branch(clogHistSeverity, oid) if sub_oid: # verify we have an object for this index index = int(sub_oid) if index in self.syslog_msgs.keys(): self.syslog_msgs[index].severity = int(val) else: # be save, create; "should" never happen msg = SyslogMsg(index) msg.severity = int(val) self.syslog_msgs[index] = msg return True sub_oid = oid_in_branch(clogHistMsgName, oid) if sub_oid: # verify we have an object for this index index = int(sub_oid) if index in self.syslog_msgs.keys(): self.syslog_msgs[index].name = val else: # be save, create; "should" never happen msg = SyslogMsg(index) msg.name = val self.syslog_msgs[index] = msg return True sub_oid = oid_in_branch(clogHistMsgText, oid) if sub_oid: # verify we have an object for this index index = int(sub_oid) if index in self.syslog_msgs.keys(): self.syslog_msgs[index].message = val else: # be save, create; "should" never happen msg = SyslogMsg(index) msg.message = val self.syslog_msgs[index] = msg return True sub_oid = oid_in_branch(clogHistTimestamp, oid) if sub_oid: # verify we have an object for this index index = int(sub_oid) # val is sysUpTime value when message was generated, ie. timetick! timetick = int(val) if index in self.syslog_msgs.keys(): # approximate / calculate the datetime value: # msg timestamp = time when sysUpTime was read minus seconds between sysUptime and msg timetick dprint( f"TIMES ARE: {self.system.time} {self.system.sys_uptime} {timetick}" ) self.syslog_msgs[ index].datetime = datetime.datetime.fromtimestamp( self.system.time - int((self.system.sys_uptime - timetick) / 100)) else: # be save, create; "should" never happen msg = SyslogMsg(index) # approximate / calculate the datetime value: # msg time = time when sysUpTime was read minus seconds between sysUptime and msg timetick msg.datetime = datetime.datetime.fromtimestamp( self.system.time - int((self.system.sys_uptime - timetick) / 100)) self.syslog_msgs[index] = msg return True return False
def _parse_mibs_cisco_vtp(self, oid, val): """ Parse Cisco specific VTP MIB """ # vlan id vlan_id = int(oid_in_branch(vtpVlanState, oid)) if vlan_id: if (int(val) == 1): self.vlans[vlan_id] = Vlan(vlan_id) return True # vlan type vlan_id = int(oid_in_branch(vtpVlanType, oid)) if vlan_id: type = int(val) if vlan_id in self.vlans.keys(): if type == CISCO_VLAN_TYPE_NORMAL: self.vlans[vlan_id].type = VLAN_TYPE_NORMAL else: self.vlans[vlan_id].type = type return True # vlan name vlan_id = int(oid_in_branch(vtpVlanName, oid)) if vlan_id: if vlan_id in self.vlans.keys(): self.vlans[vlan_id].name = str(val) return True # access or trunk mode configured? if_index = int(oid_in_branch(vlanTrunkPortDynamicState, oid)) if if_index: if (int(val) == VTP_TRUNK_STATE_ON): # trunk/tagged port if if_index in self.interfaces.keys(): self.interfaces[if_index].is_tagged = True return True # access or trunk mode actual status? # this is the actual status, not what is configured; ie NOT trunk if interface is down!!! # if_index = int(oid_in_branch(vlanTrunkPortDynamicStatus, oid)) # if if_index: # dprint(f"Cisco PORT TRUNK STATUS ifIndex {if_index} = {val}") # if(int(val) == VTP_PORT_TRUNK_ENABLED): # # trunk/tagged port # if if_index in self.interfaces.keys(): # dprint(" TRUNKED!") # self.interfaces[if_index].is_tagged = True # return True # if trunk, what is the native mode? if_index = int(oid_in_branch(vlanTrunkPortNativeVlan, oid)) if if_index: # trunk/tagged port native vlan if if_index in self.interfaces.keys(): # make sure this is a trunked interface and vlan is valid if self.interfaces[if_index].is_tagged and int( val) in self.vlans.keys(): self.interfaces[if_index].untagged_vlan = int(val) else: dprint(" TRUNK NATIVE found, but NOT TRUNK PORT") return True if_index = int(oid_in_branch(vmVlan, oid)) if if_index: untagged_vlan = int(val) if (if_index in self.interfaces.keys() and not self.interfaces[if_index].is_tagged and untagged_vlan in self.vlans.keys()): self.interfaces[if_index].untagged_vlan = untagged_vlan self.interfaces[if_index].untagged_vlan_name = self.vlans[ untagged_vlan].name else: dprint(" UNTAGGED VLAN for invalid trunk port") return True return False