#NEWLINE# def test_check( self ) : #NEWLINE# #INDENT# conf_hostname = 'foo' #NEWLINE# port = 9200 #NEWLINE# bad_port = 9405 #NEWLINE# agent_config = { #NEWLINE# #INDENT# 'hostname' : conf_hostname , #NEWLINE# 'version' : get_version ( ) , #NEWLINE# 'agent_key' : 'bar' , #NEWLINE# #UNINDENT# } #NEWLINE# tags = [ 'foo:bar' , 'baz' ] #NEWLINE# url = 'http://localhost:{0}' . format ( port ) #NEWLINE# bad_url = 'http://localhost:{0}' . format ( bad_port ) #NEWLINE# config = { #NEWLINE# #INDENT# 'instances' : [ { #NEWLINE# #INDENT# 'url' : url , #NEWLINE# 'tags' : tags , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'url' : url , #NEWLINE# 'cluster_stats' : True , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'url' : bad_url , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } #NEWLINE# self . assertRaises ( requests . exceptions . ConnectionError , self . run_check , config = config , agent_config = agent_config ) #NEWLINE# default_tags = [ 'url:http://localhost:{0}' . format ( port ) ] #NEWLINE# instance_config = self . check . get_instance_config ( config [ 'instances' ] [ 0 ] ) #NEWLINE# es_version = self . check . _get_es_version ( instance_config ) #NEWLINE# self . assertEquals ( es_version , get_es_version ( ) ) #NEWLINE# contexts = [ ( conf_hostname , ( default_tags + tags ) ) , ( socket . gethostname ( ) , default_tags ) ] #NEWLINE# for ( m_name , desc ) in self . _get_default_expected_metrics ( config ) . iteritems ( ) : #NEWLINE# #INDENT# for ( hostname , m_tags ) in contexts : #NEWLINE# #INDENT# if ( ( m_name in CLUSTER_HEALTH_METRICS ) and ( hostname == socket . gethostname ( ) ) ) : #NEWLINE# #INDENT# hostname = conf_hostname #NEWLINE# #UNINDENT# if ( desc [ 0 ] == 'gauge' ) : #NEWLINE# #INDENT# self . assertMetric ( m_name , tags = m_tags , count = 1 , hostname = hostname ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# good_sc_tags = [ 'host:localhost' , 'port:{0}' . format ( port ) ] #NEWLINE# bad_sc_tags = [ 'host:localhost' , 'port:{0}' . format ( bad_port ) ] #NEWLINE# self . assertServiceCheckOK ( 'elasticsearch.can_connect' , tags = good_sc_tags , count = 2 ) #NEWLINE# self . assertServiceCheckCritical ( 'elasticsearch.can_connect' , tags = bad_sc_tags , count = 1 ) #NEWLINE# self . assertServiceMetadata ( [ 'version' ] , count = 3 ) #NEWLINE# if ( get_es_version ( ) != [ 0 , 90 , 13 ] ) : #NEWLINE# #INDENT# self . assertServiceCheckWarning ( 'elasticsearch.cluster_health' , tags = good_sc_tags , count = 2 ) #NEWLINE# self . assertEvent ( 'ElasticSearch: foo just reported as yellow' , count = 1 , tags = ( default_tags + tags ) , msg_title = 'foo is yellow' , event_type = 'elasticsearch' , alert_type = 'warning' , source_type_name = 'elasticsearch' ) #NEWLINE# self . coverage_report ( )