forked from adw0rd/nagios_erlang
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_erlang_application.sh
executable file
·140 lines (133 loc) · 4.21 KB
/
check_erlang_application.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh
#
# ## Overview
#
# This script is used for checking that a specified node is running a specific
# application.
#
# This script only uses two status codes: OK and CRITICAL. This is due
# to the fact that it only checks existence, and does so in a purely
# binary fashion.
#
# ## Licence
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ## Acknowledgements
#
# This script owes heavily to the [check_nginx.sh][cnsh] script, upon which the Bash components
# are modeled.
#
# [cnsh]: http://exchange.nagios.org/directory/Plugins/Uncategorized/Software/check_nginx-2Esh/details "check_nginx.sh"
#
PROGNAME=`basename $0`
VERSION="Version 0.1,"
AUTHOR="2009, Will Larson [http://lethain.com]"
RANDOM=`echo | awk '{srand(); print rand()}' | awk '{sub(/\./, ""); print}'` # $RANDOM for sh
ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3
COOKIE="cookie" # cookie used by the local node
NODE="node@localhost" # name of node to check
TMP_NODE="nagios_check_app_$RANDOM" # name of temporary node to ping $NODE
TMP_HOST="`hostname`"
ERL="/usr/bin/erl" # full path to erlang executable
BEAM="`pwd`/ebin/" # full path to directory where nagios_erlang.beam exists
VERBOSITY=0 # amount of detail to be returned, 0-3
APPLICAITON="unknown" # name of application to check
print_version() {
echo "$VERSION $AUTHOR"
}
print_help() {
print_version $PROGNAME $VERSION
echo ""
echo "$PROGNAME is a Nagios plugin to check if an Erlang node is pingable from the local host."
echo ""
echo "$PROGNAME -e /usr/bin/erl -b /home/wl/nagios_erlang/ebin/ -n my_server -c my_cookie -a my_application"
echo ""
echo "Options:"
echo " -a/--application : name of application to check on"
echo " -e/--erl : the absolute path to erl binary (/usr/bin/erl)"
echo " -n/--node : the node to ping against"
echo " -b/--beam : the absolute path to directory with nagios_erlang.beam"
echo " -c/--cookie : the cookie used by node (cookie)"
echo " -h/--help : show this screen"
echo " -H/--host : host of erlang node"
echo " -v/--verbosity : level of detail, 0-3 (0)"
echo " -V/--version : version of package"
echo " -h/--help : show this screen"
}
while test -n "$1"; do
case "$1" in
--application|-a)
APPLICATION=$2
shift
;;
--help|-h)
print_help
exit $ST_UK
;;
--verbosity|-v)
VERBOSITY=$2
shift
;;
--version|-V)
print_version $PROGNAME $VERSION
exit $ST_UK
;;
--erl|-e)
ERL=$2
shift
;;
--beam|-b)
BEAM=$2
shift
;;
--cookie|-c)
COOKIE=$2
shift
;;
--node|-n)
NODE=$2
shift
;;
--host|-H)
TMP_HOST=$2
shift
;;
*)
echo "Uknown argument: $1"
print_help
exit $ST_UK
;;
esac
shift
done
TMP_NODE="$TMP_NODE@$TMP_HOST"
CMD="$ERL -pa $BEAM -run nagios_erlang check_application $NODE $APPLICATION -noshell -name $TMP_NODE -setcookie $COOKIE"
if [ $VERBOSITY -ge 3 ]
then
echo "version: $VERSION"
echo "application: $APPLICATION"
echo "node: $NODE"
echo "cookie: $COOKIE"
echo "tmp_node: $TMP_NODE"
echo "erl: $ERL"
echo "beam: $BEAM"
echo "verbosity: $VERBOSITY"
echo "full command: $CMD"
fi
$CMD