lib/splash/commands.rb in prometheus-splash-0.6.0 vs lib/splash/commands.rb in prometheus-splash-0.6.1
- old
+ new
@@ -24,11 +24,11 @@
# Constructor
# @param [String] name the name of the command
def initialize(name)
@config = get_config
- @url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}/#{@config.prometheus_pushgateway_path}"
+ @url = @config.prometheus_pushgateway_url
@name = name
unless @config.commands.keys.include? @name.to_sym then
splash_exit case: :not_found, more: "command #{@name} is not defined in configuration"
end
end
@@ -42,11 +42,11 @@
# send metrics to Prometheus PushGateway
# @param [String] value numeric.to_s
# @param [String] time execution time numeric.to_s
# @return [Hash] Exiter case :quiet_exit
def notify(value,time)
- unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then
+ unless verify_service url: @config.prometheus_pushgateway_url then
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send."}
end
@@metric_exitcode.set(value)
@@metric_time.set(time)
hostname = Socket.gethostname
@@ -82,10 +82,12 @@
:queue => "splash.#{@config.commands[@name.to_sym][:delegate_to][:host]}.input" })
exit_code = res[:exit_code]
log.receive "return with exitcode #{exit_code}", session
end
+ rescue Interrupt
+ splash_exit case: :interrupt, more: "Remote command exection"
end
else
log.info "Executing command : '#{@name}' ", session
start = Time.now
start_date = DateTime.now.to_s
@@ -134,10 +136,9 @@
get_logger.ok "Prometheus Gateway notified.",session
else
log.item "Without Prometheus notification", session
end
end
-
if options[:callback] then
on_failure = (@config.commands[@name.to_sym][:on_failure])? @config.commands[@name.to_sym][:on_failure] : false
on_success = (@config.commands[@name.to_sym][:on_success])? @config.commands[@name.to_sym][:on_success] : false
if on_failure and exit_code > 0 then
log.item "On failure callback : #{on_failure}", session