示例#1
0
 def setUp(self):
     device = Device.create(
         ethernets=[('', 'deadbeefcafe', 0)],
         model_name='HAL 9000',
         model_type=DeviceType.unknown,
         remarks="I'm sorry, Dave.",
     )
     self.deployment = Deployment(
         hostname='discovery.one',
         ip='127.0.0.1',
         mac='deadbeefcafe',
         device=device,
         preboot=None,
         venture=None,
         venture_role=None,
     )
     self.deployment.save()
     self.ip = IPAddress(address='127.0.0.1', device=device)
     self.ip.save()
     IPAddress(address='127.0.0.2', device=device).save()
     share_model = ComponentModel(type=ComponentType.share, name="share")
     share_model.save()
     share = DiskShare(wwn='x'*33, device=device, model=share_model)
     share.save()
     DiskShareMount(share=share, device=device).save()
     OperatingSystem.create(os_name='GladOS', dev=device, family='',
                            priority=0)
     Software.create(dev=device, model_name='soft', path='/', family='',
                     priority=0)
示例#2
0
 def setUp(self):
     device = Device.create(
         ethernets=[('', 'deadbeefcafe', 0)],
         model_name='HAL 9000',
         model_type=DeviceType.unknown,
         remarks="I'm sorry, Dave.",
     )
     self.deployment = Deployment(
         hostname='discovery.one',
         ip='127.0.0.1',
         mac='deadbeefcafe',
         device=device,
         preboot=None,
         venture=None,
         venture_role=None,
     )
     self.deployment.save()
     self.ip = IPAddress(address='127.0.0.1', device=device)
     self.ip.save()
     IPAddress(address='127.0.0.2', device=device).save()
     share_model = ComponentModel(type=ComponentType.share, name="share")
     share_model.save()
     share = DiskShare(wwn='x' * 33, device=device, model=share_model)
     share.save()
     DiskShareMount(share=share, device=device).save()
     OperatingSystem.create(os_name='GladOS',
                            dev=device,
                            family='',
                            priority=0)
     Software.create(dev=device,
                     model_name='soft',
                     path='/',
                     family='',
                     priority=0)
示例#3
0
def _add_cluster_member(ssh, ip):
    stdin, stdout, stderr = ssh.exec_command("ifconfig eth0 | head -n 1")
    mac = stdout.readline().split()[-1]

    dev = Device.create(ethernets=[Eth(label='eth0', mac=mac, speed=0)],
            model_name='Proxmox', model_type=DeviceType.unknown)

    Software.create(dev, 'proxmox', 'Proxmox', family='Virtualization').save()
    ipaddr, ip_created = IPAddress.concurrent_get_or_create(address=ip)
    ipaddr.is_management = False
    ipaddr.device = dev
    ipaddr.save()
    return dev
示例#4
0
文件: facts.py 项目: szaydel/ralph
def handle_facts_packages(dev, facts):
    packages_list = parse_packages(facts)
    if packages_list:
        for package in packages_list:
            package_name = '{} - {}'.format(package['name'], package['version'])
            Software.create(
                dev=dev,
                path=package_name,
                model_name=package_name,
                label=package['name'],
                family=package['name'],
                version=package['version'],
            ).save()
示例#5
0
def _add_cluster_member(ssh, ip):
    stdin, stdout, stderr = ssh.exec_command("ifconfig eth0 | head -n 1")
    mac = stdout.readline().split()[-1]

    dev = Device.create(ethernets=[Eth(label='eth0', mac=mac, speed=0)],
                        model_name='Proxmox',
                        model_type=DeviceType.unknown)

    Software.create(dev, 'proxmox', 'Proxmox', family='Virtualization').save()
    ipaddr, ip_created = IPAddress.concurrent_get_or_create(address=ip)
    ipaddr.is_management = False
    ipaddr.device = dev
    ipaddr.save()
    return dev
示例#6
0
文件: facts.py 项目: szaydel/ralph
def handle_facts_packages(dev, facts):
    packages_list = parse_packages(facts)
    if packages_list:
        for package in packages_list:
            package_name = '{} - {}'.format(package['name'],
                                            package['version'])
            Software.create(
                dev=dev,
                path=package_name,
                model_name=package_name,
                label=package['name'],
                family=package['name'],
                version=package['version'],
            ).save()
示例#7
0
def handle_facts_packages(dev, facts):
    packages_list = parse_packages(facts)
    if packages_list:
        for package in packages_list:
            version = filter(None,
                             SEPARATE_VERSION.split(package['version'], 1))[0]
            package_name = '{} - {}'.format(package['name'], version)
            Software.create(
                dev=dev,
                path=package_name,
                model_name=package_name,
                label=package['name'],
                family=package['name'],
                version=version,
                priority=SAVE_PRIORITY,
            )
示例#8
0
文件: facts.py 项目: ReJeCtAll/ralph
def handle_facts_packages(dev, facts):
    packages_list = parse_packages(facts)
    if packages_list:
        for package in packages_list:
            version = filter(
                None,
                SEPARATE_VERSION.split(package['version'], 1)
            )[0]
            package_name = '{} - {}'.format(package['name'], version)
            Software.create(
                dev=dev,
                path=package_name,
                model_name=package_name,
                label=package['name'],
                family=package['name'],
                version=version,
                priority=SAVE_PRIORITY,
            )
示例#9
0
文件: software.py 项目: smagowr/ralph
def _detect_software(ip, dev, http_family):
    detected = []
    if network.check_tcp_port(ip, 1521):
        detected.append('Oracle')
        Software.create(dev,
                        'oracle',
                        'Oracle',
                        family='Database',
                        priority=SAVE_PRIORITY)
    else:
        dev.software_set.filter(path='oracle').all().delete()
    if network.check_tcp_port(ip, 3306):
        detected.append('MySQL')
        Software.create(dev,
                        'mysql',
                        'MySQL',
                        family='Database',
                        priority=SAVE_PRIORITY)
    else:
        dev.software_set.filter(path='mysql').all().delete()
    if network.check_tcp_port(ip, 80) or network.check_tcp_port(ip, 443):
        detected.append('WWW')
        Software.create(dev,
                        'www',
                        'WWW',
                        label=http_family,
                        family='WWW',
                        priority=SAVE_PRIORITY)
    else:
        dev.software_set.filter(path='www').all().delete()
    return ', '.join(detected)
示例#10
0
 def test_software(self):
     model = ComponentModel(
         type=ComponentType.software,
         name="cobol",
     )
     model.save()
     Software(
         label='cobol',
         device=self.device,
         model=model,
         version='1.0.0',
         path='/usr/bin/cobol',
         sn='0000001',
     ).save()
     data = get_device_data(Device.objects.get(sn='123456789'))
     soft = data['installed_software']
     self.assertEqual(soft[0]['version'], "1.0.0")
     self.assertEqual(soft[0]['model_name'], "cobol")
     self.assertEqual(len(soft), 1)
示例#11
0
def save_software(software, dev):
    detected_software = []
    for item in software:
        name = item.get('label', '')
        version = item.get('version', '')
        vendor = item.get('vendor', '')
        if version in name:
            name = name.replace(version, '').replace('()', '').strip()
        package_name = '{} - {} - {}'.format(vendor, name, version)
        detected_software.append(
            Software.create(
                dev=dev,
                path=package_name,
                model_name=name,
                label=name,
                family=name,
                version=version,
                priority=SAVE_PRIORITY,
            ).id, )
    dev.software_set.exclude(id__in=detected_software).delete()
示例#12
0
def save_software(software, dev):
    detected_software = []
    for item in software:
        name = item.get("label", "")
        version = item.get("version", "")
        vendor = item.get("vendor", "")
        if version in name:
            name = name.replace(version, "").replace("()", "").strip()
        package_name = "{} - {} - {}".format(vendor, name, version)
        detected_software.append(
            Software.create(
                dev=dev,
                path=package_name,
                model_name=name,
                label=name,
                family=name,
                version=version,
                priority=SAVE_PRIORITY,
            ).id
        )
    dev.software_set.exclude(id__in=detected_software).delete()
示例#13
0
def save_software(software, dev):
    detected_software = []
    for item in software:
        name = item.get('label', '')
        version = item.get('version', '')
        vendor = item.get('vendor', '')
        if version in name:
            name = name.replace(version, '').replace('()', '').strip()
        package_name = '{} - {} - {}'.format(vendor, name, version)
        detected_software.append(
            Software.create(
                dev=dev,
                path=package_name,
                model_name=name,
                label=name,
                family=name,
                version=version,
                priority=SAVE_PRIORITY,
            ).id,
        )
    dev.software_set.exclude(id__in=detected_software).delete()
示例#14
0
def _detect_software(ip, dev, http_family):
    detected = []
    if network.check_tcp_port(ip, 1521):
        detected.append('Oracle')
        Software.create(dev, 'oracle', 'Oracle', family='Database').save()
    else:
        dev.software_set.filter(path='oracle').all().delete()
    if network.check_tcp_port(ip, 3306):
        detected.append('MySQL')
        Software.create(dev, 'mysql', 'MySQL', family='Database').save()
    else:
        dev.software_set.filter(path='mysql').all().delete()
    if network.check_tcp_port(ip, 80) or network.check_tcp_port(ip, 443):
        detected.append('WWW')
        Software.create(dev, 'www', 'WWW', label=http_family, family='WWW').save()
    else:
        dev.software_set.filter(path='www').all().delete()
    return ', '.join(detected)
示例#15
0
文件: snmp.py 项目: pb-it/ralph
def do_snmp_mac(snmp_name, community, snmp_version, ip, kwargs):
    oid = (1, 3, 6, 1, 2, 1, 2, 2, 1, 6)
    sn = None
    is_management = False
    if snmp_name.lower().startswith('sunos'):
        model_name = 'SunOs'
        model_type = DeviceType.unknown
    elif snmp_name.lower().startswith('hardware:') and 'Windows' in snmp_name:
        model_name = 'Windows'
        model_type = DeviceType.unknown
    elif snmp_name.lower().startswith('vmware esx'):
        model_name = 'VMware ESX'
        model_type = DeviceType.unknown
        oid = (1, 3, 6, 1, 2, 1, 2, 2, 1, 6)
        snmp_version = 1
    elif snmp_name.startswith('IronPort'):
        parts = snmp_name.split(',')
        model_name = parts[0].strip()
        model_type = DeviceType.smtp_gateway
        is_management = True
    elif snmp_name.startswith('Intel Modular'):
        model_type = DeviceType.blade_system
        model_name = 'Intel Modular Blade System'
        is_management = True
    elif snmp_name.startswith('IBM PowerPC CHRP Computer'):
        model_type = DeviceType.unknown
        model_name = 'IBM pSeries'
    elif 'Software:UCOS' in snmp_name:
        model_name = 'Cisco UCOS'
        model_type = DeviceType.appliance
        is_management = True
    elif snmp_name.startswith('Codian'):
        model_name = snmp_name
        model_type = DeviceType.appliance
        is_management = True
    elif snmp_name.startswith('APC'):
        m = re.search(r'\sMN:\s*(\S+)', snmp_name)
        model_name = m.group(1) if m else 'APC'
        m = re.search(r'\sSN:\s*(\S+)', snmp_name)
        sn = m.group(1) if m else None
        is_management = True
        model_type = DeviceType.power_distribution_unit
    elif 'fibre channel switch' in snmp_name.lower() or 'san switch module' in snmp_name.lower():
        model_name = snmp_name
        model_type = DeviceType.fibre_channel_switch
        is_management = True
    elif 'ethernet switch module' in snmp_name.lower() or snmp_name.startswith('ProCurve'):
        model_name= snmp_name
        if ',' in model_name:
            model_name, trash = model_name.split(',', 1)
        model_type = DeviceType.switch
        is_management = True
    elif '.f5app' in snmp_name:
        model_name, sn = snmp_f5(**kwargs)
        model_type = DeviceType.load_balancer
    elif 'StorageWorks' in snmp_name:
        model_name = snmp_name
        model_type = DeviceType.storage
    elif 'linux' in snmp_name.lower():
        model_name = 'Linux'
        model_type = DeviceType.unknown
    else:
        model_name = 'Unknown'
        model_type = DeviceType.unknown
        raise Error('no match.')
    ethernets = []
    for mac in network.snmp_macs(ip, community, oid, attempts=2,
                                 timeout=3, snmp_version=snmp_version):
        # Skip virtual devices
        if mac[0:6] in MAC_PREFIX_BLACKLIST:
            continue
        if snmp_name.startswith('Brocade') and not mac.startswith('00051E'):
            # Only use the first right mac of the Brocade switches, the rest is trash.
            continue
        if model_name == 'Windows' and mac.startswith('000C29'):
            # Skip VMWare interfaces on Windows
            continue
        if mac.startswith('0001D7') and model_type != DeviceType.load_balancer:
            # This is an F5
            model_name, sn = snmp_f5(**kwargs)
            model_type = DeviceType.load_balancer
        ethernets.append(Eth('SNMP MAC', mac, speed=None))
    if model_type == DeviceType.load_balancer:
        # For F5, macs that start with 02 are the maqueraded macs
        ethernets = [e for e in ethernets if not e.mac.startswith('02')]
    if not ethernets and not sn:
        raise Error('no MAC.')
    name = snmp_name
    dev = Device.create(ethernets=ethernets, model_name=model_name,
            model_type=model_type, name=name, sn=sn)
    ip_address = IPAddress.objects.get(address=str(ip))
    ip_address.device = dev
    ip_address.is_management = is_management
    if is_management:
        dev.management = ip_address
    if model_name == 'VMware ESX':
        snmp_vmware(dev, ip_address, **kwargs)
    ip_address.save()
    if model_name.startswith('IronPort'):
        pairs = dict((k.strip(), v.strip()) for (k, v) in
                        (part.split(':') for part in parts if ':' in part))
        dev.boot_firmware = 'AsyncOS %s %s' % (
                pairs.get('AsyncOS Version'), pairs.get('Build Date'))
        dev.sn = pairs.get('Serial #')
        dev.save(update_last_seen=True)
    elif model_name == 'Intel Modular Blade System':
        _snmp_modular(ip, community, dev)
    elif model_name == 'Linux':
        Software.create(dev, '', 'Linux', label=snmp_name, family='Linux').save()
    elif model_name == 'SunOs':
        Software.create(dev, '', 'Solaris', label=snmp_name, family='Sun').save()
    return ethernets