Exemplo n.º 1
0
def _display_link_availability_history(
        device_name: str, interface_name: str) -> Union[str, Tuple[str, int]]:
    """ Display link history based on device name and interface name  """

    if not netcat.validate_http_input(device_name):
        return netcat.http_error(
            f"Incorrect device name format: {device_name}")

    if not netcat.validate_http_input(interface_name):
        return netcat.http_error(
            f"Incorrect interface name format: {interface_name}")

    # Decode interface name
    interface_name = interface_name.replace("_", "/")

    return display_resource_availability_history(
        device_name=device_name,
        resource_name="Link",
        resource=interface_name,
        cisco_command="show ip interface brief",
        cisco_regex=
        rf"^{interface_name}\s+\S+\s+\S+\s+\S+\s+(?:administratively )?(\S+\s+\S+) *$",
        pa_command="show interface all",
        pa_regex=rf"^{interface_name}\s+\d+\s+(\S+)\s+\S+ *$",
    )
Exemplo n.º 2
0
def _display_maclookup_findings_by_url(mac_address: str, search_depth: str = str(netcat.POLL_FREQUENCY)) -> Union[str, Tuple[str, int]]:
    """ Get mac address by url and execute search """

    if not netcat.validate_mac_address(mac_address):
        return netcat.http_error(f"Incorrect MAC address format: {mac_address}")

    if not netcat.validate_search_depth(search_depth):
        return netcat.http_error(f"Incorrect search depth format: {search_depth}")

    return lookup_mac_address(netcat.convert_mac_to_cisco_format(mac_address), int(search_depth), True)
Exemplo n.º 3
0
    def wrapper(*args, **kwargs):
        try:
            return function(*args, **kwargs)

        except pymongo.errors.PyMongoError as exception:
            netcat.LOGGER.error(f"PyMongo exception: '{exception}'")
            return netcat.http_error(f"PyMongo exception: '{exception}'")
Exemplo n.º 4
0
    def wrapper(*args, **kwargs):
        try:
            return function(*args, **kwargs)

        except botocore.exceptions.ClientError as exception:
            netcat.LOGGER.error(f"Botocore exception: '{exception}'")
            return netcat.http_error(f"Botocore exception: '{exception}'")
Exemplo n.º 5
0
def _display_iplookup_findings_by_url(
    ip_address: str, search_depth: str = str(netcat.POLL_FREQUENCY)
) -> Union[str, Tuple[str, int]]:
    """ Get ip address by url and execute search """

    if not netcat.validate_ip_address(ip_address):
        return netcat.http_error(f"Incorect IP address format: {ip_address}")

    return lookup_ip_address(ip_address, int(search_depth))
Exemplo n.º 6
0
def _display_bgp_availability_history(
        device_name: str, peer_ip_address: str) -> Union[str, Tuple[str, int]]:
    """ Display bgp session history for given device name and peer ip address """

    if not netcat.validate_http_input(device_name):
        return netcat.http_error(
            f"Incorrect device name format: {device_name}")

    if not netcat.validate_ip_address(peer_ip_address):
        return netcat.http_error(
            f"Incorrect peer IP address format: {peer_ip_address}")

    return display_resource_availability_history(
        device_name=device_name,
        resource_name="BGP",
        resource=peer_ip_address,
        cisco_command="show ip bgp summary",
        cisco_regex=
        rf"^{peer_ip_address}\s+\d\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\S+\s+(\S+)$",
        pa_command="show routing protocol bgp summary",
        pa_regex=rf"^\s+peer \S+\s+ AS \d+, (\S+), IP {peer_ip_address}$",
    )