@@ -116,6 +116,12 @@ def __init__(self, name, init_config, instances):
116116 self .collect_health_checks = self .instance .get (
117117 'collect_health_checks' , self .init_config .get ('collect_health_checks' , False )
118118 )
119+ self .health_check_warning_events = is_affirmative (
120+ self .instance .get (
121+ 'health_check_warning_events' ,
122+ self .init_config .get ('health_check_warning_events' , False ),
123+ )
124+ )
119125
120126 if self .threads_count > 1 :
121127 self .thread_pool = ThreadPool (self .threads_count )
@@ -407,22 +413,33 @@ def check(self, _):
407413 self .gauge (HEALTH_CHECK_METRIC , status_value , tags = main_tags + node_tags )
408414 self .health_checks [hc_id ] = status_value
409415
410- if last_hc_value != status_value and status_value == 3 :
411- check_name = check .get ("Name" , "Consul Health Check" )
412- check_output = check .get ("Output" , "" )
413- self .event (
414- {
415- "timestamp" : timestamp (),
416- "event_type" : "consul.check_failed" ,
417- "alert_type" : "error" ,
418- "source_type_name" : SOURCE_TYPE_NAME ,
419- "msg_title" : f"{ check_name } Failed" ,
420- "aggregation_key" : "consul.status_check" ,
421- "msg_text" : f"Check { check_id } for service { service_name } , id: { service_id } "
422- f"failed on node { node_name } : { check_output } " ,
423- "tags" : node_tags ,
424- }
425- )
416+ if last_hc_value != status_value :
417+ if status_value == 3 or (status_value == 2 and self .health_check_warning_events ):
418+ check_name = check .get ("Name" , "Consul Health Check" )
419+ check_output = check .get ("Output" , "" )
420+
421+ if status_value == 3 :
422+ event_type = "consul.check_failed"
423+ alert_type = "error"
424+ label = "failed"
425+ else :
426+ event_type = "consul.check_warning"
427+ alert_type = "warning"
428+ label = "warning"
429+
430+ self .event (
431+ {
432+ "timestamp" : timestamp (),
433+ "event_type" : event_type ,
434+ "alert_type" : alert_type ,
435+ "source_type_name" : SOURCE_TYPE_NAME ,
436+ "msg_title" : f"{ check_name } { label .capitalize ()} " ,
437+ "aggregation_key" : "consul.status_check" ,
438+ "msg_text" : f"Check { check_id } for service { service_name } , id: { service_id } "
439+ f"{ label } on node { node_name } : { check_output } " ,
440+ "tags" : node_tags ,
441+ }
442+ )
426443
427444 if sc_id not in service_checks :
428445 service_checks [sc_id ] = {'status' : status , 'tags' : tags }
0 commit comments