Skip to content

Commit

Permalink
Add an option to test image's tag (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
obazoud authored and sstarcher committed Feb 7, 2017
1 parent 85817b8 commit e9c47e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)

## [Unreleased]
### Changed
- check-container.rb: add an option to test image's tag (@obazoud)

## [1.1.5] - 2016-11-26
### Changed
Expand Down
14 changes: 12 additions & 2 deletions bin/check-container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class CheckDockerContainer < Sensu::Plugin::Check::CLI
short: '-c CONTAINER',
long: '--container CONTAINER',
required: true
option :tag,
short: '-t TAG',
long: '--tag TAG'

def run
client = create_docker_client
Expand All @@ -62,9 +65,16 @@ def run
if response.body.include? 'no such id'
critical "#{config[:container]} is not running on #{config[:docker_host]}"
end

container_state = JSON.parse(response.body)['State']['Status']
body = JSON.parse(response.body)
container_state = body['State']['Status']
if container_state == 'running'
if config[:tag]
image = body['Config']['Image']
match = image.match(/^(?:([^\/]+)\/)?(?:([^\/]+)\/)?([^@:\/]+)(?:[@:](.+))?$/)
unless match && match[4] == config[:tag]
critical "#{config[:container]}'s tag is '#{match[4]}', excepting '#{config[:tag]}'"
end
end
ok "#{config[:container]} is running on #{config[:docker_host]}."
else
critical "#{config[:container]} is #{container_state} on #{config[:docker_host]}."
Expand Down

0 comments on commit e9c47e1

Please sign in to comment.