3
ܓi7 @ s d Z ddlZddlZddlZddlZddlZddlZddlZddlmZm Z ddl
Z
ddlZddlZddl
Z
ddlmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z! ddl"m#Z#m$Z$m%Z% dd Z&d
d Z'dd
Z(ej)dej*Z+dZ,G dd dZ-G dd dZ.G dd dZ/G dd dZ0G dd dZ1G dd de1Z2G dd de1Z3G dd de1Z4G d d! d!e1Z5G d"d# d#e1Z6G d$d% d%e1Z7G d&d' d'e1Z8G d(d) d)e1Z9G d*d+ d+e1Z:d.d,d-Z;dS )/z; This exports methods available for use by plugins for sos N)timesleep)datetime)Path)sos_get_command_output
import_modulegrepfileobjtail
is_executableTIMEOUT_DEFAULTpath_exists
path_isdirpath_isfilepath_islinklistdir path_joinboldfile_is_binaryrecursive_dict_values_by_key)P_FILEP_LINK
P_CONTFILEc C sB y(t |}tj| |j tjS Q R X W n tk
r< g S X dS )z=Return a list of all non overlapping matches in the string(s)N)r refindallread MULTILINEAttributeError)regexfnamef r! /usr/lib/python3.6/__init__.py
regex_findall( s
r# c C s@ t jdd| }t jdd|}t jdd|jd}|d| }|S ) Nz^/(usr/|)(bin|sbin)/ z[^\w\-\.\/]+_/.z ._-r )r substrip)commandname_maxZmanglednamer! r! r" _mangle_command1 s
r, c C sL t jdft jdft jdft jdfg}x"|D ]}|d | jr*|d S q*W dS )z return a string indicating the type of special node represented by
the stat buffer st (block, character, fifo, socket).
zblock devicezcharacter devicez
named pipeZsocketr r$ )statS_ISBLKS_ISCHRS_ISFIFOS_ISSOCKst_mode)stZ_typestr! r! r"
_node_type9 s
r6 z!----(?:-| )BEGIN.*?----(?:-| )ENDz
-----SCRUBBEDc @ s e Zd ZdZdZdZg Zg Zg Zg Z g Z
d%ddZdd Zd d
Z
dd Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd!d" Zdg g g g g i fd#d$ZdS )&SoSPredicatea A class to implement collection predicates.
A predicate gates the collection of data by an sos plugin. For any
`add_cmd_output()`, `add_copy_spec()` or `add_journal()` call, the
passed predicate will be evaulated and collection will proceed if
the result is `True`, and not otherwise.
Predicates may be used to control conditional data collection
without the need for explicit conditional blocks in plugins.
:param owner: The ``Plugin`` object creating the predicate
:type owner: ``Plugin``
:param dry_run: Is sos running in dry_run mode?
:type dry_run: ``bool``
:param kmods: Kernel module name(s) to check presence of
:type kmods: ``list``, or ``str`` of single name
:param services: Service name(s) to check if running
:type services: ``list``, or ``str`` of single name
:param packages: Package name(s) to check presence of
:type packages: ``list``, or ``str`` of single name
:param cmd_outputs: Command to run, with output string to check
:type cmd_outputs: ``list`` of ``dict``s, or single ``dict`` taking form
{'cmd':