Fixed typo.
This commit is contained in:
parent
aadcfd8668
commit
7c75fd35bd
4 changed files with 56 additions and 55 deletions
|
@ -1,6 +1,9 @@
|
||||||
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
module Channel::Filter::Icinga
|
module Channel::Filter::Icinga
|
||||||
|
# rubocop:disable Style/ClassVars
|
||||||
|
@@integration = 'icinga'
|
||||||
|
# rubocop:enable Style/ClassVars
|
||||||
|
|
||||||
# according
|
# according
|
||||||
# https://github.com/Icinga/icinga2/blob/master/etc/icinga2/scripts/mail-service-notification.sh
|
# 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
|
# http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/monitoring-basics#service-states
|
||||||
|
|
||||||
def self.run(_channel, mail)
|
def self.run(_channel, mail)
|
||||||
return if !Setting.get('ichinga_integration')
|
|
||||||
|
|
||||||
# set config
|
return if !Setting.get("#{@@integration}_integration")
|
||||||
integration = 'ichinga'
|
sender = Setting.get("#{@@integration}_sender")
|
||||||
sender = Setting.get('ichinga_sender')
|
auto_close = Setting.get("#{@@integration}_auto_close")
|
||||||
auto_close = Setting.get('ichinga_auto_close')
|
auto_close_state_id = Setting.get("#{@@integration}_auto_close_state_id")
|
||||||
auto_close_state_id = Setting.get('ichinga_auto_close_state_id')
|
|
||||||
state_recovery_match = 'OK'
|
state_recovery_match = 'OK'
|
||||||
|
|
||||||
return if !mail[:from]
|
return if !mail[:from]
|
||||||
|
@ -22,7 +23,7 @@ module Channel::Filter::Icinga
|
||||||
sender_user_id = mail[ 'x-zammad-customer-id'.to_sym ]
|
sender_user_id = mail[ 'x-zammad-customer-id'.to_sym ]
|
||||||
return if !sender_user_id
|
return if !sender_user_id
|
||||||
|
|
||||||
# check if sender is ichinga
|
# check if sender is monitoring
|
||||||
return if !mail[:from].match(/#{sender}/i)
|
return if !mail[:from].match(/#{sender}/i)
|
||||||
|
|
||||||
# get mail attibutes like host and state
|
# get mail attibutes like host and state
|
||||||
|
@ -47,11 +48,11 @@ module Channel::Filter::Icinga
|
||||||
Ticket.where(state: open_states).each {|ticket|
|
Ticket.where(state: open_states).each {|ticket|
|
||||||
next if !ticket.preferences
|
next if !ticket.preferences
|
||||||
next if !ticket.preferences['integration']
|
next if !ticket.preferences['integration']
|
||||||
next if ticket.preferences['integration'] != integration
|
next if ticket.preferences['integration'] != @@integration
|
||||||
next if !ticket.preferences['ichinga']
|
next if !ticket.preferences[@@integration]
|
||||||
next if !ticket.preferences['ichinga']['host']
|
next if !ticket.preferences[@@integration]['host']
|
||||||
next if ticket.preferences['ichinga']['host'] != result['host']
|
next if ticket.preferences[@@integration]['host'] != result['host']
|
||||||
next if ticket.preferences['ichinga']['service'] != result['service']
|
next if ticket.preferences[@@integration]['service'] != result['service']
|
||||||
|
|
||||||
# found open ticket for service+host
|
# found open ticket for service+host
|
||||||
mail[ 'x-zammad-ticket-id'.to_sym ] = ticket.id
|
mail[ 'x-zammad-ticket-id'.to_sym ] = ticket.id
|
||||||
|
@ -72,8 +73,8 @@ module Channel::Filter::Icinga
|
||||||
mail[ 'x-zammad-ticket-preferences'.to_sym ] = {}
|
mail[ 'x-zammad-ticket-preferences'.to_sym ] = {}
|
||||||
end
|
end
|
||||||
preferences = {}
|
preferences = {}
|
||||||
preferences['integration'] = integration
|
preferences['integration'] = @@integration
|
||||||
preferences['ichinga'] = result
|
preferences[@@integration] = result
|
||||||
preferences.each {|key, value|
|
preferences.each {|key, value|
|
||||||
mail[ 'x-zammad-ticket-preferences'.to_sym ][key] = value
|
mail[ 'x-zammad-ticket-preferences'.to_sym ][key] = value
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
|
||||||
)
|
)
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Define postmaster filter.',
|
title: 'Define postmaster filter.',
|
||||||
name: '5000_postmaster_filter_ichinga',
|
name: '5000_postmaster_filter_icinga',
|
||||||
area: 'Postmaster::PreFilter',
|
area: 'Postmaster::PreFilter',
|
||||||
description: 'Define postmaster filter for manage Icinga (http://www.icinga.org) emails.',
|
description: 'Define postmaster filter for manage Icinga (http://www.icinga.org) emails.',
|
||||||
options: {},
|
options: {},
|
||||||
|
@ -65,7 +65,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
|
||||||
)
|
)
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Icinga integration',
|
title: 'Icinga integration',
|
||||||
name: 'ichinga_integration',
|
name: 'icinga_integration',
|
||||||
area: 'Integration::Icinga',
|
area: 'Integration::Icinga',
|
||||||
description: 'Define if Icinga (http://www.icinga.org) is enabled or not.',
|
description: 'Define if Icinga (http://www.icinga.org) is enabled or not.',
|
||||||
options: {
|
options: {
|
||||||
|
@ -73,7 +73,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
|
||||||
{
|
{
|
||||||
display: '',
|
display: '',
|
||||||
null: true,
|
null: true,
|
||||||
name: 'ichinga_integration',
|
name: 'icinga_integration',
|
||||||
tag: 'boolean',
|
tag: 'boolean',
|
||||||
options: {
|
options: {
|
||||||
true => 'yes',
|
true => 'yes',
|
||||||
|
@ -88,7 +88,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
|
||||||
)
|
)
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Sender',
|
title: 'Sender',
|
||||||
name: 'ichinga_sender',
|
name: 'icinga_sender',
|
||||||
area: 'Integration::Icinga',
|
area: 'Integration::Icinga',
|
||||||
description: 'Define the sender email address of Icinga emails.',
|
description: 'Define the sender email address of Icinga emails.',
|
||||||
options: {
|
options: {
|
||||||
|
@ -96,7 +96,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
|
||||||
{
|
{
|
||||||
display: '',
|
display: '',
|
||||||
null: false,
|
null: false,
|
||||||
name: 'ichinga_sender',
|
name: 'icinga_sender',
|
||||||
tag: 'input',
|
tag: 'input',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -107,7 +107,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
|
||||||
)
|
)
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Auto close',
|
title: 'Auto close',
|
||||||
name: 'ichinga_auto_close',
|
name: 'icinga_auto_close',
|
||||||
area: 'Integration::Icinga',
|
area: 'Integration::Icinga',
|
||||||
description: 'Define if tickets should be closed if service is recovered.',
|
description: 'Define if tickets should be closed if service is recovered.',
|
||||||
options: {
|
options: {
|
||||||
|
@ -115,7 +115,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
|
||||||
{
|
{
|
||||||
display: '',
|
display: '',
|
||||||
null: true,
|
null: true,
|
||||||
name: 'ichinga_auto_close',
|
name: 'icinga_auto_close',
|
||||||
tag: 'boolean',
|
tag: 'boolean',
|
||||||
options: {
|
options: {
|
||||||
true => 'yes',
|
true => 'yes',
|
||||||
|
@ -130,7 +130,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
|
||||||
)
|
)
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Auto close state',
|
title: 'Auto close state',
|
||||||
name: 'ichinga_auto_close_state_id',
|
name: 'icinga_auto_close_state_id',
|
||||||
area: 'Integration::Icinga',
|
area: 'Integration::Icinga',
|
||||||
description: 'Define the ticket state of auto closed tickets.',
|
description: 'Define the ticket state of auto closed tickets.',
|
||||||
options: {
|
options: {
|
||||||
|
@ -138,7 +138,7 @@ class AddIchingaIntegration < ActiveRecord::Migration
|
||||||
{
|
{
|
||||||
display: '',
|
display: '',
|
||||||
null: false,
|
null: false,
|
||||||
name: 'ichinga_auto_close_state_id',
|
name: 'icinga_auto_close_state_id',
|
||||||
tag: 'select',
|
tag: 'select',
|
||||||
relation: 'TicketState',
|
relation: 'TicketState',
|
||||||
},
|
},
|
||||||
|
|
18
db/seeds.rb
18
db/seeds.rb
|
@ -1581,7 +1581,7 @@ Setting.create_if_not_exists(
|
||||||
)
|
)
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Define postmaster filter.',
|
title: 'Define postmaster filter.',
|
||||||
name: '5000_postmaster_filter_ichinga',
|
name: '5000_postmaster_filter_icinga',
|
||||||
area: 'Postmaster::PreFilter',
|
area: 'Postmaster::PreFilter',
|
||||||
description: 'Define postmaster filter for manage Icinga (http://www.icinga.org) emails.',
|
description: 'Define postmaster filter for manage Icinga (http://www.icinga.org) emails.',
|
||||||
options: {},
|
options: {},
|
||||||
|
@ -1590,7 +1590,7 @@ Setting.create_if_not_exists(
|
||||||
)
|
)
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Icinga integration',
|
title: 'Icinga integration',
|
||||||
name: 'ichinga_integration',
|
name: 'icinga_integration',
|
||||||
area: 'Integration::Icinga',
|
area: 'Integration::Icinga',
|
||||||
description: 'Define if Icinga (http://www.icinga.org) is enabled or not.',
|
description: 'Define if Icinga (http://www.icinga.org) is enabled or not.',
|
||||||
options: {
|
options: {
|
||||||
|
@ -1598,7 +1598,7 @@ Setting.create_if_not_exists(
|
||||||
{
|
{
|
||||||
display: '',
|
display: '',
|
||||||
null: true,
|
null: true,
|
||||||
name: 'ichinga_integration',
|
name: 'icinga_integration',
|
||||||
tag: 'boolean',
|
tag: 'boolean',
|
||||||
options: {
|
options: {
|
||||||
true => 'yes',
|
true => 'yes',
|
||||||
|
@ -1613,7 +1613,7 @@ Setting.create_if_not_exists(
|
||||||
)
|
)
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Sender',
|
title: 'Sender',
|
||||||
name: 'ichinga_sender',
|
name: 'icinga_sender',
|
||||||
area: 'Integration::Icinga',
|
area: 'Integration::Icinga',
|
||||||
description: 'Define the sender email address of Icinga emails.',
|
description: 'Define the sender email address of Icinga emails.',
|
||||||
options: {
|
options: {
|
||||||
|
@ -1621,7 +1621,7 @@ Setting.create_if_not_exists(
|
||||||
{
|
{
|
||||||
display: '',
|
display: '',
|
||||||
null: false,
|
null: false,
|
||||||
name: 'ichinga_sender',
|
name: 'icinga_sender',
|
||||||
tag: 'input',
|
tag: 'input',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1632,7 +1632,7 @@ Setting.create_if_not_exists(
|
||||||
)
|
)
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Auto close',
|
title: 'Auto close',
|
||||||
name: 'ichinga_auto_close',
|
name: 'icinga_auto_close',
|
||||||
area: 'Integration::Icinga',
|
area: 'Integration::Icinga',
|
||||||
description: 'Define if tickets should be closed if service is recovered.',
|
description: 'Define if tickets should be closed if service is recovered.',
|
||||||
options: {
|
options: {
|
||||||
|
@ -1640,7 +1640,7 @@ Setting.create_if_not_exists(
|
||||||
{
|
{
|
||||||
display: '',
|
display: '',
|
||||||
null: true,
|
null: true,
|
||||||
name: 'ichinga_auto_close',
|
name: 'icinga_auto_close',
|
||||||
tag: 'boolean',
|
tag: 'boolean',
|
||||||
options: {
|
options: {
|
||||||
true => 'yes',
|
true => 'yes',
|
||||||
|
@ -1655,7 +1655,7 @@ Setting.create_if_not_exists(
|
||||||
)
|
)
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Auto close state',
|
title: 'Auto close state',
|
||||||
name: 'ichinga_auto_close_state_id',
|
name: 'icinga_auto_close_state_id',
|
||||||
area: 'Integration::Icinga',
|
area: 'Integration::Icinga',
|
||||||
description: 'Define the ticket state of auto closed tickets.',
|
description: 'Define the ticket state of auto closed tickets.',
|
||||||
options: {
|
options: {
|
||||||
|
@ -1663,7 +1663,7 @@ Setting.create_if_not_exists(
|
||||||
{
|
{
|
||||||
display: '',
|
display: '',
|
||||||
null: false,
|
null: false,
|
||||||
name: 'ichinga_auto_close_state_id',
|
name: 'icinga_auto_close_state_id',
|
||||||
tag: 'select',
|
tag: 'select',
|
||||||
relation: 'TicketState',
|
relation: 'TicketState',
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,7 +5,7 @@ class IntegrationIcingaTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
test 'base tests' do
|
test 'base tests' do
|
||||||
|
|
||||||
Setting.set('ichinga_integration', true)
|
Setting.set('icinga_integration', true)
|
||||||
|
|
||||||
# not matching sender
|
# not matching sender
|
||||||
email_raw_string = "To: support@example.com
|
email_raw_string = "To: support@example.com
|
||||||
|
@ -37,7 +37,7 @@ Comment: [] =
|
||||||
assert_equal('new', ticket_p.state.name)
|
assert_equal('new', ticket_p.state.name)
|
||||||
assert(ticket_p.preferences)
|
assert(ticket_p.preferences)
|
||||||
assert_not(ticket_p.preferences['integration'])
|
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
|
# matching sender - CPU Load/host.internal.loc
|
||||||
email_raw_string = "To: support@example.com
|
email_raw_string = "To: support@example.com
|
||||||
|
@ -69,11 +69,11 @@ Comment: [] =
|
||||||
assert_equal('new', ticket_1.state.name)
|
assert_equal('new', ticket_1.state.name)
|
||||||
assert(ticket_1.preferences)
|
assert(ticket_1.preferences)
|
||||||
assert(ticket_1.preferences['integration'])
|
assert(ticket_1.preferences['integration'])
|
||||||
assert_equal('ichinga', ticket_1.preferences['integration'])
|
assert_equal('icinga', ticket_1.preferences['integration'])
|
||||||
assert(ticket_1.preferences['ichinga'])
|
assert(ticket_1.preferences['icinga'])
|
||||||
assert_equal('host.internal.loc', ticket_1.preferences['ichinga']['host'])
|
assert_equal('host.internal.loc', ticket_1.preferences['icinga']['host'])
|
||||||
assert_equal('CPU Load', ticket_1.preferences['ichinga']['service'])
|
assert_equal('CPU Load', ticket_1.preferences['icinga']['service'])
|
||||||
assert_equal('WARNING', ticket_1.preferences['ichinga']['state'])
|
assert_equal('WARNING', ticket_1.preferences['icinga']['state'])
|
||||||
|
|
||||||
# matching sender - Disk Usage 123/host.internal.loc
|
# matching sender - Disk Usage 123/host.internal.loc
|
||||||
email_raw_string = "To: support@example.com
|
email_raw_string = "To: support@example.com
|
||||||
|
@ -105,11 +105,11 @@ Comment: [] =
|
||||||
assert_equal('new', ticket_2.state.name)
|
assert_equal('new', ticket_2.state.name)
|
||||||
assert(ticket_2.preferences)
|
assert(ticket_2.preferences)
|
||||||
assert(ticket_2.preferences['integration'])
|
assert(ticket_2.preferences['integration'])
|
||||||
assert_equal('ichinga', ticket_2.preferences['integration'])
|
assert_equal('icinga', ticket_2.preferences['integration'])
|
||||||
assert(ticket_2.preferences['ichinga'])
|
assert(ticket_2.preferences['icinga'])
|
||||||
assert_equal('host.internal.loc', ticket_2.preferences['ichinga']['host'])
|
assert_equal('host.internal.loc', ticket_2.preferences['icinga']['host'])
|
||||||
assert_equal('Disk Usage 123', ticket_2.preferences['ichinga']['service'])
|
assert_equal('Disk Usage 123', ticket_2.preferences['icinga']['service'])
|
||||||
assert_equal('WARNING', ticket_2.preferences['ichinga']['state'])
|
assert_equal('WARNING', ticket_2.preferences['icinga']['state'])
|
||||||
assert_not_equal(ticket_2.id, ticket_1.id)
|
assert_not_equal(ticket_2.id, ticket_1.id)
|
||||||
|
|
||||||
# matching sender - follow up - CPU Load/host.internal.loc
|
# matching sender - follow up - CPU Load/host.internal.loc
|
||||||
|
@ -142,11 +142,11 @@ Comment: [] =
|
||||||
assert_equal('new', ticket_1_1.state.name)
|
assert_equal('new', ticket_1_1.state.name)
|
||||||
assert(ticket_1_1.preferences)
|
assert(ticket_1_1.preferences)
|
||||||
assert(ticket_1_1.preferences['integration'])
|
assert(ticket_1_1.preferences['integration'])
|
||||||
assert_equal('ichinga', ticket_1_1.preferences['integration'])
|
assert_equal('icinga', ticket_1_1.preferences['integration'])
|
||||||
assert(ticket_1_1.preferences['ichinga'])
|
assert(ticket_1_1.preferences['icinga'])
|
||||||
assert_equal('host.internal.loc', ticket_1_1.preferences['ichinga']['host'])
|
assert_equal('host.internal.loc', ticket_1_1.preferences['icinga']['host'])
|
||||||
assert_equal('CPU Load', ticket_1_1.preferences['ichinga']['service'])
|
assert_equal('CPU Load', ticket_1_1.preferences['icinga']['service'])
|
||||||
assert_equal('WARNING', ticket_1_1.preferences['ichinga']['state'])
|
assert_equal('WARNING', ticket_1_1.preferences['icinga']['state'])
|
||||||
assert_equal(ticket_1.id, ticket_1_1.id)
|
assert_equal(ticket_1.id, ticket_1_1.id)
|
||||||
|
|
||||||
# matching sender - follow up - recovery - CPU Load/host.internal.loc
|
# matching sender - follow up - recovery - CPU Load/host.internal.loc
|
||||||
|
@ -180,13 +180,13 @@ Comment: [] =
|
||||||
assert_equal('closed', ticket_1_2.state.name)
|
assert_equal('closed', ticket_1_2.state.name)
|
||||||
assert(ticket_1_2.preferences)
|
assert(ticket_1_2.preferences)
|
||||||
assert(ticket_1_2.preferences['integration'])
|
assert(ticket_1_2.preferences['integration'])
|
||||||
assert_equal('ichinga', ticket_1_2.preferences['integration'])
|
assert_equal('icinga', ticket_1_2.preferences['integration'])
|
||||||
assert(ticket_1_2.preferences['ichinga'])
|
assert(ticket_1_2.preferences['icinga'])
|
||||||
assert_equal('host.internal.loc', ticket_1_2.preferences['ichinga']['host'])
|
assert_equal('host.internal.loc', ticket_1_2.preferences['icinga']['host'])
|
||||||
assert_equal('CPU Load', ticket_1_2.preferences['ichinga']['service'])
|
assert_equal('CPU Load', ticket_1_2.preferences['icinga']['service'])
|
||||||
assert_equal('WARNING', ticket_1_2.preferences['ichinga']['state'])
|
assert_equal('WARNING', ticket_1_2.preferences['icinga']['state'])
|
||||||
|
|
||||||
#Setting.set('ichinga_integration', false)
|
#Setting.set('icinga_integration', false)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue