check_kafka_isr 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b64a6b52100ee319f6f55c7a993a4d6a6a93fcbc
4
+ data.tar.gz: eb62f22104ddb7b52e2a13d28bbbab0b6b8157e2
5
+ SHA512:
6
+ metadata.gz: 80c8f30262bc7e541753d77c3e2ba8f1e1b900930c560becf76d246abaaf7531a243fa34e408108988b13e55c4c38b5fcd1dd0d843a2ab45f95e2452dbb6fd55
7
+ data.tar.gz: 04e4f865ca22bb1a12dc7853925604b99981fee9e70cd467051de8a6b6e937778faf053acbd564e3c51b51ed034b604b093a9be838cf2dbb66e77d8e597251a7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.5
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in check_kafka_isr.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # CheckKafkaIsr
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/check_kafka_isr`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'check_kafka_isr'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install check_kafka_isr
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/check_kafka_isr.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require 'kazoo'
5
+ require 'sensu-plugin/check/cli'
6
+
7
+ class KafkaISRCheck < Sensu::Plugin::Check::CLI
8
+
9
+ option :zookeeper,
10
+ short: '-z ZOOKEEPER_CONNECT_STRING',
11
+ long: '--zookeeper ZOOKEEPER_CONNECT_STRING',
12
+ default: 'localhost:2181/kafka',
13
+ description: 'Zookeeper connect string (zk-1.local:2181,zk-2.local:2181/kafka)'
14
+
15
+ def initialize
16
+ super()
17
+ @crit = []
18
+ @cluster = Kazoo::Cluster.new(config[:zookeeper])
19
+ begin
20
+ @topics = @cluster.topics
21
+ rescue
22
+ abort "Failed to get topics from zookeeper (#{config[:zookeeper]})"
23
+ end
24
+ end
25
+
26
+ def configured_isr(topic_name)
27
+ topic = @cluster.zk.get(path: "/brokers/topics/#{topic_name}")
28
+ JSON.parse(topic[:data]).fetch('partitions')
29
+ end
30
+
31
+ def actual_isr(partition)
32
+ partition.isr.map(&:id)
33
+ end
34
+
35
+ def find_bad_partitions(name, topic)
36
+ @crit << "Topic '#{name}' is under-replicated (replication factor is #{topic.replication_factor}). Affected partitions:"
37
+ topic.partitions.each do |part|
38
+ if part.under_replicated?
39
+ current_isr = part.isr.map { |broker| broker.id if broker }
40
+ @crit << "P#{part.id}#{current_isr}"
41
+ end
42
+ end
43
+ end
44
+
45
+ def run
46
+ if @cluster.under_replicated?
47
+ @topics.each do |name, topic|
48
+ topic.under_replicated? &&
49
+ find_bad_partitions(name, topic)
50
+ end
51
+ critical(@crit.join(' '))
52
+ else
53
+ ok
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'check_kafka_isr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "check_kafka_isr"
8
+ spec.version = CheckKafkaIsr::VERSION
9
+ spec.authors = ["Travis Foster"]
10
+ spec.email = ["tfoster@opentable.com"]
11
+
12
+ spec.summary = 'Sensu check for Kafka ISR'
13
+ spec.description = 'Sensu check that will alert if the number of in-sync-replicas is less than the configured number of replicas'
14
+ spec.homepage = 'https://github.com/travees/check_kafka_isr'
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'bin'
27
+ spec.executables = 'check-kafka-isr'
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency 'sensu-plugin', '~> 0'
31
+ spec.add_dependency 'kazoo-ruby', '~> 0'
32
+ end
@@ -0,0 +1,5 @@
1
+ require "check_kafka_isr/version"
2
+
3
+ module CheckKafkaIsr
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module CheckKafkaIsr
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: check_kafka_isr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Travis Foster
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sensu-plugin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: kazoo-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Sensu check that will alert if the number of in-sync-replicas is less
42
+ than the configured number of replicas
43
+ email:
44
+ - tfoster@opentable.com
45
+ executables:
46
+ - check-kafka-isr
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - ".travis.yml"
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - bin/check-kafka-isr
56
+ - check_kafka_isr.gemspec
57
+ - lib/check_kafka_isr.rb
58
+ - lib/check_kafka_isr/version.rb
59
+ homepage: https://github.com/travees/check_kafka_isr
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.8
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Sensu check for Kafka ISR
83
+ test_files: []