Exemple #1
0
    def search(self, **kwargs):
        """
        Search the process list for matching rows based on key-value pairs.

        This uses the :py:func:`insights.parsers.keyword_search` function for
        searching; see its documentation for usage details.  If no search
        parameters are given, no rows are returned.

        Returns:
            list: A list of dictionaries of processes that match the given
            search criteria.

        Examples:
            >>> ps_combiner.search(COMMAND__contains='[rcu_bh]') == [
            ... {'PID': 9, 'USER': '******', 'UID': 0, 'PPID': 2, '%CPU': 0.1, '%MEM': 0.0,
            ...  'VSZ': 0.0, 'RSS': 0.0, 'TTY': '?', 'STAT': 'S', 'START': '2019', 'TIME': '0:00',
            ...  'COMMAND': '[rcu_bh]', 'COMMAND_NAME': '[rcu_bh]', 'ARGS': '', 'F': '1', 'PRI': 20,
            ...  'NI': '0', 'WCHAN': 'rcu_gp'}
            ... ]
            True
            >>> ps_combiner.search(USER='******', COMMAND='[kthreadd]') == [
            ... {'PID': 2, 'USER': '******', 'UID': 0, 'PPID': 0, '%CPU': 0.0, '%MEM': 0.0,
            ...  'VSZ': 0.0, 'RSS': 0.0, 'TTY': '?', 'STAT': 'S', 'START': '2019', 'TIME': '1:04',
            ...  'COMMAND': '[kthreadd]', 'COMMAND_NAME': '[kthreadd]', 'ARGS': '', 'F': '1', 'PRI': 20,
            ...  'NI': '0', 'WCHAN': 'kthrea'}
            ... ]
            True
        """
        return keyword_search(self._pid_data.values(), **kwargs)
Exemple #2
0
 def search(self, **kwargs):
     """
     Search for one or more key-value pairs in the given data.  See the
     documentation of meth:insights.parsers.keyword_search for more
     details on how to use it.
     """
     return keyword_search(self._rq_list, **kwargs)
Exemple #3
0
    def search(self, **kwargs):
        """
        Get the details of PCI devices by searching the table with kwargs.

        This uses the :py:func:`insights.parsers.keyword_search` function for
        searching; see its documentation for usage details. If no search
        parameters are given, no rows are returned.

        It simplify the value of the column according to actual usage.

        Returns:
            list: A list of dictionaries of PCI devices that match the given
            search criteria.

        Examples:
            >>> len(lspci.search(Subsystem__startswith='Lenovo'))
            6
            >>> len(lspci.search(Subsystem__startswith='Lenovo', Dev_Details__startswith='Audio device'))
            2
            >>> lspci.search(Driver='snd_hda_intel', Dev_Details__contains='8') == [
            ... {'Slot': '00:1b.0', 'Class': '0403', 'Vendor': '8086',
            ...  'Device': '9c20', 'SVendor': '17aa', 'SDevice': '2214',
            ...  'Rev': '04', 'Driver': 'snd_hda_intel',
            ...  'Module': ['snd_hda_intel'], 'Subsystem': 'Lenovo ThinkPad X240',
            ...  'Dev_Details': 'Audio device: Intel Corporation 8 Series HD Audio Controller (rev 04)'}]
            True
        """
        return keyword_search(self, **kwargs)
    def search(self, **kwargs):
        """
        Get the rows by searching the table with kwargs.
        This uses the :py:func:`insights.parsers.keyword_search` function for
        searching; see its documentation for usage details. If no search
        parameters are given, no rows are returned.

        It simplify the value of the column according to actual usage.

        Returns:
            list: A list of dictionaries of rows that match the given
            search criteria.

        Examples:
            >>> query.search(name__startswith='abc') == [
            ... {'name': 'abc', 'url': '', 'value': 'test'},
            ... {'name': 'abcdef', 'url': '', 'value': 'test2'}
            ... ]
            True
            >>> query.search(name__startswith='abc', value='test') == [
            ... {'name': 'abc', 'url': '', 'value': 'test'}
            ... ]
            True
        """

        return keyword_search(self, **kwargs)
Exemple #5
0
    def search(self, **kwargs):
        """
        Search the listed files for matching rows based on key-value pairs.

        This uses the :py:func:`insights.parsers.keyword_search` function for
        searching; see its documentation for usage details.  If no search
        parameters are given, no rows are returned.

        Returns:
            list: A list of dictionaries of files that match the given
            search criteria.

        Examples:
            >>> lsdev = ls.search(name__contains='dev')
            >>> len(lsdev)
            3
            >>> dev_console = {
            ...     'type': 'c', 'perms': 'rw-r--r--', 'links': 1, 'owner': 'root', 'group': 'root',
            ...     'major': 5, 'minor': 1, 'date': 'Apr 20 15:57', 'name': 'dev/console', 'dir': '',
            ...     'raw_entry': 'crw-r--r--   1 root     root       5,   1 Apr 20 15:57 dev/console'
            ... }
            >>> dev_console in lsdev
            True
            >>> 'dev/kmsg' in [l['name'] for l in lsdev]
            True
            >>> 'dev/null' in [l['name'] for l in lsdev]
            True

        """
        return keyword_search(self.data.values(), **kwargs)
Exemple #6
0
    def search(self, **kwargs):
        """
        Search for the given key/value pairs in the data.  Please refer to the
        :py:meth:`insights.parsers.keyword_search` function documentation for
        a more complete description of how to use this.

        Fields that can be searched (as per ``man fstab``):

        * ``fs_spec``: the block special or remote filesystem path or label.
        * ``fs_file``: The mount point for the filesystem.
        * ``fs_vfstype``: The file system type.
        * ``fs_mntops``: The mount options.  Since this is also a dictionary,
          this can be searched using __contains - see the examples below.
        * ``fs_freq``: The dump frequency - rarely used.
        * ``fs_passno``: The pass for file system checks - rarely used.

        Examples:

            Search for the root file system:
                ``fstab.search(fs_file='/')``
            Search for file systems mounted from a LABEL declaration
                ``fstab.search(fs_spec__startswith='LABEL=')``
            Search for file systems that use the 'uid' mount option:
                ``fstab.search(fs_mntops__contains='uid')``
            Search for XFS file systems using the 'relatime' option:
                ``fstab.search(fs_vfstype='xfs', fs_mntops__contains='relatime')``
        """
        return keyword_search(self.data, **kwargs)
Exemple #7
0
    def target_startswith(self, target):
        """Return all the targets that starts with 'target'. Useful to find the mountpoints.

        Example:

            >>> len(output.target_startswith('/run/netns')) == 3
            True
        """
        return keyword_search(self.cols, target__startswith=target)
Exemple #8
0
    def search_target(self, target):
        """Similar to __contains__() but returns the list of targets.

        Example:

            >>> output.search_target('shm') == [{'target': '/dev/shm', 'source': 'tmpfs', 'fstype': 'tmpfs', 'options': 'rw,nosuid,nodev,seclabel', 'propagation': 'shared'}]
            True
        """
        return keyword_search(self.cols, target__contains=target)
Exemple #9
0
    def search(self, **kw):
        """Search item based on key value pair.

        Example:

            >>> len(ns_lsof.search(command="neutron-n")) == 1
            True
            >>> len(ns_lsof.search(user="******")) == 0
            True
        """
        return keyword_search(self.data, **kw)
Exemple #10
0
    def search(self, **kwargs):
        """
        Search for rows in the data matching keywords in the search.

        This method searches both the active internet connections and
        active UNIX domain sockets.  If you only want to search one, specify
        the name via the ``search_list`` keyword, e.g.::

            from insights.parsers import Netstat, ACTIVE_UNIX_DOMAIN_SOCKETS
            conns.search(search_list=[ACTIVE_UNIX_DOMAIN_SOCKETS], State='LISTEN')

        The ``search_list`` can be either a list, or a string, containing
        one of the named constants defined in this module.  If
        ``search_list`` is not given, both the active internet connections
        and active UNIX domain sockets are searched, in that order.

        The results of the search are compiled into one list.  This allows
        you to search for all listening processes, whether for internet
        connections or UNIX sockets, by e.g.::

            conns.search(State__contains='LISTEN')

        This method uses the :py:func:`insights.parsers.keyword_search`
        function - see its documentation for a complete description of its
        keyword recognition capabilities.
        """
        if 'search_list' in kwargs:
            search_list = []
            if isinstance(kwargs['search_list'], list):
                # Compile a list from matching strings
                search_list = [
                    l for l in kwargs['search_list'] if l in NETSTAT_SECTION_ID
                ]
            elif isinstance(
                    kwargs['search_list'],
                    str) and kwargs['search_list'] in NETSTAT_SECTION_ID:
                # Just use this string
                search_list = [kwargs['search_list']]
            del kwargs['search_list']
        else:
            search_list = [
                ACTIVE_INTERNET_CONNECTIONS, ACTIVE_UNIX_DOMAIN_SOCKETS
            ]
        if not search_list:
            # No valid search list?  No items.
            return []

        found = []
        for l in search_list:
            found.extend(keyword_search(self.datalist[l], **kwargs))
        return found
Exemple #11
0
def test_keyword_search_None():
    # Normal search
    assert keyword_search(PS_LIST, COMMAND__default=None)[0]['PID'] == '726'
    assert keyword_search(PS_LIST, _line__contains='alloc')[0]['PID'] == '725'
    assert keyword_search(PS_LIST, COMMAND__startswith='xfs')[0]['PID'] == '725'
    assert len(keyword_search(PS_LIST, COMMAND__lower_value='KDMFLUSH')) == 2
    # Check that searches for non-existing keys
    assert keyword_search(PS_LIST, NONE__default=None) == []
    assert keyword_search(PS_LIST, NONE__startswith='xfs') == []
Exemple #12
0
    def search(self, **kwargs):
        """
        Get the rows by searching the table with kwargs.
        This uses the :py:func:`insights.parsers.keyword_search` function for
        searching; see its documentation for usage details. If no search
        parameters are given, no rows are returned.

        It simplify the value of the column according to actual usage.

        Returns:
            list: A list of dictionaries of rows that match the given
            search criteria.
        """

        return keyword_search(self, **kwargs)
    def search(self, **kwargs):
        """
        Search for rows in the data matching keywords in the search.

        This method uses the :py:func:`insights.parsers.keyword_search`
        function - see its documentation for a complete description of its
        keyword recognition capabilities.

        Arguments:
            **kwargs: Key-value pairs of search parameters.

        Returns:
            (list): A list of queues that matched the search criteria.

        """
        return keyword_search(self.data, **kwargs)
    def search(self, *args, **search_args):
        """
        Search for the given key/value pairs in the data.  Please refer to the
        :py:meth:`insights.parsers.keyword_search` function documentation for
        a more complete description of how to use this.

        Field names are searched as is, including case.

        Examples:
            >>> d_list = instances.search(instance_type='hana')  # Find instances by derived properties
            >>> d_list[0] == instances.data[0]  # List contains instances
            True
            >>> len(instances.search(SapVersionInfo__contains='changelist 1779613'))
            0

        """
        return keyword_search(self.data, **search_args)
Exemple #15
0
    def search(self, **kwargs):
        """
        Get the rows by searching the table with kwargs.
        This uses the :py:func:`insights.parsers.keyword_search` function for
        searching; see its documentation for usage details. If no search
        parameters are given, no rows are returned.

        Returns:
            list: A list of dictionaries of rows that match the given
            search criteria.

        Examples:
            >>> sorted(pmrep_doc_obj_search.search(name__endswith='lo'), key=lambda x: x['name'])
            [{'name': 'network.interface.collisions-lo', 'value': '3.000'}, {'name': 'network.interface.out.packets-lo', 'value': '1.000'}]
            >>> sorted(pmrep_doc_obj_search.search(name__endswith='swap.pagesout'), key=lambda x: x['name'])
            [{'name': 'swap.pagesout', 'value': '5.000'}]
        """
        return keyword_search(self, **kwargs)
    def search(self, **kwargs):
        """
        Search the process list for matching rows based on key-value pairs.

        This uses the py:func:`insights.parsers.keyword_search` function for
        searching; see its documentation for usage details.  If no search
        parameters are given, no rows are returned.

        Examples:

            >>> no_owner_tasks = tasks.search(Owner='')
            >>> len(no_owner_tasks)
            3
            >>> no_owner_tasks[0]['Task action']
            'Listen on candlepin events'
            >>> len(tasks.search(State='stopped', Result='error'))
            6
        """
        return keyword_search(self, **kwargs)
Exemple #17
0
    def search(self, **kwargs):
        """
        Get the list for the 'dn' attribute block by searching the ldif configuration.
        This uses the :py:func:`insights.parsers.keyword_search` function for searching,
        see its documentation for usage details. If no search parameters are given or does
        match the search, then nothing will be returned.

        Returns:
            list: A list of dictionaries for each 'dn' attribute block of the ldif configuration that match the given
            search criteria.

        Examples:
            >>> ldif_config.search(dn__contains='cn=config')[0] == ldif_config[1]
            True
            >>> ldif_config.search(dn='cn=sasl,cn=config') == []
            True
            >>> ldif_config.search(cn='changelog5')[0] == ldif_config[1]
            True
        """
        return keyword_search(self, **kwargs)
Exemple #18
0
    def search(self, **kwargs):
        """
        Returns a list of the mounts (in order) matching the given criteria.
        Keys are searched for directly - see the
        :py:func:`insights.parsers.keyword_search` utility function for more
        details.  If no search parameters are given, no rows are returned.

        Examples:

            >>> mounts.search(filesystem='proc')[0].mount_clause
            'proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)'
            >>> mounts.search(mount_options__contains='seclabel')[0].mount_clause
            '/dev/mapper/HostVG-Config on /etc/shadow type ext4 (rw,noatime,seclabel,stripe=256,data=ordered)'

        Arguments:
            **kwargs (dict): Dictionary of key-value pairs to search for.

        Returns:
            (list): The list of mount points matching the given criteria.
        """
        return keyword_search(self.rows, **kwargs)
Exemple #19
0
 def search(self, **args):
     """
     (list): This function return a list of all SCTP associations when args search matches,
             when args search do not match then it returns `[]`.
     """
     return keyword_search(self.data, **args)
def test_keyword_search():
    # No keywords, no result
    assert len(keyword_search(DATA_LIST)) == 0
    # Search on absent keywords produces empty list
    assert keyword_search(DATA_LIST, cpu_count=4) == []
    # Search on present but non-matching keyword produces empty list
    assert keyword_search(DATA_LIST, memory_gb=8) == []
    # Single result - search on string
    results = keyword_search(DATA_LIST, role='embedded')
    assert len(results) == 1
    assert results[0] == DATA_LIST[3]
    # Multiple results, name has underscore - search on integer
    results = keyword_search(DATA_LIST, memory_gb=16)
    assert len(results) == 3
    assert results == [DATA_LIST[i] for i in (0, 2, 4)]
    # Search on boolean
    results = keyword_search(DATA_LIST, ssd=False)
    assert len(results) == 3
    assert results == [DATA_LIST[i] for i in (1, 2, 3)]
    # No data, no results.
    assert len(keyword_search([], role='server')) == 0

    # Search with contains
    results = keyword_search(DATA_LIST, role__contains='e')
    assert len(results) == 4
    assert results == [DATA_LIST[i] for i in (0, 1, 2, 3)]

    # Search with startswith
    results = keyword_search(DATA_LIST, role__startswith='e')
    assert len(results) == 1
    assert results[0] == DATA_LIST[3]

    # Search for multiple keys, with spaces and dashes, and search operators
    results = keyword_search(CERT_LIST,
                             pre_save_command='',
                             key_pair_storage__startswith=
                             "type=NSSDB,location='/etc/dirsrv/slapd-PKI-IPA'")
    assert len(results) == 1
    assert results[0] == CERT_LIST[1]

    # Make sure contains can also apply to keys with dashes and spaces
    results = keyword_search(
        CERT_LIST,
        post_save_command__contains='PKI-IPA',
    )
    assert len(results) == 1
    assert results[0] == CERT_LIST[1]

    # Lower case value matching
    results = keyword_search(
        CERT_LIST,
        status__lower_value='Monitoring',
    )
    assert len(results) == 2
    assert results == CERT_LIST

    # Check that searches for keys with two underscores that aren't matcher
    # suffixes still work
    results = keyword_search(
        CERT_LIST,
        dash__space='tested',
    )
    assert len(results) == 1
    assert results[0] == CERT_LIST[1]

    # Check that we can use contains to check the contents of a dictionary
    # in a value
    results = keyword_search(CERT_LIST, certificate__contains='type')
    assert len(results) == 2
    assert results == CERT_LIST
    assert keyword_search(CERT_LIST, certificate__contains='encryption') == []