singularity_task_history 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 687770f9f92e63dbdcddc7761189f33d3d707080
4
- data.tar.gz: dc4bad4bedfb7815ee9f47f18e24ec6356c5c596
3
+ metadata.gz: ed91835a8a8bec80d1e81db362b434f154025712
4
+ data.tar.gz: 6a287813b126a21a169731d306b2b1561695f858
5
5
  SHA512:
6
- metadata.gz: 6bb03d89cd2f85562fb8d9e879694f7f2a3cc51c33da5b1fe9efd8695fa65e8c3feffb3d36759cb91b91c294fd7754d6fd93dd105ad49b6cbbd09943da0971d9
7
- data.tar.gz: bb6f613acc9dbb353b52377c03c0ce4daf450e76ee2ba02deacd891d3f10686f4d36c86cb111ec50c739f909278c01d168cf340af6945375e5978c25106b488a
6
+ metadata.gz: 4939b891c7c27e572f86d8c32910419e68cae990fbbef51fed6eaf77470f418ec6d460d7d27e283e02a8b029ca944b0fd9840f52d6149fe10ee64149dde81811
7
+ data.tar.gz: ada94f025c3cdaaa934635ef0fa03677a86979eeaf7cd9063d93c81ff57dcce8cda133f9ad474432b5fd6134e797329ec4746e578cc99198ec2314a6b524ead9
@@ -27,14 +27,14 @@ class SingularityTaskHistory < Sensu::Plugin::Check::CLI
27
27
  proc: proc { |n| n.to_i }
28
28
 
29
29
  def run
30
- warn_list = {}
31
- crit_list = {}
32
- task_list.each do |task|
33
- count = history_count(task)
34
- crit_list[task] = count if count >= config[:critical]
35
- warn_list[task] = count if count >= config[:warn]
30
+ alert_list = gen_alert_list(config[:warn], config[:critical])
31
+ if !alert_list[:crit].empty?
32
+ critical "Excessive task history\n#{report(alert_list)}"
33
+ elsif !alert_list[:warn].empty?
34
+ warning "Excessive task history\n#{report(alert_list)}"
35
+ else
36
+ ok 'Task history is fine'
36
37
  end
37
- report(crit_list, warn_list)
38
38
  end
39
39
 
40
40
  def initialize
@@ -43,6 +43,19 @@ class SingularityTaskHistory < Sensu::Plugin::Check::CLI
43
43
  @history_node = '/singularity/tasks/history'
44
44
  end
45
45
 
46
+ def gen_alert_list(warn, crit)
47
+ alerts = { crit: {}, warn: {} }
48
+ task_list.each do |task|
49
+ count = history_count(task)
50
+ if count > crit
51
+ alerts[:crit][task] = count
52
+ elsif count > warn
53
+ alerts[:warn][task] = count
54
+ end
55
+ end
56
+ alerts
57
+ end
58
+
46
59
  def child_list(znode)
47
60
  children = @z.get_children(path: znode)
48
61
  children[:children]
@@ -56,23 +69,13 @@ class SingularityTaskHistory < Sensu::Plugin::Check::CLI
56
69
  child_list(@history_node + '/' + task).count
57
70
  end
58
71
 
59
- def task_output(task_list)
60
- if task_list.length == 0
61
- ''
62
- else
63
- task_list.map { |k, v| "#{k}: #{v}" }.join("\n") + "\n"
64
- end
65
- end
66
-
67
- def report(crit_list, warn_list)
68
- warn_list.delete_if { |k, _v| crit_list.key?(k) }
69
- detail = task_output(crit_list) + task_output(warn_list)
70
- if crit_list.length > 0
71
- critical "Excessive task history:\n#{detail}"
72
- elsif warn_list.length > 0
73
- warn "Excessive task history:\n#{detail}"
74
- else
75
- ok 'All task history within limits'
72
+ def report(task_list)
73
+ output = ''
74
+ task_list.keys.each do |key|
75
+ task_list[key].keys.each do |task|
76
+ output += "#{task}: #{task_list[key][task]}\n"
77
+ end
76
78
  end
79
+ output
77
80
  end
78
81
  end
@@ -1,3 +1,3 @@
1
1
  module SingularityTaskHistory
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singularity_task_history
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Flippin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-07 00:00:00.000000000 Z
11
+ date: 2016-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zookeeper