HEX
Server: LiteSpeed
System: Linux altar46.supremepanel46.com 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
User: jysa (4021)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python2.7/site-packages/pynag/Utils/metrics.pyc
�
�O�]c@@s�dZddlmZddlZddlZddlZddlmZddlm	Z	ddlm
Z
ddlmZidd	d
6ddd6dd
d6ddd6ddd6ddd6ddd6ddd6ddd6dd6dd	d6ddd6ddd 6dd!d"6dd
d#6dd$d%6dd&d'6d(d)6d(d	d*6d(dd+6d(dd,6d(d!d-6d(d
d.6d(d$d/6d(d&d06Z
d1efd2��YZd3efd4��YZd5�Zeed6�ZdS(7s3 Classes and functions related to Perfdata metrics.i(tabsolute_importN(terrors(tnew_threshold_syntax(tclassic_threshold_syntax(tmapi
ithitkitMi	tGitTitPitEitZitYi�tkBtMBtGBitTBitPBtEBitZBitYBitkiBtMiBtGiBtTiBtPiBtEiBtZiBtYiBtPerfDataMetricc	B@s�eZdZdZdZdZdZdZdZdZ	d�Z
d�Zddddddddd�Zd�Z
d�Zd�Zd�Zd	�ZRS(
s� Data structure for one single Nagios Perfdata Metric


    Attributes:

        perfdatastring (str): Complete perfdata string

        label (str): Label section of the perfdata string

        value (str): Value section of the perfdata string

        warn (str): WARNING threshold

        crit (str): CRITICAL threshold

        min (str): Minimal value of control

        max (str): Maximal value of control

        uom (str): Measure unit (octets, bits/s, volts, ...)

    tcC@s2d|j|j|j|j|j|j|jfS(Ns'%s'=%s%s;%s;%s;%s;%s(tlabeltvaluetuomtwarntcrittmintmax(tself((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyt__repr__MscC@s
|j�S(N(R((R'((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyt__str__Xsc	C@s�||_||_||_||_||_||_||_t|�}|jdd�}t	|�dkrsdS|j
d�r�|jd�}	|	j�}
|	jd�dj
|	�}nE|jdd�}	|	r�|	jd�}n|	r�|	j�}
nd}
||_|
jd�}	t	|	�dkr^|	jd�jd�}t|�\|_|_nt	|	�dkr�|	jd�|_nt	|	�dkr�|	jd�|_nt	|	�dkr�|	jd�|_nt	|	�dkr�|	jd�|_ndS(	s�
        >>> p = PerfData(perfdatastring="size=10M;20M;;;")
        >>> metric = p.get_perfdatametric('size')
        >>> print(metric.label)
        size
        >>> print(metric.value)
        10
        >>> print(metric.uom)
        M
        >>> p = PerfDataMetric(perfdatastring="'with spaces'=10")
        >>> print(p.label)
        with spaces
        >>> print(p.value)
        10
        sRiNt't=it;(R R!R#R$R%R&R"tstrtreplacetlent
startswithtsplittpoptjointstriptsplit_value_and_uom(R'tperfdatastringR R!R#R$R%R&R"ttmpteverything_but_labeltval((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyt__init__[sF							
	cC@sIy(tj|jd|jd|j�}Wntjk
rDd}nX|S(s� Return nagios-style exit code (int 0-3) by comparing

        Example:

        self.value with self.warn and self.crit

        >>> PerfDataMetric("label1=10;20;30").get_status()
        0
        >>> PerfDataMetric("label2=25;20;30").get_status()
        1
        >>> PerfDataMetric("label3=35;20;30").get_status()
        2

        Invalid metrics always return unknown

        >>> PerfDataMetric("label3=35;invalid_metric").get_status()
        3
        twarningtcriticali(Rtcheck_thresholdR!R#R$Rt
PynagError(R'tstatus((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyt
get_status�s
(
cC@s�|jdkrtS|jdkr&tSyt|j�Wntk
rKtSXy |jdkpjt|j�Wntk
r�tSXy |jdkp�t|j�Wntk
r�tSX|jjd�dkr�|jj	d�r�|jj
d�r�tStS(s Returns True if all Performance data is valid. Otherwise False

        Example Usage:

        >>> PerfDataMetric("load1=2").is_valid()
        True
        >>> PerfDataMetric("load1").is_valid()
        False
        >>> PerfDataMetric('').is_valid()
        False
        >>> PerfDataMetric('invalid_value=invalid').is_valid()
        False
        >>> PerfDataMetric('invalid_min=0;0;0;min;0').is_valid()
        False
        >>> PerfDataMetric('invalid_min=0;0;0;0;max').is_valid()
        False
        >>> PerfDataMetric('label with spaces=0').is_valid()
        False
        >>> PerfDataMetric("'label with spaces=0'").is_valid()
        False
        >>> PerfDataMetric("value=5.5").is_valid()
        True
        >>> PerfDataMetric("value=5,5").is_valid()
        True
        Rt i����R*N(NR(NR(R tNonetFalseR!tfloatt
ValueErrorR%R&tfindR0tendswithtTrue(R'((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pytis_valid�s&
 
 
>cC@s.tj|j�|_tj|j�|_dS(s; Convert threshold from new threshold syntax to classic.

        For backwards compatibility

        Example:
            >>> p = PerfDataMetric(warn='0..100')
            >>> p.warn
            '0..100'
            >>> p.reconsile_thresholds()
            >>> p.warn == six.u('@0:100')
            True

        N(Rtconvert_to_classic_formatR#R$(R'((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pytreconsile_thresholds�scC@sJi|jd6|jd6|jd6|jd6|jd6|jd6|jd6S(sa Returns a dictionary which contents this class' attributes.

        Returns:
            Dict. With every key as a string, and every value is a string.
            {
                'label': self.label,
                'value': self.value,
                'uom': self.uom,
                'warn': self.warn,
                'crit': self.crit,
                'min': self.min,
                'max': self.max,
            }

        Examples:
            >>> p = PerfDataMetric("load=5")
            >>> p.get_dict()['min']
            ''
            >>> p.get_dict()['max']
            ''
            >>> p.get_dict()['value']
            '5'
            >>> p.get_dict()['label']
            'load'
            >>> p.get_dict()['warn']
            ''
            >>> p.get_dict()['crit']
            ''
            >>> p.get_dict()['uom']
            ''
        R R!R"R#R$R%R&(R R!R"R#R$R%R&(R'((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pytget_dicts!





cC@st|j|j|j�S(s�Get the base value for current metric.

        This is a simple convenience wrapper around get_base_value()
        module function.

        Returns:
            float. Base value of self.value after unit of measurement
            has been taken into account.

        Examples:
            >>> p = PerfDataMetric('size=10KiB')
            >>> p.get_base_value()
            10240.0
        (tget_base_valueR!R"R&(R'((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyRM,s(t__name__t
__module__t__doc__R R!R#R$R%R&R"R(R)R:R@RIRKRLRM(((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyR,s 		!C		6		+tPerfDatac	B@s_eZdZdd�Zd�Zddddddddd�Zd�Zd�Zd�ZRS(s� Data Structure for a nagios perfdata string with multiple perfdata metric

    Example string:

    >>> perf = PerfData("load1=10 load2=10 load3=20 'label with spaces'=5")
    >>> perf.metrics
    ['load1'=10;;;;, 'load2'=10;;;;, 'load3'=20;;;;, 'label with spaces'=5;;;;]
    >>> for i in perf.metrics: print("%s %s" % (i.label, i.value))
    load1 10
    load2 10
    load3 20
    label with spaces 5
    RcC@s�g|_g|_|jdd�}yYtj|�}xC|D];}y|j|�Wq=tk
rw|jj|�q=Xq=WWntk
r�dSXdS(sC
        >>> perf = PerfData("load1=10 load2=10 load3=20")
        sRN(	tmetricstinvalid_metricsR.tshlexR1tadd_perfdatametrict	ExceptiontappendRE(R'R6tperfdatatmetric((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyR:Ns		


cC@s(x!|jD]}|j�s
tSq
WtS(sO Returns True if the every metric in the string is valid

        Example usage:

        >>> PerfData("load1=10 load2=10 load3=20").is_valid()
        True
        >>> PerfData("10b").is_valid()
        False
        >>> PerfData("load1=").is_valid()
        False
        >>> PerfData("load1=10 10").is_valid()
        False
        (RRRIRCRH(R'ti((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyRIasc	
C@sMtd|d|d|d|d|d|d|d|�}	|jj|	�d	S(
s� Add a new perfdatametric to existing list of metrics.

        Args:

            perfdatastring (str): Complete perfdata string

            label (str): Label section of the perfdata string

            value (str): Value section of the perfdata string

            warn (str): WARNING threshold

            crit (str): CRITICAL threshold

            min (str): Minimal value of control

            max (str): Maximal value of control

            uom (str): Measure unit (octets, bits/s, volts, ...)

        Example:

        >>> s = PerfData()
        >>> s.add_perfdatametric("a=1")
        >>> s.add_perfdatametric(label="utilization",value="10",uom="%")
        R6R R!R#R$R%R&R"N(RRRRW(
R'R6R R!R#R$R%R&R"RY((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyRUvs9cC@s+x$|jD]}|j|kr
|Sq
WdS(s< Get one specific perfdatametric

        Args:
            metric_name (str): Name of the metric to return

        Example:

        >>> s = PerfData("cpu=90% memory=50% disk_usage=20%")
        >>> my_metric = s.get_perfdatametric('cpu')
        >>> my_metric.label, my_metric.value
        ('cpu', '90')
        N(RRR (R'tmetric_nameRZ((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pytget_perfdatametric�s
cC@s"x|jD]}|j�q
WdS(s'Convert all warn and crit thresholds into classic thresholds format.

        Example:
            >>> p = PerfData('load=15;0..5;;;')
            >>> print(p)
            'load'=15;0..5;;;
            >>> p.reconsile_thresholds()
            >>> print(p)
            'load'=15;@0:5;;;

        N(RRRK(R'RZ((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyRK�scC@s/g|jD]}|j�^q
}dj|�S(s� Simple string representation of our PerfData.

        Example:
            >>> p = PerfData('load=15')
            >>> str(p)
            "'load'=15;;;;"

        RA(RRR)R3(R'txRR((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyR)�s	"(	RNRORPR:RIRUR\RKR)(((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyRQ>s	!		cC@s0tjd|�}t|�dkr(dS|dS(s4split_value_and_uom("10mb") -> ('10', 'mb')

    Args:
        value: String. Usually a perfdata metric like '10mb'

    Returns:
        A tuple of ('str', 'str') e.g. ('10', 'mb')

    Examples:
        >>> split_value_and_uom( "10" )
        ('10', '')
        >>> split_value_and_uom( "10c" )
        ('10', 'c')
        >>> split_value_and_uom( "10B" )
        ('10', 'B')
        >>> split_value_and_uom( "10MB" )
        ('10', 'MB')
        >>> split_value_and_uom( "10KB" )
        ('10', 'KB')
        >>> split_value_and_uom( "10TB" )
        ('10', 'TB')
        >>> split_value_and_uom( "10%" )
        ('10', '%')
        >>> split_value_and_uom( "10s" )
        ('10', 's')
        >>> split_value_and_uom( "10us" )
        ('10', 'us')
        >>> split_value_and_uom( "10ms" )
        ('10', 'ms')

    s([-]*[\d.]*\d+)(.*)iR(RR(tretfindallR/(R!R7((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyR5�s cC@s�t|�}i}x*tj�D]\}}|||j�<qW|sI|S|dkru|rutd||f��nj|dkr�|dt|�S|tkr�|t|S|j�|kr�|||j�Std|��dS(s� Get base value of a metric (i.e. turns 1KB into 1024).

    Examples:
        >>> get_base_value(value=50)
        50.0
        >>> get_base_value(value=1, uom='kib')
        1024.0
        >>> get_base_value(value=1, uom='k')
        1000.0
        >>> get_base_value(value=1, uom='kb')
        1000.0
        >>> get_base_value(value=1, uom='gib')
        1073741824.0
        >>> get_base_value(value=1, uom='g')
        1000000000.0
        >>> get_base_value(value=50, uom='%', maximum=10)
        5.0
        >>> get_base_value(value=50, uom='%')
        Traceback (most recent call last):
          ...
        ValueError: Cant get absolute value for 50% unless max is defined.
        >>> get_base_value(value=50, uom='FOO')
        Traceback (most recent call last):
          ...
        ValueError: Dont know how to get the base value of a "FOO".

    Returns:
        float. Base value of self.value after uom has been taken into account.
    t%s7Cant get absolute value for %s%s unless max is defined.g{�G�z�?s.Dont know how to get the base value of a "%s".N(RDtMULTIPLIERStitemstlowerRE(R!R"tmaximumtfloat_valuetall_multipliers_in_lowercasetkeyt
multiplier((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyRM�s(RPt
__future__RRTtsixR^tpynagRt
pynag.PluginsRRt	six.movesRRatobjectRRQR5RBRM(((s7/usr/lib/python2.7/site-packages/pynag/Utils/metrics.pyt<module>sN��	&