forked from inuits/monitoring-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_topology
executable file
·103 lines (91 loc) · 2.19 KB
/
check_topology
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
#!/bin/bash
#
# Author: Bart Janssens
# Email: [email protected]
# Date: Wed Apr 6 2016
#
# Requires the jq package to work
#
showhelp () {
cat <<eof
A check that looks for the status of the specified topology.
Parameters:
--topology-name|-n : The name of the topology
--help|-h : Shows help
--debug|-d : Enable debug, aka echo some params
--state|-s : Expected state, defaults to running
--url|-u : Pass alternative API url
Example usage:
./check_storm_topology -n nameofthetopology
eof
exit 3
}
defaults () {
if [[ -z "${url}" ]]; then url='localhost:8080'; fi
if [[ -z "${expected_status}" ]]; then expected_status='ACTIVE'; fi
if [[ -z "${debug}" ]]; then debug=false; fi
if [[ -z "${topology_name}" ]]; then message="Unknown: You need to specify, --topology-name or use --help."; exitstatus='3'; quit; fi
}
data () {
# Get the data
if $debug; then echo "curl -s http://${url}/api/v1/topology/summary"; fi
get=$( curl -s http://${url}/api/v1/topology/summary )
if $debug; then echo $get; fi
}
do_main_check () {
# Parse the data
topology_status=$( echo $get | jq ".[\"topologies\"] | map(select(.name == \"${topology_name}\" )) | .[].status" -r )
if $debug; then echo $topology_status; fi
# Depending on what the status is, exit
if [[ ! "${topology_status}" == "${expected_status}" ]]
then
if [[ -z $topology_status ]]
then
message="Unknown: Topology ${topology_name} wasn't found!"
exitstatus='3'
else
message="Critical: Topology ${topology_name} state ${topology_status} doesn't match ${expected_status}!"
exitstatus='2'
fi
else
message="Ok: Topology ${topology_name} is running."
exitstatus='0'
fi
}
quit () {
echo "${message}" && exit $exitstatus
}
while test -n "$1"
do
case "$1" in
--help|-h)
showhelp
;;
--topology-name|-n)
shift
topology_name=$1
shift
;;
--status|-s)
shift
expected_status=$1
shift
;;
--url|-u)
shift
url=$1
shift
;;
--debug|-d)
shift
debug=true
;;
*)
showhelp
;;
esac
done
defaults
data
do_main_check
quit