<s> """<STR_LIT>""" <EOL> import httplib , urllib , urllib2 , base64 <EOL> import json <EOL> import argparse <EOL> import sys <EOL> from pprint import pprint <EOL> from urllib2 import HTTPError <EOL> from urllib2 import URLError <EOL> OK_CODE = <NUM_LIT:0> <EOL> WARNING_CODE = <NUM_LIT:1> <EOL> CRITICAL_CODE = <NUM_LIT:2> <EOL> UNKNOWN_CODE = <NUM_LIT:3> <EOL> class NagiosHelper : <EOL> """<STR_LIT>""" <EOL> message_prefixes = { OK_CODE : '<STR_LIT:OK>' , WARNING_CODE : '<STR_LIT>' , CRITICAL_CODE : '<STR_LIT>' , UNKNOWN_CODE : '<STR_LIT>' } <EOL> performance_data = '<STR_LIT>' <EOL> warning_message = '<STR_LIT>' <EOL> critical_message = '<STR_LIT>' <EOL> unknown_message = '<STR_LIT>' <EOL> def getMessage ( self ) : <EOL> """<STR_LIT>""" <EOL> text = "<STR_LIT>" % ( self . message_prefixes [ self . getCode ( ) ] , self . message_prefixes [ self . getCode ( ) ] ) <EOL> text += self . warning_message <EOL> text += self . critical_message <EOL> text += self . unknown_message <EOL> if self . performance_data : <EOL> text += "<STR_LIT>" % self . performance_data <EOL> return text <EOL> def getCode ( self ) : <EOL> code = OK_CODE <EOL> if ( self . warning_message != '<STR_LIT>' ) : <EOL> code = WARNING_CODE <EOL> if ( self . critical_message != '<STR_LIT>' ) : <EOL> code = CRITICAL_CODE <EOL> if ( self . unknown_message != '<STR_LIT>' ) : <EOL> code = UNKNOWN_CODE <EOL> return code <EOL> def append_warning ( self , warning_message ) : <EOL> self . warning_message += warning_message <EOL> def append_critical ( self , critical_message ) : <EOL> self . critical_message += critical_message <EOL> def append_unknown ( self , unknown_message ) : <EOL> self . critical_message += unknown_message <EOL> def append_metrics ( self , ( performance_data , warning_message , critical_message ) ) : <EOL> self . performance_data += performance_data <EOL> self . append_warning ( warning_message ) <EOL> self . append_critical ( critical_message ) <EOL> class JsonHelper : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , json_data , separator ) : <EOL> self . data = json_data <EOL> self . separator = separator <EOL> self . arrayOpener = '<STR_LIT:(>' <EOL> self . arrayCloser = '<STR_LIT:)>' <EOL> def getSubElement ( self , key , data ) : <EOL> separatorIndex = key . find ( self . separator ) <EOL> partialKey = key [ : separatorIndex ] <EOL> remainingKey = key [ separatorIndex + <NUM_LIT:1> : ] <EOL> if partialKey in data : <EOL> return self . get ( remainingKey , data [ partialKey ] ) <EOL> else : <EOL> return ( None , '<STR_LIT>' ) <EOL> def getSubArrayElement ( self , key , data ) : <EOL> subElemKey = key [ : key . find ( self . arrayOpener ) ] <EOL> index = int ( key [ key . find ( self . arrayOpener ) + <NUM_LIT:1> : key . find ( self . arrayCloser ) ] ) <EOL> remainingKey = key [ key . find ( self . arrayCloser + self . separator ) + <NUM_LIT:2> : ] <EOL> if key . find ( self . arrayCloser + self . separator ) == - <NUM_LIT:1> : <EOL> remainingKey = key [ key . find ( self . arrayCloser ) + <NUM_LIT:1> : ] <EOL> if subElemKey in data : <EOL> if index < len ( data [ subElemKey ] ) : <EOL> return self . get ( remainingKey , data [ subElemKey ] [ index ] ) <EOL> else : <EOL> return ( None , '<STR_LIT>' ) <EOL> else : <EOL> if not subElemKey : <EOL> return self . get ( remainingKey , data [ index ] ) <EOL> else : <EOL> return ( None , '<STR_LIT>' ) <EOL> def equals ( self , key , value ) : return self . exists ( key ) and str ( self . get ( key ) ) in value . split ( '<STR_LIT::>' ) <EOL> def lte ( self , key , value ) : return self . exists ( key ) and float ( self . get ( key ) ) <= float ( value ) <EOL> def lt ( self , key , value ) : return self . exists ( key ) and float ( self . get ( key ) ) < float ( value ) <EOL> def gte ( self , key , value ) : return self . exists ( key ) and float ( self . get ( key ) ) >= float ( value ) <EOL> def gt ( self , key , value ) : return self . exists ( key ) and float ( self . get ( key ) ) > float ( value ) <EOL> def exists ( self , key ) : return ( self . get ( key ) != ( None , '<STR_LIT>' ) ) <EOL> def get ( self , key , temp_data = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if temp_data : <EOL> data = temp_data <EOL> else : <EOL> data = self . data <EOL> if len ( key ) <= <NUM_LIT:0> : <EOL> return data <EOL> if key . find ( self . separator ) != - <NUM_LIT:1> and key . find ( self . arrayOpener ) != - <NUM_LIT:1> : <EOL> if key . find ( self . separator ) < key . find ( self . arrayOpener ) : <EOL> return self . getSubElement ( key , data ) <EOL> else : <EOL> return self . getSubArrayElement ( key , data ) <EOL> else : <EOL> if key . find ( self . separator ) != - <NUM_LIT:1> : <EOL> return self . getSubElement ( key , data ) <EOL> else : <EOL> if key . find ( self . arrayOpener ) != - <NUM_LIT:1> : <EOL> return self . getSubArrayElement ( key , data ) <EOL> else : <EOL> if key in data : <EOL> return data [ key ] <EOL> else : <EOL> return ( None , '<STR_LIT>' ) <EOL> def _getKeyAlias ( original_key ) : <EOL> key = original_key <EOL> alias = original_key <EOL> if '<STR_LIT:>>' in original_key : <EOL> keys = original_key . split ( '<STR_LIT:>>' ) <EOL> if len ( keys ) == <NUM_LIT:2> : <EOL> key , alias = keys <EOL> return key , alias <EOL> class JsonRuleProcessor : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , json_data , rules_args ) : <EOL> self . data = json_data <EOL> self . rules = rules_args <EOL> separator = '<STR_LIT:.>' <EOL> if self . rules . separator : separator = self . rules . separator <EOL> self . helper = JsonHelper ( self . data , separator ) <EOL> debugPrint ( rules_args . debug , "<STR_LIT>" % rules_args ) <EOL> debugPrint ( rules_args . debug , "<STR_LIT>" % separator ) <EOL> def checkExists ( self , exists_list ) : <EOL> failure = '<STR_LIT>' <EOL> for k in exists_list : <EOL> key , alias = _getKeyAlias ( k ) <EOL> if ( self . helper . exists ( key ) == False ) : <EOL> failure += "<STR_LIT>" % alias <EOL> return failure <EOL> def checkEquality ( self , equality_list ) : <EOL> failure = '<STR_LIT>' <EOL> for kv in equality_list : <EOL> k , v = kv . split ( '<STR_LIT:U+002C>' ) <EOL> key , alias = _getKeyAlias ( k ) <EOL> if ( self . helper . equals ( key , v ) == False ) : <EOL> failure += "<STR_LIT>" % ( alias , v ) <EOL> return failure <EOL> def checkThreshold ( self , key , alias , r ) : <EOL> failure = '<STR_LIT>' <EOL> invert = False <EOL> start = <NUM_LIT:0> <EOL> end = '<STR_LIT>' <EOL> if r . startswith ( '<STR_LIT:@>' ) : <EOL> invert = True <EOL> r = r [ <NUM_LIT:1> : ] <EOL> vals = r . split ( '<STR_LIT::>' ) <EOL> if len ( vals ) == <NUM_LIT:1> : <EOL> end = vals [ <NUM_LIT:0> ] <EOL> if len ( vals ) == <NUM_LIT:2> : <EOL> start = vals [ <NUM_LIT:0> ] <EOL> if vals [ <NUM_LIT:1> ] != '<STR_LIT>' : <EOL> end = vals [ <NUM_LIT:1> ] <EOL> if ( start == '<STR_LIT>' ) : <EOL> if ( invert and self . helper . lte ( key , end ) ) : <EOL> failure += "<STR_LIT>" % ( alias , end ) <EOL> elif ( not invert and self . helper . gt ( key , end ) ) : <EOL> failure += "<STR_LIT>" % ( alias , end ) <EOL> elif ( end == '<STR_LIT>' ) : <EOL> if ( invert and self . helper . gte ( key , start ) ) : <EOL> failure += "<STR_LIT>" % ( alias , start ) <EOL> elif ( not invert and self . helper . lt ( key , start ) ) : <EOL> failure += "<STR_LIT>" % ( alias , start ) <EOL> else : <EOL> if ( invert and self . helper . gte ( key , start ) and self . helper . lte ( key , end ) ) : <EOL> failure += "<STR_LIT>" % ( alias , start , end ) <EOL> elif ( not invert and ( self . helper . lt ( key , start ) or self . helper . gt ( key , end ) ) ) : <EOL> failure += "<STR_LIT>" % ( alias , start , end ) <EOL> return failure <EOL> def checkThresholds ( self , threshold_list ) : <EOL> failure = '<STR_LIT>' <EOL> for threshold in threshold_list : <EOL> k , r = threshold . split ( '<STR_LIT:U+002C>' ) <EOL> key , alias = _getKeyAlias ( k ) <EOL> failure += self . checkThreshold ( key , alias , r ) <EOL> return failure <EOL> def checkWarning ( self ) : <EOL> failure = '<STR_LIT>' <EOL> if self . rules . key_threshold_warning != None : <EOL> failure += self . checkThresholds ( self . rules . key_threshold_warning ) <EOL> if self . rules . key_value_list != None : <EOL> failure += self . checkEquality ( self . rules . key_value_list ) <EOL> if self . rules . key_list != None : <EOL> failure += self . checkExists ( self . rules . key_list ) <EOL> return failure <EOL> def checkCritical ( self ) : <EOL> failure = '<STR_LIT>' <EOL> if self . rules . key_threshold_critical != None : <EOL> failure += self . checkThresholds ( self . rules . key_threshold_critical ) <EOL> if self . rules . key_value_list_critical != None : <EOL> failure += self . checkEquality ( self . rules . key_value_list_critical ) <EOL> if self . rules . key_list_critical != None : <EOL> failure += self . checkExists ( self . rules . key_list_critical ) <EOL> return failure <EOL> def checkMetrics ( self ) : <EOL> """<STR_LIT>""" <EOL> metrics = '<STR_LIT>' <EOL> warning = '<STR_LIT>' <EOL> critical = '<STR_LIT>' <EOL> if self . rules . metric_list != None : <EOL> for metric in self . rules . metric_list : <EOL> key = metric <EOL> minimum = maximum = warn_range = crit_range = None <EOL> uom = '<STR_LIT>' <EOL> if '<STR_LIT:U+002C>' in metric : <EOL> vals = metric . split ( '<STR_LIT:U+002C>' ) <EOL> if len ( vals ) == <NUM_LIT:2> : <EOL> key , uom = vals <EOL> if len ( vals ) == <NUM_LIT:4> : <EOL> key , uom , warn_range , crit_range = vals <EOL> if len ( vals ) == <NUM_LIT:6> : <EOL> key , uom , warn_range , crit_range , minimum , maximum = vals <EOL> key , alias = _getKeyAlias ( key ) <EOL> if self . helper . exists ( key ) : <EOL> metrics += "<STR_LIT>" % ( alias , self . helper . get ( key ) ) <EOL> if uom : metrics += uom <EOL> if warn_range != None : <EOL> warning += self . checkThreshold ( key , alias , warn_range ) <EOL> metrics += "<STR_LIT>" % warn_range <EOL> if crit_range != None : <EOL> critical += self . checkThreshold ( key , alias , crit_range ) <EOL> metrics += "<STR_LIT>" % crit_range <EOL> if minimum != None : <EOL> critical += self . checkThreshold ( key , alias , minimum + '<STR_LIT::>' ) <EOL> metrics += "<STR_LIT>" % minimum <EOL> if maximum != None : <EOL> critical += self . checkThreshold ( key , alias , '<STR_LIT>' + maximum ) <EOL> metrics += "<STR_LIT>" % maximum <EOL> metrics += '<STR_LIT:U+0020>' <EOL> return ( "<STR_LIT:%s>" % metrics , warning , critical ) <EOL> def parseArgs ( ) : <EOL> parser = argparse . ArgumentParser ( description = <EOL> '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:host>' , required = True , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:port>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:path>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , type = int , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:data>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , nargs = '<STR_LIT:*>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:-c>' , '<STR_LIT>' , dest = '<STR_LIT>' , nargs = '<STR_LIT:*>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , nargs = '<STR_LIT:*>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , nargs = '<STR_LIT:*>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , nargs = '<STR_LIT:*>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , nargs = '<STR_LIT:*>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , nargs = '<STR_LIT:*>' , <EOL> help = '<STR_LIT>' ) <EOL> return parser . parse_args ( ) <EOL> def debugPrint ( debug_flag , message , pretty_flag = False ) : <EOL> if debug_flag : <EOL> if pretty_flag : <EOL> pprint ( message ) <EOL> else : <EOL> print message <EOL> if __name__ == "<STR_LIT:__main__>" and len ( sys . argv ) >= <NUM_LIT:2> and sys . argv [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> import unittest <EOL> class RulesHelper : <EOL> separator = '<STR_LIT:.>' <EOL> debug = False <EOL> key_threshold_warning , key_value_list , key_list , key_threshold_critical , key_value_list_critical , key_list_critical , metric_list = None , None , None , None , None , None , None <EOL> def dash_m ( self , data ) : <EOL> self . metric_list = data ; return self <EOL> def dash_e ( self , data ) : <EOL> self . key_list = data ; return self <EOL> def dash_E ( self , data ) : <EOL> self . key_list_critical = data ; return self <EOL> def dash_q ( self , data ) : <EOL> self . key_value_list = data ; return self <EOL> def dash_Q ( self , data ) : <EOL> self . key_value_list_critical = data ; return self <EOL> def dash_w ( self , data ) : <EOL> self . key_threshold_warning = data ; return self <EOL> def dash_c ( self , data ) : <EOL> self . key_threshold_critical = data ; return self <EOL> class UnitTest ( unittest . TestCase ) : <EOL> rules = RulesHelper ( ) <EOL> def check_data ( self , args , jsondata , code ) : <EOL> data = json . loads ( jsondata ) <EOL> nagios = NagiosHelper ( ) <EOL> processor = JsonRuleProcessor ( data , args ) <EOL> nagios . append_warning ( processor . checkWarning ( ) ) <EOL> nagios . append_critical ( processor . checkCritical ( ) ) <EOL> nagios . append_metrics ( processor . checkMetrics ( ) ) <EOL> self . assertEqual ( code , nagios . getCode ( ) ) <EOL> def test_metrics ( self ) : <EOL> self . check_data ( RulesHelper ( ) . dash_m ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , WARNING_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_m ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , CRITICAL_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_m ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , CRITICAL_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_m ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , CRITICAL_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_m ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> def test_exists ( self ) : <EOL> self . check_data ( RulesHelper ( ) . dash_e ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , WARNING_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_E ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , CRITICAL_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_e ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> def test_equality ( self ) : <EOL> self . check_data ( RulesHelper ( ) . dash_q ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , WARNING_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_Q ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , CRITICAL_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_q ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> def test_warning_thresholds ( self ) : <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , WARNING_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , WARNING_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , WARNING_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , WARNING_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , WARNING_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , WARNING_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , WARNING_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_w ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , WARNING_CODE ) <EOL> def test_critical_thresholds ( self ) : <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , OK_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , CRITICAL_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , CRITICAL_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , CRITICAL_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , CRITICAL_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , CRITICAL_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , CRITICAL_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , CRITICAL_CODE ) <EOL> self . check_data ( RulesHelper ( ) . dash_c ( [ '<STR_LIT>' ] ) , '<STR_LIT>' , CRITICAL_CODE ) <EOL> def test_separator ( self ) : <EOL> rules = RulesHelper ( ) <EOL> rules . separator = '<STR_LIT:_>' <EOL> self . check_data ( <EOL> rules . dash_q ( [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' , <EOL> OK_CODE ) <EOL> unittest . main ( ) <EOL> exit ( <NUM_LIT:0> ) <EOL> """<STR_LIT>""" <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> args = parseArgs ( ) <EOL> nagios = NagiosHelper ( ) <EOL> if args . ssl : <EOL> url = "<STR_LIT>" % args . host <EOL> else : <EOL> url = "<STR_LIT>" % args . host <EOL> if args . port : url += "<STR_LIT>" % args . port <EOL> if args . path : url += "<STR_LIT>" % args . path <EOL> debugPrint ( args . debug , "<STR_LIT>" % url ) <EOL> try : <EOL> req = urllib2 . Request ( url ) <EOL> if args . auth : <EOL> base64str = base64 . encodestring ( args . auth ) . replace ( '<STR_LIT:\n>' , '<STR_LIT>' ) <EOL> req . add_header ( '<STR_LIT>' , '<STR_LIT>' % base64str ) <EOL> if args . headers : <EOL> headers = json . loads ( args . headers ) <EOL> debugPrint ( args . debug , "<STR_LIT>" % headers ) <EOL> for header in headers : <EOL> req . add_header ( header , headers [ header ] ) <EOL> if args . timeout and args . data : <EOL> response = urllib2 . urlopen ( req , timeout = args . timeout , data = args . data ) <EOL> elif args . timeout : <EOL> response = urllib2 . urlopen ( req , timeout = args . timeout ) <EOL> elif args . data : <EOL> response = urllib2 . urlopen ( req , data = args . data ) <EOL> else : <EOL> response = urllib2 . urlopen ( req ) <EOL> except HTTPError as e : <EOL> nagios . append_unknown ( "<STR_LIT>" % ( str ( e . code ) , url ) ) <EOL> except URLError as e : <EOL> nagios . append_critical ( "<STR_LIT>" % ( str ( e . reason ) , url ) ) <EOL> else : <EOL> jsondata = response . read ( ) <EOL> data = json . loads ( jsondata ) <EOL> debugPrint ( args . debug , '<STR_LIT>' ) <EOL> debugPrint ( args . debug , data , True ) <EOL> processor = JsonRuleProcessor ( data , args ) <EOL> nagios . append_warning ( processor . checkWarning ( ) ) <EOL> nagios . append_critical ( processor . checkCritical ( ) ) <EOL> nagios . append_metrics ( processor . checkMetrics ( ) ) <EOL> print nagios . getMessage ( ) <EOL> exit ( nagios . getCode ( ) ) </s>
