Improved state detection for host down/up with new icinga email templates.
This commit is contained in:
parent
95f71f65df
commit
1c941ec317
2 changed files with 66 additions and 6 deletions
|
@ -46,17 +46,19 @@ class Channel::Filter::MonitoringBase
|
||||||
# check min. params
|
# check min. params
|
||||||
return if result['host'].blank?
|
return if result['host'].blank?
|
||||||
|
|
||||||
# get state from body
|
# get state by body - ichinga new templates
|
||||||
if result['state'].blank?
|
if result['state'].blank?
|
||||||
if mail[:body] =~ /==>.*\sis\s(.+?)\!\s+?<==/
|
if mail[:body] =~ /==>.*\sis\s(.+?)\!\s+?<==/
|
||||||
result['state'] = $1
|
result['state'] = $1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# get state from subject
|
# get state by subject - ichinga new templates "state:" is not in body anymore
|
||||||
|
# Subject: [PROBLEM] Ping IPv4 on host1234.dc.example.com is WARNING!
|
||||||
|
# Subject: [PROBLEM] Host host1234.dc.example.com is DOWN!
|
||||||
if result['state'].blank?
|
if result['state'].blank?
|
||||||
if mail[:subject] =~ /on\s.+?\sis\s(.+?)\!/
|
if mail[:subject] =~ /(on|Host)\s.+?\sis\s(.+?)\!/
|
||||||
result['state'] = $1
|
result['state'] = $2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -319,7 +319,7 @@ Comment: [] =
|
||||||
Subject: [PROBLEM] Ping IPv4 on apn4711.dc.example.com is WARNING!
|
Subject: [PROBLEM] Ping IPv4 on apn4711.dc.example.com is WARNING!
|
||||||
From: icinga2@monitoring.example.com (icinga)
|
From: icinga2@monitoring.example.com (icinga)
|
||||||
|
|
||||||
***** Service Monitoring on monitoring.znuny.com *****
|
***** Service Monitoring on monitoring.example.com *****
|
||||||
|
|
||||||
Ping IPv4 on apn4711.dc.example.com is WARNING!
|
Ping IPv4 on apn4711.dc.example.com is WARNING!
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ IPv4: 127.0.0.1="
|
||||||
Subject: [RECOVERY] Ping IPv4 on apn4711.dc.example.com is OK!
|
Subject: [RECOVERY] Ping IPv4 on apn4711.dc.example.com is OK!
|
||||||
From: icinga2@monitoring.example.com (icinga)
|
From: icinga2@monitoring.example.com (icinga)
|
||||||
|
|
||||||
***** Service Monitoring on monitoring.znuny.com *****
|
***** Service Monitoring on monitoring.example.com *****
|
||||||
|
|
||||||
Ping IPv4 on apn4711.dc.example.com is OK!
|
Ping IPv4 on apn4711.dc.example.com is OK!
|
||||||
|
|
||||||
|
@ -363,6 +363,64 @@ IPv4: 127.0.0.1="
|
||||||
assert_equal('apn4711.dc.example.com', ticket_4.preferences['icinga']['host'])
|
assert_equal('apn4711.dc.example.com', ticket_4.preferences['icinga']['host'])
|
||||||
assert_equal('Ping IPv4', ticket_4.preferences['icinga']['service'])
|
assert_equal('Ping IPv4', ticket_4.preferences['icinga']['service'])
|
||||||
assert_equal('WARNING', ticket_4_1.preferences['icinga']['state'])
|
assert_equal('WARNING', ticket_4_1.preferences['icinga']['state'])
|
||||||
|
|
||||||
|
# host down
|
||||||
|
email_raw_string = "To: support@example.com
|
||||||
|
Subject: [PROBLEM] Host apn4709.dc.example.com is DOWN!
|
||||||
|
User-Agent: Heirloom mailx 12.5 7/5/10
|
||||||
|
MIME-Version: 1.0
|
||||||
|
Content-Type: text/plain; charset=us-ascii
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
From: icinga2@monitoring.example.com (icinga)
|
||||||
|
|
||||||
|
***** Host Monitoring on monitoring.example.com *****
|
||||||
|
|
||||||
|
apn4709.dc.example.com is DOWN!
|
||||||
|
|
||||||
|
Info: CRITICAL - Plugin timed out
|
||||||
|
|
||||||
|
|
||||||
|
When: 2017-09-29 14:19:40 +0200
|
||||||
|
Host: apn4709.dc.example.com
|
||||||
|
IPv4:=09 127.0.0.1="
|
||||||
|
|
||||||
|
ticket_5, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
|
assert_equal('new', ticket_5.state.name)
|
||||||
|
assert(ticket_5.preferences)
|
||||||
|
assert(ticket_5.preferences['icinga'])
|
||||||
|
assert_equal('apn4709.dc.example.com', ticket_5.preferences['icinga']['host'])
|
||||||
|
assert_nil(ticket_5.preferences['icinga']['service'])
|
||||||
|
assert_equal('DOWN', ticket_5.preferences['icinga']['state'])
|
||||||
|
assert_not_equal(ticket_5.id, ticket_1.id)
|
||||||
|
|
||||||
|
# host up
|
||||||
|
email_raw_string = "To: support@example.com
|
||||||
|
Subject: [RECOVERY] Host apn4709.dc.example.com is UP!
|
||||||
|
User-Agent: Heirloom mailx 12.5 7/5/10
|
||||||
|
MIME-Version: 1.0
|
||||||
|
Content-Type: text/plain; charset=us-ascii
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
From: icinga2@monitoring.example.com (icinga)
|
||||||
|
|
||||||
|
***** Host Monitoring on monitoring.example.com *****
|
||||||
|
|
||||||
|
apn4709.dc.example.com is UP!
|
||||||
|
|
||||||
|
Info: PING OK - Packet loss =3D 0%, RTA =3D 20.20 ms
|
||||||
|
|
||||||
|
When: 2017-09-29 14:23:36 +0200
|
||||||
|
Host: apn4709.dc.example.com
|
||||||
|
IPv4:=09 127.0.0.1=
|
||||||
|
"
|
||||||
|
ticket_5_1, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
|
assert_equal(ticket_5.id, ticket_5_1.id)
|
||||||
|
assert_equal('closed', ticket_5_1.state.name)
|
||||||
|
assert(ticket_5_1.preferences)
|
||||||
|
assert(ticket_5_1.preferences['icinga'])
|
||||||
|
assert_equal('apn4709.dc.example.com', ticket_5.preferences['icinga']['host'])
|
||||||
|
assert_nil(ticket_5_1.preferences['icinga']['service'])
|
||||||
|
assert_equal('DOWN', ticket_5_1.preferences['icinga']['state'])
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'not matching sender tests' do
|
test 'not matching sender tests' do
|
||||||
|
|
Loading…
Reference in a new issue