From 77ba57444931731f244636e5ada653ff8f3ddcb7 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 25 Oct 2017 13:20:10 +0200 Subject: [PATCH] Added email channel for Check_MK integration. --- .../controllers/_integration/check_mk.coffee | 9 ++-- app/models/channel/filter/check_mk.rb | 7 ++++ ...> 20171024000002_check_mk_integration2.rb} | 42 +++++++++++++++++-- 3 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 app/models/channel/filter/check_mk.rb rename db/migrate/{20170820000001_check_mk_integration.rb => 20171024000002_check_mk_integration2.rb} (72%) diff --git a/app/assets/javascripts/app/controllers/_integration/check_mk.coffee b/app/assets/javascripts/app/controllers/_integration/check_mk.coffee index 33c58ecf4..7a4c58903 100644 --- a/app/assets/javascripts/app/controllers/_integration/check_mk.coffee +++ b/app/assets/javascripts/app/controllers/_integration/check_mk.coffee @@ -3,7 +3,7 @@ class Index extends App.ControllerIntegrationBase featureName: 'Check_MK' featureConfig: 'check_mk_config' description: [ - ['This service receives http requests from %s and creates tickets with host and service.', 'Check_MK'] + ['This service receives http requests or emails from %s and creates tickets with host and service.', 'Check_MK'] ['If the host and service is recovered again, the ticket will be closed automatically.'] ] @@ -18,9 +18,11 @@ class Index extends App.ControllerIntegrationBase el: @$('.js-scriptSnipped') facility: 'check_mk' style: 'bash' - content: "#!/bin/bash\n\ncurl -X POST -F 'event_id=123' -F 'host=host1' -F 'service=http' -F 'state=down' #{App.Config.get('http_type')}://#{App.Config.get('fqdn')}/api/v1/integration/check_mk/#{App.Setting.get('check_mk_token')}" + content: "#!/bin/bash\n\ncurl -X POST -F \"event_id=$NOTIFY_SERVICEPROBLEMID\" -F \"host=$NOTIFY_HOSTNAME\" -F \"service=$NOTIFY_SERVICEDESC\" -F \"state=$NOTIFY_SERVICESTATE\" -F \"text=$NOTIFY_SERVICEOUTPUT\" #{App.Config.get('http_type')}://#{App.Config.get('fqdn')}/api/v1/integration/check_mk/#{App.Setting.get('check_mk_token')}" description: [ - ['To enable %s for sending http requests to %s, you need create "%s" in the admin interface if %s.', 'Check_MK', 'Zammad', 'Event Actions', 'Check_MK'] + ['To enable %s for sending http requests to %s, you need create a own "notification rule" in %s.', 'Check_MK', 'Zammad', 'Check_MK'] + ['Configurable in the admin interface of %s.', 'Check_MK'] + ['You can use the following script to post the data to %s.', 'Zammad'] ] ) @@ -41,6 +43,7 @@ App.Config.set( description: 'An open source monitoring tool.' controller: Index state: State + permission: ['admin.integration.check_mk'] } 'NavBarIntegrations' ) diff --git a/app/models/channel/filter/check_mk.rb b/app/models/channel/filter/check_mk.rb new file mode 100644 index 000000000..2d4c85989 --- /dev/null +++ b/app/models/channel/filter/check_mk.rb @@ -0,0 +1,7 @@ +# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ + +class Channel::Filter::CheckMk < Channel::Filter::MonitoringBase + def self.integration_name + 'check_mk' + end +end diff --git a/db/migrate/20170820000001_check_mk_integration.rb b/db/migrate/20171024000002_check_mk_integration2.rb similarity index 72% rename from db/migrate/20170820000001_check_mk_integration.rb rename to db/migrate/20171024000002_check_mk_integration2.rb index c8d390a2b..9b38e652b 100644 --- a/db/migrate/20170820000001_check_mk_integration.rb +++ b/db/migrate/20171024000002_check_mk_integration2.rb @@ -1,4 +1,4 @@ -class CheckMkIntegration < ActiveRecord::Migration[4.2] +class CheckMkIntegration2 < ActiveRecord::Migration[4.2] def up # return if it's a new setup @@ -30,6 +30,29 @@ class CheckMkIntegration < ActiveRecord::Migration[4.2] }, frontend: false ) + Setting.create_if_not_exists( + title: 'Sender', + name: 'check_mk_sender', + area: 'Integration::CheckMK', + description: 'Defines the sender email address of the service emails.', + options: { + form: [ + { + display: '', + null: false, + name: 'check_mk_sender', + tag: 'input', + placeholder: 'check_mk@monitoring.example.com', + }, + ], + }, + state: 'check_mk@monitoring.example.com', + preferences: { + prio: 2, + permission: ['admin.integration'], + }, + frontend: false, + ) Setting.create_if_not_exists( title: 'Group', name: 'check_mk_group_id', @@ -48,7 +71,7 @@ class CheckMkIntegration < ActiveRecord::Migration[4.2] }, state: 1, preferences: { - prio: 2, + prio: 3, permission: ['admin.integration'], }, frontend: false @@ -69,12 +92,13 @@ class CheckMkIntegration < ActiveRecord::Migration[4.2] true => 'yes', false => 'no', }, + translate: true, }, ], }, state: true, preferences: { - prio: 3, + prio: 4, permission: ['admin.integration'], }, frontend: false @@ -92,12 +116,13 @@ class CheckMkIntegration < ActiveRecord::Migration[4.2] name: 'check_mk_auto_close_state_id', tag: 'select', relation: 'TicketState', + translate: true, }, ], }, state: 4, preferences: { - prio: 4, + prio: 5, permission: ['admin.integration'], }, frontend: false @@ -114,6 +139,15 @@ class CheckMkIntegration < ActiveRecord::Migration[4.2] }, frontend: false ) + Setting.create_if_not_exists( + title: 'Defines postmaster filter.', + name: '5200_postmaster_filter_check_mk', + area: 'Postmaster::PreFilter', + description: 'Defines postmaster filter to manage Check_MK (http://mathias-kettner.com/check_mk.html) emails.', + options: {}, + state: 'Channel::Filter::CheckMk', + frontend: false + ) end end