Skip to content

Commit

Permalink
Change alert definition meta
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooli Tayer committed Jan 18, 2018
1 parent a80fca5 commit 918e9e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def extract_event_data(event)
#
# {
# "annotations": {
# "message": "Node ocp-compute01.10.35.48.236.nip.io is down",
# "severity": "HIGH",
# "description": "Node ocp-compute01.10.35.48.236.nip.io is down",
# "source": "ManageIQ",
# "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
# },
# "endsAt": "0001-01-01T00:00:00Z",
# "generatorURL": "http://prometheus-4018548653-w3str:9090/graph?g0.expr=container_fs_usage_bytes%7Bcontainer_name%3D%22%22%2Cdevice%3D%22%2Fdev%2Fmapper%2Fvg0-lv_root%22%7D+%3E+4e%2B07&g0.tab=0",
# "labels": {
# "severity": "error",
# "alertname": "Node down",
# "beta_kubernetes_io_arch": "amd64",
# "beta_kubernetes_io_os": "linux",
Expand All @@ -76,17 +76,18 @@ def extract_event_data(event)
event = event.dup

annotations = event["annotations"]
event[:url] = annotations["url"]
event[:severity] = parse_severity(annotations["severity"])
labels = event["labels"]

event[:url] = annotations["url"]
event[:severity] = parse_severity(labels["severity"])
# TODO(mtayer): remove after https://github.com/ManageIQ/manageiq/pull/16339
event[:ems_ref] = incident_identifier(labels, annotations, event["startsAt"])
event[:resolved] = event["status"] == "resolved"
{
:source => "DATAWAREHOUSE",
:timestamp => Time.zone.now,
:event_type => "datawarehouse_alert",
:message => annotations["message"],
:message => annotations["description"],
:ems_ref => incident_identifier(labels, annotations, event["startsAt"]),
:full_data => event.to_h
}.merge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ def initialize(ems)
let(:node_annotations) { {"miqTarget" => 'ContainerNode'} }
let(:ext_annotations) { {"miqTarget" => 'ExtManagementSystem'} }

context "#extract_event_data" do
it "extracts severity based on the severity label" do
expect(subject).to receive(:parse_severity).with("info").and_call_original
expect(
subject.extract_event_data(
"labels" => {"severity" => "info"},
"annotations" => {"severity" => "ignoreme"},
)[:full_data]
).to include(:severity => "info")
end

it "extracts messaged based on the description annotation" do
expect(
subject.extract_event_data(
"annotations" => {
"description" => "important",
"message" => "ignoreme",
},
"labels" => {},
)
).to include(:message => "important")
end
end

context "#find_target" do
it "binds to container node by default" do
target = FactoryGirl.create(:container_node, :name => 'testing')
Expand Down

0 comments on commit 918e9e5

Please sign in to comment.