bin/check-marathon-apps.rb in sensu-plugins-mesos-2.3.0 vs bin/check-marathon-apps.rb in sensu-plugins-mesos-2.4.0
- old
+ new
@@ -1,11 +1,11 @@
#! /usr/bin/env ruby
#
# check-marathon-apps
#
# DESCRIPTION:
-# This plugin creates checks results for each Marathon app that is running,
+# This check script creates checks results for each Marathon app that is running,
# and reports the status of the app based on Marathon Application Status Reference.
# https://mesosphere.github.io/marathon/docs/marathon-ui.html#application-status-reference
#
# OUTPUT:
# plain text
@@ -171,11 +171,11 @@
required: false,
description: 'Similar to `--default-check-config` but read from given file. If both parameters are provided '\
'`--default-check-config` will override this one.'
option :sensu_client_url,
- description: 'Sensu client HTTP URL socket',
+ description: 'Sensu client HTTP URL',
long: '--sensu-client-url url',
default: 'http://localhost:3031'
option :timeout,
description: 'timeout in seconds',
@@ -244,11 +244,11 @@
check_result['output'] = "#{reference.upcase} #{state.capitalize} - "\
"tasksRunning(#{app['tasksRunning'].to_i}), tasksStaged(#{app['tasksStaged'].to_i}), "\
"tasksHealthy(#{app['tasksHealthy'].to_i}), tasksUnhealthy(#{app['tasksUnhealthy'].to_i})"
# Make sure that check result data types are correct
- sanitize_check_result(check_result)
+ enforce_sensu_field_types(check_result)
# Send the result to sensu-client HTTP socket
post_check_result(check_result)
end
end
@@ -265,11 +265,11 @@
'output' => '',
'status' => 3
}
end
- def sanitize_check_result(check_result)
+ def enforce_sensu_field_types(check_result)
# Force data types of different fields on the check result
# https://sensuapp.org/docs/latest/reference/checks.html#example-check-definition
# https://sensuapp.org/docs/latest/reference/checks.html#check-result-specification
check_result.each do |k, v|
if %w(publish standalone auto_resolve force_resolve handle truncate_output).include?(k)
@@ -283,11 +283,11 @@
check_result[k] = Array(v.split(','))
end
end
end
- def get(path)
+ def rest_client(path)
RestClient.get("#{config[:url]}#{path}",
user: config[:username],
password: config[:password],
accept: 'application/json',
timeout: config[:timeout]).body
@@ -296,15 +296,15 @@
end
def fetch_apps
# http://mesosphere.github.io/marathon/api-console/index.html
resources_query = APPS_EMBED_RESOURCES.map { |resource| "embed=#{resource}" }.join('&')
- parse_json(get("/v2/apps?#{resources_query}"))['apps']
+ parse_json(rest_client("/v2/apps?#{resources_query}"))['apps']
end
def fetch_queue
# http://mesosphere.github.io/marathon/api-console/index.html
- parse_json(get('/v2/queue'))['queue']
+ parse_json(rest_client('/v2/queue'))['queue']
end
def post_check_result(data)
RestClient.post("#{config[:sensu_client_url]}/results",
data.to_json,