Class: Garrison::Checks::Check
- Inherits:
-
Object
- Object
- Garrison::Checks::Check
- Defined in:
- lib/garrison/agents/check.rb
Instance Attribute Summary collapse
-
#departments ⇒ Object
Returns the value of attribute departments.
-
#family ⇒ Object
Returns the value of attribute family.
-
#options ⇒ Object
Returns the value of attribute options.
-
#run_uuid ⇒ Object
Returns the value of attribute run_uuid.
-
#severity ⇒ Object
Returns the value of attribute severity.
-
#source ⇒ Object
Returns the value of attribute source.
-
#state ⇒ Object
Returns the value of attribute state.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #after_perform ⇒ Object
- #alert(params = {}) ⇒ Object
- #before_perform ⇒ Object
-
#initialize(options = {}) ⇒ Check
constructor
A new instance of Check.
- #key_values ⇒ Object
- #perform ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Check
Returns a new instance of Check.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/garrison/agents/check.rb', line 14 def initialize( = {}) @source = ENV['GARRISON_ALERT_SOURCE'] @severity = ENV['GARRISON_ALERT_SEVERITY'] @type = ENV['GARRISON_ALERT_TYPE'] @family = ENV['GARRISON_ALERT_FAMILY'] @departments = ENV['GARRISON_ALERT_DEPARTMENTS'] ? ENV['GARRISON_ALERT_DEPARTMENTS'].split(',') : [] @options = @state = :initial Logging.logger.progname = Api.configuration.uuid Logging.info "Starting... #{self.class.name}" inherit_settings Logging.info "Agent Settings (uuid=#{Api.configuration.uuid} source=#{self.source} severity=#{self.severity || 'dynamic'} type=#{self.type} family=#{self.family} departments=#{self.departments.join(',')})" = .map do |key, value| value = value.is_a?(Array) ? value.join(',') : value "#{key}=#{value}" end Logging.info "Check Settings (#{.join(' ')})" if .any? end |
Instance Attribute Details
#departments ⇒ Object
Returns the value of attribute departments.
9 10 11 |
# File 'lib/garrison/agents/check.rb', line 9 def departments @departments end |
#family ⇒ Object
Returns the value of attribute family.
8 9 10 |
# File 'lib/garrison/agents/check.rb', line 8 def family @family end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/garrison/agents/check.rb', line 10 def @options end |
#run_uuid ⇒ Object
Returns the value of attribute run_uuid.
11 12 13 |
# File 'lib/garrison/agents/check.rb', line 11 def run_uuid @run_uuid end |
#severity ⇒ Object
Returns the value of attribute severity.
6 7 8 |
# File 'lib/garrison/agents/check.rb', line 6 def severity @severity end |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/garrison/agents/check.rb', line 5 def source @source end |
#state ⇒ Object
Returns the value of attribute state.
12 13 14 |
# File 'lib/garrison/agents/check.rb', line 12 def state @state end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/garrison/agents/check.rb', line 7 def type @type end |
Instance Method Details
#after_perform ⇒ Object
54 55 56 57 58 |
# File 'lib/garrison/agents/check.rb', line 54 def after_perform self.state = :complete Api::Run.update(self) Api::Alert.obsolete_previous_runs(self) if ENV["GARRISON_AUTO_OBSOLETE"] end |
#alert(params = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/garrison/agents/check.rb', line 64 def alert(params = {}) Logging.info "Raising alert for '#{params[:target]}'" utc_time_now = Time.now.utc alert = Api::Alert.new alert.run_uuid = self.run_uuid alert.type = type alert.family = family alert.source = source alert.departments = departments alert.name = params[:name] alert.target = params[:target] alert.detail = params[:detail] alert.severity = params[:external_severity] || severity alert.count = params[:count] || 1 alert.finding = params[:finding] alert.finding_id = params[:finding_id] alert.first_detected_at = params[:first_detected_at] || utc_time_now alert.last_detected_at = params[:last_detected_at] || utc_time_now alert.urls = params[:urls] alert.key_values = (self.key_values + params[:key_values]).uniq { |h| h[:key] } alert.no_repeat = params[:no_repeat] alert.save end |
#before_perform ⇒ Object
50 51 52 |
# File 'lib/garrison/agents/check.rb', line 50 def before_perform self.run_uuid = Api::Run.create(self) end |
#key_values ⇒ Object
60 61 62 |
# File 'lib/garrison/agents/check.rb', line 60 def key_values [] end |
#perform ⇒ Object
46 47 48 |
# File 'lib/garrison/agents/check.rb', line 46 def perform raise 'You must provide a perform method in your check class' end |
#run ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/garrison/agents/check.rb', line 35 def run before_perform begin perform rescue Exception => e Logging.fatal "#{e} - #{e.}" self.state = :failed end after_perform end |