Sha256: 262d47d4686b8322ea1cad256da758f13936042056f94ae978368e4f6b7d1c60

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

#! /usr/bin/env ruby
#
#   check-jenkins
#
# DESCRIPTION:
#   This plugin checks that the Jenkins Metrics healthcheck is healthy throughout
#
# OUTPUT:
#   plain text
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#   gem: rest-client
#   gem: json
#
# USAGE:
#   #YELLOW
#
# NOTES:
#
# LICENSE:
#   Copyright 2015, Cornel Foltea cornel.foltea@gmail.com
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'sensu-plugin/check/cli'
require 'rest-client'
require 'json'

#
# Jenkins Metrics Health Check
#
class JenkinsMetricsHealthChecker < Sensu::Plugin::Check::CLI
  option :server,
         description: 'Jenkins Host',
         short: '-s SERVER',
         long: '--server SERVER',
         default: 'localhost'

  option :uri,
         description: 'Jenkins Metrics Healthcheck URI',
         short: '-u URI',
         long: '--uri URI',
         default: '/metrics/currentUser/healthcheck'

  def run
    r = RestClient::Resource.new("http://#{config[:server]}:8080#{config[:uri]}", timeout: 5).get
    if r.code == 200
      healthchecks = JSON.parse(r)
      healthchecks.each do |_, healthcheck_hash_value|
        if healthcheck_hash_value['healthy'] != true
          critical 'Jenkins Health Parameters not OK'
        end
      end
      ok 'Jenkins Health Parameters are OK'
    else
      critical 'Jenkins Service is not responding'
    end
  rescue Errno::ECONNREFUSED
    critical 'Jenkins Service is not responding'
  rescue RestClient::RequestTimeout
    critical 'Jenkins Service Connection timed out'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sensu-plugins-jenkins-0.0.2 bin/check-jenkins-health.rb
sensu-plugins-jenkins-0.0.1 bin/check-jenkins-health.rb