[201911][Monit] Fix the template file of dhcp_relay (#8714)

Why I did it
This PR aims to fix the bug in Monit template file of dhcp_relay container.

If Multi-VLAN were configured on device, multiple dhcrelay processes will be spawned in dhcp_relay container. Then there will be an entry for each dhcrelay process in Monit configuration file of dhcp_relay container.

Currently Monit template file of dhcp_relay container can not be rendered correctly to generate configuration file and will cause Monit can not start up.
This commit is contained in:
yozhao101 2021-09-13 08:34:42 -07:00 committed by GitHub
parent 30f2503ab3
commit 987cf377b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,31 +6,32 @@
## dhcrelay ## dhcrelay
################################################################################ ################################################################################
{# If our configuration has VLANs... #} {# If our configuration has VLANs... #}
{%- if VLAN_INTERFACE -%} {% if VLAN_INTERFACE %}
{# Count how may VLANs require a DHCP relay agent... #} {# Count how may VLANs require a DHCP relay agent... #}
{%- set num_relays = namespace(count=0) -%} {% set num_relays = namespace(count=0) %}
{%- for vlan_name in VLAN_INTERFACE -%} {% for vlan_name in VLAN_INTERFACE %}
{%- if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 -%} {% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
{%- set num_relays.count = num_relays.count + 1 -%} {% set num_relays.count = num_relays.count + 1 %}
{%- endif -%} {% endif %}
{%- endfor -%} {% endfor %}
{# if one or more VLANs require DHCP relay agent #} {# if one or more VLANs require DHCP relay agent #}
{%- if num_relays.count > 0 -%} {% if num_relays.count > 0 %}
{%- set relay_for_ipv4 = namespace(flag=False) -%} {% set relay_for_ipv4 = namespace(flag=False) %}
{%- for vlan_name in VLAN_INTERFACE -%} {% for vlan_name in VLAN_INTERFACE %}
{%- if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length >0 -%} {% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length >0 %}
{%- for dhcp_server in VLAN[vlan_name]['dhcp_servers'] -%} {% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
{%- if dhcp_server | ipv4 -%} {% if dhcp_server | ipv4 %}
{%- set relay_for_ipv4.flag = True -%} {% set relay_for_ipv4.flag = True %}
{%- endif -%} {% endif %}
{%- endfor -%} {% endfor %}
{%- if relay_for_ipv4.flag -%} {% if relay_for_ipv4.flag %}
{%- set relay_for_ipv4 = False -%} {% set relay_for_ipv4 = False %}
{# Check the running status of each DHCP relay agent instance #} {# Check the running status of each DHCP relay agent instance #}
check program dhcp_relay|dhcrelay_{{ vlan_name }} with path "/usr/bin/process_checker dhcp_relay /usr/sbin/dhcrelay -d -m discard -a %h:%p %P --name-alias-map-file /tmp/port-name-alias-map.txt -id {{ vlan_name }}" check program dhcp_relay|dhcrelay_{{ vlan_name }} with path "/usr/bin/process_checker dhcp_relay /usr/sbin/dhcrelay -d -m discard -a %h:%p %P --name-alias-map-file /tmp/port-name-alias-map.txt -id {{ vlan_name }}"
if status != 0 for 5 times within 5 cycles then alert repeat every 1 cycles if status != 0 for 5 times within 5 cycles then alert repeat every 1 cycles
{%- endif -%}
{%- endif -%} {% endif %}
{%- endfor -%} {% endif %}
{%- endif -%} {% endfor %}
{%- endif -%} {% endif %}
{% endif %}