Class: Alerty::Command
- Inherits:
-
Object
- Object
- Alerty::Command
- Defined in:
- lib/alerty/command.rb
Instance Method Summary collapse
-
#initialize(command:) ⇒ Command
constructor
A new instance of Command.
- #run! ⇒ Object
Constructor Details
Instance Method Details
#run! ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/alerty/command.rb', line 13 def run! record = {} with_retry do |retries| started_at = Time.now begin result = with_clean_env { Frontkick.exec("#{@command} 2>&1", @opts) } rescue Frontkick::Timeout => e record = { hostname: @hostname, command: @command, exitstatus: 1, output: "`#{@command}` is timeout (#{@opts[:timeout]} sec)", started_at: started_at.to_f, duration: @opts[:timeout], retries: retries, } rescue Frontkick::Locked => e record = { hostname: @hostname, command: @command, exitstatus: 1, output: "`#{@opts[:exclusive]}` is locked by another process", started_at: started_at.to_f, duration: 0, retries: retries, } else record = { hostname: @hostname, command: @command, exitstatus: result.exitstatus, output: result.stdout, started_at: started_at.to_f, duration: result.duration, retries: retries, } end Alerty.logger.info { "result: #{record.to_json}" } record end unless record[:exitstatus] == 0 Config.plugins.each do |plugin| begin plugin.alert(record) rescue => e Alerty.logger.warn "#{e.class} #{e.} #{e.backtrace.join("\n")}" end end exit record[:exitstatus] end end |