Enable OpenVSwitch alerts only when using OVS.

Fixes PROD-34715

Change-Id: I2803bb1313c5cd856679d3cad2b2aa017cb5627e
diff --git a/telegraf/meta/grafana.yml b/telegraf/meta/grafana.yml
index 42f8787..03d6556 100644
--- a/telegraf/meta/grafana.yml
+++ b/telegraf/meta/grafana.yml
@@ -1,5 +1,13 @@
-{%- if pillar.neutron is defined and (pillar.neutron.get('gateway', {}).get('enabled', False) == True or (pillar.neutron.get('compute',{}).get('enabled', False) == True and pillar.neutron.get('compute',{}).get('dhcp_agent_enabled', False) == True)) or
-       pillar.opencontrail is defined and pillar.opencontrail.get('compute', {}).get('enabled', False) == True %}
+{%- if (pillar.neutron is defined
+        and ((pillar.neutron.get('gateway', {}).get('enabled', False) == True
+              and 'ovs' in pillar.neutron.get('gateway', {}).get('backend', {}).get('mechanism', {}).keys())
+          or (pillar.neutron.get('compute', {}).get('enabled', False) == True
+              and 'ovs' in pillar.neutron.get('compute', {}).get('backend', {}).get('mechanism', {}).keys()
+              and pillar.neutron.get('compute', {}).get('dhcp_agent_enabled', False) == True)
+            )
+       )
+    or (pillar.opencontrail is defined
+        and pillar.opencontrail.get('compute', {}).get('enabled', False) == True) %}
 dashboard:
   kpi_downtime_prometheus:
     datasource: prometheus
diff --git a/telegraf/meta/prometheus.yml b/telegraf/meta/prometheus.yml
index ae9742c..5d8b320 100644
--- a/telegraf/meta/prometheus.yml
+++ b/telegraf/meta/prometheus.yml
@@ -37,8 +37,10 @@
         description: "Telegraf has gathering errors on the {{ $labels.host }} node for the last 10 minutes."
 {%- endraw %}
 {%- if pillar.neutron is defined %}
-  {%- if pillar.neutron.get('gateway', {}).get('enabled', False) == True or pillar.neutron.get('compute',{}).get('enabled', False) == True %}
-{%- raw %}
+  {%- for component in ['gateway', 'compute'] %}
+    {%- set neutron_config = pillar.neutron.get(component, {}) %}
+    {%- if neutron_config.get('enabled', False) == True and 'ovs' in neutron_config.get('backend', {}).get('mechanism', {}).keys() %}
+      {%- raw %}
     OVSTooManyPortRunningOnAgent:
       if: >-
         sum by (host) (ovs_bridge_status)  > 1500
@@ -78,8 +80,8 @@
       annotations:
         summary: "Failed to Gather OVS information"
         description: "Failed to Gather OVS information on host {{ $labels.host }}"
-    {%- endraw %}
-    {%- if pillar.neutron.get('gateway', {}).get('enabled', False) == True or pillar.neutron.get('compute',{}).get('dhcp_agent_enabled', False) == True %}
+      {%- endraw %}
+      {%- if pillar.neutron.get('gateway', {}).get('enabled', False) == True or pillar.neutron.get('compute',{}).get('dhcp_agent_enabled', False) == True %}
     OVSInstanceArpingCheckDown:
       if: instance_arping_check_up == 0
       for: 2m
@@ -91,8 +93,9 @@
         {%- raw %}
         description: "The OVS instance arping check on the {{ $labels.host }} node is down for 2 minutes."
         {%- endraw %}
+      {%- endif %}
     {%- endif %}
-  {%- endif %}
+  {%- endfor %}
 {%- endif %}
 {%- if pillar.opencontrail is defined %}
   {%- if pillar.opencontrail.get('compute', {}).get('enabled', False) == True %}
@@ -110,7 +113,8 @@
   {%- endif %}
 {%- endif %}
 {%- if pillar.neutron is defined %}
-  {%- if pillar.neutron.get('gateway', {}).get('enabled', False) == True or (pillar.neutron.get('compute',{}).get('enabled', False) == True and pillar.neutron.get('compute',{}).get('dhcp_agent_enabled', False) == True) %}
+  {%- if (pillar.neutron.get('gateway', {}).get('enabled', False) == True and 'ovs' in pillar.neutron.get('gateway', {}).get('backend', {}).get('mechanism', {}).keys()) %}
+      or (pillar.neutron.get('compute', {}).get('enabled', False) == True and 'ovs' in pillar.neutron.get('compute', {}).get('backend', {}).get('mechanism', {}).keys() and pillar.neutron.get('compute', {}).get('dhcp_agent_enabled', False) == True) %}
   recording:
     instance_id:instance_arping_success:
       query: >-
diff --git a/telegraf/meta/telegraf.yml b/telegraf/meta/telegraf.yml
index 6a7dda7..3436bf0 100644
--- a/telegraf/meta/telegraf.yml
+++ b/telegraf/meta/telegraf.yml
@@ -1,20 +1,23 @@
 {%- if pillar.neutron is defined %}
-  {%- if pillar.neutron.get('gateway', {}).get('enabled', False) == True or pillar.neutron.get('compute',{}).get('enabled', False) == True %}
+  {%- for component in ['gateway', 'compute'] %}
+    {%- set neutron_config = pillar.neutron.get(component, {}) %}
+    {%- if neutron_config.get('enabled', False) == True and 'ovs' in neutron_config.get('backend', {}).get('mechanism', {}).keys() %}
 agent:
   input:
     ovs_parse_bridge:
       template: telegraf/files/input/exec.conf
       commands: "/usr/local/bin/ovs_parse_bridge.py"
       interval: 45s
-    {%- if pillar.neutron.get('gateway', {}).get('enabled', False) == True or pillar.neutron.get('compute',{}).get('dhcp_agent_enabled', False) == True %}
+      {%- if pillar.neutron.get('gateway', {}).get('enabled', False) == True or pillar.neutron.get('compute',{}).get('dhcp_agent_enabled', False) == True %}
       {%- set prometheus_address = pillar._param.stacklight_monitor_address %}
     ovs_arping_check:
       template: telegraf/files/input/exec.conf
       commands: "/usr/local/bin/check_ovs_arping.py --host {{ prometheus_address }} --port 15010"
       timeout: 30s
       interval: 45s
+      {%- endif %}
     {%- endif %}
-  {%- endif %}
+  {%- endfor %}
 {%- endif %}
 
 {%- if pillar.opencontrail is defined %}
diff --git a/telegraf/script.sls b/telegraf/script.sls
index cb72478..2845888 100644
--- a/telegraf/script.sls
+++ b/telegraf/script.sls
@@ -1,5 +1,7 @@
 {%- if pillar.neutron is defined %}
-  {%- if pillar.neutron.get('gateway', {}).get('enabled', False) == True or pillar.neutron.get('compute',{}).get('enabled', False) == True %}
+  {%- for component in ['gateway', 'compute'] %}
+    {%- set neutron_config = pillar.neutron.get(component, {}) %}
+    {%- if neutron_config.get('enabled', False) == True and 'ovs' in neutron_config.get('backend', {}).get('mechanism', {}).keys() %}
 ovs_parse_bridge:
   file.managed:
   - name: /usr/local/bin/ovs_parse_bridge.py
@@ -7,7 +9,7 @@
   - template: jinja
   - mode: 750
 
-    {%- if pillar.neutron.get('gateway', {}).get('enabled', False) == True or pillar.neutron.get('compute',{}).get('dhcp_agent_enabled', False) == True %}
+      {%- if pillar.neutron.get('gateway', {}).get('enabled', False) == True or pillar.neutron.get('compute',{}).get('dhcp_agent_enabled', False) == True %}
 ovs_arping_check_telegraf_script:
   file.managed:
   - name: /usr/local/bin/check_ovs_arping.py
@@ -15,8 +17,9 @@
   - template: jinja
   - mode: 750
 
+      {%- endif %}
     {%- endif %}
-  {%- endif %}
+  {%- endfor %}
 {%- endif %}
 
 {%- if pillar.opencontrail is defined %}