From 0b78df6fffecc7ce1a395fef1cb9e938d913d683 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 14 Jan 2017 14:23:11 +0100 Subject: [PATCH] Added host DOWN/UP detection. --- app/models/channel/filter/monitoring_base.rb | 2 +- test/unit/integration_icinga_test.rb | 70 ++++++++++++++++++++ test/unit/integration_nagios_test.rb | 70 ++++++++++++++++++++ 3 files changed, 141 insertions(+), 1 deletion(-) diff --git a/app/models/channel/filter/monitoring_base.rb b/app/models/channel/filter/monitoring_base.rb index 094f11104..80e155fc8 100644 --- a/app/models/channel/filter/monitoring_base.rb +++ b/app/models/channel/filter/monitoring_base.rb @@ -18,7 +18,7 @@ class Channel::Filter::MonitoringBase sender = Setting.get("#{integration}_sender") auto_close = Setting.get("#{integration}_auto_close") auto_close_state_id = Setting.get("#{integration}_auto_close_state_id") - state_recovery_match = 'OK' + state_recovery_match = '(OK|UP)' return if !mail[:from] return if !mail[:body] diff --git a/test/unit/integration_icinga_test.rb b/test/unit/integration_icinga_test.rb index b849a7166..05237c129 100644 --- a/test/unit/integration_icinga_test.rb +++ b/test/unit/integration_icinga_test.rb @@ -191,6 +191,76 @@ Comment: [] = assert_equal('CPU Load', ticket_1_2.preferences['icinga']['service']) assert_equal('WARNING', ticket_1_2.preferences['icinga']['state']) + # host down + email_raw_string = "To: support@example.com +Subject: PROBLEM - apn4711.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 +Message-Id: <20160131094621.29ECD400F29C-icinga-5@monitoring.znuny.com> +From: icinga@monitoring.example.com (icinga) + +***** Icinga ***** + +Notification Type: PROBLEM + +Host: apn4711.dc.example.com +Address: 127.0.0.1 +State: DOWN + +Date/Time: 2017-01-14 11:33:02 +0100 + +Additional Info: CRITICAL - Host Unreachable (127.0.0.1) + +Comment: [] = +" + ticket_3, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string) + assert_equal('new', ticket_3.state.name) + assert(ticket_3.preferences) + assert(ticket_3.preferences['integration']) + assert_equal('icinga', ticket_3.preferences['integration']) + assert(ticket_3.preferences['icinga']) + assert_equal('apn4711.dc.example.com', ticket_3.preferences['icinga']['host']) + assert_equal(nil, ticket_3.preferences['icinga']['service']) + assert_equal('DOWN', ticket_3.preferences['icinga']['state']) + assert_not_equal(ticket_3.id, ticket_1.id) + + # host up + email_raw_string = "To: support@example.com +Subject: RECOVERY - apn4711.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 +Message-Id: <20160131094621.29ECD400F29C-icinga-5@monitoring.znuny.com> +From: icinga@monitoring.example.com (icinga) + +***** Icinga ***** + +Notification Type: RECOVERY + +Host: apn4711.dc.example.com +Address: 127.0.0.1 +State: UP + +Date/Time: 2017-01-14 12:07:11 +0100 + +Additional Info: PING OK - Packet loss = 0%, RTA = 21.37 ms + +Comment: [] = +" + ticket_3_1, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string) + assert_equal(ticket_3.id, ticket_3_1.id) + assert_equal('closed', ticket_3_1.state.name) + assert(ticket_3_1.preferences) + assert(ticket_3_1.preferences['integration']) + assert_equal('icinga', ticket_3_1.preferences['integration']) + assert(ticket_3_1.preferences['icinga']) + assert_equal('apn4711.dc.example.com', ticket_3.preferences['icinga']['host']) + assert_equal(nil, ticket_3_1.preferences['icinga']['service']) + assert_equal('DOWN', ticket_3_1.preferences['icinga']['state']) + #Setting.set('icinga_integration', false) end diff --git a/test/unit/integration_nagios_test.rb b/test/unit/integration_nagios_test.rb index 186e636c8..667f17484 100644 --- a/test/unit/integration_nagios_test.rb +++ b/test/unit/integration_nagios_test.rb @@ -177,6 +177,76 @@ Additional Info: assert_equal('CPU Load', ticket_1_2.preferences['nagios']['service']) assert_equal('WARNING', ticket_1_2.preferences['nagios']['state']) + # host down + email_raw_string = "To: support@example.com +Subject: ** PROBLEM Host Alert: apn4711.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 +Message-Id: <20160131094621.29ECD400F29C-nagios-5@monitoring.znuny.com> +From: nagios@monitoring.example.com (nagios) + +***** Nagios ***** + +Notification Type: PROBLEM + +Host: apn4711.dc.example.com +Address: 127.0.0.1 +State: DOWN + +Date/Time: 2017-01-14 11:33:02 +0100 + +Additional Info: CRITICAL - Host Unreachable (127.0.0.1) + +Comment: [] = +" + ticket_3, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string) + assert_equal('new', ticket_3.state.name) + assert(ticket_3.preferences) + assert(ticket_3.preferences['integration']) + assert_equal('nagios', ticket_3.preferences['integration']) + assert(ticket_3.preferences['nagios']) + assert_equal('apn4711.dc.example.com', ticket_3.preferences['nagios']['host']) + assert_equal(nil, ticket_3.preferences['nagios']['service']) + assert_equal('DOWN', ticket_3.preferences['nagios']['state']) + assert_not_equal(ticket_3.id, ticket_1.id) + + # host up + email_raw_string = "To: support@example.com +Subject: ** RECOVERY Host Alert: apn4711.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 +Message-Id: <20160131094621.29ECD400F29C-nagios-5@monitoring.znuny.com> +From: nagios@monitoring.example.com (nagios) + +***** Nagios ***** + +Notification Type: RECOVERY + +Host: apn4711.dc.example.com +Address: 127.0.0.1 +State: UP + +Date/Time: 2017-01-14 12:07:11 +0100 + +Additional Info: PING OK - Packet loss = 0%, RTA = 21.37 ms + +Comment: [] = +" + ticket_3_1, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string) + assert_equal(ticket_3.id, ticket_3_1.id) + assert_equal('closed', ticket_3_1.state.name) + assert(ticket_3_1.preferences) + assert(ticket_3_1.preferences['integration']) + assert_equal('nagios', ticket_3_1.preferences['integration']) + assert(ticket_3_1.preferences['nagios']) + assert_equal('apn4711.dc.example.com', ticket_3.preferences['nagios']['host']) + assert_equal(nil, ticket_3_1.preferences['nagios']['service']) + assert_equal('DOWN', ticket_3_1.preferences['nagios']['state']) + #Setting.set('nagios_integration', false) end