Browse Source

Use 'status' from Netbox for Icinga2 node generation.

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
Maximilian Wilhelm 4 years ago
parent
commit
a15d5d9747
2 changed files with 8 additions and 5 deletions
  1. 3 3
      icinga2/host.conf.tmpl
  2. 5 2
      icinga2/init.sls

+ 3 - 3
icinga2/host.conf.tmpl

@@ -6,7 +6,7 @@
 {%- set address = salt['ffho_net.get_loopback_ip'] (node_config, node_id, 'v4') %}
 {%- set address6 = salt['ffho_net.get_loopback_ip'] (node_config, node_id, 'v6') %}
 {%- set monitoring_config = node_config.get ('monitoring', {}) %}
-{%- set state = node_config.get ('state', 'operation') %}
+{%- set status = node_config.get ('status', 'active') %}
 
 {%- if 'icinga2server' not in roles %}
 object Endpoint "{{ node_id }}" {
@@ -27,9 +27,9 @@ object Host "{{ node_id }}" {
 	address = "{{ address }}"
 	address6 = "{{ address6 }}"
 
-{%- if state != 'operation' %}
+{%- if status != 'active' %}
 
-	# This node has state {{ state }}, don't whine about anything here
+	# This node has status {{ status }}, don't whine about anything here
 	enable_notifications = false
 {%- endif %}
 

+ 5 - 2
icinga2/init.sls

@@ -187,7 +187,11 @@ Cleanup /etc/icinga2/ffho-conf.d/hosts/generated/:
 
   # Generate config file for every client known to pillar
   {% for node_id, node_config in salt['pillar.get']('nodes', {}).items () %}
-    {% if node_config.get ('icinga2', "") != 'ignore' %}
+    {# Only monitor hosts which are active or staged. #}
+    {% if node_config.get ('status', '') not in [ '', 'active', 'staged' ] %}
+      {% continue %}
+    {% endif %}
+
 /etc/icinga2/ffho-conf.d/hosts/generated/{{ node_id }}.conf:
   file.managed:
     - source: salt://icinga2/host.conf.tmpl
@@ -201,7 +205,6 @@ Cleanup /etc/icinga2/ffho-conf.d/hosts/generated/:
       - file: Cleanup /etc/icinga2/ffho-conf.d/hosts/generated/
     - watch_in:
       - service: icinga2
-    {% endif %}
   {% endfor %}