<s> from socket import gethostname , error <EOL> class RiemannReporter : <EOL> def __init__ ( self , client , default_ttl = <NUM_LIT> ) : <EOL> self . hostname = gethostname ( ) <EOL> self . service = '<STR_LIT>' <EOL> self . client = client <EOL> self . default_ttl = default_ttl <EOL> def send ( self , attrs ) : <EOL> if not self . client : <EOL> return <EOL> d = { '<STR_LIT:host>' : self . hostname , '<STR_LIT>' : self . service , "<STR_LIT>" : self . default_ttl } <EOL> d . update ( attrs ) <EOL> try : <EOL> log . error ( "<STR_LIT>" % ( d , ) ) <EOL> self . client . send ( d ) <EOL> except error , e : <EOL> log . error ( "<STR_LIT>" , e ) <EOL> def send_docker_unhealthy ( self ) : <EOL> self . send ( { '<STR_LIT:description>' : '<STR_LIT>' , '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT:error>' ] , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> def send_docker_healthy ( self ) : <EOL> self . send ( { '<STR_LIT:description>' : '<STR_LIT>' , '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> def get_riemann ( riemann_arg , default_ttl , log_param ) : <EOL> import bernhard <EOL> client = None <EOL> if riemann_arg : <EOL> global log <EOL> log = log_param <EOL> protocol , host , port = riemann_arg . split ( '<STR_LIT::>' ) <EOL> port = int ( port ) <EOL> if protocol == '<STR_LIT>' : <EOL> proto_impl = bernhard . UDPTransport <EOL> elif protocol == '<STR_LIT>' : <EOL> proto_impl = bernhard . TCPTransport <EOL> else : <EOL> log . error ( "<STR_LIT>" % protocol ) <EOL> client = bernhard . Client ( host , port , transport = proto_impl ) <EOL> return RiemannReporter ( client , default_ttl ) </s>
