from hawkeye_monitor.checks.base import ElasticsearchCheck from hawkeye_monitor.config import ALERTING_CONFIG from hawkeye_monitor.data import CheckResult from absl import logging class CheckNonNullableFields(ElasticsearchCheck): def run_check(self, client, index) -> CheckResult: """ Runs null checks on given fields in the query (in this case GSR ID and UUID) params: -client (Elastisearch Client): Elasticsearch Client -index (str) - index to run query returns: CheckResult """ logging.info(f"{self.__class__.__name__} running check!") # set index self.index = index # response = client.count(index=index, query=self.query) return self.validate(response) def validate(self, response, alert_config=ALERTING_CONFIG) -> CheckResult: """ Validates responses from search params: - response(dict) response object from the ES query - alert_config (dict) - configuration for how to handle alerting returns: - CheckResult """ # push alerts onto stack # - this is to ensure higher alert levels get raised first alerts_raised = [] # check alert levels for _, alert_level_vals in alert_config.items(): if response["count"] >= alert_level_vals["threshold"]: alerts_raised.append( CheckResult( **{ "check_name": self.__class__.__name__, "check_passed": False, "message": f"NullCheck Failed on ES Index ({self.index})", "kwargs": alert_level_vals, } ) ) # Check for any fcrossed thresholds if len(alerts_raised) > 0: # pop stack and return return alerts_raised.pop() # Passed return CheckResult( **{ "check_name": self.__class__.__name__, "check_passed": True, "message": "NonNullable Fields Checks Passed!", } )