예제 #1
0
async def start(
    device: Device, executor: CollectorExecutor, spec: ifdom.CollectorModel
):
    """
    The IF DOM collector start coroutine for Cisco NXOS SSH devices.  The
    purpose of this coroutine is to start the collector task.  Nothing fancy.

    Parameters
    ----------
    device:
        The device driver instance for the Arista device

    executor:
        The executor that is used to start one or more collector tasks. In this
        instance, there is only one collector task started per device.

    spec:
        The collector model instance that contains information about the
        collector; for example the collector configuration values.
    """
    log.get_logger().info(
        f"{device.name}: Starting Cisco NXOS SSH Interface DOM collection"
    )
    executor.start(
        # required args
        spec=spec,
        coro=get_dom_metrics,
        device=device,
        # kwargs to collector coroutine:
        config=spec.config,
    )
def parse_show_interface_transceiver(parse_text: str) -> Optional[dict]:
    """
    This function is used to parse the IOS CLI text from the command
    "show interfaces transceiver" into a dictionary whose
        key=<if_name>
        value=<dict>:
            <tag>: <value>
            <tag>_flag: <flag_value>

    Where <tag> is the name of the DOM item such as "rxpower" and the <tag>_flag
    is the Cisco marker (++,--,+,-) that indicates the DOM item exceeds a
    threshold value.

    Parameters
    ----------
    parse_text : str
        The CLI output obtained from the device

    Returns
    -------
    The dictionary of output as described, if the output contains any transceivers.
    None otherwise.
    """

    # make a clean copy of the TTP parser and use the provided cli cli_text.
    try:
        parser = ttp(data=parse_text, template=_TEMPLATE)
        parser.parse()
        res = parser.result()
        ifdom_data = res[0][0]["interfaces"]

    except (IndexError, KeyError):
        return None

    ret_ifs_dom = defaultdict(dict)

    for if_name, if_dom_data in ifdom_data.items():
        try:
            for item in ("temp", "voltage", "txpower", "rxpower"):
                tag, *flag = item.split()
                ret_ifs_dom[if_name].update({
                    tag: if_dom_data[tag],
                    tag + "_flag": first(flag) or ""
                })

        except KeyError:
            from netpaca.log import get_logger

            emsg = (
                f"NXOS-SSH interface-transceiver parser failed on interface: {if_name}"
            )
            get_logger().critical(emsg)
            raise RuntimeError(emsg)

    return ret_ifs_dom
예제 #3
0
 def __init__(self, name):
     self.name = name
     self.device_host = None
     self.private = None
     self.tags = dict()
     self.creds = None
     self.log = log.get_logger()
예제 #4
0
 def __init__(self, config):
     self.config: ConfigModel = config
     exporter_name = first(self.config.defaults.exporters) or first(
         self.config.exporters.keys()
     )
     self.exporter: ExporterBase = self.config.exporters[exporter_name]
     self.log = log.get_logger()
예제 #5
0
async def async_main_device(executor, inventory_rec, config: ConfigModel):
    lgr = log.get_logger()
    interval = config.defaults.interval

    device_name = inventory_rec["host"]

    if not (os_name := inventory_rec["os_name"]) in config.device_drivers:
        lgr.error(
            f"{device_name} uses os_name {os_name} not found in config, skipping."
        )
        return
예제 #6
0
 def __init__(self, name):
     super().__init__(name)
     self.server_url = None
     self.post_url = None
     self.httpx = None
     self.log = log.get_logger()