Beispiel #1
0
def get_os_agent(agent_id, offset=0, limit=common.database_limit, select={}, search={}, sort={}, filters={}, q='',
                 nested=True):
    """
    Get info about an agent's OS

    :param agent_id: Agent ID
    :param offset: First item to return
    :param limit: Maximum number of items to return
    :param select: Select fields to return. Format: {"fields": ["field1", "field2"]}
    :param search: Looks for items with the specified string. Format: {"fields": ["field1", "field2"]}
    :param sort: Sorts the items. Format: {"fields": ["field1", "field2"], "order": "asc|desc"}
    :param filters: Defines field filters required by the user. Format: {"field1": "value1", "field2": ["value2","value3"]}
    :param q: Defines query to filter
    :param nested: Fields to nest

    :return: Dictionary: {'items': array of items, 'totalItems': Number of items (without applying the limit)}
    """
    agent_obj = Agent(agent_id)
    agent_obj.get_basic_information()

    # The osinfo fields in database are different in Windows and Linux
    os_name = agent_obj.get_agent_attr('os_name')
    windows_fields = {'hostname': 'hostname', 'os_version': 'os_version', 'os_name': 'os_name',
                      'architecture': 'architecture', 'os_major': 'os_major', 'os_minor': 'os_minor',
                      'os_build': 'os_build', 'version': 'version', 'os_release': 'os_release', 'scan_time': 'scan_time',
                      'scan_id': 'scan_id'}
    linux_fields = {**windows_fields, **{'os_codename': 'os_codename', 'os_platform': 'os_platform',
                                         'sysname': 'sysname', 'release': 'release'}}

    valid_select_fields = windows_fields if 'Windows' in os_name else linux_fields

    return get_item_agent(agent_id=agent_id, offset=offset, limit=limit, select=select, nested=nested,
                          search=search, sort=sort, filters=filters, valid_select_fields=valid_select_fields,
                          table='sys_osinfo', query=q)
Beispiel #2
0
def get_os_agent(agent_id,
                 offset=0,
                 limit=common.database_limit,
                 select={},
                 search={},
                 sort={},
                 filters={},
                 nested=True):
    """
    Get info about an agent's OS
    """
    agent_obj = Agent(agent_id)
    agent_obj.get_basic_information()

    offset = int(offset)
    limit = int(limit)

    # The osinfo fields in database are different in Windows and Linux
    os_name = agent_obj.get_agent_attr('os_name')
    windows_fields = {
        'hostname', 'os_version', 'os_name', 'architecture', 'os_major',
        'os_minor', 'os_build', 'version', 'scan_time', 'scan_id'
    }
    linux_fields = windows_fields | {
        'os_codename', 'os_platform', 'sysname', 'release'
    }

    valid_select_fields = windows_fields if 'Windows' in os_name else linux_fields

    allowed_sort_fields = {'os_name', 'hostname', 'architecture'}

    return get_item_agent(agent_id=agent_id,
                          offset=offset,
                          limit=limit,
                          select=select,
                          search=search,
                          sort=sort,
                          filters=filters,
                          allowed_sort_fields=allowed_sort_fields,
                          valid_select_fields=valid_select_fields,
                          table='sys_osinfo',
                          nested=nested)