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/Plugins/__init__.pyc
�
�O�]c@@sTdZddlmZddlmZddlmZddlZddlZddlZddlZddl	m
Z
mZddlm
Z
mZddlmZddlZddlZdd	lmZdd
lmZddlZdddd
f\ZZZZdddd
f\ZZZZiZded<ded<ded<ded<ded<ded<ded<d
ed<d
ed<ded<ded<ded<ded<ded<ded<d
ed<iZ de e<de e<de e<d e e<d!ej!j"fd"��YZ#d#e$fd$��YZ%d%e$fd&��YZ&ej'Z'ej(Z(dS('u
Python Nagios extensions
i(tprint_function(tunicode_literals(tabsolute_importN(tOptionParsertOptionGroup(tPerfDatatreconsile_threshold(tExtraOptsParser(tnew_threshold_syntax(tclassic_threshold_syntaxiiiuokuwarninguwarnuwucriticalucritucuunknownuuuUPuDOWNuUNREACHABLEuOKuWARNINGuCRITICALuUNKNOWNuWarninguCriticaluUnknowntPluginErrorcB@seZdZRS(u%Base class for errors in this module.(t__name__t
__module__t__doc__(((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyR
Gstsimplec
B@s�eZdZdddddddded�	Zddd�Zd�Zdddddd�Zd�Z	ddd	d
�Z
d�Zd�Zd
�Z
d�Zd�Zd�Zd�Zddd�Zd�Zd�Zd�ZRS(u\
    Nagios plugin helper library based on Nagios::Plugin

    Sample usage

    from pynag.Plugins import WARNING, CRITICAL, OK, UNKNOWN, simple as Plugin

    # Create plugin object
    np = Plugin()
    # Add arguments
    np.add_arg("d", "disk")
    # Do activate plugin
    np.activate()
    ... check stuff, np['disk'] to address variable assigned above...
    # Add a status message and severity
    np.add_message( WARNING, "Disk nearing capacity" )
    # Get parsed code and messages
    (code, message) = np.check_messages()
    # Return information and exit
    nagios_exit(code, message)
    ic

C@sg|_g|_t�|_d|_|	|_i|_g|jd<igt6gt	6gt
6gt6|jd<d|jd<idd6dd6dd	6d
d6|_idd6dd6d	d6dd
6|_
|s�tjjdtjd�|jd
<n
||jd
<dS(Nuperfdataumessagesu
threshholdiuOKiuWARNINGiuCRITICALiuUNKNOWNu%su	shortname(textra_list_optionaltextra_list_requiredRtparsertNonetoptstmust_thresholdtdatatOKtWARNINGtCRITICALtUNKNOWNterrorststatus_texttostpathtbasenametsystargv(
tselft	shortnametversiontblurbtextraturltlicensetpluginttimeoutR((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyt__init__cs 					
&
%"'iustorecC@sn|jjd|d|dd|d|dd|j�d|�|rZ|jj|�n|jj|�dS(	u�
        Add an argument to be handled by the option parser.  By default, the arg is not required.

        required = optional parameter
        action = [store, append, store_true]
        u-%su--%stdestu%sthelptmetavartactionN(Rt
add_optiontupperRtappendR(R!t	spec_abbrtspect	help_texttrequiredR.((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytadd_arg�s
$cC@s�d%}d}|jjdddddddd	d
d�|jjdddd
dddd�|jjdddddddd�|jtkr�|jjdddddddd�|jjdddddddd�n|jj�\}}t|j�d&kr t|j�|jd"<n
||jd"<|j	rI|j	|jd
<n|j
re|j
|jd<n
||jd<|jtkr�|jr�|jr�|jj
d#�nt|d�r�|j|jd<n
d%|jd<t|d�r�|j|jd<n
d%|jd<x5|jD]*}|j|s|jj
d$|�qqWxC|jj�D]2\}}||j|jkrN||j|<qNqNWd%S('u�
        Parse out all command line options and get ready to process the plugin.  This should be run after argument preps
        iu-vu	--verboseR+uverboseR,uVerbosity LevelR-uVERBOSEtdefaultu-Hu--hostuhostuTarget HostuHOSTu-tu	--timeoututimeoutuConnection TimeoutuTIMEOUTu-cu
--criticalucriticaluCritical ThreshholduCRITICALu-wu	--warninguwarninguWarn ThreshholduWARNINGiiiu	verbosityu0You must provide a WARNING and/or CRITICAL valueuoption '%s' is requiredN(iiii(RRR/RtTruet
parse_argstinttverboseRthostR)tcriticaltwarningterrorthasattrRt__dict__titemsR(R!R)R;toptionstargst
extra_itemtkeytvalue((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytactivate�sJ	"				
		
#	



cC@sI|jdji|d6|d6|d6|d6|d6|d6|d6�d	S(
uB
        Append perfdata string to the end of the message
        uperfdataulabeluvalueuuomuwarnucrituminumaxN(RR1(R!tlabelRGtuomtwarntcrittminimumtmaximum((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytadd_perfdata�scC@sLx;|jdD],}|j|d|d|d|d�qW|j�dS(Nuperfdatauvalueuwarnucritulabel(Rt_add_message_from_range_checkt_check_messages_and_exit(R!tperfdata((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytcheck_perfdata_as_metric�sudatacC@s�|p	|s)|jd}|jd}n|rb|j||�rb|jtd|||f�nY|r�|j||�r�|jtd|||f�n |jtd||||f�dS(Nucriticaluwarningu#%s %s is outside critical range: %su"%s %s is outside warning range: %su*%s %s is inside warning=%s and critical=%s(Rt_range_checkertadd_messageRRR(R!RGR>R=RI((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyRP�s
cC@s&|j�\}}|j||�dS(N(tcheck_messagestnagios_exit(R!tcodetmessage((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyRQ�scC@s$d|_|j|�|j�dS(uU
        Check if a value is within a given range.  This should replace change_threshold eventually. Exits with appropriate exit code given the range.

        Taken from:  http://nagiosplug.sourceforge.net/developer-guidelines.html
        Range definition

        Generate an alert if x...
        10        < 0 or > 10, (outside the range of {0 .. 10})
        10:        < 10, (outside {10 .. #})
        ~:10    > 10, (outside the range of {-# .. 10})
        10:20    < 10 or > 20, (outside the range of {10 .. 20})
        @10:20    # 10 and # 20, (inside the range of {10 .. 20})
        uN(thr_rangeRPRQ(R!RG((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytcheck_range�s	
cC@std|d|�S(uF deprecated. Use pynag.Plugins.classic_threshold_syntax.check_range() RGtrange_threshold(R[(R!RGR\((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyRTscO@sGd|kr0d|kr0|d|d<|d=ntjj||�dS(uI Wrapper around pynag.Utils.send_nsca - here for backwards compatibility uncsahostunscahosti(tpynagtUtilst	send_nsca(R!RDtkwargs((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyR_s

cC@sD|j|�}td|j|||j�f�tj|�dS(uG
        Exit with exit_code, message, and optionally perfdata
        u	%s: %s %sN(tcode_string2inttprintRtperfdata_stringRtexit(R!t	code_textRYRX((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyRWs$cC@s�|jdrd}nd}xr|jdD]c}|d|d|d|dpQd|dp^d|d	pkd|d
pxd|dp�df7}q*W|S(Nuperfdatau|uu '%s'=%s%s;%s;%s;%s;%sulabeluvalueuuomuwarnucrituminumax(R(R!R1tpd((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyRc's
	



cC@s+|j|�}|jd|j|�dS(u�
        Add a message with code to the object. May be called
        multiple times.  The messages added are checked by check_messages,
        following.

        Only CRITICAL, WARNING, OK and UNKNOWN are accepted as valid codes.
        umessagesN(RaRR1(R!RXRY((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyRU;s	u cC@s�t|jdj��}|jdt�t}x)|D]!}t|jd|�r6Pq6q6W|dkr�|j|jd|�}nSd}xJ|D]B}t|jd|�r�||j|jd|�|7}q�q�W||j	|�fS(u�
        Check the current set of messages and return an appropriate nagios
        return code and/or a result message. In scalar context, returns
        only a return code; in list context returns both a return code and
        an output message, suitable for passing directly to nagios_exit()

        joinstr = string
            A string used to join the relevant array to generate the
            message string returned in list context i.e. if the 'critical'
            array is non-empty, check_messages would return:
                joinstr.join(critical)

        joinallstr = string
            By default, only one set of messages are joined and returned in
            the result message i.e. if the result is CRITICAL, only the
            'critical' messages are included in the result; if WARNING,
            only the 'warning' messages are included; if OK, the 'ok'
            messages are included (if supplied) i.e. the default is to
            return an 'errors-only' type message.

            If joinallstr is supplied, however, it will be used as a string
            to join the resultant critical, warning, and ok messages
            together i.e.  all messages are joined and returned.
        umessagestreverseuN(
tlistRtkeystsortR8RtlenRtjointrstrip(R!tjoinstrt
joinallstrRiRXRYtc((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyRVHs

	 cC@s5y|jt|�}Wntk
r0|}nX|S(u�
        Changes CRITICAL, WARNING, OK and UNKNOWN code_text to integer
        representation for use within add_message() and nagios_exit()
        (RtstrtKeyError(R!ReRX((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyRaws


cC@s||j|<dS(N(R(R!RFtitem((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyt__setitem__�scC@s"||jkr|j|SdSdS(N(RR(R!RF((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyt__getitem__�sN(RRR
RR8R*R6RHRORSRPRQR[RTR_RWRcRURVRaRtRu(((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyRKs$$	@
								
/		tPluginHelperc	B@s�eZdZdZdZdZdZeZ	eZ
eZeZe
Ze
Ze
ZdZdZdZdZd�Zdd�Zd�Zd�Zd�Zd�Zd	�Zd
�Zd�Zd�Zdd
�Zdd�Z ddddddddd�Z!ddd�Z"d�Z#d�Z$d�Z%ddddd�Z&dd�Z'ddddd�Z(d�Z)d�Z*d�Z+d�Z,d�Z-d�Z.RS( uD PluginHelper takes away some of the tedious work of writing Nagios plugins. Primary features include:

    * Keep a collection of your plugin messages (queue for both summary and longoutput)
    * Keep record of exit status
    * Keep a collection of your metrics (for both perfdata and thresholds)
    * Automatic Command-line arguments
    * Make sure output of your plugin is within Plugin Developer Guidelines

    Usage:
    p = PluginHelper()
    p.status(warning)
    p.add_summary('Example Plugin with warning status')
    p.add_metric('cpu load', '90')
    p.exit()
    i����i:c
C@sEg|_g|_g|_t�|_t�|_t|jd�}|jdddddddd	d
d|j	�|jddgdd
ddd	ddd�|jddgddddd	ddd�|jdddddd	d�|jddd	dddddddd|j
�t|jd�}|jdd d	d!dd"dd#ddd|j�|jd$d	d%dd&dd'd|j�|jd(d	d)dd*dd'd|j
�|jd+d	d,dd-dd'd|j�|jd.d	d/dd0dddt�|jd1d	d2dd3ddd|j�|jj|�|jj|�dS(4NuGeneric Optionsu	--timeoutR,u/Exit plugin with unknown status after x secondsttypeuintR-u50R+utimeoutR7u--thresholdu.Thresholds in standard nagios threshold formaturangeu
thresholdsR.uappendu--thuSame as --thresholdu--extra-optsuFRead options from an ini file. See http://nagiosplugins.org/extra-optsu@fileu
extra_optsu-du--debugu
show_debuguPrint debug infoudu
store_trueuDisplay Optionsu-vu	--verboseuverboseuPrint more verbose infouvu
--no-perfdatau
show_perfdatauDont show any performance dataustore_falseu--no-longoutputushow_longoutputuSHide longoutput from the plugin output (i.e. only display first line of the output)u--no-summaryushow_summaryuHide summary from plugin outputu
--get-metricsuget_metricsuEPrint all available metrics and exit (can be combined with --verbose)u--legacyushow_legacyuDeprecated, do not use(t_long_outputt_summaryt
thresholdsRt	_perfdataRRRR/R)t
show_debugR;t
show_perfdatatshow_longoutputtshow_summarytFalsetshow_legacytadd_option_group(R!t
generic_groupt
display_group((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyR*�s�			
	
	




cC@s4|jjd|�\|_|_|jj}|dk	r�|dkrTd}d}n3d|kr{|jdd�\}}n|}d}|j||�}|jjd|d|�\|_|_n|jj|_|jj	|_	|jj
|_
|jj|_|jj|_|jj
|_
|j|jj�dS(u� Parsers commandline arguments, prints error if there is a syntax error.

        Creates:
            self.options   -- As created by OptionParser.parse()
            self.arguments -- As created by OptionParser.parse()
        Arguments:
            argument_list -- By default use sys.argv[1:], override only if you know what you are doing.
        Returns:
            None
        RDuu@itvaluesN(RR9RCt	argumentst
extra_optsRtsplittget_default_valuesRzR~R}R�R|R;tset_timeoutR)(R!t
argument_listR�tsection_nametconfig_fileR�((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytparse_argumentss*	cC@s|jj|�dS(u� Appends message to the end of Plugin long_output. Message does not need a 
 suffix

        Examples:
          >>> p = PluginHelper()
          >>> p.add_long_output('Status of sensor 1')
          >>> p.add_long_output('* Temperature: OK')
          >>> p.add_long_output('* Humidity: OK')
          >>> p.get_long_output() == six.u(str('Status of sensor 1\n* Temperature: OK\n* Humidity: OK'))
          True
        N(RxR1(R!RY((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytadd_long_output>scO@s|jj||�S(u" Same as self.parser.add_option() (RR/(R!RDR`((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyR/KscC@sdj|j�S(uA Returns all long_output that has been added via add_long_output u
(RlRx(R!((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytget_long_outputOscC@s|g|_dS(u Overwrite current long_output with message

        Example:
        >>> s = PluginHelper()
        >>> s.add_long_output('first long output')
        >>> s.set_long_output('Fatal error')
        >>> s.get_long_output() == six.u(str('Fatal error'))
        True
        N(Rx(R!RY((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytset_long_outputSs
cC@s|jj|j��dS(u  Adds message to Plugin Summary N(RyR1tstrip(R!RY((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytadd_summary_scC@s|g|_dS(u� Overwrite current summary with message

        Example:
        >>> s = PluginHelper()
        >>> s.add_summary('first summary')
        >>> s.set_summary('Fatal error')
        >>> s.get_summary() == six.u(str('Fatal error'))
        True
        N(Ry(R!RY((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytset_summarycs
cC@sdj|j�S(Nu. (RlRy(R!((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytget_summaryoscC@s|jdkrtS|jSdS(u� Returns the worst nagios status (integer 0,1,2,3) that has been put with add_status()

        If status has never been added, returns 3 for UNKNOWN
        i����N(t_nagios_statusR(R!((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyt
get_statusrscC@s8|dkr|j�S|tkr+t}n|j|�S(uP Same as get_status() if new_status=None, otherwise call add_status(new_status) N(RR�t
state_texttunknownt
add_status(R!t
new_status((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytstatus~s

	cC@s]t|tj�rD|j�tkr1t|}qDtd|��nt|j|�|_dS(uF Update exit status of the nagios plugin. This function will keep history of the worst status added

        Examples:
        >>> p = PluginHelper()
        >>> p.add_status(0) # ok
        >>> p.add_status(2) # critical
        >>> p.add_status(1) # warning
        >>> p.get_status()  #
        2

        >>> p = PluginHelper()
        >>> p.add_status('warning')
        >>> p.add_status('ok')
        >>> p.get_status()
        1
        >>> p.add_status('okay')
        Traceback (most recent call last):
        ...
        Exception: Invalid status supplied "okay"
        uInvalid status supplied "%s"N(t
isinstancetsixtstring_typestlowertstatet	ExceptiontmaxR�(R!R�((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyR��s
uc		C@s]|d	k	r"|jjd|�n7|jjd|d|d|d|d|d|d|�d	S(
u� Add numerical metric (will be outputted as nagios performanca data)

        Examples:
          >>> p = PluginHelper()
          >>> p.add_metric(label="load1", value="7")
          >>> p.add_metric(label="load5", value="5")
          >>> p.add_metric(label="load15",value="2")
          >>> p.get_perfdata()
          "'load1'=7;;;; 'load5'=5;;;; 'load15'=2;;;;"

          >>> p = PluginHelper()
          >>> p.add_metric(perfdatastring="load1=6;;;;")
          >>> p.add_metric(perfdatastring="load5=4;;;;")
          >>> p.add_metric(perfdatastring="load15=1;;;;")
          >>> p.get_perfdata()
          "'load1'=6;;;; 'load5'=4;;;; 'load15'=1;;;;"

        tperfdatastringRIRGRKRLtminR�RJN(RR{tadd_perfdatametric(	R!RIRGRKRLR�R�RJR�((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyt
add_metric�scC@s�|jj�}td|d|�j�}xp|jjD]b}|j}||kr7|jdkr{t||||j�q�t||||jd�q7q7W|S(u� Returns an optionParser.Values instance of all defaults after parsing extra opts config file

        The Nagios extra-opts spec we use is the same as described here: http://nagiosplugins.org/extra-opts

        Arguments

        R�R�uappendi(RR�Rt
get_valuestoption_listR+R.tsetattr(R!R�R�R�R�toptiontname((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyR��s		"cC@s.x'|jjD]}|j|kr
|Sq
WdS(ut Return one specific metric (PerfdataMetric object) with the specified label. Returns None if not found.

        Example:
        >>> p = PluginHelper()
        >>> p.add_metric(label="load1", value="7")
        >>> p.add_metric(label="load15",value="2")
        >>> p.get_metric("load1")
        'load1'=7;;;;
        >>> p.get_metric("unknown") # Returns None

        N(R{tmetricsRIR(R!RIti((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyt
get_metric�scC@s9x2|D]*}t|j�|_t|j�|_qWdS(u� Converts new threshold range format to old one. Returns None.

        Examples:
            x..y -> x:y
            inf..y -> :y
            -inf..y -> :y
            x..inf -> x:
            -inf..inf -> :
        N(RRKRLR(R!RRtmetric((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytconvert_perfdata�s

cC@s |j|jj�t|j�S(u� Get perfdatastring for all valid perfdatametrics collected via add_perfdata

        Examples:
        >>> p = PluginHelper()
        >>> p.add_metric(label="load1", value="7", warn="-inf..10", crit="10..inf")
        >>> p.add_metric(label="load5", value="5", warn="-inf..7", crit="7..inf")
        >>> p.add_metric(label="load15",value="2", warn="-inf..5", crit="5..inf")
        >>> p.get_perfdata()
        "'load1'=7;10:;~:10;; 'load5'=5;7:;~:7;; 'load15'=2;5:;~:5;;"

        Example with legacy output (show_legacy should be set with a cmdline option):
        >>> p.show_legacy = True
        >>> p.get_perfdata()
        "'load1'=7;10:;~:10;; 'load5'=5;7:;~:7;; 'load15'=2;5:;~:5;;"

        (R�R{R�Rq(R!((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytget_perfdata�scC@s>|dkr|j�}n|dkr6|j�}n|dkrQ|j�}n|dkrl|j�}nd}|jtkr�|dt|7}n|jtkr�||7}n|j	tkr�t
|�dkr�|d|7}n|jd�s|d7}n|jtkr.t
|�dkr.||7}n|j
�}|S(uH Get all plugin output as it would be printed to screen with self.exit()

        Examples of functionality:
        >>> p = PluginHelper()
        >>> p.get_plugin_output() == six.u(str('Unknown -'))
        True

        >>> p = PluginHelper()
        >>> p.add_summary('Testing')
        >>> p.add_long_output('Long testing output')
        >>> p.add_long_output('More output')
        >>> p.get_plugin_output(exit_code=0) == six.u(str('OK - Testing\nLong testing output\nMore output'))
        True

        >>> p = PluginHelper()
        >>> p.add_summary('Testing')
        >>> p.add_status(0)
        >>> p.get_plugin_output() == six.u(str('OK - Testing'))
        True

        >>> p = PluginHelper()
        >>> p.show_status_in_summary = False
        >>> p.add_summary('Testing')
        >>> p.add_metric(label="load1", value="7")
        >>> p.add_metric(label="load5", value="5")
        >>> p.add_metric(label="load15",value="2")
        >>> p.get_plugin_output(exit_code=0) == six.u(str("Testing | 'load1'=7;;;; 'load5'=5;;;; 'load15'=2;;;;"))
        True

        >>> p = PluginHelper()
        >>> p.show_status_in_summary = False
        >>> p.add_summary('Testing')
        >>> p.add_long_output('Long testing output')
        >>> p.add_long_output('More output')
        >>> p.add_metric(label="load1", value="7")
        >>> p.add_metric(label="load5", value="5")
        >>> p.add_metric(label="load15",value="2")
        >>> p.get_plugin_output(exit_code=0) == six.u(str("Testing | 'load1'=7;;;; 'load5'=5;;;; 'load15'=2;;;;\nLong testing output\nMore output"))
        True

        uu%s - iu | %s
u
N(RR�R�R�R�tshow_status_in_summaryR8R�RR}RktendswithR~R�(R!t	exit_codetsummarytlong_outputRRt
return_buffer((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytget_plugin_outputs**
!
!
i2c@s6��fd�}tjtj|�tj��dS(u> Configures plugin to timeout after seconds number of seconds c@s�jtdd��S(NR�u)Plugin timeout exceeded after %s seconds.(RdR�(txty(tsecondsR!(s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyt<lambda>SsN(tsignaltSIGALRMtalarm(R!R�R)((R�R!s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyR�Qsc	C@s�|dkr|j�}n|jr�|jjtkr�d}g}xL|jjD]>}|jjtkr}|jt	|��qO|j|j
�qOWdj|�}n|jd|d|d|d|�}t
|�tj|�dS(u� Print all collected output to screen and exit nagios style, no arguments are needed
            except if you want to override default behavior.

        Arguments:
            summary     -- Is this text as the plugin summary instead of self.get_summary()
            long_output -- Use this text as long_output instead of self.get_long_output()
            perfdata    -- Use this text instead of self.get_perfdata()
            exit_code   -- Use this exit code instead of self.status()
        u"Available metrics for this plugin:u
R�R�R�RRN(RR�RCtget_metricsR8R{R�R;R1RqRIRlR�RbRRd(R!R�R�R�RRR�R�t
plugin_output((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyRdXs
	
cC@sm|jd|�}|dkr@|jt�|jd|�dSd}d}t}xw|D]o\}}|jdkr�|tkr�||_n'|jdkr�|t	kr�||_n|tkrYd}qYqYWx)|D]!\}}t
||�}ytj|j
|�}	Wnstjjk
r||jdt|||f�|jd	�|jd
�|jd�|jt�|j�nX|	r�t
||�}|jd|t||f�|tkr�|jd
�t}Pq�q�|jd|t||f�q�W|dkr
|}n|j|�dt||f}
|dkrJ|j|
�n|jtkri|j|
�ndS(u� Check one specific metric against a list of thresholds. Updates self.status() and writes to summary or longout as appropriate.

        Arguments:
          metric_name -- A string representing the name of the metric (the label part of the performance data)
          thresholds  -- a list in the form of [ (level,range) ] where range is a string in the format of "start..end"

        Examples:
        >>> p = PluginHelper()
        >>> thresholds = [(warning,'2..5'), (critical,'5..inf')]
        >>> p.get_plugin_output() == six.u(str('Unknown -'))
        True
        >>> p.add_metric('load15', '3')
        >>> p.check_metric('load15',thresholds)
        >>> p.get_plugin_output() == six.u(str("Warning - Warning on load15 | 'load15'=3;@2:5;~:5;;"))
        True
        >>> p = PluginHelper()
        >>> thresholds = [(warning,'2..5'), (critical,'5..inf')]
        >>> p.add_metric('load15', '3')
        >>> p.verbose = True
        >>> p.check_metric('load15',thresholds)
        >>> p.get_plugin_output() == six.u(str("Warning - Warning on load15 | 'load15'=3;@2:5;~:5;;\nWarning on load15"))
        True

        Invalid metric:
        >>> p = PluginHelper()
        >>> p.add_status(ok)
        >>> p.add_summary('Everythings fine!')
        >>> p.get_plugin_output() == six.u(str('OK - Everythings fine!'))
        True
        >>> thresholds = [(warning,'2..5'), (critical,'5..inf')]
        >>> p.check_metric('never_added_metric', thresholds)
        >>> p.get_plugin_output() == six.u(str('Unknown - Everythings fine!. Metric never_added_metric not found'))
        True

        Invalid threshold:
        >>> p = PluginHelper()
        >>> thresholds = [(warning, 'invalid'), (critical,'5..inf')]
        >>> p.add_metric('load1', '10')
        >>> p.check_metric('load1', thresholds)
        Traceback (most recent call last):
        ...
        SystemExit: 3

        Returns:
          None
        RIuMetric %s not foundNi����iuiu-Could not parse threshold %s=%s for metric %suOThresholds should be in the format metric=<metric_name>,ok=0..90,warning=90..95u	Example: u5--th metric=load,ok=0..1,warning=1..5,critical=5..infu%s is within %s range "%s"u6OK threshold matches, not checking any more thresholdsu%s is outside %s range "%s"u%s on %s(R�RR�R�R�tokRKR>RLR=R�RR[RGR]Rt
PynagErrorR�R�R�R�RdtdebugR�R;R8(R!tmetric_nameRzR�t
metric_statust
default_statet
highest_leveltleveltthreshold_rangetin_rangeRY((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytcheck_metricusf/



			
cC@s�g}xQ|jD]F}tj|�}|d}|d}|j||�|j|�qWx�|jjD]�}|j|kr�qgng}|jdkr�|jt	|jf�n|j
dkr�|jt|j
f�n|j|j|�qgWdS(u} Checks all metrics (add_metric() against any thresholds set in self.options.thresholds or with --threshold from commandline)umetricu
thresholdsuN(RzRtparse_thresholdR�R1R{R�RIRKR>RLR=(R!tchecked_metricst	thresholdtparsed_thresholdR�RzR�((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytcheck_all_metrics�s 

c
	O@s|y|||�Wndtk
rwtj�\}}}t}d|}tj�}	|jd|d|d|	dd�nXdS(uo Executes "function" and exits Nagios style with status "unkown"
        if there are any exceptions. The stacktrace will be in long_output.

        Example:
        >>> p = PluginHelper()
        >>> p.add_status('ok')
        >>> p.get_status()
        0
        >>> p.add_status('okay')
        Traceback (most recent call last):
        ...
        Exception: Invalid status supplied "okay"
        >>> p.run_function( p.add_status, 'warning' )
        >>> p.get_status()
        1
        >>> p.run_function( p.add_status, 'okay' )
        Traceback (most recent call last):
        ...
        SystemExit: 3
        u?Unhandled '%s' exception while running plugin (traceback below)R�R�R�RRuN(R�Rtexc_infoR�t	tracebackt
format_excRd(
R!tfunctionRDR`texc_typet	exc_valuet
exc_tracebackR�R�R�((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pytrun_functions

cC@s'|jtkr#|jd|�ndS(Nu	debug: %s(R|R8R�(R!RY((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyR�"scC@s
|j�S(u�
        >>> p = PluginHelper()
        >>> p.add_status(ok)
        >>> p.add_summary('Test')
        >>> print(p)
        OK - Test
        (R�(R!((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyt__str__&scC@s|jdddd�S(NR�uRR(R�(R!((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyt__repr__0sN(/RRR
R�RRxRyR{R8R~R}RR�R�R�R;R|R)RzRCR�R*R�R�R/R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�RdR�R�R�R�R�R�(((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyRv�sT	d(	
							!!			C	v		 		
()R
t
__future__RRRRRR�R�toptparseRRtpynag.UtilsRRt
pynag.ParsersRR]tpynag.errorst
pynag.PluginsRR	R�RRRRR�R>R=R�R�R�RR�R
tobjectRRvR[tcheck_threshold(((s:/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.pyt<module>s^



















�E���