Class: ZAWS::Helper::Output
- Inherits:
-
Object
- Object
- ZAWS::Helper::Output
- Defined in:
- lib/zaws/helper/output.rb
Class Method Summary collapse
- .binary_nagios_check(ok_condition, ok_msg, critical_msg, textout = nil) ⇒ Object
- .cloudtrail(json_data, format = "csv") ⇒ Object
- .colorize(text, color_code) ⇒ Object
- .opt_exclusive(output, opt_arr) ⇒ Object
- .opt_minimum(output, min, opt_arr) ⇒ Object
- .opt_required(output, opt_arr) ⇒ Object
- .out_change(output, text) ⇒ Object
- .out_nagios_critical(output, text) ⇒ Object
- .out_nagios_ok(output, text) ⇒ Object
- .out_no_op(output, text) ⇒ Object
- .return_change(text) ⇒ Object
- .return_no_op(text) ⇒ Object
Class Method Details
.binary_nagios_check(ok_condition, ok_msg, critical_msg, textout = nil) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# 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") ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# 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) ⇒ Object
41 42 43 |
# 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) ⇒ Object
49 50 51 52 |
# 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) ⇒ Object
54 55 56 57 |
# 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) ⇒ Object
45 46 47 |
# 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) ⇒ Object
29 30 31 |
# 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) ⇒ Object
21 22 23 |
# 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) ⇒ Object
17 18 19 |
# 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) ⇒ Object
25 26 27 |
# 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) ⇒ Object
33 34 35 |
# 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) ⇒ Object
37 38 39 |
# File 'lib/zaws/helper/output.rb', line 37 def self.return_no_op( text) return colorize(text, AWS_consts::COLOR_GREEN) end |