sensu-run-check 0.1.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: 4c955968a850e224f8c594fa95232dbce3753c7a
4
+ data.tar.gz: 6edb3a30525201462fccde5ead01242d8fc9bacd
5
+ SHA512:
6
+ metadata.gz: 830cb80b44157a7212ff4b10ac928a0f7169fc52f82bc9bf57450c871758a14dc03ff0b655c2d02336e0b8f50dde568c89a50e2a1d35e92fa13b37666e3e06d7
7
+ data.tar.gz: ea68e6f66aaf102e246197aebb41dbfc62c3da8db7e19aa6452ac8ed9433ecb2602c4aad8654f23d17af2ddca526b596d2d75d22f3d869aaf51be7f9cef3ea56
@@ -0,0 +1 @@
1
+ Gemfile.lock
@@ -0,0 +1 @@
1
+ 2.0.0-p481
@@ -0,0 +1,8 @@
1
+ ---
2
+ language: ruby
3
+ bundler_args: --without development
4
+ script: "bundle exec rake spec SPEC_OPTS='--format documentation'"
5
+ rvm:
6
+ - 2.0.0
7
+ notifications:
8
+ email: true
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ Change history for sensu-run-check.
4
+
5
+ ## 0.1.0
6
+
7
+ * Initial version
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sensu-run-check.gemspec
4
+ gemspec
5
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Rickard von Essen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # Sensu Run Check
2
+
3
+ Often after just doing a change on servers you want to just be sure that they’re all going to pass a certain or all Sensu checks. This gem exposes Sensus checks to be executed local on the command line.
4
+
5
+ _WARNING_ This is very much a hack and will break with other versions* of Sensu!
6
+
7
+ *) see the ```sensu-run-check.gemspec``` for the required version.
8
+
9
+ ## Installation
10
+
11
+ Be sure to install it in the Sensu embedded ruby.
12
+
13
+ ```
14
+ /opt/sensu/embedded/bin/gem install sensu-run-check
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Print the help
20
+
21
+ ```
22
+ /opt/sensu/embedded/bin/sensu-run-check -h
23
+ ```
24
+
25
+ List all checks defined on this host, you must point out your Sensu config file/dir.
26
+
27
+ ```
28
+ /opt/sensu/embedded/bin/sensu-run-check -d /etc/sensu/conf.d -l
29
+ ```
30
+
31
+ Run the _disk_ check.
32
+
33
+ ```
34
+ /opt/sensu/embedded/bin/sensu-run-check -d /etc/sensu/conf.d -r disk
35
+ ```
36
+
37
+ Run all checks defined on this host.
38
+
39
+ ```
40
+ /opt/sensu/embedded/bin/sensu-run-check -d /etc/sensu/conf.d -R
41
+ ```
42
+
43
+ # License
44
+
45
+ (c) 2015 - Rickard von Essen
46
+
47
+ Released under the MIT license, see LICENSE.txt
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = "--color"
6
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ unless $:.include?(File.dirname(__FILE__) + "/../lib/")
4
+ $: << File.dirname(__FILE__) + "/../lib"
5
+ end
6
+
7
+ require "sensu-run-check/cli"
8
+ require "sensu-run-check/runner"
9
+
10
+ options = SensuRunCheck::CLI.read
11
+ SensuRunCheck::Runner.run(options)
@@ -0,0 +1,5 @@
1
+ require "sensu-run-check/version"
2
+
3
+ module SensuRunCheck
4
+
5
+ end
@@ -0,0 +1,45 @@
1
+ require "optparse"
2
+
3
+ module SensuRunCheck
4
+ class CLI
5
+ # Parse CLI arguments using Ruby stdlib `optparse`. This method
6
+ # provides SensuRunCheck with process options and can
7
+ # provide users with information, such as the SensuRunCheck version.
8
+ #
9
+ # @param arguments [Array] to parse.
10
+ # @return [Hash] options
11
+ def self.read(arguments=ARGV)
12
+ options = {}
13
+ optparse = OptionParser.new do |opts|
14
+ opts.on("-h", "--help", "Display this message") do
15
+ puts opts
16
+ exit
17
+ end
18
+ opts.on("-V", "--version", "Display version") do
19
+ puts VERSION
20
+ exit
21
+ end
22
+ opts.on("-c", "--config FILE", "Sensu JSON config FILE") do |file|
23
+ options[:config_file] = file
24
+ end
25
+ opts.on("-d", "--config_dir DIR[,DIR]", "DIR or comma-delimited DIR list for Sensu JSON config files") do |dir|
26
+ options[:config_dirs] = dir.split(",")
27
+ end
28
+ opts.on("-e", "--extension_dir DIR", "DIR for Sensu extensions") do |dir|
29
+ options[:extension_dir] = dir
30
+ end
31
+ opts.on("-r", "--run_check CHECK", "CHECK to run") do |check|
32
+ options[:run_check] = check
33
+ end
34
+ opts.on("-l", "--list_checks", "List all defined checks") do
35
+ options[:list_checks] = true
36
+ end
37
+ opts.on("-R", "--run_all_checks", "Run all defined checks") do
38
+ options[:run_all_checks] = true
39
+ end
40
+ end
41
+ optparse.parse!(arguments)
42
+ options
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,99 @@
1
+ require "rubygems"
2
+
3
+ require "sensu-run-check/version"
4
+ require "sensu/client/process"
5
+ require "sensu/settings"
6
+
7
+ module Sensu
8
+ # Intercepts https://github.com/sensu/sensu-spawn/blob/master/lib/sensu/spawn.rb
9
+ module Spawn
10
+ class << self
11
+
12
+ # See https://github.com/sensu/sensu-spawn/blob/master/lib/sensu/spawn.rb#L22
13
+ #
14
+ # @param [String] command to run.
15
+ # @param [Hash] options to create a child process with.
16
+ # @param [Proc] IGNORED
17
+ # @return [Array] stdout, exit code
18
+ def process(command, options={}, &callback)
19
+ child_process(command, options)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ module SensuRunCheck
26
+ # Imposter for https://github.com/sensu/sensu/blob/master/lib/sensu/client/process.rb
27
+ class Runner <Sensu::Client::Process
28
+
29
+ def self.run(options={})
30
+ s = SensuRunCheck::Runner.new(options)
31
+ if options[:list_checks]
32
+ puts s.get_all_checks.collect{ |check| check[:name] }.sort.join(",")
33
+ elsif options[:run_all_checks]
34
+ statuses = []
35
+ s.get_all_checks.collect{ |check| check[:name] }.sort.each do |checkname|
36
+ stdout, status = s.run_check(checkname)
37
+ statuses << status
38
+ puts "#{checkname} #{status} #{stdout}"
39
+ end
40
+ exit(statuses.max)
41
+ else
42
+ stdout, status = s.run_check(options[:run_check])
43
+ puts stdout
44
+ exit(status)
45
+ end
46
+ end
47
+
48
+ # Create a new impostor.
49
+ #
50
+ # @param [Hash] options to create the ipostor with.
51
+ # At least it should contain
52
+ # {:config_dirs => [ "<sensu_conf_dir>" ]}
53
+ def initialize(options={})
54
+ @checks_in_progress = []
55
+ @settings = Sensu::Settings.get(options)
56
+ @settings.validate
57
+ @logger = SensuRunCheck::NilLog.new
58
+ end
59
+
60
+ # Find a Sensu check by name.
61
+ #
62
+ # @param [String] name of the check
63
+ # @return [Hash] check
64
+ def get_check(checkname)
65
+ @settings.checks.select{ |c| c[:name] == checkname }.first
66
+ end
67
+
68
+ # Get all Sensu checks.
69
+ #
70
+ # @return [Array] of checks
71
+ def get_all_checks
72
+ @settings.checks
73
+ end
74
+
75
+ # Run a Sensu check by name.
76
+ #
77
+ # @param [String] name of the check to run.
78
+ # @return [Array] with stdout, exit code.
79
+ def run_check(checkname)
80
+ check = @settings.checks.select{ |c| c[:name] == checkname }.first
81
+ if check == nil
82
+ return "No such check: #{checkname}", 3
83
+ else
84
+ execute_check_command(check)
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ # Swallow logs
91
+ class NilLog
92
+ def debug(*ignore)
93
+ # Ignore
94
+ end
95
+ def warn(*ignore)
96
+ # Ignore
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,3 @@
1
+ module SensuRunCheck
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sensu-run-check/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'sensu-run-check'
8
+ spec.version = SensuRunCheck::VERSION
9
+ spec.authors = ['Rickard von Essen']
10
+ spec.email = ['rickard.von.essen@gmail.com']
11
+ spec.summary = 'Run Sensu checks localy on the command line.'
12
+ spec.description = 'Run Sensu checks localy on the command line.'
13
+ spec.homepage = 'https://github.com/rickard-von-essen/sensu-run-check'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'sensu', '= 0.17.2'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.2.0'
26
+ #spec.add_development_dependency 'mocha', '~> 0.10.0'
27
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.describe "something" do
2
+ it "TODO" do
3
+ # pass
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-run-check
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rickard von Essen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sensu
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.17.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.17.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.0
69
+ description: Run Sensu checks localy on the command line.
70
+ email:
71
+ - rickard.von.essen@gmail.com
72
+ executables:
73
+ - sensu-run-check
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .ruby-version
79
+ - .travis.yml
80
+ - CHANGELOG.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/sensu-run-check
86
+ - lib/sensu-run-check.rb
87
+ - lib/sensu-run-check/cli.rb
88
+ - lib/sensu-run-check/runner.rb
89
+ - lib/sensu-run-check/version.rb
90
+ - sensu-run-check.gemspec
91
+ - spec/sensu-run-check/runner_spec.rb
92
+ homepage: https://github.com/rickard-von-essen/sensu-run-check
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.0.14
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Run Sensu checks localy on the command line.
116
+ test_files:
117
+ - spec/sensu-run-check/runner_spec.rb