Skip to content

Commit

Permalink
Extend and add Healthchecks (#125)
Browse files Browse the repository at this point in the history
* add http, dns checks
* improve tcp,ssl, misc checks
* make tcp connect ip optional
* update examples
* renamed dns checks
* and dns_check documentation
* remove leading space to keep compatibility
* updated documentation
* remove new default values from template, bugfixes, update docs
  • Loading branch information
thehawkes authored and evrardjp committed Jan 14, 2020
1 parent edb747a commit 5cba18f
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 12 deletions.
116 changes: 109 additions & 7 deletions templates/keepalived.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ virtual_server {{ vserver.ip }} {{ vserver.port }} {
TCP_CHECK {
connect_port {{ tcp_check.connect_port }}
connect_timeout {{ tcp_check.connect_timeout | default('5') }}
{% if tcp_check.connect_ip is defined and tcp_check.connect_ip %}
connect_ip {{ tcp_check.connect_ip }}
{% endif %}
{% if tcp_check.retry is defined and tcp_check.retry | int %}
retry {{ tcp_check.retry }}
{% endif %}
{% if tcp_check.delay_before_retry is defined and tcp_check.delay_before_retry | int %}
delay_before_retry {{ tcp_check.delay_before_retry }}
{% endif %}
{% if tcp_check.bindto is defined and tcp_check.bindto %}
bindto {{ tcp_check.bindto }}
{% endif %}
{% if tcp_check.bind_port is defined and tcp_check.bind_port %}
bind_port {{ tcp_check.bind_port }}
{% endif %}
{% if tcp_check.fwmark is defined and tcp_check.fwmark %}
fwmark {{ tcp_check.fwmark }}
{% endif %}
{% if tcp_check.warmup is defined and tcp_check.warmup %}
warmup {{ tcp_check.warmup }}
{% endif %}
}
{% endfor %}
{% endif %}
Expand All @@ -183,22 +204,103 @@ virtual_server {{ vserver.ip }} {{ vserver.port }} {
{% if mcheck.warmup is defined and mcheck.warmup %}
warmup {{ mcheck.warmup }}
{% endif %}
{% if mcheck.misc_dynamic is defined and mcheck.misc_dynamic %}
{% if mcheck.misc_dynamic is defined %}
misc_dynamic
{% endif %}
{% if mcheck.user is defined and mcheck.user %}
{% if mcheck.group is defined and mcheck.group %}
user {{ mcheck.user }} {{ mcheck.group }}
{% else %}
user {{ mcheck.user }}
{% endif %}
{% endif %}
}
{% endfor %}
{% endif %}
{% if rserver.http_get is defined %}
{% for http_check in rserver.http_get %}
HTTP_GET {
url {
path {{ http_check.url_path }}
digest {{ http_check.url_digest }}
}
connect_timeout {{ http_check.connect_timeout | default('3') }}
nb_get_retry {{ http_check.nb_get_retry | default('3') }}
delay_before_retry {{ http_check.delay_before_retry | default('2') }}
{% if http_check.connect_port is defined and http_check.connect_port %}
connect_port {{ http_check.connect_port }}
{% endif %}
{% if http_check.connect_ip is defined and http_check.connect_ip %}
connect_ip {{ http_check.connect_ip }}
{% endif %}
{% if http_check.bindto is defined and http_check.bindto %}
bindto {{ http_check.bindto }}
{% endif %}
{% if http_check.fwmark is defined and http_check.fwmark %}
fwmark {{ http_check.fwmark }}
{% endif %}
{% if http_check.warmup is defined and http_check.warmup %}
warmup {{ http_check.warmup }}
{% endif %}
}
{% endfor %}
{% endif %}
{% if rserver.ssl_get is defined %}
{% for sslcheck in rserver.ssl_get %}
{% for ssl_check in rserver.ssl_get %}
SSL_GET {
url {
path {{ sslcheck.url_path }}
digest {{ sslcheck.url_digest }}
path {{ ssl_check.url_path }}
digest {{ ssl_check.url_digest }}
}
connect_timeout {{ sslcheck.connect_timeout | default('3') }}
nb_get_retry {{ sslcheck.nb_get_retry | default('3') }}
delay_before_retry {{ sslcheck.delay_before_retry | default('2') }}
connect_timeout {{ ssl_check.connect_timeout | default('3') }}
nb_get_retry {{ ssl_check.nb_get_retry | default('3') }}
delay_before_retry {{ ssl_check.delay_before_retry | default('2') }}
{% if ssl_check.connect_port is defined and ssl_check.connect_port %}
connect_port {{ ssl_check.connect_port }}
{% endif %}
{% if ssl_check.connect_ip is defined and ssl_check.connect_ip %}
connect_ip {{ ssl_check.connect_ip }}
{% endif %}
{% if ssl_check.bindto is defined and ssl_check.bindto %}
bindto {{ ssl_check.bindto }}
{% endif %}
{% if ssl_check.fwmark is defined and ssl_check.fwmark %}
fwmark {{ ssl_check.fwmark }}
{% endif %}
{% if ssl_check.warmup is defined and ssl_check.warmup %}
warmup {{ ssl_check.warmup }}
{% endif %}
}
{% endfor %}
{% endif %}
{% if rserver.dns_checks is defined %}
{% for dns_check in rserver.dns_checks %}
DNS_CHECK {
connect_ip {{ dns_check.connect_ip }}
{% if dns_check.connect_port is defined and dns_check.connect_port %}
connect_port {{ dns_check.connect_port }}
{% endif %}
{% if dns_check.bindto is defined and dns_check.bindto %}
bindto {{ dns_check.bindto }}
{% endif %}
{% if dns_check.bind_port is defined and dns_check.bind_port %}
bind_port {{ dns_check.bind_port }}
{% endif %}
{% if dns_check.connect_timeout is defined and dns_check.connect_timeout | int %}}
connect_timeout {{ dns_check.connect_timeout }}
{% endif %}
{% if dns_check.fwmark is defined and dns_check.fwmark %}
fwmark {{ dns_check.fwmark }}
{% endif %}
{% if dns_check.retry is defined and dns_check.retry | int %}
retry {{ dns_check.retry }}
{% endif %}
{% if dns_check.type is defined and dns_check.type %}
type {{ dns_check.type }}
{% endif %}
{% if dns_check.name is defined and dns_check.name %}
name {{ dns_check.name }}
{% endif %}
}
{% endfor %}
{% endif %}
Expand Down
80 changes: 75 additions & 5 deletions tests/keepalived_haproxy_master_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,33 +105,103 @@ keepalived_instances:
# Uncomment and adjust to make use of keepalived's virtual_server functions.
#keepalived_virtual_servers:
# # Example with recycled {{ keepalived_internal_vip_cidr }}
# - ip: "{{ keepalived_internal_vip_cidr | ipaddr('address') }}"
# - IP: "{{ keepalived_internal_vip_cidr | ipaddr('address') }}"
# port: '53'
# protocol: 'UDP'
# lvs_method: 'NAT'
# # Optional, set false or omit to not use it.
# ha_suspend: true
# real_servers:
# - ip: '8.8.8.8'
# - IP: '8.8.8.8'
# port: '53'
# # Currently on MISC_CHECK is supported. Section is optional.
# misc_check:
# - misc_path: '/usr/bin/host -W 1 github.com 8.8.8.8'
# # Role default is 3
# misc_timeout: '2'
# - ip: '8.8.4.4'
# - IP: '8.8.4.4'
# port: '53'
# misc_check:
# - misc_path: '/usr/bin/host -W 1 github.com 8.8.4.4'
# # Optional
# misc_timeout: '10'
# # Optinal, set false or omit to not use it.
# # Optional, set false or omit to not use it.
# warmup: true
# # Optinal, set false or omit to not use it.
# # Optional, set false or omit to not use it.
# misc_dynamic: true
# # Optional, Specify the username/groupname that the script should
# be run under.
# If group is not specified, the group of the user
# is used
# user: 'root'
# group: 'root'
# ssl_get:
# - url_path: '/'
# url_digest: 'a797b47875d8fd5c949066182902099d'
# # Optional
# connect_timeout: 3
# # Optional
# nb_get_retry: 3
# # Optional
# delay_before_retry: 2
# # Optional, IP to connect to, if not set real_server IP will be used
# connect_ip: '10.0.0.1'
# # Optional, Port to connect to, if not set real_server Port will be used
# connect_port: 443
# # Optional, source IP
# bindto: '10.0.0.2'
# # Optional, fwmark to mark all outgoing checker packets with
# fwmark: 2
# # Optional, random delay to start the initial check
# warmup: 2
# http_get:
# - url_path: '/'
# url_digest: 'a797b47875d8fd5c949066182902099d'
# # Optional
# connect_timeout: 3
# nb_get_retry: 3
# delay_before_retry: 2
# # Optional, IP to connect to, if not set real_server IP will be used
# connect_ip: '10.0.0.1'
# # Optional, Port to connect to, if not set real_server Port will be used
# connect_port: 80
# # Optional, source IP
# bindto: '10.0.0.2'
# # Optional, Optional fwmark to mark all outgoing checker packets with
# fwmark: 2
# # Optional random delay to start the initial check
# warmup: 2
# tcp_checks:
# #Port to connect to
# connect_port: 23
# # Optional, IP to connect to, if not set real_server IP will be used
# connect_ip: '10.0.0.1'
# # Optional
# connect_timeout: 3
# # Optional
# retry: 3
# # Optional
# delay_before_retry: 2
# # Optional, source IP
# bindto: '10.0.0.2'
# # Optional, fwmark to mark all outgoing checker packets with
# fwmark: 2
# # Optional, random delay to start the initial check
# warmup: 2
# dns_checks:
# # IP to connect to
# connect_ip: '10.0.0.1'
# # Optional, Port to connect to, if not set real_server Port will be used
# connect_port: 1053
# # Optional
# connect_timeout: 3
# # Optional
# retry: 3
# # Optional, source IP
# bindto: '10.0.0.2'
# # Optional, fwmark to mark all outgoing checker packets with
# fwmark: 2
# # Optional, DNS type to query (SOA is default)
# type: SOA
# # Optional, DNS name to query ("." is default)
# name: '.'

0 comments on commit 5cba18f

Please sign in to comment.