@@ -1108,9 +1108,7 @@ def service(
11081108 '/v1/catalog/service/%s' % service , params = params )
11091109
11101110 class Health (object ):
1111- # TODO: All of the health endpoints support blocking queries and all
1112- # consistency modes
1113- # TODO: still need to add node and checks endpoints
1111+ # TODO: All of the health endpoints support all consistency modes
11141112 def __init__ (self , agent ):
11151113 self .agent = agent
11161114
@@ -1162,6 +1160,42 @@ def callback(response):
11621160 callback ,
11631161 '/v1/health/service/%s' % service , params = params )
11641162
1163+ def checks (self , service , index = None , wait = None , dc = None ):
1164+ """
1165+ Returns a tuple of (*index*, *checks*) with *checks* being the
1166+ checks associated with the service.
1167+
1168+ *service* is the name of the service being checked.
1169+
1170+
1171+ *index* is the current Consul index, suitable for making subsequent
1172+ calls to wait for changes since this query was last run.
1173+
1174+ *wait* the maximum duration to wait (e.g. '10s') to retrieve
1175+ a given index. this parameter is only applied if *index* is also
1176+ specified. the wait time by default is 5 minutes.
1177+
1178+ *dc* is the datacenter of the node and defaults to this agents
1179+ datacenter.
1180+
1181+ """
1182+ params = {}
1183+ if index :
1184+ params ['index' ] = index
1185+ if wait :
1186+ params ['wait' ] = wait
1187+ dc = dc or self .agent .dc
1188+ if dc :
1189+ params ['dc' ] = dc
1190+
1191+ def callback (response ):
1192+ data = json .loads (response .body )
1193+ return response .headers ['X-Consul-Index' ], data
1194+
1195+ return self .agent .http .get (
1196+ callback ,
1197+ '/v1/health/checks/%s' % service , params = params )
1198+
11651199 def state (self , name , index = None , wait = None , dc = None ):
11661200 """
11671201 Returns a tuple of (*index*, *nodes*)
0 commit comments