UNPKG

1.52 kBPlain TextView Raw
1#!/bin/bash
2
3# Check the status of a statsd or statsd proxy connecting directly to the
4# management console.
5
6# This script can be used both for Nagios and Keepalived passing a parameter.
7# The default behaviour is the Nagios one.
8
9OK=0;
10CRITICAL=2;
11UNKNOWN=3;
12KEEPALIVED_CRITICAL=1;
13
14HOST="127.0.0.1"
15PORT="8126"
16MODE_KEEPALIVED=0
17
18print_usage() {
19 echo "Usage: check_statsd_health [-H host] [-P port] [-k]"
20 echo "Options:"
21 echo " -H host Specify the host to check. [default: 127.0.0.1]"
22 echo " -P port Specify the port to check. [default: 8126]"
23 echo " -k Use exit status for Keepalived MISC_CHECK. [default: false]"
24
25 if [[ "${MODE_KEEPALIVED}" -eq "1" ]]; then
26 exit ${KEEPALIVED_CRITICAL}
27 else
28 exit ${UNKNOWN}
29 fi
30}
31
32while getopts ":H:P:k" opt; do
33 case $opt in
34 H) HOST="${OPTARG}";;
35 P) PORT="${OPTARG}";;
36 k) MODE_KEEPALIVED=1;;
37
38 :)
39 echo "Missing mandatory value for option '-${OPTARG}'" >&2
40 print_usage
41 ;;
42
43 \?)
44 echo "Invalid option '${OPTARG}'" >&2
45 print_usage
46 ;;
47
48 esac
49done
50
51HEALTH="$(echo -e "health\n" | nc "${HOST}" "${PORT}")"
52echo "Statsd '${HOST}:${PORT}' responded: '${HEALTH}'"
53
54if [[ "${HEALTH}" == "health: up" ]]; then
55 exit ${OK}
56else
57 if [[ "${MODE_KEEPALIVED}" -eq "1" ]]; then
58 exit ${KEEPALIVED_CRITICAL}
59 else
60 exit ${CRITICAL}
61 fi
62fi