Example #1
0
def ssh_linux(**kwargs):
    if "nx-os" in kwargs.get("snmp_name", "").lower():
        return False, "incompatible Nexus found.", kwargs
    kwargs["guessmodel"] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gmodel not in {"Linux", "ESX", "XEN"}:
        return False, "no match: %s %s" % (gvendor, gmodel), kwargs
    ip = str(kwargs["ip"])
    if not network.check_tcp_port(ip, 22):
        return False, "closed.", kwargs
    ssh = None
    auths = [(settings.SSH_USER or "root", settings.SSH_PASSWORD), (settings.XEN_USER, settings.XEN_PASSWORD)]
    try:
        for user, password in auths:
            if user is None or password is None:
                continue
            try:
                ssh = network.connect_ssh(ip, user, password)
            except network.AuthError:
                pass
            else:
                break
        else:
            return False, "Authorization failed", kwargs
        name = run_ssh_linux(ssh, ip)
    except (network.Error, paramiko.SSHException) as e:
        return False, str(e), kwargs
    return True, name, kwargs
Example #2
0
def ssh_linux(**kwargs):
    if 'nx-os' in kwargs.get('snmp_name', '').lower():
        return False, 'incompatible Nexus found.', kwargs
    kwargs['guessmodel'] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gmodel not in {'Linux', 'ESX', 'XEN'}:
        return False, 'no match: %s %s' % (gvendor, gmodel), kwargs
    ip = str(kwargs['ip'])
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    ssh = None
    auths = [
        (settings.SSH_USER or 'root', settings.SSH_PASSWORD),
        (settings.XEN_USER, settings.XEN_PASSWORD),
    ]
    try:
        for user, password in auths:
            if user is None or password is None:
                continue
            try:
                ssh = network.connect_ssh(ip, user, password)
            except network.AuthError:
                pass
            else:
                break
        else:
            return False, 'Authorization failed', kwargs
        name = run_ssh_linux(ssh, ip)
    except (network.Error, paramiko.SSHException) as e:
        return False, str(e), kwargs
    return True, name, kwargs
Example #3
0
def scan_address(ip_address, **kwargs):
    if 'nx-os' in (kwargs.get('snmp_name', '') or '').lower():
        raise NoMatchError('Incompatible Nexus found.')
    kwargs['guessmodel'] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gvendor != 'Cisco' or gmodel not in ('',):
        raise NoMatchError('It is not Cisco.')
    if not SSH_USER or not SSH_PASS:
        raise NotConfiguredError(
            "SSH not configured in plugin {}.".format(__name__),
        )
    ssh = _connect_ssh(ip_address, SSH_USER, SSH_PASS)
    try:
        lines = ssh.asa_command(
            "show version | grep (^Hardware|Boot microcode|^Serial|address is)"
        )
    finally:
        ssh.close()
    pairs = parse.pairs(lines=[line.strip() for line in lines])
    sn = pairs.get('Serial Number', None)
    model, ram, cpu = pairs['Hardware'].split(',')
    boot_firmware = pairs['Boot microcode']
    macs = []
    for i in xrange(99):
        try:
            junk, label, mac = pairs['%d' % i].split(':')
        except KeyError:
            break
        mac = mac.split(',', 1)[0]
        mac = mac.replace('address is', '')
        mac = mac.replace('.', '').upper().strip()
        label = label.strip()
        if mac.replace(':', '').upper()[:6] not in MAC_PREFIX_BLACKLIST:
            macs.append(mac)
    ram_size = re.search('[0-9]+', ram).group()
    cpu_match = re.search('[0-9]+ MHz', cpu)
    cpu_speed = cpu_match.group()[:-4]
    cpu_model = cpu[:cpu_match.start()][4:].strip()
    result = get_base_result_template('ssh_cisco_asa')
    result.update({
        'status': 'success',
        'device': {
            'model_name': 'Cisco ' + model,
            'type': str(DeviceType.firewall),
            'mac_addresses': macs,
            'boot_firmware': boot_firmware,
            'management_ip_addresses': [ip_address],
            'memory': [{
                'size': int(ram_size),
            }],
            'processors': [{
                'model_name': cpu_model,
                'speed': int(cpu_speed),
                'family': cpu_model,
            }],
        },
    })
    if sn not in SERIAL_BLACKLIST:
        result['device']['serial_number'] = sn
    return result
Example #4
0
def ssh_cisco_asa(**kwargs):
    ip = str(kwargs['ip'])
    kwargs['guessmodel'] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gvendor != 'Cisco' or gmodel not in ('',):
        return False, 'no match: %s %s' % (gvendor, gmodel), kwargs
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    try:
        name = run_ssh_asa(ip)
    except (network.Error, Error) as e:
        return False, str(e), kwargs
    except paramiko.SSHException as e:
        return False, str(e), kwargs
    return True, name, kwargs
Example #5
0
def ssh_cisco_asa(**kwargs):
    ip = str(kwargs['ip'])
    if 'nx-os' in kwargs.get('snmp_name', '').lower():
        return False, 'incompatible Nexus found.', kwargs
    kwargs['guessmodel'] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gvendor != 'Cisco' or gmodel not in ('',):
        return False, 'no match: %s %s' % (gvendor, gmodel), kwargs
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    try:
        name = run_ssh_asa(ip)
    except (network.Error, Error) as e:
        return False, str(e), kwargs
    except paramiko.SSHException as e:
        return False, str(e), kwargs
    return True, name, kwargs
Example #6
0
def ssh_cisco_asa(**kwargs):
    ip = str(kwargs['ip'])
    if 'nx-os' in kwargs.get('snmp_name', '').lower():
        return False, 'incompatible Nexus found.', kwargs
    kwargs['guessmodel'] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gvendor != 'Cisco' or gmodel not in ('', ):
        return False, 'no match: %s %s' % (gvendor, gmodel), kwargs
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    try:
        name = run_ssh_asa(ip)
    except (network.Error, Error) as e:
        return False, str(e), kwargs
    except paramiko.SSHException as e:
        return False, str(e), kwargs
    return True, name, kwargs
Example #7
0
def scan_address(ip, **kwargs):
    if 'nx-os' in kwargs.get('snmp_name', '').lower():
        raise NoMatchError("Incompatible Nexus found.")
    if AIX_USER is None:
        raise NotConfiguredError("No credentials set up")
    kwargs['guessmodel'] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gvendor != 'IBM':
        raise NoMatchError("No match")
    snmp_name = kwargs.get('snmp_name', '')
    if snmp_name and not snmp_name.startswith('IBM PowerPC'):
        raise NoMatchError("No match")
    device = run_ssh_aix(ip)
    ret = {
        'status': 'success',
        'device': device,
    }
    tpl = get_base_result_template('ssh_cisco_catalyst')
    tpl.update(ret)
    return tpl
Example #8
0
def ssh_aix(**kwargs):
    ip = str(kwargs['ip'])
    if AIX_USER is None:
        return False, 'no auth.', kwargs
    kwargs['guessmodel'] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gvendor != 'IBM':
        return False, 'no match: %s %s' % (gvendor, gmodel), kwargs
    snmp_name = kwargs.get('snmp_name', '')
    if snmp_name and not snmp_name.startswith('IBM PowerPC'):
        return False, 'no match.', kwargs
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    try:
        name = run_ssh_aix(ip)
    except (network.Error, Error) as e:
        return False, str(e), kwargs
    except paramiko.SSHException as e:
        return False, str(e), kwargs
    except Error as e:
        return False, str(e), kwargs
    return True, name, kwargs
Example #9
0
def ssh_aix(**kwargs):
    if 'nx-os' in kwargs.get('snmp_name', '').lower():
        return False, 'incompatible Nexus found.', kwargs
    ip = str(kwargs['ip'])
    if AIX_USER is None:
        return False, 'no auth.', kwargs
    kwargs['guessmodel'] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gvendor != 'IBM':
        return False, 'no match: %s %s' % (gvendor, gmodel), kwargs
    snmp_name = kwargs.get('snmp_name', '')
    if snmp_name and not snmp_name.startswith('IBM PowerPC'):
        return False, 'no match.', kwargs
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    try:
        name = run_ssh_aix(ip)
    except (network.Error, Error) as e:
        return False, str(e), kwargs
    except paramiko.SSHException as e:
        return False, str(e), kwargs
    except Error as e:
        return False, str(e), kwargs
    return True, name, kwargs
Example #10
0
def scan_address(ip_address, **kwargs):
    if 'nx-os' in (kwargs.get('snmp_name', '') or '').lower():
        raise NoMatchError('Incompatible Nexus found.')
    kwargs['guessmodel'] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gvendor != 'Cisco' or gmodel not in ('', ):
        raise NoMatchError('It is not Cisco.')
    if not SSH_USER or not SSH_PASS:
        raise NotConfiguredError(
            "SSH not configured in plugin {}.".format(__name__), )
    ssh = _connect_ssh(ip_address, SSH_USER, SSH_PASS)
    try:
        lines = ssh.asa_command(
            "show version | grep (^Hardware|Boot microcode|^Serial|address is)"
        )
    finally:
        ssh.close()
    pairs = parse.pairs(lines=[line.strip() for line in lines])
    sn = pairs.get('Serial Number', None)
    model, ram, cpu = pairs['Hardware'].split(',')
    boot_firmware = pairs['Boot microcode']
    macs = []
    for i in xrange(99):
        try:
            junk, label, mac = pairs['%d' % i].split(':')
        except KeyError:
            break
        mac = mac.split(',', 1)[0]
        mac = mac.replace('address is', '')
        mac = mac.replace('.', '').upper().strip()
        label = label.strip()
        if mac.replace(':', '').upper()[:6] not in MAC_PREFIX_BLACKLIST:
            macs.append(mac)
    ram_size = re.search('[0-9]+', ram).group()
    cpu_match = re.search('[0-9]+ MHz', cpu)
    cpu_speed = cpu_match.group()[:-4]
    cpu_model = cpu[:cpu_match.start()][4:].strip()
    result = get_base_result_template('ssh_cisco_asa')
    result.update({
        'status': 'success',
        'device': {
            'model_name':
            'Cisco ' + model,
            'type':
            str(DeviceType.firewall),
            'mac_addresses':
            macs,
            'boot_firmware':
            boot_firmware,
            'management_ip_addresses': [ip_address],
            'memory': [{
                'size': int(ram_size),
            }],
            'processors': [{
                'model_name': cpu_model,
                'speed': int(cpu_speed),
                'family': cpu_model,
            }],
        },
    })
    if sn not in SERIAL_BLACKLIST:
        result['device']['serial_number'] = sn
    return result