class ZAWS::Helper::Output

Public Class Methods

binary_nagios_check(ok_condition, ok_msg, critical_msg, textout=nil) click to toggle source
# File lib/zaws/helper/output.rb, line 59
def self.binary_nagios_check(ok_condition, ok_msg, critical_msg, textout=nil)
  if ok_condition
    out_nagios_ok(textout, ok_msg) if textout
    return 0
  else
    out_nagios_critical(textout, critical_msg) if textout
    return 2
  end
end
cloudtrail(json_data, format = "csv") click to toggle source
# File lib/zaws/helper/output.rb, line 69
def self.cloudtrail(json_data, format = "csv")
  parsed = JSON.parse(json_data)
  records = parsed["Records"]

  str_out = ""
  if format == "csv"
    records.each do |record|
      str_out << "#{record["userIdentity"]["userName"]}, "
      str_out << "#{record["eventTime"]}, "
      str_out << "#{record["eventSource"]}, "
      str_out << "#{record["eventName"]}"

      if record["errorCode"]
        str_out << ", "
        str_out << "#{record["errorCode"]}, "
        str_out << "#{record["errorMessage"]}"
      end

      str_out << "\n"
    end
  elsif format == "raw"
    str_out=json_data
  end

  return str_out
end
colorize(text, color_code) click to toggle source
# File lib/zaws/helper/output.rb, line 41
def self.colorize(text, color_code)
  "\e[#{color_code}m#{text}\e[0m"
end
opt_exclusive(output, opt_arr) click to toggle source
# File lib/zaws/helper/output.rb, line 49
def self.opt_exclusive(output, opt_arr)
  output.puts("  These options cannot be combined:")
  opt_arr.each { |opt| output.puts("    --#{opt}") }
end
opt_minimum(output, min, opt_arr) click to toggle source
# File lib/zaws/helper/output.rb, line 54
def self.opt_minimum(output, min, opt_arr)
  output.puts("  At mininum, #{min} of the following is required:")
  opt_arr.each { |opt| output.puts("    --#{opt}") }
end
opt_required(output, opt_arr) click to toggle source
# File lib/zaws/helper/output.rb, line 45
def self.opt_required(output, opt_arr)
  opt_arr.each { |opt| output.puts(" --#{opt} required!") }
end
out_change(output, text) click to toggle source
# File lib/zaws/helper/output.rb, line 29
def self.out_change(output, text)
  output.puts colorize(text, AWS_consts::COLOR_YELLOW) if output
end
out_nagios_critical(output, text) click to toggle source
# File lib/zaws/helper/output.rb, line 21
def self.out_nagios_critical(output, text)
  output.puts colorize(text, AWS_consts::COLOR_RED) if output
end
out_nagios_ok(output, text) click to toggle source
# File lib/zaws/helper/output.rb, line 17
def self.out_nagios_ok(output, text)
  output.puts colorize(text, AWS_consts::COLOR_GREEN) if output
end
out_no_op(output, text) click to toggle source
# File lib/zaws/helper/output.rb, line 25
def self.out_no_op(output, text)
  output.puts colorize(text, AWS_consts::COLOR_GREEN) if output
end
return_change(text) click to toggle source
# File lib/zaws/helper/output.rb, line 33
def self.return_change(text)
  return colorize(text, AWS_consts::COLOR_YELLOW)
end
return_no_op( text) click to toggle source
# File lib/zaws/helper/output.rb, line 37
def self.return_no_op( text)
  return colorize(text, AWS_consts::COLOR_GREEN)
end