From bb4f38114137439c303e622c68395e89c4a9f100 Mon Sep 17 00:00:00 2001 From: Nick Muerdter Date: Tue, 7 Feb 2017 15:04:17 -0700 Subject: [PATCH] Add script to check external website connectivity. --- .../check_external_connectivity | 53 +++++++++++++++++++ metadata.rb | 2 +- recipes/check_external_connectivity.rb | 5 ++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 files/default/nagios_plugins/check_external_connectivity create mode 100644 recipes/check_external_connectivity.rb diff --git a/files/default/nagios_plugins/check_external_connectivity b/files/default/nagios_plugins/check_external_connectivity new file mode 100644 index 0000000..3073e1e --- /dev/null +++ b/files/default/nagios_plugins/check_external_connectivity @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +set -u + +exit_ok=0 +exit_warning=1 +exit_critical=2 +max_time=1.5 +urls=( + http://www.google.com/ + https://www.google.com/ + http://www.bing.com/ + https://www.bing.com/ + http://www.yahoo.com/ + https://www.yahoo.com/ +) +timer_format="\n\ntime_namelookup: %{time_namelookup} +time_connect: %{time_connect} +time_appconnect: %{time_appconnect} +time_pretransfer: %{time_pretransfer} +time_redirect: %{time_redirect} +time_starttransfer: %{time_starttransfer} +---------- +time_total: %{time_total}" + +for url in "${urls[@]}"; do + output=$(curl -v -w "$timer_format" -o /dev/null "$url" 2>&1) + if [[ $? != 0 ]]; then + echo -e "Request failed to $url\n\nOutput:\n$output" + exit $exit_critical + else + # Check for network IPv6 routing issues. + if [[ $output == *"No route to host"* ]]; then + echo -e "IPv6 failure to $url\n\nOutput:\n$output" + exit $exit_warning + + # Check for network SSL interception issues. + elif [[ $output == *"Server certificate:"* && $output == *"O=National Renewable Energy Laboratory"* ]]; then + echo -e "SSL failure to $url\n\nOutput:\n$output" + exit $exit_warning + else + # Check response times. + time_total=$(echo "$output" | grep -Eo "time_total: ([0-9\.]+)" | grep -Eo "[0-9\.]+") + if [[ $(echo "$time_total>$max_time" | bc -l) != 0 ]]; then + echo -e "Response time too long for $url\n\nOutput:\n$output" + exit $exit_warning + fi + fi + fi +done + +echo "OK" +exit $exit_ok diff --git a/metadata.rb b/metadata.rb index 5d8661b..829f851 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license "All rights reserved" description "Installs/Configures opsview" long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc')) -version "0.1.2" +version "0.1.3" depends "acl" depends "apache2" diff --git a/recipes/check_external_connectivity.rb b/recipes/check_external_connectivity.rb new file mode 100644 index 0000000..e7c0bb4 --- /dev/null +++ b/recipes/check_external_connectivity.rb @@ -0,0 +1,5 @@ +include_recipe "opsview::client" + +nrpe_plugin "check_external_connectivity" do + source "nagios_plugins/check_external_connectivity" +end