From 1f62741b170f005b88bee171e3fe19a0aba0893d Mon Sep 17 00:00:00 2001 From: Hamid Lotfi Date: Tue, 7 Jan 2025 12:35:27 +0000 Subject: [PATCH] If any of the consul agents such as manage, tenant, or warehouse are not set. This exception is raised: Exception when host-monitored by console: Object 'NoneType' has no attribute 'get_health': AttributeError: Object 'NoneType' has no attribute 'get_health'. Now to handle this exception, we just need to check the condition whether the name exists in 'agents.name'. Change-Id: I00ca3271f52eb4de770dbd719a57b2d15c138833 --- .../doc/source/reference/conf.rst | 12 ++++++++++ .../hostmonitor/consul_check/consul_helper.py | 22 ++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 masakari-monitors/doc/source/reference/conf.rst diff --git a/masakari-monitors/doc/source/reference/conf.rst b/masakari-monitors/doc/source/reference/conf.rst new file mode 100644 index 0000000..cc17817 --- /dev/null +++ b/masakari-monitors/doc/source/reference/conf.rst @@ -0,0 +1,12 @@ +.. _monitors-config: + +--------------------------------------- +Masakari Monitors Configuration Options +--------------------------------------- + +The following is an overview of all available configuration options in +masakari-monitors. +To see sample configuration file, see :ref:`monitors-config-file`. + +.. _show-options:: + :config-file: etc/masakarimonitors/masakarimonitors-config-generator.conf \ No newline at end of file diff --git a/masakarimonitors/hostmonitor/consul_check/consul_helper.py b/masakarimonitors/hostmonitor/consul_check/consul_helper.py index d9ecdd1..d314c97 100644 --- a/masakarimonitors/hostmonitor/consul_check/consul_helper.py +++ b/masakarimonitors/hostmonitor/consul_check/consul_helper.py @@ -71,21 +71,23 @@ class ConsulManager(object): hosts_health = {} all_agents = [] for name in sequence: - consul_agent = self.agents.get(name) - agent_health = consul_agent.get_health() - hosts_health[name] = agent_health - if not all_agents: - all_agents = agent_health.keys() + if name in self.agents: + consul_agent = self.agents.get(name) + agent_health = consul_agent.get_health() + hosts_health[name] = agent_health + if not all_agents: + all_agents = agent_health.keys() sequence_hosts_health = {} for host in all_agents: sequence_hosts_health[host] = [] for name in sequence: - state = hosts_health[name].get(host) - if state: - sequence_hosts_health[host].append(state) - else: - continue + if name in self.agents: + state = hosts_health[name].get(host) + if state: + sequence_hosts_health[host].append(state) + else: + continue return sequence_hosts_health