check_chef_converge 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f139f27e4ea54bd160129e71e25294e5a78950e
4
+ data.tar.gz: 52de5277d16963be482d2d69e02b7b1ab0a58e30
5
+ SHA512:
6
+ metadata.gz: 146f5cf6b3c3ac1bda4ce549c03bee121e5e2d9bfcdced71b5b6ac95307dfed470f74ea6a684949a127f23fe138b8360cc3d9461ff9ae4b8996960b3c3da706c
7
+ data.tar.gz: 00c208d25998e8de4b1e3dc0b5592f4480b9bbc61276d8c592ffab41eec666f160d1ab0cf153ed8bf361ea296234b7eb4bb60cf6b49c993760dfc1745c8e738a
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.swp
11
+ ~*
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in check_chef_converge.gemspec
4
+ gemspec
@@ -0,0 +1,47 @@
1
+ # CheckChefConverge
2
+
3
+ This is a Nagios/Sensu check that can check if nodes returned from a chef search
4
+ have converged recently.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'check_chef_converge'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install check_chef_converge
21
+
22
+ ## Usage
23
+
24
+ ```
25
+ Usage: check_chef_converge
26
+ -w, --warn-minutes MINUTES Warning when chef has not converged in minutes.Default 65
27
+ -c, --crit-minutes MINUTES Critical when chef has not converged in minutes.Default 70
28
+ -q, --query SEARCH Chef query to filter on. Default 'fqdn:travis-work-mbp.local'
29
+ --chef-client-config CONFIG Chef client configuration.
30
+ --chef-server-url URL Chef Server URL. Must pass client-name and client-key or client-key-file with this option.
31
+ --chef-client-name NAME Chef Client Name. Only used with server-url
32
+ --chef-client-key KEY Chef Client Key (string). Only used with server-url. Takes precedence over client-key-file.
33
+ --chef-client-key-file PATH Chef Client Key File. Only used with server-url
34
+ -h, --help Show this message
35
+ --version Show version
36
+ ```
37
+
38
+ ## Development
39
+
40
+ 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.
41
+
42
+ 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).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Altiscale/check_chef_converge. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
47
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "check_chef_converge"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'check_chef_converge/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "check_chef_converge"
8
+ spec.version = CheckChefConverge::VERSION
9
+ spec.authors = ["Travis Thompson"]
10
+ spec.email = ["travis@altiscale.com"]
11
+ spec.license = "Apache 2.0"
12
+
13
+ spec.summary = %q{Nagios/Sensu check for chef convergence on a chef search}
14
+ spec.description = File.read(File.join(__dir__, 'README.md'))
15
+ spec.homepage = "https://github.com/Altiscale/check_chef_converge"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "nagiosplugin", "~> 3.0"
23
+ spec.add_dependency "ridley", "~> 4.5"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec"
28
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'check_chef_converge'
4
+ require 'check_chef_converge/cli'
5
+ require 'check_chef_converge/check'
6
+
7
+ CheckChefConverge::Check.run! CheckChefConverge::CLI.parse(ARGV)
@@ -0,0 +1,5 @@
1
+ require "check_chef_converge/version"
2
+
3
+ module CheckChefConverge
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,81 @@
1
+ require 'check_chef_converge'
2
+ require 'nagiosplugin'
3
+ require 'ridley'
4
+
5
+ module CheckChefConverge
6
+ class Check < Nagios::Plugin
7
+ def initialize(options)
8
+ @warn = options[:warn_minutes]
9
+ @crit = options[:crit_minutes]
10
+ @query = options[:query]
11
+ @nodes = {}
12
+ @warning = {}
13
+ @critical = {}
14
+ @start_time = Time.now.to_i
15
+
16
+ if options[:chef_server_url]
17
+ client_key = if options[:chef_client_key]
18
+ options[:chef_client_key]
19
+ elsif options[:chef_client_key_file]
20
+ File.read(options[:chef_client_key_file])
21
+ else
22
+ raise ArgumentError, 'Must pass either --chef-client-key'\
23
+ ' or --chef-client-key-file if passing --chef-server-url'
24
+ end
25
+ @ridley = Ridley.new(
26
+ server_url: options[:chef_server_url],
27
+ client_name: options[:chef_client_name],
28
+ client_key: client_key)
29
+ elsif options[:chef_client_config]
30
+ @ridley = Ridley.from_chef_config(options[:chef_client_config])
31
+ else
32
+ @ridley = Ridley.from_chef_config
33
+ end
34
+ end
35
+
36
+ def critical?
37
+ @critical.count > 0
38
+ end
39
+
40
+ def warning?
41
+ @warning.count > 0
42
+ end
43
+
44
+ def ok?
45
+ true
46
+ end
47
+
48
+ def check
49
+ @ridley.search(:node, @query).each do |node|
50
+ @nodes[node['automatic']['fqdn']] = (@start_time - node['automatic']['ohai_time'].to_i) / 60
51
+ end
52
+ @ridley.log.level = Logger::FATAL
53
+
54
+ @nodes.each do |node,time|
55
+ if time >= @crit
56
+ @critical[node] = time
57
+ @nodes.delete(node)
58
+ elsif time >= @warn
59
+ @warning[node] = time
60
+ @nodes.delete(node)
61
+ end
62
+ end
63
+ end
64
+
65
+ def message
66
+ crit = warn = ok = ''
67
+ if @critical.count > 0
68
+ crit = "Critical Nodes: " << @critical.map{|k,v| "#{k}:#{v}m"}.join(',')
69
+ end
70
+
71
+ if @warning.count > 0
72
+ warn = "Warning Nodes: " << @warning.map{|k,v| "#{k}:#{v}m"}.join(',')
73
+ end
74
+
75
+ if @nodes.count > 0
76
+ ok = 'OK Nodes: ' << @nodes.map{|k,v| "#{k}:#{v}m"}.join(',')
77
+ end
78
+ return [crit, warn, ok].reject(&:empty?).join(' ; ')
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,71 @@
1
+ require 'check_chef_converge'
2
+ require 'optparse'
3
+ require 'ostruct'
4
+ require 'socket'
5
+
6
+ module CheckChefConverge
7
+ class CLI
8
+ def self.parse(args)
9
+ options = OpenStruct.new
10
+ options[:warn_minutes] = 65
11
+ options[:crit_minutes] = 70
12
+ options[:query] = "fqdn:#{Socket.gethostname}"
13
+
14
+ opt_parser = OptionParser.new do |opts|
15
+ opts.banner = "Usage: #{$0}"
16
+ opts.on('-w', '--warn-minutes MINUTES', "Warning when chef has not converged in minutes."\
17
+ "Default #{options[:warn_minutes]}") do |ret|
18
+ options[:warn_minutes] = ret.to_i
19
+ end
20
+
21
+ opts.on('-c', '--crit-minutes MINUTES', "Critical when chef has not converged in minutes."\
22
+ "Default #{options[:crit_minutes]}") do |ret|
23
+ options[:crit_minutes] = ret.to_i
24
+ end
25
+
26
+ opts.on('-q', '--query SEARCH', "Chef query to filter on. "\
27
+ "Default '#{options[:query]}'") do |ret|
28
+ options[:query] = ret
29
+ end
30
+
31
+ opts.on('--chef-client-config CONFIG', 'Chef client configuration.') do |ret|
32
+ options[:chef_client_config] = ret
33
+ end
34
+
35
+ opts.on('--chef-server-url URL', 'Chef Server URL. Must pass client-name and'\
36
+ ' client-key or client-key-file with this option.') do |ret|
37
+ options[:chef_server_url] = ret
38
+ end
39
+
40
+ opts.on('--chef-client-name NAME', 'Chef Client Name. Only used with '\
41
+ ' server-url') do |ret|
42
+ options[:chef_client_name] = ret
43
+ end
44
+
45
+ opts.on('--chef-client-key KEY', 'Chef Client Key (string). Only used with '\
46
+ ' server-url. Takes precedence over client-key-file.') do |ret|
47
+ options[:chef_client_key] = ret
48
+ end
49
+
50
+ opts.on('--chef-client-key-file PATH', 'Chef Client Key File. Only used with '\
51
+ ' server-url') do |ret|
52
+ options[:chef_client_key_file] = ret
53
+ end
54
+
55
+ opts.on_tail("-h", "--help", "Show this message") do
56
+ puts opts
57
+ exit
58
+ end
59
+
60
+ opts.on_tail("--version", "Show version") do
61
+ puts CheckChefConverge::VERSION
62
+ exit
63
+ end
64
+ end
65
+
66
+ opt_parser.parse!(args)
67
+
68
+ return options
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module CheckChefConverge
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: check_chef_converge
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Travis Thompson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nagiosplugin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ridley
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '4.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '4.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: |+
84
+ # CheckChefConverge
85
+
86
+ This is a Nagios/Sensu check that can check if nodes returned from a chef search
87
+ have converged recently.
88
+
89
+ ## Installation
90
+
91
+ Add this line to your application's Gemfile:
92
+
93
+ ```ruby
94
+ gem 'check_chef_converge'
95
+ ```
96
+
97
+ And then execute:
98
+
99
+ $ bundle
100
+
101
+ Or install it yourself as:
102
+
103
+ $ gem install check_chef_converge
104
+
105
+ ## Usage
106
+
107
+ ```
108
+ Usage: check_chef_converge
109
+ -w, --warn-minutes MINUTES Warning when chef has not converged in minutes.Default 65
110
+ -c, --crit-minutes MINUTES Critical when chef has not converged in minutes.Default 70
111
+ -q, --query SEARCH Chef query to filter on. Default 'fqdn:travis-work-mbp.local'
112
+ --chef-client-config CONFIG Chef client configuration.
113
+ --chef-server-url URL Chef Server URL. Must pass client-name and client-key or client-key-file with this option.
114
+ --chef-client-name NAME Chef Client Name. Only used with server-url
115
+ --chef-client-key KEY Chef Client Key (string). Only used with server-url. Takes precedence over client-key-file.
116
+ --chef-client-key-file PATH Chef Client Key File. Only used with server-url
117
+ -h, --help Show this message
118
+ --version Show version
119
+ ```
120
+
121
+ ## Development
122
+
123
+ 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.
124
+
125
+ 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).
126
+
127
+ ## Contributing
128
+
129
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Altiscale/check_chef_converge. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
130
+
131
+ email:
132
+ - travis@altiscale.com
133
+ executables:
134
+ - check_chef_converge
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - .gitignore
139
+ - CODE_OF_CONDUCT.md
140
+ - Gemfile
141
+ - Gemfile.lock
142
+ - README.md
143
+ - Rakefile
144
+ - bin/console
145
+ - bin/setup
146
+ - check_chef_converge.gemspec
147
+ - exe/check_chef_converge
148
+ - lib/check_chef_converge.rb
149
+ - lib/check_chef_converge/check.rb
150
+ - lib/check_chef_converge/cli.rb
151
+ - lib/check_chef_converge/version.rb
152
+ homepage: https://github.com/Altiscale/check_chef_converge
153
+ licenses:
154
+ - Apache 2.0
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.4.6
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Nagios/Sensu check for chef convergence on a chef search
176
+ test_files: []