How to use the patchman.hosts.models.Host function in patchman

To help you get started, we’ve selected a few patchman examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github furlongm / patchman / patchman / reports / models.py View on Github external
if self.os and self.kernel and self.arch:
            os, c = OS.objects.get_or_create(name=self.os)
            arch, c = MachineArchitecture.objects.get_or_create(name=self.arch)

            if not self.domain:
                self.domain = 'unknown'

            domain, c = Domain.objects.get_or_create(name=self.domain)

            if not self.host:
                try:
                    self.host = str(gethostbyaddr(self.report_ip)[0])
                except:
                    self.host = self.report_ip

            host, c = Host.objects.get_or_create(
                hostname=self.host,
                defaults={
                    'ipaddress': self.report_ip,
                    'arch': arch,
                    'os': os,
                    'domain': domain,
                    'lastreport': self.time,
                })

            host.ipaddress = self.report_ip
            host.kernel = self.kernel
            host.arch = arch
            host.os = os
            host.domain = domain
            host.lastreport = self.time
# TODO: fix this to record the history of installed
github furlongm / patchman / scripts / import-pakiti2-data.py View on Github external
def import_hosts(conn):
    
    cursor = conn.cursor(MySQLdb.cursors.DictCursor)

    cursor.execute('SELECT * FROM host')
    rows = cursor.fetchall()

    plength = len(rows)
    pbar = progress_bar('Hosts', plength)
    i = 0

    for row in rows:
        pbar.update(i+1)
        i += 1
        
        host, created = Host.objects.get_or_create(
            hostname=row['host'],
            id=row['id'],
            arch=MachineArchitecture.objects.get(id=row['arch_id']),
            defaults={
                'ipaddress': row['report_ip'],
                'os': OS.objects.get(id=row['os_id']),
                'domain': Domain.objects.get(id=row['dmn_id']),
                'lastreport': row['pkgs_change_timestamp'],
                },
            tag=row['admin'],
            kernel=row['kernel']
            )
    cursor.close()
github furlongm / patchman / sbin / patchman.py View on Github external
host_objs = []

    if hosts:
        if type(hosts) == str:
            host_obj = get_host(hosts, action)
            if host_obj is not None:
                host_objs.append(host_obj)
        elif type(hosts) == list:
            for host in hosts:
                host_obj = get_host(host, action)
                if host_obj is not None:
                    host_objs.append(host_obj)
    else:
        if verbose:
            print '{0!s} for all hosts'.format(action)
        host_objs = Host.objects.all()

    return host_objs
github furlongm / patchman / scripts / import-pakiti2-data.py View on Github external
cursor = conn.cursor(MySQLdb.cursors.DictCursor)

    cursor.execute('SELECT * FROM installed_pkgs')
    rows = cursor.fetchall()

    plength = len(rows)
    pbar = progress_bar('Installed Packages', plength)
    i = 0

    for row in rows:
        pbar.update(i+1)
        i += 1
        try:
            host = Host.objects.get(id=row['host_id'])
        except Host.DoesNotExist:
            continue
        arch, c = PackageArchitecture.objects.get_or_create(name=row['arch'])
        package, c = Package.objects.get_or_create(name=PackageName.objects.get(id=row['pkg_id']), version=row['version'], release=row['rel'], arch=arch)
        host.packages.add(package)

    cursor.close()