Ejemplo n.º 1
0
    def run_background(self):
        """
        We trigger the health checks periodically in a background process
        """
        while True:

            config_path = os.getenv('HK_CONFIG_PATH', "resources/config.yaml")
            cfg = Config(path=config_path)

            if not cfg.data:
                print("ERROR: No health-checks valid config found. Please check syntax.")
            else:
                try:
                    print(time.strftime("%c")+" Checking endpoints")
                    chk = Check(cfg.data)
                    chk.check_endpoints()
                    chk.send_notifications()
                    print(time.strftime("%c") + " Endpoints checked")
                except Exception as e:
                    print("ERROR: Killing application. Reason:\n"+str(e))
                    #os.kill(os.getpid(), signal.SIGTERM)
                    #sys.exit()
                    self.server.stop()

            time.sleep(self.interval)
Ejemplo n.º 2
0
    def test_check_endpoints_timeout(self):

        endpoint = {'notificationEndpoint': {'url': ''}, 'checks': [{'request': {'endpoint': 'http://127.0.0.1:1',  'method': 'GET', 'connectTimeout': 0.001}, 'response': {'codes': [200]}, 'service': 'Gitlab'}]}

        my_check = Check(endpoint)
        my_check.check_endpoints()

        result = len(my_check.errors_list)
        self.assertEqual(result, 1)