Unverified Commit 9a52dd2e authored by Marius Hellmann's avatar Marius Hellmann Committed by GitHub

Merge pull request #140 from citronalco/check_websites_ipv4

nrpe: check_websites-ipv4
parents 1c3101cc 86f70e96
......@@ -222,6 +222,28 @@ object Service "Check Bird6 Sessions" {
vars.notification.hipchat = "1"
}
{% if nrpe.check_websites_upstream_ipv4 is defined and hostvars[item].ffrl_nat_ip is defined %}
object Service "Check selected Websites via FFRL tunnel (HTTP/IPv4) " {
import "generic-service"
host_name = "{{ item }}"
check_command = "nrpe2"
vars.nrpe_command = "check_websites-ffrl-ipv4"
vars.sla = "24x7"
vars.notification.hipchat = "1"
}
{% endif %}
{% if nrpe.check_websites_upstream_ipv4 is defined and hostvars[item].ffnw_nat_ip is defined %}
object Service "Check selected Websites via FFNW tunnel (HTTP/IPv4) " {
import "generic-service"
host_name = "{{ item }}"
check_command = "nrpe2"
vars.nrpe_command = "check_websites-ffnw-ipv4"
vars.sla = "24x7"
vars.notification.hipchat = "1"
}
{% endif %}
{% if hostvars[item].domaenenliste is defined %}
{% for domaene in hostvars[item].domaenenliste|dictsort %}
object Service "Check BATMAN Dom {{domaene[0]}} via IP" {
......
#!/bin/bash
PLUGINDIR=$(dirname "$0")
. "${PLUGINDIR}/utils.sh"
DOMAINS=()
TIMEOUT=2
while [[ $# -gt 0 ]]; do
opt="$1"
shift
case "${opt}" in
"-w" ) WARN="$1"; shift;;
"-c" ) CRIT="$1"; shift;;
"-s" ) SOURCE_IP="$1"; shift;;
"-t" ) TIMEOUT="$1"; shift;;
*) DOMAINS+=("${opt}");;
esac
done
if [ -z "${CRIT}" ] || [ -z "${WARN}" ] || [ ${#DOMAINS[@]} -eq 0 ]; then
echo "$0 -w <WARNING> -c <CRITICAL> [-s <SOURCE_IP>] [-t TIMEOUT] DOMAIN [DOMAIN ...]"
echo
echo " If at less than WARNING or CRITICAL percent of the domains are reachable within TIMEOUT seconds (default: 2) on HTTP, this script returns state WARNING or CRITICAL."
echo
echo " If SOURCE_IP is set to an IP address or interface name, this is used to initiate the HTTP connections."
echo " In that case a domain is skipped if it is also unreachable via the default interface."
echo
exit "${STATE_UNKNOWN}"
fi
DOMAINS_TOTAL=${#DOMAINS[@]}
DOMAINS_OK=0
PIDS=()
for DOMAIN in "${DOMAINS[@]}"; do
(
if [ -n "${SOURCE_IP}" ]; then
curl -4 --interface "${SOURCE_IP}" --max-time "${TIMEOUT}" --head --output /dev/null --silent http://"${DOMAIN}" && exit 0
curl -4 --max-time "${TIMEOUT}" --head --output /dev/null --silent http://"${DOMAIN}" && exit 1
exit 2
else
curl -4 --max-time "${TIMEOUT}" --head --output /dev/null --silent http://"${DOMAIN}" && exit 0
exit 1
fi
) &
PIDS+=($!)
done
# Wait for all jobs to finish. The "wait" command forwards the exit state of the command that was executed in the background
for P in ${PIDS[*]}; do
wait "$P"
RETVAL=$?
if [ ${RETVAL} -eq 0 ]; then
DOMAINS_OK=$((DOMAINS_OK+1))
elif [ ${RETVAL} -eq 2 ]; then
DOMAINS_TOTAL=$((DOMAINS_TOTAL-1))
fi
done
if [ ${DOMAINS_TOTAL} -eq 0 ]; then
echo "UNKNOWN: No domains to test"
exit "${STATE_UNKNOWN}"
fi
PERCENTAGE_OK=$((100*DOMAINS_OK/DOMAINS_TOTAL))
PERFDATA="Domains reachable=${PERCENTAGE_OK}%;${WARN};${CRIT};0;100"
if [ ${PERCENTAGE_OK} -lt "${CRIT}" ]; then
echo "CRITICAL: ${PERCENTAGE_OK}% of ${DOMAINS_TOTAL} domains reachable|${PERFDATA}"
exit "${STATE_CRITICAL}"
elif [ ${PERCENTAGE_OK} -lt "${WARN}" ]; then
echo "WARNING: ${PERCENTAGE_OK}% of ${DOMAINS_TOTAL} domains reachable|${PERFDATA}"
exit "${STATE_WARNING}"
else
echo "OK: ${PERCENTAGE_OK}% of ${DOMAINS_TOTAL} domains reachable|${PERFDATA}"
exit "${STATE_OK}"
fi
......@@ -86,6 +86,9 @@
- name: Install check_borg
copy: "src=check_borg dest='/usr/lib/nagios/plugins/check_borg' owner=root group=root mode=a+x"
- name: Install check_websites-ipv4
copy: "src=check_websites-ipv4 dest='/usr/lib/nagios/plugins/check_websites-ipv4' owner=root group=root mode=a+x"
- name: Install sudo permissions
template: "src=sudoers.j2 dest='/etc/sudoers.d/nrpe' owner=root group=root mode=440"
......
......@@ -49,6 +49,12 @@ command[check_iproute]=/usr/lib/nagios/plugins/check_iproute
command[check_iproute6]=/usr/lib/nagios/plugins/check_iproute6
command[check_bird_sessions]=sudo /usr/lib/nagios/plugins/check_bird_sessions
command[check_bird6_sessions]=sudo /usr/lib/nagios/plugins/check_bird6_sessions
{% if nrpe.check_websites_upstream_ipv4 is defined and ffrl_nat_ip is defined %}
command[check_websites-ffrl-ipv4]=/usr/lib/nagios/plugins/check_websites-ipv4 -t 2 -s {{ ffrl_nat_ip }} -w 99 -c 95 {{ nrpe.check_websites_upstream_ipv4 }}
{% endif %}
{% if nrpe.check_websites_upstream_ipv4 is defined and ffnw_nat_ip is defined %}
command[check_websites-ffnw-ipv4]=/usr/lib/nagios/plugins/check_websites-ipv4 -t 2 -s {{ ffnw_nat_ip }} -w 99 -c 95 {{ nrpe.check_websites_upstream_ipv4 }}
{% endif %}
# Service VM Server
command[check_nginx]=/usr/lib/nagios/plugins/check_procs -c 1: -w 1: -C nginx
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment