sensu-plugins-chef-automate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 789b04f3c27965f2998ed6a0f50ff186752b452e
4
+ data.tar.gz: 6314bb1a7ca6a3d140e2587e09b5ecec4d1b66a6
5
+ SHA512:
6
+ metadata.gz: '08fbbf51f02d7b8c160323b9d066ff9e76c7490c5af02f98dcfb8f554da0fd507ac9ab0e27003fec4c754e4acd9be1fbd44b5581030d7a387a1ebae35a3adc4d'
7
+ data.tar.gz: e989ace353e1ef8db15934f4b3c876f9bfa2c4771392373b9feb61f6b29a897bde8339d3f77d9d2f53ddf72bfe1014086eb8360a30c1390cab6218c6f2c4027a
data/README.md ADDED
@@ -0,0 +1 @@
1
+ Development repo for various sensu checks for chef automate
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ require 'sensu-plugin/check/cli'
3
+ require 'sensu-plugins-chef-automate/helpers'
4
+
5
+ class CheckAutomateRunners < Sensu::Plugin::Check::CLI
6
+
7
+ option :count,
8
+ :long => '--count COUNT',
9
+ :short => '-c COUNT',
10
+ :description => 'Number of runners that should be available',
11
+ :proc => Proc.new { |l| l.to_i },
12
+ :required => true
13
+
14
+ option :fqdn,
15
+ :long => '--fqdn FQDN',
16
+ :short => '-f FQDN',
17
+ :description => 'FQDN of your automate server',
18
+ :required => true
19
+
20
+ option :enterprise,
21
+ :long => '--enterprise ENTERPRISE',
22
+ :short => '-e ENTERPRISE',
23
+ :description => 'The name of your automate enterprise',
24
+ :required => true
25
+
26
+ option :verbose,
27
+ :long => '--verbose',
28
+ :short => '-v',
29
+ :description => 'Enable additional output',
30
+ :boolean => true
31
+
32
+ option :help,
33
+ :short => "-h",
34
+ :long => "--help",
35
+ :description => "Show this message",
36
+ :on => :tail,
37
+ :boolean => true,
38
+ :show_options => true,
39
+ :exit => 0
40
+
41
+ def run
42
+ api = AutomateApi.new(config[:fqdn], config[:enterprise], config[:verbose])
43
+ response = api.request('get', 'runners', {})
44
+ # We could probably just use response.length here as the response is a
45
+ # list of hashes containing runner information, but I do a quick check to
46
+ # make sure there's a hostname attribute on each result to make sure we
47
+ # actually got runners back.
48
+ count = response.select{|r| r["hostname"]}.length
49
+ message "#{count} runners"
50
+ count >= config[:count] ? ok : critical
51
+ end
52
+ end
@@ -0,0 +1,60 @@
1
+ # Library for performing automate API calls
2
+ # Usage:
3
+ # Create a json file ~/.automate_sensu_credentials
4
+ require 'rest-client'
5
+ require 'json'
6
+
7
+ class AutomateApi
8
+ def initialize(fqdn, enterprise, verbose)
9
+ @automate_fqdn = fqdn
10
+ @automate_enterprise = enterprise
11
+ @base_url = "https://#{@automate_fqdn}/api/v0/e/#{@automate_enterprise}"
12
+ @creds = load_creds
13
+ @verbose = verbose
14
+ RestClient.log = 'stdout' if verbose
15
+ @token = get_token
16
+ end
17
+
18
+ def load_creds
19
+ creds_file = "#{ENV['HOME']}/.automate_sensu_credentials"
20
+ JSON.parse(File.read(creds_file))
21
+ end
22
+
23
+ def get_new_token
24
+ response = RestClient.post \
25
+ "#{@base_url}/get-token", \
26
+ {username: @creds['username'], password: @creds['password']}.to_json,
27
+ {content_type: :json, accept: :json}
28
+ data = JSON.parse(response)
29
+ data['expiry'] = (Time.now + data['ttl']).iso8601
30
+ data
31
+ end
32
+
33
+ def get_token
34
+ token_file = "#{ENV['HOME']}/.automate_sensu_token"
35
+ grace_period = 3600
36
+ data = JSON.parse(File.read(token_file)) rescue Hash.new
37
+ expiry = Time.iso8601(data['expiry']) rescue Time.now
38
+ if expiry < Time.now + grace_period
39
+ puts "Token expired, getting a new one" if @verbose
40
+ data = get_new_token
41
+ File.write(token_file, data.to_json)
42
+ end
43
+ data['token']
44
+ end
45
+
46
+ def request(method, endpoint, data)
47
+ JSON.parse(RestClient::Request.execute(
48
+ method: method,
49
+ url: "#{@base_url}/#{endpoint}",
50
+ payload: data.to_json,
51
+ headers: {
52
+ content_type: :json,
53
+ accept: :json,
54
+ "chef-delivery-token": @token,
55
+ "chef-delivery-user": @creds['username'],
56
+ "chef-delivery-enterprise": @automate_enterprise
57
+ },
58
+ ))
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module SensuPluginsChefAutomate
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-chef-automate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chef Operations
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-23 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: 2.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-coolline
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
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: Checks that are specific to the Chef Automate product
84
+ email:
85
+ - ops@chef.io
86
+ executables:
87
+ - check-automate-runners.rb
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - README.md
92
+ - bin/check-automate-runners.rb
93
+ - lib/sensu-plugins-chef-automate/helpers.rb
94
+ - lib/sensu-plugins-chef-automate/version.rb
95
+ homepage: https://github.com/chef/sensu-plugins-chef-automate
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 2.1.0
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.6.11
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Sensu Plugins for Chef Automate
119
+ test_files: []