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.
-
#severity ⇒ Object
Returns the value of attribute severity.
-
#source ⇒ Object
Returns the value of attribute source.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #alert(params = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Check
constructor
A new instance of Check.
- #key_values ⇒ Object
- #perform ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Check
Returns a new instance of Check.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/garrison/agents/check.rb', line 12 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 = Logging.info "Starting... #{self.class.name}" inherit_settings Logging.info "Agent Settings (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 |
#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 |
#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
#alert(params = {}) ⇒ Object
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 64 65 66 |
# File 'lib/garrison/agents/check.rb', line 39 def alert(params = {}) Logging.info "Raising alert for '#{params[:target]}'" utc_time_now = Time.now.utc alert = Api::Alert.new 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 |
#key_values ⇒ Object
35 36 37 |
# File 'lib/garrison/agents/check.rb', line 35 def key_values [] end |
#perform ⇒ Object
31 32 33 |
# File 'lib/garrison/agents/check.rb', line 31 def perform raise 'You must provide a perform method in your check class' end |