Skip to content

Commit

Permalink
Pass additional metadata from alert to event
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooli Tayer committed Mar 21, 2017
1 parent ab5f789 commit 95ebfe0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app/models/ems_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,13 @@ def self.first_chained_event(ems_id, chain_id)
end

def parse_event_metadata
data = full_data || {}
[
event_type == "datawarehouse_alert" ? message : nil,
full_data.try(:[], :severity),
full_data.try(:[], :url),
data[:severity],
data[:url],
data[:ems_ref],
data[:resolved],
]
end

Expand Down
5 changes: 4 additions & 1 deletion app/models/miq_alert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,16 @@ def evaluate(target, inputs = {})
end

def add_status_post_evaluate(target, result, event)
status_description, severity, url = event.parse_event_metadata if event.respond_to?(:parse_event_metadata)
status_description, severity, url, ems_ref, resolved = event.try(:parse_event_metadata)
status = miq_alert_statuses.find_or_initialize_by(:resource => target)

status.result = result
status.ems_id = target.try(:ems_id)
status.description = status_description || description
status.severity = severity unless severity.blank?
status.url = url unless url.blank?
status.event_ems_ref = ems_ref unless ems_ref.blank?
status.resolved = resolved
status.evaluated_on = Time.now.utc
status.save
miq_alert_statuses << status
Expand Down

0 comments on commit 95ebfe0

Please sign in to comment.