-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathcheck_nodering.py
executable file
·55 lines (50 loc) · 2.06 KB
/
check_nodering.py
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
#! /usr/bin/python
#
# Rackspace Cloud Monitoring Plug-In
# Check the status of a cassandra nodering and make sure none of the nodes
# have a '?' as a status.
#
# (c) 2017 Jim Wang <[email protected]>
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Usage:
# Place plug-in in /usr/lib/rackspace-monitoring-agent/plugins
#
# It accepts three arguments, the path to the nodetool executable, the cassandra hostname
# and the port on which to run on
#
# Returns 1 metric, nodering_status:
# 0 if the nodes don't have a '?' as a status
# 1 if the nodes have a '?' as a status
#
#! /usr/bin/python
from subprocess import check_output
import sys
import argparse
parser = argparse.ArgumentParser(description='Run nodetool to check for inconsistent state')
parser.add_argument('-p', '--port', dest='portforcassandra', default='9080', help='port that cassandra is running on')
parser.add_argument('-t', '--tool', dest='pathtonodetool', default='/opt/cassandra/bin/', help='path to nodetool executable (ex /opt/cassandra/bin)')
parser.add_argument('-o', '--host', dest='cassandrahost', default='localhost', help='host cassandra is running on.')
args = parser.parse_args();
nodetooloutput = check_output([args.pathtonodetool + '/nodetool', '-h',
args.cassandrahost, '-p', args.portforcassandra, 'ring'])
if nodetooloutput.find('?') >= 0 :
print 'status critical nodering not consistent'
print 'metric nodering_status uint32 1'
sys.exit(2)
else :
print 'status ok nodering in consistent state'
print 'metric nodering_status uint32 0'
sys.exit(0)