Skip to content

Commit

Permalink
Add script to check external website connectivity.
Browse files Browse the repository at this point in the history
  • Loading branch information
GUI committed Feb 7, 2017
1 parent 1ca7fdf commit bb4f381
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
53 changes: 53 additions & 0 deletions files/default/nagios_plugins/check_external_connectivity
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions recipes/check_external_connectivity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include_recipe "opsview::client"

nrpe_plugin "check_external_connectivity" do
source "nagios_plugins/check_external_connectivity"
end

0 comments on commit bb4f381

Please sign in to comment.