From 7f14332fe087b42c0de53a3c96604ca68d47f1b3 Mon Sep 17 00:00:00 2001 From: Marcel Herrguth Date: Mon, 13 Jul 2020 10:44:33 +0200 Subject: [PATCH] Maintenance: Check_MK changed its name to Checkmk. --- .../controllers/_integration/check_mk.coffee | 72 ++++++++----------- .../controllers/widget/script_snipped.coffee | 19 ----- .../app/views/integration/base.jst.eco | 7 +- .../app/views/integration/check_mk.jst.eco | 56 +++++++++++++++ .../app/views/widget/script_snipped.jst.eco | 10 --- .../integration/check_mk_controller.rb | 6 +- ...aintenance_checkmk_wordings_on_settings.rb | 18 +++++ db/seeds/settings.rb | 10 +-- 8 files changed, 112 insertions(+), 86 deletions(-) delete mode 100644 app/assets/javascripts/app/controllers/widget/script_snipped.coffee create mode 100644 app/assets/javascripts/app/views/integration/check_mk.jst.eco delete mode 100644 app/assets/javascripts/app/views/widget/script_snipped.jst.eco create mode 100644 db/migrate/20200709091905_maintenance_checkmk_wordings_on_settings.rb diff --git a/app/assets/javascripts/app/controllers/_integration/check_mk.coffee b/app/assets/javascripts/app/controllers/_integration/check_mk.coffee index 39f6cc98a..3079b129d 100644 --- a/app/assets/javascripts/app/controllers/_integration/check_mk.coffee +++ b/app/assets/javascripts/app/controllers/_integration/check_mk.coffee @@ -1,59 +1,22 @@ class Index extends App.ControllerIntegrationBase featureIntegration: 'check_mk_integration' - featureName: 'Check_MK' + featureName: 'Checkmk' featureConfig: 'check_mk_config' description: [ - ['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.'] + ['This service receives http requests or emails from %s and creates tickets with host and service.', 'Checkmk'] + ['If the host and service has recovered, the ticket can be closed automatically.'] ] render: => super + new App.SettingsForm( area: 'Integration::CheckMK' el: @$('.js-form') ) - new App.ScriptSnipped( - el: @$('.js-scriptSnippedPre') - style: 'bash' - description: [ - ['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'] - ] - ) - - new App.ScriptSnipped( - el: @$('.js-scriptSnipped') - header: 'Service Notification' - style: 'bash' - description: [ - ['Script can be located under: ||%s||', '/opt/omd/site/SITENAME/local/share/check_mk/notifications/zammad-service'] - ['Please make sure that the script is executable: ||%s||', 'chmod +x /opt/omd/site/SITENAME/local/share/check_mk/notifications/zammad-service'] - ] - 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')}" - ) - - new App.ScriptSnipped( - el: @$('.js-scriptSnippedExtended') - header: 'Host Notification' - style: 'bash' - description: [ - ['Script can be located under: ||%s||', '/opt/omd/site/SITENAME/local/share/check_mk/notifications/zammad-host'] - ['Please make sure that the script is executable: ||%s||', 'chmod +x /opt/omd/site/SITENAME/local/share/check_mk/notifications/zammad-host'] - ] - content: "#!/bin/bash\n\ncurl -X POST -F \"event_id=$NOTIFY_HOSTPROBLEMID\" -F \"host=$NOTIFY_HOSTNAME\" -F \"service=$NOTIFY_SERVICEDESC\" -F \"state=$NOTIFY_HOSTSTATE\" -F \"text=$NOTIFY_HOSTOUTPUT\" #{App.Config.get('http_type')}://#{App.Config.get('fqdn')}/api/v1/integration/check_mk/#{App.Setting.get('check_mk_token')}" - ) - - new App.ScriptSnipped( - el: @$('.js-scriptSnippedPost') - header: 'Further Attributes' - style: 'bash' - description: [ - ['It is also possible to set further attributes of created tickets. To do this, you only need to pass one additional parameter.'] - ] - content: '... -F "additional_ticket_attribute=some_value" ...' + new Form( + el: @$('.js-usage') ) new App.HttpLog( @@ -65,10 +28,31 @@ class State @current: -> App.Setting.get('check_mk_integration') +class Form extends App.Controller + events: + 'click .js-tabItem': 'toogle' + 'click .js-select': 'selectAll' + + constructor: -> + super + @render() + + render: -> + @html App.view('integration/check_mk')() + + @$('.js-code').each((i, block) -> + hljs.highlightBlock block + ) + + toogle: (e) => + target = $(e.target).data('tablist') + @$('.js-tablistItem').addClass('hidden') + @$(".js-#{target}").removeClass('hidden') + App.Config.set( 'IntegrationCheckMk' { - name: 'Check_MK' + name: 'Checkmk' target: '#system/integration/check_mk' description: 'An open source monitoring tool.' controller: Index diff --git a/app/assets/javascripts/app/controllers/widget/script_snipped.coffee b/app/assets/javascripts/app/controllers/widget/script_snipped.coffee deleted file mode 100644 index f623b891a..000000000 --- a/app/assets/javascripts/app/controllers/widget/script_snipped.coffee +++ /dev/null @@ -1,19 +0,0 @@ -class App.ScriptSnipped extends App.Controller - elements: - '.js-code': 'code' - - constructor: -> - super - @render() - - render: => - @html App.view('widget/script_snipped')( - header: @header || 'Usage', - description: @description - style: @style - content: @content - ) - - @code.each((i, block) -> - hljs.highlightBlock block - ) diff --git a/app/assets/javascripts/app/views/integration/base.jst.eco b/app/assets/javascripts/app/views/integration/base.jst.eco index a8884ff56..ce7596b8d 100644 --- a/app/assets/javascripts/app/views/integration/base.jst.eco +++ b/app/assets/javascripts/app/views/integration/base.jst.eco @@ -14,9 +14,6 @@ <% end %> <% end %>
-
-
-
-
+
- \ No newline at end of file + diff --git a/app/assets/javascripts/app/views/integration/check_mk.jst.eco b/app/assets/javascripts/app/views/integration/check_mk.jst.eco new file mode 100644 index 000000000..3159483cc --- /dev/null +++ b/app/assets/javascripts/app/views/integration/check_mk.jst.eco @@ -0,0 +1,56 @@ +
+ +

<%- @T('Usage') %>

+ +

<%- @T('To enable %s for sending http requests to %s, you need create a own "notification rule" in %s.', 'Checkmk', 'Zammad', 'Checkmk') %>

+ +
+ + + + + + + +
<%- @T('Type') %> + <%- @T('URL') %> +
<%- @T('Endpoint') %> + +
+ +
+
+
+ +
+ +

<%- @T('Examples') %>

+ +

<%- @T('You can use the following script to post the data to %s.', 'Zammad') %>

+ + + +
+
+

<%- @T('Script can be located under: ||%s|| and needs to be executable.', '/opt/omd/sites/{SITENAME}/local/share/check_mk/notifications/zammad-service') %>

+ +

+#!/bin/bash
+
+curl -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') %>
+    
+
+ + +
diff --git a/app/assets/javascripts/app/views/widget/script_snipped.jst.eco b/app/assets/javascripts/app/views/widget/script_snipped.jst.eco deleted file mode 100644 index d18a59f2f..000000000 --- a/app/assets/javascripts/app/views/widget/script_snipped.jst.eco +++ /dev/null @@ -1,10 +0,0 @@ -
-

<%- @T(@header) %>

-<% if @description: %> - <% for item in @description: %> -

<%- @T(item...) %>

- <% end %> -<% end %> -<% if @content: %> -
<%- @content %>
-<% end %> diff --git a/app/controllers/integration/check_mk_controller.rb b/app/controllers/integration/check_mk_controller.rb index e1310123a..260d232d2 100644 --- a/app/controllers/integration/check_mk_controller.rb +++ b/app/controllers/integration/check_mk_controller.rb @@ -39,11 +39,11 @@ class Integration::CheckMkController < ApplicationController title = "#{params[:host]} is #{params[:state]}" body = "EventID: #{params[:event_id]} Host: #{params[:host]} -Service: #{params[:service]} +Service: #{params[:service] || '-'} State: #{params[:state]} -Text: #{params[:text]} +Text: #{params[:text] || '-'} RemoteIP: #{request.remote_ip} -UserAgent: #{request.env['HTTP_USER_AGENT']} +UserAgent: #{request.env['HTTP_USER_AGENT'] || '-'} " # add article diff --git a/db/migrate/20200709091905_maintenance_checkmk_wordings_on_settings.rb b/db/migrate/20200709091905_maintenance_checkmk_wordings_on_settings.rb new file mode 100644 index 000000000..c2f5155ee --- /dev/null +++ b/db/migrate/20200709091905_maintenance_checkmk_wordings_on_settings.rb @@ -0,0 +1,18 @@ +class MaintenanceCheckmkWordingsOnSettings < ActiveRecord::Migration[5.2] + def change + + # return if it's a new setup + return if !Setting.find_by(name: 'system_init_done') + + Setting.find_by(name: 'check_mk_integration').update!( + title: 'Checkmk integration', + description: 'Defines if Checkmk (https://checkmk.com/) is enabled or not.', + ) + + Setting.find_by(name: 'check_mk_token').update!( + title: 'Checkmk token', + description: 'Defines the Checkmk token for allowing updates.', + ) + + end +end diff --git a/db/seeds/settings.rb b/db/seeds/settings.rb index a09976d39..7aacb571f 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -3681,10 +3681,10 @@ Setting.create_if_not_exists( frontend: false ) Setting.create_if_not_exists( - title: 'Check_MK integration', + title: 'Checkmk integration', name: 'check_mk_integration', area: 'Integration::Switch', - description: 'Defines if Check_MK (http://mathias-kettner.com/check_mk.html) is enabled or not.', + description: 'Defines if Checkmk (https://checkmk.com/) is enabled or not.', options: { form: [ { @@ -3739,7 +3739,7 @@ Setting.create_if_not_exists( { display: '', null: true, - name: 'check_mk_auto_close', + name: 'checkmk_auto_close', tag: 'boolean', options: { true => 'yes', @@ -3779,10 +3779,10 @@ Setting.create_if_not_exists( frontend: false ) Setting.create_if_not_exists( - title: 'Check_MK tolen', + title: 'Checkmk token', name: 'check_mk_token', area: 'Core', - description: 'Defines the Check_MK token for allowing updates.', + description: 'Defines the Checkmk token for allowing updates.', options: {}, state: ENV['CHECK_MK_TOKEN'] || SecureRandom.hex(16), preferences: {