@@ -22,6 +22,7 @@ class Config:
2222 CW_METRICS_NAMESPACE = 'CW_METRICS_NAMESPACE'
2323 CW_METRICS_METRIC_NAME = 'CW_METRICS_METRIC_NAME'
2424 BODY_REGEX_MATCH = 'BODY_REGEX_MATCH'
25+ STATUS_CODE_MATCH = 'STATUS_CODE_MATCH'
2526
2627 def __init__ (self , event ):
2728 self .event = event
@@ -34,7 +35,8 @@ def __init__(self, event):
3435 self .REPORT_AS_CW_METRICS : '1' ,
3536 self .CW_METRICS_NAMESPACE : 'HttpCheck' ,
3637 self .HEADERS : '' ,
37- self .BODY_REGEX_MATCH : None
38+ self .BODY_REGEX_MATCH : None ,
39+ self .STATUS_CODE_MATCH : None
3840 }
3941
4042 def __get_property (self , property_name ):
@@ -83,6 +85,10 @@ def headers(self):
8385 @property
8486 def bodyregexmatch (self ):
8587 return self .__get_property (self .BODY_REGEX_MATCH )
88+
89+ @property
90+ def statuscodematch (self ):
91+ return self .__get_property (self .STATUS_CODE_MATCH )
8692
8793 @property
8894 def cwoptions (self ):
@@ -102,6 +108,7 @@ def __init__(self, config):
102108 self .payload = config .payload
103109 self .headers = config .headers
104110 self .bodyregexmatch = config .bodyregexmatch
111+ self .statuscodematch = config .statuscodematch
105112
106113 def execute (self ):
107114 url = urlparse (self .endpoint )
@@ -145,6 +152,9 @@ def execute(self):
145152 regex = re .compile (self .bodyregexmatch )
146153 value = 1 if regex .match (response_body ) else 0
147154 result ['ResponseBodyRegexMatch' ] = value
155+
156+ if self .statuscodematch is not None :
157+ result ['StatusCodeMatch' ] = int (int (response_data .status ) == int (self .statuscodematch ))
148158
149159 # return structure with data
150160 return result
@@ -189,15 +199,16 @@ def report(self, result):
189199 'Unit' : 'None' ,
190200 'Value' : int (result ['StatusCode' ])
191201 })
192- if 'ResponseBodyRegexMatch' in result :
193- metric_data .append ({
194- 'MetricName' : 'ResponseBodyRegexMatch' ,
195- 'Dimensions' : [
196- {'Name' : 'Endpoint' , 'Value' : self .endpoint }
197- ],
198- 'Unit' : 'None' ,
199- 'Value' : int (result ['ResponseBodyRegexMatch' ])
200- })
202+ for additional_metric in ['ResponseBodyRegexMatch' , 'StatusCodeMatch' ]:
203+ if additional_metric in result :
204+ metric_data .append ({
205+ 'MetricName' : additional_metric ,
206+ 'Dimensions' : [
207+ {'Name' : 'Endpoint' , 'Value' : self .endpoint }
208+ ],
209+ 'Unit' : 'None' ,
210+ 'Value' : int (result [additional_metric ])
211+ })
201212
202213 result = cloudwatch .put_metric_data (
203214 MetricData = metric_data ,
0 commit comments