sensu-run 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +6 -0
- data/exe/sensu-run +5 -3
- data/lib/sensu/run.rb +2 -0
- data/lib/sensu/run/api_client.rb +26 -4
- data/lib/sensu/run/check.rb +12 -18
- data/lib/sensu/run/entity.rb +23 -0
- data/lib/sensu/run/event.rb +19 -0
- data/lib/sensu/run/version.rb +1 -1
- metadata +3 -2
- data/Gemfile.lock +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f98b0011438777bc994c41d4645b91aa74f311b2
|
4
|
+
data.tar.gz: c896f234147e52ce8219f9fb8984513fbf406336
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d62f1a5e3d6f824974b312a1bed210e1251c6a9d9af4a405b116a197db521a09c3e51ffbfba9494a0952a65893cd16b9967878d0b9836e4c0bdbd8ed0741c534
|
7
|
+
data.tar.gz: 99bacbf4faa0600679e07d429d5d2a8851622e68e5ceb2396385a584570307662c3820193c7f9547db156d7507319a868ec0e5cc621f2ee17f264e84f217da23
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
5
5
|
and this project adheres to [Semantic
|
6
6
|
Versioning](http://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [0.2.0] - 2020-01-10
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- Create proxy Entity if missing
|
12
|
+
- Check TTL
|
13
|
+
|
8
14
|
## [0.1.0] - 2020-01-10
|
9
15
|
|
10
16
|
### Added
|
data/exe/sensu-run
CHANGED
@@ -8,9 +8,11 @@ require "sensu/run"
|
|
8
8
|
|
9
9
|
options = Sensu::Run.read_cli_opts
|
10
10
|
|
11
|
+
entity = Sensu::Run::Entity.new(options)
|
11
12
|
check = Sensu::Run::Check.new(options)
|
12
|
-
check.exec
|
13
|
-
event = check
|
13
|
+
check.exec!
|
14
|
+
event = Sensu::Run::Event.new(entity, check)
|
14
15
|
|
15
16
|
api = Sensu::Run::APIClient.new(options)
|
16
|
-
api.
|
17
|
+
api.create_entity_if_missing(entity)
|
18
|
+
api.create_event(event)
|
data/lib/sensu/run.rb
CHANGED
data/lib/sensu/run/api_client.rb
CHANGED
@@ -19,12 +19,34 @@ module Sensu
|
|
19
19
|
@backends.shift
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
|
24
|
-
request = Net::HTTP::Post.new("/api/core/v2/namespaces/#{namespace}/events")
|
22
|
+
def entity_exists?(entity)
|
23
|
+
request = Net::HTTP::Get.new("/api/core/v2/namespaces/#{entity.namespace}/entities/#{entity.name}")
|
25
24
|
request["Content-Type"] = "application/json"
|
26
25
|
request["Authorization"] = "Key #{@options[:api_key]}"
|
27
|
-
|
26
|
+
response = @http.request(request)
|
27
|
+
response.code == "200"
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_entity(entity)
|
31
|
+
request = Net::HTTP::Post.new("/api/core/v2/namespaces/#{entity.namespace}/entities")
|
32
|
+
request["Content-Type"] = "application/json"
|
33
|
+
request["Authorization"] = "Key #{@options[:api_key]}"
|
34
|
+
request.body = JSON.dump(entity.to_hash)
|
35
|
+
response = @http.request(request)
|
36
|
+
puts response.inspect
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_entity_if_missing(entity)
|
40
|
+
unless entity_exists?(entity)
|
41
|
+
post_entity(entity)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_event(event)
|
46
|
+
request = Net::HTTP::Post.new("/api/core/v2/namespaces/#{event.entity.namespace}/events")
|
47
|
+
request["Content-Type"] = "application/json"
|
48
|
+
request["Authorization"] = "Key #{@options[:api_key]}"
|
49
|
+
request.body = JSON.dump(event.to_hash)
|
28
50
|
response = @http.request(request)
|
29
51
|
puts response.inspect
|
30
52
|
end
|
data/lib/sensu/run/check.rb
CHANGED
@@ -3,37 +3,31 @@ require "open3"
|
|
3
3
|
module Sensu
|
4
4
|
module Run
|
5
5
|
class Check
|
6
|
-
attr_reader :output, :status
|
6
|
+
attr_reader :name, :namespace, :output, :status
|
7
7
|
|
8
8
|
def initialize(options={})
|
9
9
|
@options = options
|
10
|
+
@name = @options[:check_name]
|
11
|
+
@namespace = @options.fetch(:namespace, "default")
|
10
12
|
end
|
11
13
|
|
12
|
-
def exec
|
14
|
+
def exec!
|
13
15
|
stdin, stdout, stderr, wait = Open3.popen3(@options[:command])
|
14
16
|
@output = "#{stdout.read}\n#{stderr.read}"
|
15
17
|
@status = wait.value.exitstatus
|
16
18
|
[@output, @status]
|
17
19
|
end
|
18
20
|
|
19
|
-
def
|
21
|
+
def to_hash
|
20
22
|
{
|
21
|
-
:
|
22
|
-
:
|
23
|
-
|
24
|
-
:namespace => @options.fetch(:namespace, "default")
|
25
|
-
},
|
26
|
-
:entity_class => "proxy"
|
23
|
+
:metadata => {
|
24
|
+
:name => @name,
|
25
|
+
:namespace => @namespace
|
27
26
|
},
|
28
|
-
:
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
},
|
33
|
-
:command => @options[:command],
|
34
|
-
:output => @output,
|
35
|
-
:status => @status
|
36
|
-
}
|
27
|
+
:command => @options[:command],
|
28
|
+
:output => @output,
|
29
|
+
:status => @status,
|
30
|
+
:ttl => @options.fetch(:ttl, 0)
|
37
31
|
}
|
38
32
|
end
|
39
33
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Run
|
3
|
+
class Entity
|
4
|
+
attr_reader :name, :namespace
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@options = options
|
8
|
+
@name = options[:entity_name]
|
9
|
+
@namespace = options.fetch(:namespace, "default")
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_hash
|
13
|
+
{
|
14
|
+
:metadata => {
|
15
|
+
:name => @name,
|
16
|
+
:namespace => @namespace
|
17
|
+
},
|
18
|
+
:entity_class => "proxy"
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Run
|
3
|
+
class Event
|
4
|
+
attr_reader :entity, :check
|
5
|
+
|
6
|
+
def initialize(entity, check)
|
7
|
+
@entity = entity
|
8
|
+
@check = check
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_hash
|
12
|
+
{
|
13
|
+
:entity => @entity.to_hash,
|
14
|
+
:check => @check.to_hash
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/sensu/run/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-run
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Porter
|
@@ -67,7 +67,6 @@ files:
|
|
67
67
|
- ".travis.yml"
|
68
68
|
- CHANGELOG.md
|
69
69
|
- Gemfile
|
70
|
-
- Gemfile.lock
|
71
70
|
- LICENSE.txt
|
72
71
|
- README.md
|
73
72
|
- Rakefile
|
@@ -77,6 +76,8 @@ files:
|
|
77
76
|
- lib/sensu/run.rb
|
78
77
|
- lib/sensu/run/api_client.rb
|
79
78
|
- lib/sensu/run/check.rb
|
79
|
+
- lib/sensu/run/entity.rb
|
80
|
+
- lib/sensu/run/event.rb
|
80
81
|
- lib/sensu/run/version.rb
|
81
82
|
- sensu-run.gemspec
|
82
83
|
homepage: https://github.com/sensu/sensu-run
|
data/Gemfile.lock
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
sensu-run (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
diff-lcs (1.3)
|
10
|
-
rake (10.5.0)
|
11
|
-
rspec (3.8.0)
|
12
|
-
rspec-core (~> 3.8.0)
|
13
|
-
rspec-expectations (~> 3.8.0)
|
14
|
-
rspec-mocks (~> 3.8.0)
|
15
|
-
rspec-core (3.8.2)
|
16
|
-
rspec-support (~> 3.8.0)
|
17
|
-
rspec-expectations (3.8.4)
|
18
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
-
rspec-support (~> 3.8.0)
|
20
|
-
rspec-mocks (3.8.1)
|
21
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
-
rspec-support (~> 3.8.0)
|
23
|
-
rspec-support (3.8.2)
|
24
|
-
|
25
|
-
PLATFORMS
|
26
|
-
ruby
|
27
|
-
|
28
|
-
DEPENDENCIES
|
29
|
-
bundler (~> 1.16)
|
30
|
-
rake (~> 10.0)
|
31
|
-
rspec (~> 3.0)
|
32
|
-
sensu-run!
|
33
|
-
|
34
|
-
BUNDLED WITH
|
35
|
-
1.16.2
|