def _load_snmp_tables(self):
        """Load all cisco required snmp tables.

        :return:
        """
        self._logger.info("Start loading MIB tables:")
        if_table = self._snmp.get_table(SnmpMibObject(*port_constants.PORT_DESCR_NAME))
        if not if_table:
            if_table = self._snmp.get_table(SnmpMibObject(*port_constants.PORT_NAME))
            if not if_table:
                if_table = self._snmp.get_table(
                    SnmpMibObject(*port_constants.PORT_INDEX)
                )
        self._if_table = if_table.keys()
        self._logger.info("ifIndex table loaded")
    def get_sys_desc(self):
        """

        :return:
        """
        with Snmp().get_snmp_service(snmp_parameters=self._snmp_params, logger=self._logger) as snmp_service:
            return snmp_service.get_property(SnmpMibObject("SNMPv2-MIB", "sysDescr", "0")).safe_value
 def port_channel_ports(self):
     if self._port_channel_ports is None:
         self._port_channel_ports = self._snmp.get_table(
             SnmpMibObject("IEEE8023-LAG-MIB",
                           "dot3adAggPortAttachedAggID"))
         self._logger.info("dot3adAggPortAttachedAggID table loaded")
     return self._port_channel_ports
Exemple #4
0
 def if_type(self):
     if not self._if_type:
         self._if_type = "other"
         if_type = self._snmp.get_property(
             SnmpMibObject(*(port_constants.PORT_TYPE +
                             (self.if_index, )))).safe_value
         if if_type and if_type:
             self._if_type = if_type.replace("'", "")
     return self._if_type
 def _get_cisco_duplex(self):
     if not self._cisco_duplex:
         state_table = self._port_attributes_snmp_tables.cisco_duplex_state_table
         cisco_duplex_id = state_table.get(str(self.if_index))
         if cisco_duplex_id:
             self._cisco_duplex = self._snmp.get_property(
                 SnmpMibObject("CISCO-STACK-MIB", "portDuplex",
                               cisco_duplex_id)).safe_value.replace(
                                   "'", "")
     return self._cisco_duplex
Exemple #6
0
    def _get_auto_neg(self):
        """Get port auto negotiation status.

        :return return "True"
        """
        index = "{}.{}".format(self.if_index, 1)
        auto_negotiation = self._snmp.get_property(
            SnmpMibObject(*(port_constants.PORT_AUTO_NEG +
                            (index, )))).safe_value
        if auto_negotiation and "enabled" in auto_negotiation.lower():
            return "True"
    def build_chassis(self, resource_model):
        """Get Chassis element attributes.

        :param cloudshell.shell.standards.firewall.autoload_model.
        FirewallResourceModel resource_model:
        """
        self.logger.info("Building Chassis")

        chassis_id = self.CHASSIS_ID
        serial_number = self.snmp_service.get_property(
            SnmpMibObject("CHECKPOINT-MIB", "svnApplianceSerialNumber", chassis_id)
        ).safe_value
        chassis_object = resource_model.entities.Chassis(chassis_id)
        chassis_object.model = self.snmp_service.get_property(
            SnmpMibObject("CHECKPOINT-MIB", "svnApplianceProductName", chassis_id)
        ).safe_value
        chassis_object.serial_number = serial_number
        resource_model.connect_chassis(chassis_object)
        self.logger.info("Added " + chassis_object.model + " Chassis")
        self.logger.info("Building Chassis completed")
        return {chassis_id: chassis_object}
 def cisco_duplex_state_table(self):
     if self._cisco_duplex_state_table is None:
         self._cisco_duplex_state_table = {}
         cisco_duplex_state_table = self._snmp.get_table(
             SnmpMibObject("CISCO-STACK-MIB", "portIfIndex"))
         if cisco_duplex_state_table:
             self._cisco_duplex_state_table = {
                 v.get("portIfIndex", "").lower(): k
                 for k, v in cisco_duplex_state_table.iteritems()
             }
         self._logger.info("Duplex portIfIndex table loaded")
     return self._cisco_duplex_state_table
 def lldp_local_table(self):
     if self._lldp_local_table is None:
         lldp_local_table = self._snmp.get_table(
             SnmpMibObject(*port_constants.PORT_ADJACENT_LOC_TABLE))
         if lldp_local_table:
             self._lldp_local_table = {
                 str(v.get("lldpLocPortDesc", "")).lower(): k
                 for k, v in lldp_local_table.iteritems()
             }
         else:
             self._lldp_local_table = defaultdict()
         self._logger.info("lldpLocPortDesc table loaded")
     return self._lldp_local_table
    def build_root(self, resource_model):
        """Get root element attributes.

        :param cloudshell.shell.standards.firewall.autoload_model.
        FirewallResourceModel resource_model:
        """
        self.logger.info("Building Root")
        resource_model.contact_name = self.snmp_service.get_property(
            SnmpMibObject("SNMPv2-MIB", "sysContact", "0")
        ).safe_value
        resource_model.system_name = self.snmp_service.get_property(
            SnmpMibObject("SNMPv2-MIB", "sysName", "0")
        ).safe_value
        resource_model.location = self.snmp_service.get_property(
            SnmpMibObject("SNMPv2-MIB", "sysLocation", "0")
        ).safe_value
        resource_model.os_version = self.snmp_service.get_property(
            SnmpMibObject("CHECKPOINT-MIB", "svnVersion", "0")
        ).safe_value
        resource_model.vendor = "Checkpoint"
        resource_model.model = self.snmp_service.get_property(
            SnmpMibObject("CHECKPOINT-MIB", "svnApplianceProductName", "0")
        ).safe_value
Exemple #11
0
    def _get_duplex(self):
        """Get current duplex state.

        :return str "Full"
        """
        for key, value in self._port_attributes_snmp_tables.duplex_table.items(
        ):
            if "dot3StatsIndex" in value.keys(
            ) and value["dot3StatsIndex"] == str(self.if_index):
                interface_duplex = self._snmp.get_property(
                    SnmpMibObject("EtherLike-MIB", "dot3StatsDuplexStatus",
                                  key)).safe_value
                if "fullDuplex" in interface_duplex:
                    return "Full"
    def build_power_modules(self, resource_model, chassis_table):
        """Get attributes for power ports provided in self.power_supply_list.

        :param cloudshell.shell.standards.firewall.autoload_model.
        FirewallResourceModel resource_model:
        :param dict chassis_table:
        """
        power_port_table = {}
        self.logger.info("Building PowerPorts")
        pp_table = self.snmp_service.get_table(
            SnmpMibObject("CHECKPOINT-MIB", "powerSupplyTable")
        )
        chassis = chassis_table.get(self.CHASSIS_ID)
        for port_id in pp_table:
            power_port = resource_model.entities.PowerPort(port_id)

            status = pp_table.get(port_id, {}).get("powerSupplyStatus", "")
            if status:
                power_port.port_description = "Power port Status - " + status
            chassis.connect_power_port(power_port)
            power_port_table[port_id] = power_port
            self.logger.info("Added Power Port")
        self.logger.info("Building Power Ports completed")
        return power_port_table
Exemple #13
0
    def _get_adjacent(self):
        """Get ajacent.

        Get connected device interface and device name to the specified
        port id, using cdp or lldp protocols.

        :return: device's name and port connected to port id
        :rtype string
        """
        # ToDo rebuild this. Iterating through dictionary
        #  again and again looks bad, very bad.
        if self._port_attributes_snmp_tables.lldp_local_table:
            if_name = self.if_name
            if not if_name:
                if_name = ""
            interface_name = if_name.lower()
            if interface_name:
                key = self._port_attributes_snmp_tables.lldp_local_table.get(
                    interface_name, None)
                if key:
                    for (
                            port_id,
                            rem_table,
                    ) in self._port_attributes_snmp_tables.lldp_remote_table.items(
                    ):
                        if key in port_id.split("."):
                            remote_sys_name = rem_table.get("lldpRemSysName")
                            remote_port_name = self._snmp.get_property(
                                SnmpMibObject(**(port_constants.
                                                 PORT_ADJACENT_REM_PORT_DESCR +
                                                 (port_id, )))).safe_value
                            if remote_port_name and remote_sys_name:
                                return self.ADJACENT_TEMPLATE.format(
                                    remote_host=remote_sys_name,
                                    remote_port=remote_port_name,
                                )
 def ip_mixed_dict(self):
     if self._ip_mixed_table is None:
         self._ip_mixed_table = self._snmp.get_table(
             SnmpMibObject("IP-MIB", "ipAddressIfIndex"))
         self._logger.info("ipAddressIfIndex table loaded")
     return self._ip_mixed_table
 def duplex_table(self):
     if self._duplex_table is None:
         self._duplex_table = self._snmp.get_table(
             SnmpMibObject("EtherLike-MIB", "dot3StatsIndex"))
         self._logger.info("dot3StatsIndex table loaded")
     return self._duplex_table
Exemple #16
0
 def if_descr_name(self):
     if not self._if_descr_name:
         self._if_descr_name = self._snmp.get_property(
             SnmpMibObject(*PORT_DESCR_NAME + (self.if_index, ))).safe_value
     return self._if_descr_name
 def lldp_remote_table(self):
     if self._lldp_remote_table is None:
         self._lldp_remote_table = self._snmp.get_table(
             SnmpMibObject(*port_constants.PORT_ADJACENT_REM_TABLE))
         self._logger.info("lldpRemSysName table loaded")
     return self._lldp_remote_table
Exemple #18
0
 def if_mac(self):
     if not self._if_mac:
         self._if_mac = self._snmp.get_property(
             SnmpMibObject(*(port_constants.PORT_MAC +
                             (self.if_index, )))).safe_value
     return self._if_mac
Exemple #19
0
 def if_port_description(self):
     if not self._if_alias:
         self._if_alias = self._snmp.get_property(
             SnmpMibObject(*PORT_DESCRIPTION +
                           (self.if_index, ))).safe_value
     return self._if_alias
Exemple #20
0
 def if_speed(self):
     if not self._if_speed:
         self._if_speed = self._snmp.get_property(
             SnmpMibObject(*(port_constants.PORT_SPEED +
                             (self.if_index, )))).safe_value
     return self._if_speed
 def ip_v6_dict(self):
     if self._ip_v6_table is None:
         self._ip_v6_table = self._snmp.get_table(
             SnmpMibObject("IPV6-MIB", "ipv6AddrType"))
         self._logger.info("ipv6IfDescr table loaded")
     return self._ip_v6_table
from cloudshell.snmp.core.domain.snmp_oid import SnmpMibObject

SYS_DESCR = SnmpMibObject("SNMPv2-MIB", "sysDescr", "0")
SYS_LOCATION = SnmpMibObject("SNMPv2-MIB", "sysLocation", "0")
SYS_CONTACT = SnmpMibObject("SNMPv2-MIB", "sysContact", "0")
SYS_NAME = SnmpMibObject("SNMPv2-MIB", "sysName", "0")
SYS_OBJECT_ID = SnmpMibObject("SNMPv2-MIB", "sysObjectId", "0")
 def ip_v4_old_list(self):
     if self._ip_v4_old_table is None:
         self._ip_v4_old_table = self._snmp.walk(
             SnmpMibObject("IP-MIB", "ipAdEntIfIndex"))
         self._logger.info("ipAdEntIfIndex table loaded")
     return self._ip_v4_old_table
Exemple #24
0
 def get_snmp_mib_oid(self, index=None):
     return SnmpMibObject(self.mib_name, self.mib_id, index)
 def device_info(self):
     system_description = self.snmp_service.get_property(
         SnmpMibObject("SNMPv2-MIB", "sysObjectID", "0")
     ).safe_value
     return system_description
Exemple #26
0
from cloudshell.snmp.core.domain.snmp_oid import SnmpMibObject

from cloudshell.snmp.autoload.core.snmp_oid_template import SnmpMibOidTemplate

PORT_INDEX = SnmpMibOidTemplate("IF-MIB", "ifIndex")
PORT_DESCR_NAME = SnmpMibOidTemplate("IF-MIB", "ifDescr")
PORT_NAME = SnmpMibOidTemplate("IF-MIB", "ifName")
PORT_DESCRIPTION = SnmpMibOidTemplate("IF-MIB", "ifAlias")
PORT_TYPE = SnmpMibOidTemplate("IF-MIB", "ifType")
PORT_MTU = SnmpMibOidTemplate("IF-MIB", "ifMtu")
PORT_SPEED = SnmpMibOidTemplate("IF-MIB", "ifHighSpeed")
PORT_MAC = SnmpMibOidTemplate("IF-MIB", "ifPhysAddress")
PORT_ADJACENT_REM_TABLE = SnmpMibObject("LLDP-MIB", "lldpRemSysName")
PORT_ADJACENT_REM_PORT_DESCR = SnmpMibOidTemplate("LLDP-MIB",
                                                  "lldpRemPortDesc")
PORT_ADJACENT_LOC_TABLE = SnmpMibObject("LLDP-MIB", "lldpLocPortDesc")
PORT_AUTO_NEG = SnmpMibOidTemplate("MAU-MIB", "ifMauAutoNegAdminStatus")
 def cdp_table(self):
     if self._cdp_table is None:
         self._cdp_table = self._snmp.get_table(
             SnmpMibObject("CISCO-CDP-MIB", "cdpCacheDeviceId"))
         self._logger.info("cdpCacheDeviceId table loaded")
     return self._cdp_table