Created
May 3, 2016 23:11
-
-
Save csbogdan/0474bdff604fb7be2877f2a9732585fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.unshift File.join(File.dirname(__FILE__),'..','lib') | |
require 'net/https' | |
require 'json' | |
require 'open-uri' | |
module APIG | |
SEVERITY_TO_STATUS = { | |
1 => {'status' => 'critical', 'message' => 'Severity 1 issue. Look into it asap!'}, | |
2 => {'status' => 'warning', 'message' => 'Severity 2 issue.'}, | |
3 => {'status' => 'warning', 'message' => 'Severity 3 issue.'} | |
} | |
ENVIRONMENT_URL = Array[] | |
ENVIRONMENT_URL.push("https://oxhqnq4np6.execute-api.eu-west-1.amazonaws.com/int") | |
def APIG.get_cluster_health(env_index) | |
begin | |
url = ENVIRONMENT_URL[env_index]+'/__health' | |
uri = URI.parse(url) | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
request = Net::HTTP::Get.new(uri.request_uri, { 'Accept' => 'application/json', 'User-Agent' => 'ft-dashing-monitor'}) | |
response = http.request(request) | |
case response | |
when Net::HTTPSuccess | |
json_response = JSON.parse(response.body) | |
return parse_json_response_and_get_status(json_response) | |
else | |
return {"status" => "critical", "message" => "Error while retrieving cluster health"} | |
end | |
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, | |
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e | |
return {"status" => "critical", "message" => "Cluster down or unreachable"} | |
rescue JSON::ParserError => e | |
return {"status" => "critical", "message" => "Error while parsing cluster health response"} | |
end | |
end | |
def APIG.parse_json_response_and_get_status(json_response) | |
status = json_response["ok"] | |
if status == true | |
return {"status" => "ok", "message" => "Healthy"} | |
else | |
return SEVERITY_TO_STATUS[json_response["severity"]] | |
end | |
end | |
def APIG.get_environment_url(env_index) | |
return ENVIRONMENT_URL[env_index] | |
end | |
end | |
SCHEDULER.every '25s', :first_in => 0 do |job| | |
send_event('inspectah-int', APIG.get_cluster_health(0)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment