예제 #1
0
def main():
    log.info("[INIT] Initializing health check")
    devices = []
    credentials = {"username": None, "password": None}
    log.info("[CFG] Analyzing configuration...")
    analyze_configuration(devices, credentials)
    log.info("[HLTH] Performing health check on %s devices", len(devices))
    for device in devices:
        nxapi_conn = NXAPI(device["ip"], credentials["username"],
                           credentials["password"])
        # Verifies:
        # - Device model/modules
        # - Device NX-OS software release
        # - Device module diagnostic tests have passed
        nxapi_conn.check_device_modules()
        log.info(
            "[DEV] Device with IP %s is a %s running NX-OS %s",
            nxapi_conn.ip,
            nxapi_conn.model,
            nxapi_conn.nxos_version,
        )
        if nxapi_conn.hw_diags_passed:
            log.info("[DEV] \tDiagnostics passing: %s",
                     nxapi_conn.hw_diags_passed)
        elif not nxapi_conn.hw_diags_passed:
            log.error("[DEV] \tDiagnostics passing: %s",
                      nxapi_conn.hw_diags_passed)
        nxapi_conn.check_device_error_counters()
        report_interfaces(nxapi_conn.interfaces)
        nxapi_conn.check_copp_counters()
        report_copp_counters(nxapi_conn.copp_counters)
        nxapi_conn.check_intf_status()
        report_intf_status(nxapi_conn.interfaces)
예제 #2
0
    def __init__(self,
                 username='******',
                 password='******',
                 ip='192.168.200.50',
                 protocol='http',
                 port=None,
                 timeout=30):

        if protocol not in ('http', 'https'):
            raise ValueError('protocol must be http or https')

        self.username = username
        self.password = password
        self.ip = ip
        self.protocol = protocol
        self.timeout = timeout
        self.port = port
        self.sw1 = NXAPI()
        if self.port is not None:
            self.sw1.set_target_url('%s://%s:%s/ins' %
                                    (self.protocol, self.ip, self.port))
        else:
            self.sw1.set_target_url('%s://%s/ins' % (self.protocol, self.ip))

        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)
        self.sw1.set_timeout(self.timeout)
예제 #3
0
파일: device.py 프로젝트: plucena24/pycsco
    def __init__(self,
                 username='******',
                 password='******',
                 ip='192.168.200.50'):

        self.username = username
        self.password = password
        self.ip = ip
        self.sw1 = NXAPI()
        self.sw1.set_target_url('http://' + self.ip + '/ins')
        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)
예제 #4
0
파일: device.py 프로젝트: GGabriele/pycsco
    def __init__(self,
                 username='******',
                 password='******',
                 ip='192.168.200.50',
                 protocol='http',
                 port=None,
                 timeout=30):

        if protocol not in ('http', 'https'):
            raise ValueError('protocol must be http or https')

        self.username = username
        self.password = password
        self.ip = ip
        self.protocol = protocol
        self.timeout = timeout
        self.port = port
        self.sw1 = NXAPI()
        if self.port is not None:
            self.sw1.set_target_url('%s://%s:%s/ins' % (self.protocol,
                                                        self.ip, self.port))
        else:
            self.sw1.set_target_url('%s://%s/ins' % (self.protocol,
                                                     self.ip))

        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)
        self.sw1.set_timeout(self.timeout)
예제 #5
0
    def __init__(self,
                 username='******',
                 password='******',
                 ip='192.168.200.50',
                 protocol='http'):

        if protocol not in ('http', 'https'):
            raise ValueError('protocol must be http or https')

        self.username = username
        self.password = password
        self.ip = ip
        self.protocol = protocol
        self.sw1 = NXAPI()
        self.sw1.set_target_url('%s://%s/ins' % (self.protocol, self.ip))
        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)
예제 #6
0
    def __init__(self,
                 username='******',
                 password='******',
                 ip='192.168.200.50'):

        self.username = username
        self.password = password
        self.ip = ip
        self.sw1 = NXAPI()
        self.sw1.set_target_url('http://'+self.ip+'/ins')
        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)
예제 #7
0
    def __init__(self,
                 username='******',
                 password='******',
                 ip='192.168.200.50',
                 protocol='http'):

        if protocol not in ('http', 'https'):
            raise ValueError('protocol must be http or https')

        self.username = username
        self.password = password
        self.ip = ip
        self.protocol = protocol
        self.sw1 = NXAPI()
        self.sw1.set_target_url('%s://%s/ins' % (self.protocol, self.ip))
        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)
예제 #8
0
    def open(self):

        self.sw1 = NXAPI()
        self.sw1.set_target_url('http://' + self.ip + '/ins')
        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)
예제 #9
0
class Device():
    def __init__(self,
                 username='******',
                 password='******',
                 ip='172.31.217.133'):

        self.username = username
        self.password = password
        self.ip = ip

    def open(self):

        self.sw1 = NXAPI()
        self.sw1.set_target_url('http://' + self.ip + '/ins')
        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)

    def show(self, command, fmat='xml'):

        self.sw1.set_msg_type('cli_show')
        self.sw1.set_out_format(fmat)
        self.sw1.set_cmd(command)

        return self.sw1.send_req()

    def conf(self, command, fmat='xml'):

        self.sw1.set_msg_type('cli_conf')
        self.sw1.set_out_format(fmat)
        self.sw1.set_cmd(command)

        return self.sw1.send_req()
예제 #10
0
파일: device.py 프로젝트: mzbenami/pycsco
class Device():

    def __init__(self,
                 username='******',
                 password='******',
                 ip='192.168.200.50',
                 protocol='http',
                 timeout=30):

        if protocol not in ('http', 'https'):
            raise ValueError('protocol must be http or https')

        self.username = username
        self.password = password
        self.ip = ip
        self.protocol = protocol
        self.timeout = timeout
        self.sw1 = NXAPI()
        self.sw1.set_target_url('%s://%s/ins' % (self.protocol, self.ip))
        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)
        self.sw1.set_timeout(self.timeout)

    def open(self):
        # keeping to phase out programs that still use it.
        pass

    def cli_error_check(self, data_dict):
        clierror = None
        msg = None

        error_check_list = data_dict['ins_api']['outputs']['output']
        try:
            for each in error_check_list:
                clierror = each.get('clierror', None)
                msg = each.get('msg', None)
        except AttributeError:
            clierror = error_check_list.get('clierror', None)
            msg = error_check_list.get('msg', None)

        if clierror:
            return CLIError(clierror, msg)

    def show(self, command, fmat='xml', text=False):
        if text is False:
            self.sw1.set_msg_type('cli_show')
        elif text:
            self.sw1.set_msg_type('cli_show_ascii')

        self.sw1.set_out_format(fmat)
        self.sw1.set_cmd(command)

        data = self.sw1.send_req()

        if fmat == 'xml':
            data_dict = xmltodict.parse(data[1])
        elif fmat == 'json':
            data_dict = json.loads(data[1])

        clierror = self.cli_error_check(data_dict)
        if clierror:
            raise clierror

        return data

    def config(self, command, fmat='xml'):
        self.sw1.set_msg_type('cli_conf')
        self.sw1.set_out_format(fmat)
        self.sw1.set_cmd(command)

        data = self.sw1.send_req()
        # return self.sw1.send_req
        if fmat == 'xml':
            data_dict = xmltodict.parse(data[1])
        elif fmat == 'json':
            data_dict = json.loads(data[1])

        clierror = self.cli_error_check(data_dict)
        if clierror:
            raise clierror

        return data
예제 #11
0
    def open(self):

        self.sw1 = NXAPI()
        self.sw1.set_target_url("http://" + self.ip + "/ins")
        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)
예제 #12
0
class Device():
    def __init__(self,
                 username='******',
                 password='******',
                 ip='192.168.200.50',
                 protocol='http',
                 port=None,
                 timeout=30):

        if protocol not in ('http', 'https'):
            raise ValueError('protocol must be http or https')

        self.username = username
        self.password = password
        self.ip = ip
        self.protocol = protocol
        self.timeout = timeout
        self.port = port
        self.sw1 = NXAPI()
        if self.port is not None:
            self.sw1.set_target_url('%s://%s:%s/ins' %
                                    (self.protocol, self.ip, self.port))
        else:
            self.sw1.set_target_url('%s://%s/ins' % (self.protocol, self.ip))

        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)
        self.sw1.set_timeout(self.timeout)

    def open(self):
        # keeping to phase out programs that still use it.
        pass

    def cli_error_check(self, data_dict):
        clierror = None
        msg = None
        has_clierror = False
        error_check_list = data_dict['ins_api']['outputs']['output']

        try:
            for index, each in enumerate(error_check_list):
                clierror = each.get('clierror', None)
                msg = each.get('msg', None)
                if 'clierror' in each:
                    has_clierror = True
        except AttributeError:
            clierror = error_check_list.get('clierror', None)
            msg = error_check_list.get('msg', None)
            has_clierror = 'clierror' in error_check_list

        if clierror or has_clierror:
            return CLIError(clierror, msg, index)

    def show(self, command, fmat='xml', text=False):
        if text is False:
            self.sw1.set_msg_type('cli_show')
        elif text:
            self.sw1.set_msg_type('cli_show_ascii')

        self.sw1.set_out_format(fmat)
        self.sw1.set_cmd(command)

        data = self.sw1.send_req()

        if fmat == 'xml':
            data_dict = xmltodict.parse(data[1])
        elif fmat == 'json':
            data_dict = json.loads(data[1])

        clierror = self.cli_error_check(data_dict)
        if clierror:
            raise clierror

        return data

    def config(self, command, fmat='xml'):
        self.sw1.set_msg_type('cli_conf')
        self.sw1.set_out_format(fmat)
        self.sw1.set_cmd(command)

        data = self.sw1.send_req()
        # return self.sw1.send_req
        if fmat == 'xml':
            data_dict = xmltodict.parse(data[1])
        elif fmat == 'json':
            data_dict = json.loads(data[1])

        clierror = self.cli_error_check(data_dict)
        if clierror:
            raise clierror

        return data
예제 #13
0
파일: device.py 프로젝트: plucena24/pycsco
class Device():
    def __init__(self,
                 username='******',
                 password='******',
                 ip='192.168.200.50'):

        self.username = username
        self.password = password
        self.ip = ip
        self.sw1 = NXAPI()
        self.sw1.set_target_url('http://' + self.ip + '/ins')
        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)

    def open(self):
        # keeping to phase out programs that still use it.
        pass

    def show(self, command, fmat='xml', text=False):

        if text is False:
            self.sw1.set_msg_type('cli_show')
        elif text:
            self.sw1.set_msg_type('cli_show_ascii')

        self.sw1.set_out_format(fmat)
        self.sw1.set_cmd(command)

        return self.sw1.send_req()

    def config(self, command, fmat='xml'):

        self.sw1.set_msg_type('cli_conf')
        self.sw1.set_out_format(fmat)
        self.sw1.set_cmd(command)

        # return self.sw1.send_req
        data = self.sw1.send_req()
        clierror = None
        data_dict = xmltodict.parse(data[1])

        error_check_list = data_dict['ins_api']['outputs']['output']
        try:
            for each in error_check_list:
                clierror = each.get('clierror', None)
                msg = each.get('msg', None)
        except AttributeError:
            clierror = error_check_list.get('clierror', None)
            msg = error_check_list.get('msg', None)
        except:
            return data

        if clierror:
            raise IOError(clierror, msg)
        return data
예제 #14
0
  def open(self):

    self.sw1 = NXAPI()
    self.sw1.set_target_url('http://'+self.ip+'/ins')
    self.sw1.set_username(self.username)
    self.sw1.set_password(self.password)
예제 #15
0
class Device:
    def __init__(self, username="******", password="******", ip="192.168.200.50"):

        self.username = username
        self.password = password
        self.ip = ip
        self.protocol = "https"

    def open(self):

        self.sw1 = NXAPI()
        self.sw1.set_target_url("http://" + self.ip + "/ins")
        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)

    def show(self, command, fmat="xml"):

        self.sw1.set_msg_type("cli_show")
        self.sw1.set_out_format(fmat)
        self.sw1.set_cmd(command)

        return self.sw1.send_req()

    def conf(self, command, fmat="xml"):

        self.sw1.set_msg_type("cli_conf")
        self.sw1.set_out_format(fmat)
        self.sw1.set_cmd(command)

        return self.sw1.send_req()
예제 #16
0
class Device():
  
  def __init__(self,username='******',password='******',ip='172.31.217.133'):
    
    self.username = username
    self.password = password
    self.ip = ip
    
  def open(self):

    self.sw1 = NXAPI()
    self.sw1.set_target_url('http://'+self.ip+'/ins')
    self.sw1.set_username(self.username)
    self.sw1.set_password(self.password)

  def show(self,command,fmat='xml'):

    self.sw1.set_msg_type('cli_show')
    self.sw1.set_out_format(fmat)
    self.sw1.set_cmd(command)

    return self.sw1.send_req()

  def conf(self,command,fmat='xml'):

    self.sw1.set_msg_type('cli_conf')
    self.sw1.set_out_format(fmat)
    self.sw1.set_cmd(command)

    return self.sw1.send_req()
예제 #17
0
class Device():

    def __init__(self,
                 username='******',
                 password='******',
                 ip='192.168.200.50'):

        self.username = username
        self.password = password
        self.ip = ip
        self.sw1 = NXAPI()
        self.sw1.set_target_url('http://'+self.ip+'/ins')
        self.sw1.set_username(self.username)
        self.sw1.set_password(self.password)

    def open(self):
        # keeping to phase out programs that still use it.
        pass

    def show(self, command, fmat='xml', text=False):

        if text is False:
            self.sw1.set_msg_type('cli_show')
        elif text:
            self.sw1.set_msg_type('cli_show_ascii')

        self.sw1.set_out_format(fmat)
        self.sw1.set_cmd(command)

        return self.sw1.send_req()

    def config(self, command, fmat='xml'):

        self.sw1.set_msg_type('cli_conf')
        self.sw1.set_out_format(fmat)
        self.sw1.set_cmd(command)

        # return self.sw1.send_req
        data = self.sw1.send_req()
        clierror = None
        data_dict = xmltodict.parse(data[1])

        error_check_list = data_dict['ins_api']['outputs']['output']
        try:
            for each in error_check_list:
                clierror = each.get('clierror', None)
                msg = each.get('msg', None)
        except AttributeError:
            clierror = error_check_list.get('clierror', None)
            msg = error_check_list.get('msg', None)
        except:
            return data

        if clierror:
            raise IOError(clierror, msg)
        return data