Skip to content

Commit 66a6858

Browse files
authored
Merge pull request #9 from Altiscale/karthik_check_zookeeper_mode
check zookeeper mode
2 parents b4a3c2d + 19d4278 commit 66a6858

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
55

66
## [Unreleased]
77

8+
## [1.1.0]
9+
- check-zookeeper-mode
10+
811
## [1.0.0] - 2017-03-21
912
### Added
1013
- check-zookeeper-reqs (@grem11n)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* check-zookeeper-latency.rb - Check average latency on Zookeeper node
1616
* check-zookeeper-reqs.rb - Check if Zookeeper node has reliable number of outstanding requests
1717
* check-zookeeper-ruok.rb - Check if Zookeeper node responds to 'ruok' query succesfully
18+
* check-zookeeper-mode.rb - Check if Zookeeper node is in standalone or cluster(leader or follower) mode
1819
* metrics-zookeeper.rb - Gather metrics from Zookeeper
1920

2021
## Usage

bin/check-zookeeper-mode.rb

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env ruby
2+
# encoding: UTF-8
3+
#
4+
# check-zookeeper-mode
5+
#
6+
# DESCRIPTION:
7+
# Check if Zookeeper node is in expected mode.
8+
#
9+
# 'mode' is ZooKeeper's mode which can be standalone or in a cluster.
10+
# In cluster mode a Zookeeper node can be either leader or follower.
11+
# We use stat command to get the mode and check if zookeeper node is a
12+
# standalone or leader or follower.
13+
#
14+
# PLATFORMS:
15+
# All
16+
#
17+
# DEPENDENCIES:
18+
# gem: sensu-plugin
19+
#
20+
# USAGE:
21+
# Check if a node has Zookeeper running and responds with imok.
22+
# ./check-zookeeeper-mode.rb -m 'leader follower'
23+
# ./check-zookeeeper-mode.rb -s localhost -p 2181 -m 'leader follower'
24+
# ./check-zookeeeper-mode.rb --server localhost --port 2181 --mode 'leader follower'
25+
#
26+
27+
require 'sensu-plugin/check/cli'
28+
require 'socket'
29+
30+
class CheckZookeeperMode < Sensu::Plugin::Check::CLI
31+
option :server,
32+
description: 'Zookeeper hostname to connect to.',
33+
short: '-s HOSTNAME',
34+
long: '--server HOSTNAME',
35+
default: 'localhost'
36+
37+
option :port,
38+
description: 'Zookeeper port to connect to.',
39+
short: '-p PORT',
40+
long: '--port PORT',
41+
default: 2181
42+
43+
option :timeout,
44+
description: 'How long to wait for a reply in seconds.',
45+
short: '-t SECS',
46+
long: '--timeout SECS',
47+
proc: proc(&:to_i),
48+
default: 5
49+
50+
option :mode,
51+
description: 'Space separated expected modes.',
52+
short: '-m MODE',
53+
long: '--mode MODE',
54+
required: true
55+
56+
def zk_command(four_letter_word)
57+
Socket.tcp(config[:server], config[:port]) do |sock|
58+
sock.print "#{four_letter_word}\r\n"
59+
sock.close_write
60+
sock.read
61+
end
62+
end
63+
64+
def run
65+
response = zk_command(:stat)
66+
mode = get_mode(response)
67+
expected_modes = config[:mode].split
68+
if expected_modes.include?(mode)
69+
ok(mode)
70+
else
71+
critical("Zookeeper mode is #{mode} and it does not match #{expected_modes.join(', ')}")
72+
end
73+
end
74+
75+
private
76+
77+
def get_mode(response)
78+
response.each_line do |line|
79+
line = line.chomp
80+
k, v = line.split(': ')
81+
return v if k == 'Mode'
82+
end
83+
end
84+
end

lib/sensu-plugins-zookeeper/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module SensuPluginsZookeeper
22
module Version
33
MAJOR = 1
4-
MINOR = 0
4+
MINOR = 1
55
PATCH = 0
66

77
VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')

0 commit comments

Comments
 (0)