Fixed typo.

This commit is contained in:
Martin Edenhofer 2016-04-12 14:56:41 +02:00
parent aadcfd8668
commit 7c75fd35bd
4 changed files with 56 additions and 55 deletions

View file

@ -1,6 +1,9 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Channel::Filter::Icinga
# rubocop:disable Style/ClassVars
@@integration = 'icinga'
# rubocop:enable Style/ClassVars
# according
# https://github.com/Icinga/icinga2/blob/master/etc/icinga2/scripts/mail-service-notification.sh
@ -8,13 +11,11 @@ module Channel::Filter::Icinga
# http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/monitoring-basics#service-states
def self.run(_channel, mail)
return if !Setting.get('ichinga_integration')
# set config
integration = 'ichinga'
sender = Setting.get('ichinga_sender')
auto_close = Setting.get('ichinga_auto_close')
auto_close_state_id = Setting.get('ichinga_auto_close_state_id')
return if !Setting.get("#{@@integration}_integration")
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'
return if !mail[:from]
@ -22,7 +23,7 @@ module Channel::Filter::Icinga
sender_user_id = mail[ 'x-zammad-customer-id'.to_sym ]
return if !sender_user_id
# check if sender is ichinga
# check if sender is monitoring
return if !mail[:from].match(/#{sender}/i)
# get mail attibutes like host and state
@ -47,11 +48,11 @@ module Channel::Filter::Icinga
Ticket.where(state: open_states).each {|ticket|
next if !ticket.preferences
next if !ticket.preferences['integration']
next if ticket.preferences['integration'] != integration
next if !ticket.preferences['ichinga']
next if !ticket.preferences['ichinga']['host']
next if ticket.preferences['ichinga']['host'] != result['host']
next if ticket.preferences['ichinga']['service'] != result['service']
next if ticket.preferences['integration'] != @@integration
next if !ticket.preferences[@@integration]
next if !ticket.preferences[@@integration]['host']
next if ticket.preferences[@@integration]['host'] != result['host']
next if ticket.preferences[@@integration]['service'] != result['service']
# found open ticket for service+host
mail[ 'x-zammad-ticket-id'.to_sym ] = ticket.id
@ -72,8 +73,8 @@ module Channel::Filter::Icinga
mail[ 'x-zammad-ticket-preferences'.to_sym ] = {}
end
preferences = {}
preferences['integration'] = integration
preferences['ichinga'] = result
preferences['integration'] = @@integration
preferences[@@integration] = result
preferences.each {|key, value|
mail[ 'x-zammad-ticket-preferences'.to_sym ][key] = value
}

View file

@ -56,7 +56,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
)
Setting.create_if_not_exists(
title: 'Define postmaster filter.',
name: '5000_postmaster_filter_ichinga',
name: '5000_postmaster_filter_icinga',
area: 'Postmaster::PreFilter',
description: 'Define postmaster filter for manage Icinga (http://www.icinga.org) emails.',
options: {},
@ -65,7 +65,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
)
Setting.create_if_not_exists(
title: 'Icinga integration',
name: 'ichinga_integration',
name: 'icinga_integration',
area: 'Integration::Icinga',
description: 'Define if Icinga (http://www.icinga.org) is enabled or not.',
options: {
@ -73,7 +73,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
{
display: '',
null: true,
name: 'ichinga_integration',
name: 'icinga_integration',
tag: 'boolean',
options: {
true => 'yes',
@ -88,7 +88,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
)
Setting.create_if_not_exists(
title: 'Sender',
name: 'ichinga_sender',
name: 'icinga_sender',
area: 'Integration::Icinga',
description: 'Define the sender email address of Icinga emails.',
options: {
@ -96,7 +96,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
{
display: '',
null: false,
name: 'ichinga_sender',
name: 'icinga_sender',
tag: 'input',
},
],
@ -107,7 +107,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
)
Setting.create_if_not_exists(
title: 'Auto close',
name: 'ichinga_auto_close',
name: 'icinga_auto_close',
area: 'Integration::Icinga',
description: 'Define if tickets should be closed if service is recovered.',
options: {
@ -115,7 +115,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
{
display: '',
null: true,
name: 'ichinga_auto_close',
name: 'icinga_auto_close',
tag: 'boolean',
options: {
true => 'yes',
@ -130,7 +130,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
)
Setting.create_if_not_exists(
title: 'Auto close state',
name: 'ichinga_auto_close_state_id',
name: 'icinga_auto_close_state_id',
area: 'Integration::Icinga',
description: 'Define the ticket state of auto closed tickets.',
options: {
@ -138,7 +138,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
{
display: '',
null: false,
name: 'ichinga_auto_close_state_id',
name: 'icinga_auto_close_state_id',
tag: 'select',
relation: 'TicketState',
},

View file

@ -1581,7 +1581,7 @@ Setting.create_if_not_exists(
)
Setting.create_if_not_exists(
title: 'Define postmaster filter.',
name: '5000_postmaster_filter_ichinga',
name: '5000_postmaster_filter_icinga',
area: 'Postmaster::PreFilter',
description: 'Define postmaster filter for manage Icinga (http://www.icinga.org) emails.',
options: {},
@ -1590,7 +1590,7 @@ Setting.create_if_not_exists(
)
Setting.create_if_not_exists(
title: 'Icinga integration',
name: 'ichinga_integration',
name: 'icinga_integration',
area: 'Integration::Icinga',
description: 'Define if Icinga (http://www.icinga.org) is enabled or not.',
options: {
@ -1598,7 +1598,7 @@ Setting.create_if_not_exists(
{
display: '',
null: true,
name: 'ichinga_integration',
name: 'icinga_integration',
tag: 'boolean',
options: {
true => 'yes',
@ -1613,7 +1613,7 @@ Setting.create_if_not_exists(
)
Setting.create_if_not_exists(
title: 'Sender',
name: 'ichinga_sender',
name: 'icinga_sender',
area: 'Integration::Icinga',
description: 'Define the sender email address of Icinga emails.',
options: {
@ -1621,7 +1621,7 @@ Setting.create_if_not_exists(
{
display: '',
null: false,
name: 'ichinga_sender',
name: 'icinga_sender',
tag: 'input',
},
],
@ -1632,7 +1632,7 @@ Setting.create_if_not_exists(
)
Setting.create_if_not_exists(
title: 'Auto close',
name: 'ichinga_auto_close',
name: 'icinga_auto_close',
area: 'Integration::Icinga',
description: 'Define if tickets should be closed if service is recovered.',
options: {
@ -1640,7 +1640,7 @@ Setting.create_if_not_exists(
{
display: '',
null: true,
name: 'ichinga_auto_close',
name: 'icinga_auto_close',
tag: 'boolean',
options: {
true => 'yes',
@ -1655,7 +1655,7 @@ Setting.create_if_not_exists(
)
Setting.create_if_not_exists(
title: 'Auto close state',
name: 'ichinga_auto_close_state_id',
name: 'icinga_auto_close_state_id',
area: 'Integration::Icinga',
description: 'Define the ticket state of auto closed tickets.',
options: {
@ -1663,7 +1663,7 @@ Setting.create_if_not_exists(
{
display: '',
null: false,
name: 'ichinga_auto_close_state_id',
name: 'icinga_auto_close_state_id',
tag: 'select',
relation: 'TicketState',
},

View file

@ -5,7 +5,7 @@ class IntegrationIcingaTest < ActiveSupport::TestCase
test 'base tests' do
Setting.set('ichinga_integration', true)
Setting.set('icinga_integration', true)
# not matching sender
email_raw_string = "To: support@example.com
@ -37,7 +37,7 @@ Comment: [] =
assert_equal('new', ticket_p.state.name)
assert(ticket_p.preferences)
assert_not(ticket_p.preferences['integration'])
assert_not(ticket_p.preferences['ichinga'])
assert_not(ticket_p.preferences['icinga'])
# matching sender - CPU Load/host.internal.loc
email_raw_string = "To: support@example.com
@ -69,11 +69,11 @@ Comment: [] =
assert_equal('new', ticket_1.state.name)
assert(ticket_1.preferences)
assert(ticket_1.preferences['integration'])
assert_equal('ichinga', ticket_1.preferences['integration'])
assert(ticket_1.preferences['ichinga'])
assert_equal('host.internal.loc', ticket_1.preferences['ichinga']['host'])
assert_equal('CPU Load', ticket_1.preferences['ichinga']['service'])
assert_equal('WARNING', ticket_1.preferences['ichinga']['state'])
assert_equal('icinga', ticket_1.preferences['integration'])
assert(ticket_1.preferences['icinga'])
assert_equal('host.internal.loc', ticket_1.preferences['icinga']['host'])
assert_equal('CPU Load', ticket_1.preferences['icinga']['service'])
assert_equal('WARNING', ticket_1.preferences['icinga']['state'])
# matching sender - Disk Usage 123/host.internal.loc
email_raw_string = "To: support@example.com
@ -105,11 +105,11 @@ Comment: [] =
assert_equal('new', ticket_2.state.name)
assert(ticket_2.preferences)
assert(ticket_2.preferences['integration'])
assert_equal('ichinga', ticket_2.preferences['integration'])
assert(ticket_2.preferences['ichinga'])
assert_equal('host.internal.loc', ticket_2.preferences['ichinga']['host'])
assert_equal('Disk Usage 123', ticket_2.preferences['ichinga']['service'])
assert_equal('WARNING', ticket_2.preferences['ichinga']['state'])
assert_equal('icinga', ticket_2.preferences['integration'])
assert(ticket_2.preferences['icinga'])
assert_equal('host.internal.loc', ticket_2.preferences['icinga']['host'])
assert_equal('Disk Usage 123', ticket_2.preferences['icinga']['service'])
assert_equal('WARNING', ticket_2.preferences['icinga']['state'])
assert_not_equal(ticket_2.id, ticket_1.id)
# matching sender - follow up - CPU Load/host.internal.loc
@ -142,11 +142,11 @@ Comment: [] =
assert_equal('new', ticket_1_1.state.name)
assert(ticket_1_1.preferences)
assert(ticket_1_1.preferences['integration'])
assert_equal('ichinga', ticket_1_1.preferences['integration'])
assert(ticket_1_1.preferences['ichinga'])
assert_equal('host.internal.loc', ticket_1_1.preferences['ichinga']['host'])
assert_equal('CPU Load', ticket_1_1.preferences['ichinga']['service'])
assert_equal('WARNING', ticket_1_1.preferences['ichinga']['state'])
assert_equal('icinga', ticket_1_1.preferences['integration'])
assert(ticket_1_1.preferences['icinga'])
assert_equal('host.internal.loc', ticket_1_1.preferences['icinga']['host'])
assert_equal('CPU Load', ticket_1_1.preferences['icinga']['service'])
assert_equal('WARNING', ticket_1_1.preferences['icinga']['state'])
assert_equal(ticket_1.id, ticket_1_1.id)
# matching sender - follow up - recovery - CPU Load/host.internal.loc
@ -180,13 +180,13 @@ Comment: [] =
assert_equal('closed', ticket_1_2.state.name)
assert(ticket_1_2.preferences)
assert(ticket_1_2.preferences['integration'])
assert_equal('ichinga', ticket_1_2.preferences['integration'])
assert(ticket_1_2.preferences['ichinga'])
assert_equal('host.internal.loc', ticket_1_2.preferences['ichinga']['host'])
assert_equal('CPU Load', ticket_1_2.preferences['ichinga']['service'])
assert_equal('WARNING', ticket_1_2.preferences['ichinga']['state'])
assert_equal('icinga', ticket_1_2.preferences['integration'])
assert(ticket_1_2.preferences['icinga'])
assert_equal('host.internal.loc', ticket_1_2.preferences['icinga']['host'])
assert_equal('CPU Load', ticket_1_2.preferences['icinga']['service'])
assert_equal('WARNING', ticket_1_2.preferences['icinga']['state'])
#Setting.set('ichinga_integration', false)
#Setting.set('icinga_integration', false)
end