sensu-plugins-edgelab 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/check-nomad-jobs.rb +41 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea0c07087191700425e9030541a612e62b7bce0c
|
4
|
+
data.tar.gz: 8f26d3185e70df103814a71d80bfeb0a0f345aed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d785ffe04f0a3d3fe258c70f565e6c70dc2dec837bbd3fcf15eeaa22dd35cfd43cab1f5c3aafd6d923acc9e6bb7bac271f8267b706e95456423f93f5d10805d4
|
7
|
+
data.tar.gz: ebab2d70d72dae8eb52960e5f0d92218b21568458ab3f9727cbe55e46176daa8ec9ba659809e26022a6fc617f9abc4b9bfc148d482c62ab586e6f025ef92cdda
|
data/bin/check-nomad-jobs.rb
CHANGED
@@ -17,10 +17,14 @@ class CheckNomadAllocations < Sensu::Plugin::Check::CLI
|
|
17
17
|
description: 'nomad server address',
|
18
18
|
long: '--nomad SERVER',
|
19
19
|
default: 'http://localhost:4646'
|
20
|
+
option :alloc_starting_time,
|
21
|
+
description: '',
|
22
|
+
long: '--alloc-starting-time',
|
23
|
+
default: 300
|
20
24
|
|
21
|
-
#
|
22
|
-
def
|
23
|
-
url = config[:nomad] +
|
25
|
+
# Call Nomad api and parse the json response
|
26
|
+
def api_call(endpoint)
|
27
|
+
url = config[:nomad] + endpoint
|
24
28
|
begin
|
25
29
|
response = RestClient.get(url)
|
26
30
|
rescue => e
|
@@ -34,8 +38,40 @@ class CheckNomadAllocations < Sensu::Plugin::Check::CLI
|
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
41
|
+
# Check that allocations are in the desired status
|
42
|
+
def check_allocations(job, failed)
|
43
|
+
allocations = api_call "/v1/job/#{job['ID']}/allocations"
|
44
|
+
|
45
|
+
allocations.each do |alloc|
|
46
|
+
if alloc['DesiredStatus'] == 'run'
|
47
|
+
# Batch stay in run DesiredStatus even if task completed successfully.
|
48
|
+
next if job['Type'] == 'batch' and alloc['ClientStatus'] == 'complete'
|
49
|
+
|
50
|
+
alloc['TaskStates'].each do |_, state|
|
51
|
+
if state['State'] == 'dead'
|
52
|
+
failed << "Alloc #{alloc['Name']} is dead but desired status is 'run'"
|
53
|
+
|
54
|
+
# Check that pending alloc are not too old
|
55
|
+
elsif state['State'] == 'pending'
|
56
|
+
# Get the last event timestamp (which is in microseconds in Nomad)
|
57
|
+
event_time = state['Events'][-1]['Time'] / 1_000_000_000
|
58
|
+
starting_time = (Time.new - Time.at(event_time)).round
|
59
|
+
|
60
|
+
if starting_time > config[:alloc_starting_time]
|
61
|
+
failed << "Alloc #{alloc['Name']} is pending since #{starting_time} seconds"
|
62
|
+
|
63
|
+
# No need to check other task in the same task group.
|
64
|
+
break
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
37
73
|
def run
|
38
|
-
jobs =
|
74
|
+
jobs = api_call '/v1/jobs'
|
39
75
|
if jobs.empty?
|
40
76
|
critical 'No jobs found in Nomad.'
|
41
77
|
end
|
@@ -43,11 +79,7 @@ class CheckNomadAllocations < Sensu::Plugin::Check::CLI
|
|
43
79
|
failed = []
|
44
80
|
|
45
81
|
jobs.each do |job|
|
46
|
-
job
|
47
|
-
if summary['Failed'] != 0
|
48
|
-
failed << "#{job['Name']}.#{group}"
|
49
|
-
end
|
50
|
-
end
|
82
|
+
check_allocations job, failed
|
51
83
|
end
|
52
84
|
|
53
85
|
if failed.any?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-edgelab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgelab
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|