#NEWLINE# def test_server_agent( self ) : #NEWLINE# #INDENT# obj = Monitoring ( ) #NEWLINE# obj . engine = EngineEmul ( ) #NEWLINE# obj . parameters . merge ( { #NEWLINE# #INDENT# 'server-agent' : [ { #NEWLINE# #INDENT# 'address' : '127.0.0.1:4444' , #NEWLINE# 'metrics' : [ 'cpu' , 'disks' ] , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'address' : '10.0.0.1' , #NEWLINE# 'metrics' : [ 'something1' , 'something2' ] , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# listener = LoggingMonListener ( ) #NEWLINE# obj . add_listener ( listener ) #NEWLINE# widget = obj . get_widget ( ) #NEWLINE# obj . add_listener ( widget ) #NEWLINE# crit_conf = BetterDict ( ) #NEWLINE# crit_conf . merge ( { #NEWLINE# #INDENT# 'threshold' : 5 , #NEWLINE# 'subject' : '127.0.0.1:4444/cpu' , #NEWLINE# #UNINDENT# } ) #NEWLINE# criteria = MonitoringCriteria ( crit_conf , obj ) #NEWLINE# obj . add_listener ( criteria ) #NEWLINE# obj . client_classes = { #NEWLINE# #INDENT# 'server-agent' : ServerAgentClientEmul , #NEWLINE# #UNINDENT# } #NEWLINE# obj . prepare ( ) #NEWLINE# obj . startup ( ) #NEWLINE# for _ in range ( 1 , 10 ) : #NEWLINE# #INDENT# obj . clients [ 0 ] . socket . recv_data += ( '%s\t%s\n' % ( random . random ( ) , random . random ( ) ) ) #NEWLINE# obj . check ( ) #NEWLINE# logging . debug ( 'Criteria state: %s' , criteria ) #NEWLINE# time . sleep ( 1 ) #NEWLINE# #UNINDENT# obj . shutdown ( ) #NEWLINE# obj . post_process ( ) #NEWLINE# self . assertEquals ( 'test\ninterval:1\nmetrics:cpu\tdisks\nexit\n' , obj . clients [ 0 ] . socket . sent_data )