sensu-plugins-docker-checks 0.0.1 → 0.0.2

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: e66c6a89bc7a2e4a3a8c2ee1e945ce87b1b760cf
4
- data.tar.gz: 464bbab9b876eee82e4866bf64bf935da4bf6031
3
+ metadata.gz: 358a68a10e452abe00d29f24bbdabafc2c827878
4
+ data.tar.gz: 0b56fba66c9ccb78d3e471c33cd0642a04b7e7b8
5
5
  SHA512:
6
- metadata.gz: cda400d576c3e1acf97870d749a3e65dff128d17505641bd33226ad339cf0e65e2b9a4c9290c0b90ba0a45ee538665bb4594e54dc7ee7c0ab7bf94ef0bf2ebf7
7
- data.tar.gz: 2645e419baed0ded27ef9df9d1046322603e9b66ee27964077e5b4e14fec293c36fba705dea57c7dd80aa21b4d66345b87756c8db2c87df9c6922cd70579c7e3
6
+ metadata.gz: ba4bbd18cb810ab6ad8039764b84e833196d24c550214ca73c70dd9d3f04925a6c2577647483f41585de44a5e7740a2e0c15d1f12785988053c919625ceafde0
7
+ data.tar.gz: 0282aa18eb0d74230c8c0606bdb100e3207ba5c97b0c241344293c067b685112d1e6e04a18a1d0d6337d7ad22868e35a69cff749401de27da2199d7d011c46d1
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ ## [0.0.2] - 2016-01-07
9
+ ### Added
10
+ - Added support to monitor when container restarts.
11
+
8
12
  ## [0.0.1] - 2015-12-28
9
13
  ### Added
10
14
  - Initial release
data/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  # Sensu plugin for monitoring Docker containers
2
2
 
3
- A sensu plugin to monitor Docker containers.
3
+ A sensu plugin to monitor Docker containers. The plugin can also notify when a container restarts.
4
4
 
5
5
  ## Usage
6
6
 
7
7
  The plugin accepts the following command line options:
8
8
 
9
9
  ```
10
- Usage: check-docker-container.rb (options)
10
+ Usage: check-docker-container.rb <options> <containerId>
11
+ --uptime <SECONDS> Warn if UPTIME exceeds the container uptime
11
12
  --url <URL> Docker daemon URL (default: unix:///var/run/docker.sock)
12
13
  ```
13
14
 
@@ -7,6 +7,8 @@
7
7
 
8
8
  require 'sensu-plugin/check/cli'
9
9
  require 'docker'
10
+ require 'fileutils'
11
+ require 'date'
10
12
 
11
13
  class CheckDockerContainer < Sensu::Plugin::Check::CLI
12
14
  banner "Usage: #{$0} <options> <containerId>"
@@ -16,6 +18,11 @@ class CheckDockerContainer < Sensu::Plugin::Check::CLI
16
18
  :long => "--url <URL>",
17
19
  :default => "unix:///var/run/docker.sock"
18
20
 
21
+ option :uptime,
22
+ :description => "Warn if UPTIME exceeds the container uptime",
23
+ :long => "--uptime <SECONDS>",
24
+ :default => 300
25
+
19
26
  def initialize()
20
27
  super
21
28
 
@@ -30,15 +37,23 @@ class CheckDockerContainer < Sensu::Plugin::Check::CLI
30
37
  begin
31
38
  container = Docker::Container.get(@container_id)
32
39
 
33
- if container.info['State']['Running']
40
+ started_at = DateTime.parse(container.info['State']['StartedAt']).to_time
41
+ finished_at = DateTime.parse(container.info['State']['FinishedAt']).to_time
42
+
43
+ uptime = Time.now - started_at
44
+ if uptime <= config[:uptime] and finished_at != DateTime.parse('0001-01-01T00:00:00Z').to_time
45
+ warning("Container ID '#{@container_id}' restarted #{uptime.to_i} seconds ago")
46
+ elsif container.info['State']['Restarting']
47
+ warning("Container ID '#{@container_id}' is restarting")
48
+ elsif container.info['State']['Running']
34
49
  ok("Container ID '#{@container_id}' is running")
35
50
  else
36
51
  critical("Container ID '#{@container_id}' is not running")
37
52
  end
38
53
  rescue Docker::Error::NotFoundError
39
- critical("Container ID '#{id}' not running on host (Not found)")
54
+ critical("Container ID '#{@container_id}' not running on host (Reason: Not found)")
40
55
  rescue
41
- unknown("Failed to look up container ID '#{@container_id}' (#{$!})")
56
+ unknown("Failed to look up container ID '#{@container_id}' (Reason: #{$!})")
42
57
  end
43
58
  end
44
59
  end
@@ -2,7 +2,7 @@ module SensuPluginsDockerChecks
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 1
5
+ PATCH = 2
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-docker-checks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Cerutti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-29 00:00:00.000000000 Z
11
+ date: 2016-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin