diff --git a/src/modules/host.py b/src/modules/host.py index 3a81d439e..7e0581088 100644 --- a/src/modules/host.py +++ b/src/modules/host.py @@ -398,14 +398,21 @@ def refresh_status(self, id): if not host: logger.warning("No host found with id=" + id) return False - if not self.host_agents[host.type]\ - .refresh_status(host.worker_api): - logger.warning("Host {} is inactive".format(id)) - self.db_set_by_id(id, **{"status": "inactive"}) - return False + if host.type == WORKER_TYPE_K8S: + if not self.host_agents[host.type]\ + .refresh_status(host.k8s_param): + logger.warning("Host {} is inactive".format(id)) + self.db_set_by_id(id, **{"status": "inactive"}) + return False else: - self.db_set_by_id(id, **{"status": "active"}) - return True + if not self.host_agents[host.type]\ + .refresh_status(host.worker_api): + logger.warning("Host {} is inactive".format(id)) + self.db_set_by_id(id, **{"status": "inactive"}) + return False + + self.db_set_by_id(id, **{"status": "active"}) + return True def is_active(self, host_id): """ diff --git a/src/watchdog.py b/src/watchdog.py index f8ca9e027..f3d00d1b5 100644 --- a/src/watchdog.py +++ b/src/watchdog.py @@ -18,6 +18,7 @@ MONGODB_PORT = int(os.getenv('MONGODB_PORT', 27017)) MONGODB_USERNAME = os.getenv('MONGODB_USERNAME', '') MONGODB_PASSWORD = os.getenv('MONGODB_PASSWORD', '') +PERIOD_TIME = int(os.getenv('PERIOD_TIME', 15)) connect(MONGODB_DB, host=MONGODB_HOST, username=MONGODB_USERNAME, password=MONGODB_PASSWORD, connect=False, tz_aware=True) @@ -133,4 +134,4 @@ def watch_run(period=15): if __name__ == '__main__': - watch_run() + watch_run(PERIOD_TIME)