sensu-plugins-mesos 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b392ea0583f41c9de4879adf2b0244d41323839a
4
- data.tar.gz: b9442e37d652f22eb6c0a001a0eb8ddbf921a8b0
3
+ metadata.gz: 9bb2b08b42ff7321fea875982453469fd5bcec99
4
+ data.tar.gz: f29e66d69c0fc30184155bf626ef3ca923e899af
5
5
  SHA512:
6
- metadata.gz: 8d54692b973fc4fec0415880f38fe019a8de8a323239ce66c5313eb827af66eecc92b7a9dfad72220012672af6fde58d8ea72180e36172989d53e71b4768cf1f
7
- data.tar.gz: 95df61c707b333c517e7c7d70c73620241ddf80899541d2e8ecdb2500c6ec2cf56ef596713fffe58fcf79937d198592201c936aef2280e2917bc1c8c9daa0a15
6
+ metadata.gz: f802bd1574f2d06c538b7ad53fc07e84867bf8982d17ae9f0fb3358bed80623878ca805453fd45ca6dea3621640b31c1d2d6140f02b4968ac365d237b3461d67
7
+ data.tar.gz: 84b13e54808f809da09dc77e86daa24d9b61a5e42d94f7fb136c1f5d33466742d0b40644cd480742138e8488f939187d924c53c1de768e85f7c0a75f368e2817
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [2.1.0] - 2017-10-20
9
+ ### Changed
10
+ - check-marathon-task.rb: if instances are not defined, plugin will check number of configured instances in Marathon. Also removed Net::HTTP in favour of Restclient::Resource
11
+
8
12
  ## [2.0.0] - 2017-07-15
9
13
  ### Added
10
14
  - Ruby 2.3.0 testing
@@ -74,7 +78,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
74
78
  ### Added
75
79
  - initial release
76
80
 
77
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mesos/compare/2.0.0...HEAD
81
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mesos/compare/2.1.0...HEAD
82
+ [2.1.0]: https://github.com/sensu-plugins/sensu-plugins-mesos/compare/2.0.0...2.1.0
78
83
  [2.0.0]: https://github.com/sensu-plugins/sensu-plugins-mesos/compare/1.1.0...2.0.0
79
84
  [1.1.0]: https://github.com/sensu-plugins/sensu-plugins-mesos/compare/1.0.0...1.1.0
80
85
  [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-mesos/compare/0.1.1...1.0.0
@@ -30,13 +30,13 @@
30
30
  #
31
31
 
32
32
  require 'sensu-plugin/check/cli'
33
- require 'net/http'
33
+ require 'rest-client'
34
34
  require 'json'
35
35
 
36
36
  # This plugin checks that the given Mesos/Marathon task is running properly.
37
37
  #
38
38
  # This means that all of the following is true:
39
- # 1. There are N tasks for the app, as defined by the --instances parameter
39
+ # 1. There are N tasks for the app, as defined by the --instances parameter or checks configured tasks in Marathon as fallback
40
40
  # 2. Each task's state is running
41
41
  # 3. No task is unhealthy, as defined in Marathon
42
42
  #
@@ -71,7 +71,8 @@ class MarathonTaskCheck < Sensu::Plugin::Check::CLI
71
71
  option :instances,
72
72
  short: '-i INSTANCES',
73
73
  long: '--instances INSTANCES',
74
- required: true,
74
+ required: false,
75
+ default: 0,
75
76
  proc: proc(&:to_i)
76
77
 
77
78
  option :protocol,
@@ -89,11 +90,14 @@ class MarathonTaskCheck < Sensu::Plugin::Check::CLI
89
90
  long: '--password PASSWORD',
90
91
  required: false
91
92
 
92
- def run
93
- if config[:instances].zero?
94
- unknown 'number of instances should be an integer'
95
- end
93
+ option :timeout,
94
+ description: 'timeout in seconds',
95
+ short: '-T TIMEOUT',
96
+ long: '--timeout TIMEOUT',
97
+ proc: proc(&:to_i),
98
+ default: 5
96
99
 
100
+ def run
97
101
  if !config[:username].nil? && config[:password].nil? ||
98
102
  config[:username].nil? && !config[:password].nil?
99
103
  unknown 'You must provide both username and password'
@@ -103,28 +107,21 @@ class MarathonTaskCheck < Sensu::Plugin::Check::CLI
103
107
  uri = config[:uri]
104
108
  config[:server].split(',').each do |s|
105
109
  begin
106
- url = URI.parse("#{config[:protocol]}://#{s}:#{config[:port]}#{uri}")
107
- req = Net::HTTP::Get.new(url)
108
- req.add_field('Accept', 'application/json')
109
- if !config[:username].nil? && !config[:password].nil?
110
- req.basic_auth(config[:username], config[:password])
111
- end
112
- r = Net::HTTP.start(url.host, url.port,
113
- use_ssl: config[:protocol] == 'https') do |h|
114
- h.request(req)
115
- end
110
+ auth_headers = {}
111
+ auth_headers = { Authorization: "#{config[:username]} #{config[:password]}" } if !config[:username].nil? && !config[:password].nil?
112
+ r = RestClient::Resource.new("#{config[:protocol]}://#{s}:#{config[:port]}#{uri}", auth_headers, config[:timeout]).get
113
+ expected = if config[:instances].zero?
114
+ default_tasks(s)
115
+ else
116
+ config[:instances]
117
+ end
118
+ ok_count, unhealthy = check_tasks r
116
119
 
117
- ok_count, unhealthy = check_tasks r.body
120
+ message = "#{ok_count}/#{expected} #{config[:task]} tasks running"
118
121
 
119
- message = "#{ok_count}/#{config[:instances]} #{config[:task]} tasks running"
122
+ message << ":\n" << unhealthy.join("\n") if unhealthy.any?
120
123
 
121
- if unhealthy.any?
122
- message << ":\n" << unhealthy.join("\n")
123
- end
124
-
125
- if unhealthy.any? || ok_count < config[:instances]
126
- critical message
127
- end
124
+ critical message if unhealthy.any? || ok_count < config[:instances]
128
125
 
129
126
  ok message
130
127
  rescue Errno::ECONNREFUSED, SocketError
@@ -173,4 +170,13 @@ class MarathonTaskCheck < Sensu::Plugin::Check::CLI
173
170
 
174
171
  [tasks.length, unhealthy]
175
172
  end
173
+
174
+ def default_tasks(server)
175
+ expected_tasks_url = "/v2/apps/#{config[:task]}"
176
+ auth_headers = {}
177
+ auth_headers = { Authorization: "#{config[:username]} #{config[:password]}" } if !config[:username].nil? && !config[:password].nil?
178
+ r = RestClient::Resource.new("#{config[:protocol]}://#{server}:#{config[:port]}#{expected_tasks_url}", auth_headers, config[:timeout]).get
179
+ n_tasks = JSON.parse(r)['app']['instances']
180
+ n_tasks
181
+ end
176
182
  end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsMesos
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-mesos
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-15 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -268,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
268
  version: '0'
269
269
  requirements: []
270
270
  rubyforge_project:
271
- rubygems_version: 2.4.5
271
+ rubygems_version: 2.6.14
272
272
  signing_key:
273
273
  specification_version: 4
274
274
  summary: Sensu plugins for checking mesos