Initial Check_MK integration.
This commit is contained in:
parent
ab33cd491d
commit
24696c00ee
20 changed files with 780 additions and 76 deletions
|
@ -0,0 +1,46 @@
|
||||||
|
class Index extends App.ControllerIntegrationBase
|
||||||
|
featureIntegration: 'check_mk_integration'
|
||||||
|
featureName: 'Check_MK'
|
||||||
|
featureConfig: 'check_mk_config'
|
||||||
|
description: [
|
||||||
|
['This service receives http requests 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.']
|
||||||
|
]
|
||||||
|
|
||||||
|
render: =>
|
||||||
|
super
|
||||||
|
new App.SettingsForm(
|
||||||
|
area: 'Integration::CheckMK'
|
||||||
|
el: @$('.js-form')
|
||||||
|
)
|
||||||
|
|
||||||
|
new App.ScriptSnipped(
|
||||||
|
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')}"
|
||||||
|
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']
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
new App.HttpLog(
|
||||||
|
el: @$('.js-log')
|
||||||
|
facility: 'check_mk'
|
||||||
|
)
|
||||||
|
|
||||||
|
class State
|
||||||
|
@current: ->
|
||||||
|
App.Setting.get('check_mk_integration')
|
||||||
|
|
||||||
|
App.Config.set(
|
||||||
|
'IntegrationCheckMk'
|
||||||
|
{
|
||||||
|
name: 'Check_MK'
|
||||||
|
target: '#system/integration/check_mk'
|
||||||
|
description: 'An open source monitoring tool.'
|
||||||
|
controller: Index
|
||||||
|
state: State
|
||||||
|
}
|
||||||
|
'NavBarIntegrations'
|
||||||
|
)
|
|
@ -1,7 +1,7 @@
|
||||||
class SidebarCustomer extends App.Controller
|
class SidebarCustomer extends App.Controller
|
||||||
sidebarItem: =>
|
sidebarItem: =>
|
||||||
return if !@permissionCheck('ticket.agent')
|
return if !@permissionCheck('ticket.agent')
|
||||||
{
|
items = {
|
||||||
head: 'Customer'
|
head: 'Customer'
|
||||||
name: 'customer'
|
name: 'customer'
|
||||||
icon: 'person'
|
icon: 'person'
|
||||||
|
@ -11,14 +11,16 @@ class SidebarCustomer extends App.Controller
|
||||||
name: 'customer-change'
|
name: 'customer-change'
|
||||||
callback: @changeCustomer
|
callback: @changeCustomer
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: 'Edit Customer'
|
|
||||||
name: 'customer-edit'
|
|
||||||
callback: @editCustomer
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
callback: @showCustomer
|
callback: @showCustomer
|
||||||
}
|
}
|
||||||
|
return items if @ticket && @ticket.customer_id == 1
|
||||||
|
items.actions.push {
|
||||||
|
title: 'Edit Customer'
|
||||||
|
name: 'customer-edit'
|
||||||
|
callback: @editCustomer
|
||||||
|
}
|
||||||
|
items
|
||||||
|
|
||||||
showCustomer: (el) =>
|
showCustomer: (el) =>
|
||||||
@el = el
|
@el = el
|
||||||
|
|
|
@ -25,6 +25,7 @@ class App.HttpLog extends App.Controller
|
||||||
render: =>
|
render: =>
|
||||||
@html App.view('widget/http_log')(
|
@html App.view('widget/http_log')(
|
||||||
records: @records
|
records: @records
|
||||||
|
description: @description
|
||||||
)
|
)
|
||||||
|
|
||||||
show: (e) =>
|
show: (e) =>
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
class App.ScriptSnipped extends App.Controller
|
||||||
|
#events:
|
||||||
|
# 'click .js-record': 'show'
|
||||||
|
|
||||||
|
elements:
|
||||||
|
'.js-code': 'code'
|
||||||
|
|
||||||
|
|
||||||
|
constructor: ->
|
||||||
|
super
|
||||||
|
#@fetch()
|
||||||
|
@records = []
|
||||||
|
@render()
|
||||||
|
|
||||||
|
render: =>
|
||||||
|
@html App.view('widget/script_snipped')(
|
||||||
|
records: @records
|
||||||
|
description: @description
|
||||||
|
style: @style
|
||||||
|
content: @content
|
||||||
|
)
|
||||||
|
|
||||||
|
@code.each (i, block) ->
|
||||||
|
hljs.highlightBlock block
|
File diff suppressed because one or more lines are too long
|
@ -10,9 +10,10 @@
|
||||||
<div class="page-content">
|
<div class="page-content">
|
||||||
<% if @description: %>
|
<% if @description: %>
|
||||||
<% for item in @description: %>
|
<% for item in @description: %>
|
||||||
<p><%- @T(item[0], item[1], item[2]) %></p>
|
<p><%- @T(item...) %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="js-form"></div>
|
<div class="js-form"></div>
|
||||||
|
<div class="js-scriptSnipped"></div>
|
||||||
<div class="js-log"></div>
|
<div class="js-log"></div>
|
||||||
</div>
|
</div>
|
|
@ -1,11 +1,15 @@
|
||||||
<hr>
|
<hr>
|
||||||
|
<h2><%- @T('Recent logs') %></h2>
|
||||||
<h2><%- @T('Recent logs') %></h2>
|
<% if @description: %>
|
||||||
<div class="settings-entry">
|
<% for item in @description: %>
|
||||||
|
<p><%- @T(item...) %></p>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<div class="settings-entry">
|
||||||
<% if !@records.length: %>
|
<% if !@records.length: %>
|
||||||
<table class="settings-list settings-list--stretch settings-list--placeholder">
|
<table class="settings-list settings-list--stretch settings-list--placeholder">
|
||||||
<thead><tr><th><%- @T('No Entries') %>
|
<thead><tr><th><%- @T('No Entries') %>
|
||||||
</table>
|
</table>
|
||||||
<% else: %>
|
<% else: %>
|
||||||
<table class="settings-list settings-list--stretch">
|
<table class="settings-list settings-list--stretch">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -24,4 +28,4 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<hr>
|
||||||
|
<h2><%- @T('Usage') %></h2>
|
||||||
|
<% if @description: %>
|
||||||
|
<% for item in @description: %>
|
||||||
|
<p><%- @T(item...) %></p>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<pre><code class="language-<%- @style %> js-code"><%- @content %></code></pre>
|
|
@ -15,22 +15,26 @@ module ApplicationController::HandlesErrors
|
||||||
def not_found(e)
|
def not_found(e)
|
||||||
logger.error e
|
logger.error e
|
||||||
respond_to_exception(e, :not_found)
|
respond_to_exception(e, :not_found)
|
||||||
|
http_log
|
||||||
end
|
end
|
||||||
|
|
||||||
def unprocessable_entity(e)
|
def unprocessable_entity(e)
|
||||||
logger.error e
|
logger.error e
|
||||||
respond_to_exception(e, :unprocessable_entity)
|
respond_to_exception(e, :unprocessable_entity)
|
||||||
|
http_log
|
||||||
end
|
end
|
||||||
|
|
||||||
def internal_server_error(e)
|
def internal_server_error(e)
|
||||||
logger.error e
|
logger.error e
|
||||||
respond_to_exception(e, :internal_server_error)
|
respond_to_exception(e, :internal_server_error)
|
||||||
|
http_log
|
||||||
end
|
end
|
||||||
|
|
||||||
def unauthorized(e)
|
def unauthorized(e)
|
||||||
error = humanize_error(e.message)
|
error = humanize_error(e.message)
|
||||||
response.headers['X-Failure'] = error.fetch(:error_human, error[:error])
|
response.headers['X-Failure'] = error.fetch(:error_human, error[:error])
|
||||||
respond_to_exception(e, :unauthorized)
|
respond_to_exception(e, :unauthorized)
|
||||||
|
http_log
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
138
app/controllers/integration/check_mk_controller.rb
Normal file
138
app/controllers/integration/check_mk_controller.rb
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
|
class Integration::CheckMkController < ApplicationController
|
||||||
|
skip_before_action :verify_csrf_token
|
||||||
|
before_action :check_configured
|
||||||
|
|
||||||
|
def update
|
||||||
|
|
||||||
|
# check params
|
||||||
|
raise Exceptions::UnprocessableEntity, 'event_id is missing!' if params[:event_id].blank?
|
||||||
|
raise Exceptions::UnprocessableEntity, 'state is missing!' if params[:state].blank?
|
||||||
|
raise Exceptions::UnprocessableEntity, 'host is missing!' if params[:host].blank?
|
||||||
|
|
||||||
|
# search for open ticket
|
||||||
|
auto_close = Setting.get('check_mk_auto_close')
|
||||||
|
auto_close_state_id = Setting.get('check_mk_auto_close_state_id')
|
||||||
|
group_id = Setting.get('check_mk_group_id')
|
||||||
|
state_recovery_match = '(OK|UP)'
|
||||||
|
|
||||||
|
# check if ticket with host is open
|
||||||
|
customer = User.lookup(id: 1)
|
||||||
|
|
||||||
|
# follow up detection by meta data
|
||||||
|
integration = 'check_mk'
|
||||||
|
open_states = Ticket::State.by_category(:open)
|
||||||
|
ticket_ids = Ticket.where(state: open_states).order(created_at: :desc).limit(5000).pluck(:id)
|
||||||
|
ticket_ids_found = []
|
||||||
|
ticket_ids.each { |ticket_id|
|
||||||
|
ticket = Ticket.find_by(id: ticket_id)
|
||||||
|
next if !ticket
|
||||||
|
next if !ticket.preferences
|
||||||
|
next if !ticket.preferences[integration]
|
||||||
|
next if !ticket.preferences[integration]['host']
|
||||||
|
next if ticket.preferences[integration]['host'] != params[:host]
|
||||||
|
next if ticket.preferences[integration]['service'] != params[:service]
|
||||||
|
|
||||||
|
# found open ticket for service+host
|
||||||
|
ticket_ids_found.push ticket.id
|
||||||
|
}
|
||||||
|
|
||||||
|
# new ticket, set meta data
|
||||||
|
title = "#{params[:host]} is #{params[:state]}"
|
||||||
|
body = "EventID: #{params[:event_id]}
|
||||||
|
Host: #{params[:host]}
|
||||||
|
Service: #{params[:service]}
|
||||||
|
State: #{params[:state]}
|
||||||
|
Text: #{params[:text]}
|
||||||
|
RemoteIP: #{request.remote_ip}
|
||||||
|
UserAgent: #{request.env['HTTP_USER_AGENT']}
|
||||||
|
"
|
||||||
|
|
||||||
|
# add article
|
||||||
|
if params[:state].present? && ticket_ids_found.present?
|
||||||
|
ticket_ids_found.each { |ticket_id|
|
||||||
|
ticket = Ticket.find_by(id: ticket_id)
|
||||||
|
next if !ticket
|
||||||
|
article = Ticket::Article.create!(
|
||||||
|
ticket_id: ticket_id,
|
||||||
|
type_id: Ticket::Article::Type.find_by(name: 'web').id,
|
||||||
|
sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
|
||||||
|
body: body,
|
||||||
|
subject: title,
|
||||||
|
internal: false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (!auto_close && params[:state].match(/#{state_recovery_match}/i)) || !params[:state].match(/#{state_recovery_match}/i)
|
||||||
|
render json: {
|
||||||
|
result: 'ticket already open, added note',
|
||||||
|
ticket_ids: ticket_ids_found,
|
||||||
|
}
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# check if service is recovered
|
||||||
|
if auto_close && params[:state].present? && params[:state].match(/#{state_recovery_match}/i)
|
||||||
|
if ticket_ids_found.blank?
|
||||||
|
render json: {
|
||||||
|
result: 'no open tickets found, ignore action',
|
||||||
|
}
|
||||||
|
return
|
||||||
|
end
|
||||||
|
state = Ticket::State.lookup(id: auto_close_state_id)
|
||||||
|
ticket_ids_found.each { |ticket_id|
|
||||||
|
ticket = Ticket.find_by(id: ticket_id)
|
||||||
|
next if !ticket
|
||||||
|
ticket.state_id = auto_close_state_id
|
||||||
|
ticket.save!
|
||||||
|
}
|
||||||
|
render json: {
|
||||||
|
result: "closed tickets with ids #{ticket_ids_found.join(',')}",
|
||||||
|
ticket_ids: ticket_ids_found,
|
||||||
|
}
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
ticket = Ticket.create!(
|
||||||
|
group_id: group_id,
|
||||||
|
customer_id: customer.id,
|
||||||
|
title: title,
|
||||||
|
preferences: {
|
||||||
|
check_mk: {
|
||||||
|
host: params[:host],
|
||||||
|
service: params[:service],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
article = Ticket::Article.create!(
|
||||||
|
ticket_id: ticket.id,
|
||||||
|
type_id: Ticket::Article::Type.find_by(name: 'web').id,
|
||||||
|
sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
|
||||||
|
body: body,
|
||||||
|
subject: title,
|
||||||
|
internal: false,
|
||||||
|
)
|
||||||
|
|
||||||
|
render json: {
|
||||||
|
result: "new ticket created (ticket id: #{ticket.id})",
|
||||||
|
ticket_id: ticket.id,
|
||||||
|
ticket_number: ticket.number,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def check_configured
|
||||||
|
http_log_config facility: 'check_mk'
|
||||||
|
|
||||||
|
if !Setting.get('check_mk_integration')
|
||||||
|
raise Exceptions::UnprocessableEntity, 'Feature is disable, please contact your admin to enable it!'
|
||||||
|
end
|
||||||
|
|
||||||
|
if Setting.get('check_mk_token') != params[:token]
|
||||||
|
raise Exceptions::UnprocessableEntity, 'Invalid token!'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -62,8 +62,6 @@ class Channel::Filter::MonitoringBase
|
||||||
ticket = Ticket.find_by(id: ticket_id)
|
ticket = Ticket.find_by(id: ticket_id)
|
||||||
next if !ticket
|
next if !ticket
|
||||||
next if !ticket.preferences
|
next if !ticket.preferences
|
||||||
next if !ticket.preferences['integration']
|
|
||||||
next if ticket.preferences['integration'] != integration
|
|
||||||
next if !ticket.preferences[integration]
|
next if !ticket.preferences[integration]
|
||||||
next if !ticket.preferences[integration]['host']
|
next if !ticket.preferences[integration]['host']
|
||||||
next if ticket.preferences[integration]['host'] != result['host']
|
next if ticket.preferences[integration]['host'] != result['host']
|
||||||
|
@ -88,7 +86,6 @@ class Channel::Filter::MonitoringBase
|
||||||
mail[ 'x-zammad-ticket-preferences'.to_sym ] = {}
|
mail[ 'x-zammad-ticket-preferences'.to_sym ] = {}
|
||||||
end
|
end
|
||||||
preferences = {}
|
preferences = {}
|
||||||
preferences['integration'] = integration
|
|
||||||
preferences[integration] = 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
|
||||||
|
|
|
@ -7,6 +7,9 @@ class Observer::Ticket::UserTicketCounter::BackgroundJob
|
||||||
def perform
|
def perform
|
||||||
|
|
||||||
# open ticket count
|
# open ticket count
|
||||||
|
tickets_open = 0
|
||||||
|
tickets_closed = 0
|
||||||
|
if @customer_id != 1
|
||||||
state_open = Ticket::State.by_category(:open)
|
state_open = Ticket::State.by_category(:open)
|
||||||
tickets_open = Ticket.where(
|
tickets_open = Ticket.where(
|
||||||
customer_id: @customer_id,
|
customer_id: @customer_id,
|
||||||
|
@ -19,6 +22,7 @@ class Observer::Ticket::UserTicketCounter::BackgroundJob
|
||||||
customer_id: @customer_id,
|
customer_id: @customer_id,
|
||||||
state_id: state_closed,
|
state_id: state_closed,
|
||||||
).count()
|
).count()
|
||||||
|
end
|
||||||
|
|
||||||
# check if update is needed
|
# check if update is needed
|
||||||
customer = User.lookup(id: @customer_id)
|
customer = User.lookup(id: @customer_id)
|
||||||
|
|
5
config/routes/integration_check_mk.rb
Normal file
5
config/routes/integration_check_mk.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
Zammad::Application.routes.draw do
|
||||||
|
api_path = Rails.configuration.api_path
|
||||||
|
|
||||||
|
match api_path + '/integration/check_mk/:token', to: 'integration/check_mk#update', via: :post, defaults: { format: 'json' }
|
||||||
|
end
|
|
@ -7,3 +7,4 @@ rm -rf app/assets/javascripts/app/views/layout_ref/
|
||||||
rm app/assets/javascripts/app/controllers/karma.coffee
|
rm app/assets/javascripts/app/controllers/karma.coffee
|
||||||
rm app/assets/javascripts/app/controllers/report.coffee
|
rm app/assets/javascripts/app/controllers/report.coffee
|
||||||
rm app/assets/javascripts/app/controllers/report_profile.coffee
|
rm app/assets/javascripts/app/controllers/report_profile.coffee
|
||||||
|
rm app/assets/javascripts/app/controllers/_integration/check_mk.coffee
|
||||||
|
|
119
db/migrate/20170820000001_check_mk_integration.rb
Normal file
119
db/migrate/20170820000001_check_mk_integration.rb
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
class CheckMkIntegration < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
|
||||||
|
# return if it's a new setup
|
||||||
|
return if !Setting.find_by(name: 'system_init_done')
|
||||||
|
|
||||||
|
Setting.create_if_not_exists(
|
||||||
|
title: 'Check_MK integration',
|
||||||
|
name: 'check_mk_integration',
|
||||||
|
area: 'Integration::Switch',
|
||||||
|
description: 'Defines if Check_MK (http://mathias-kettner.com/check_mk.html) is enabled or not.',
|
||||||
|
options: {
|
||||||
|
form: [
|
||||||
|
{
|
||||||
|
display: '',
|
||||||
|
null: true,
|
||||||
|
name: 'check_mk_integration',
|
||||||
|
tag: 'boolean',
|
||||||
|
options: {
|
||||||
|
true => 'yes',
|
||||||
|
false => 'no',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
state: false,
|
||||||
|
preferences: {
|
||||||
|
prio: 1,
|
||||||
|
permission: ['admin.integration'],
|
||||||
|
},
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
Setting.create_if_not_exists(
|
||||||
|
title: 'Group',
|
||||||
|
name: 'check_mk_group_id',
|
||||||
|
area: 'Integration::CheckMK',
|
||||||
|
description: 'Defines the group of created tickets.',
|
||||||
|
options: {
|
||||||
|
form: [
|
||||||
|
{
|
||||||
|
display: '',
|
||||||
|
null: false,
|
||||||
|
name: 'check_mk_group_id',
|
||||||
|
tag: 'select',
|
||||||
|
relation: 'Group',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
state: 1,
|
||||||
|
preferences: {
|
||||||
|
prio: 2,
|
||||||
|
permission: ['admin.integration'],
|
||||||
|
},
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
Setting.create_if_not_exists(
|
||||||
|
title: 'Auto close',
|
||||||
|
name: 'check_mk_auto_close',
|
||||||
|
area: 'Integration::CheckMK',
|
||||||
|
description: 'Defines if tickets should be closed if service is recovered.',
|
||||||
|
options: {
|
||||||
|
form: [
|
||||||
|
{
|
||||||
|
display: '',
|
||||||
|
null: true,
|
||||||
|
name: 'check_mk_auto_close',
|
||||||
|
tag: 'boolean',
|
||||||
|
options: {
|
||||||
|
true => 'yes',
|
||||||
|
false => 'no',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
state: true,
|
||||||
|
preferences: {
|
||||||
|
prio: 3,
|
||||||
|
permission: ['admin.integration'],
|
||||||
|
},
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
Setting.create_if_not_exists(
|
||||||
|
title: 'Auto close state',
|
||||||
|
name: 'check_mk_auto_close_state_id',
|
||||||
|
area: 'Integration::CheckMK',
|
||||||
|
description: 'Defines the state of auto closed tickets.',
|
||||||
|
options: {
|
||||||
|
form: [
|
||||||
|
{
|
||||||
|
display: '',
|
||||||
|
null: false,
|
||||||
|
name: 'check_mk_auto_close_state_id',
|
||||||
|
tag: 'select',
|
||||||
|
relation: 'TicketState',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
state: 4,
|
||||||
|
preferences: {
|
||||||
|
prio: 4,
|
||||||
|
permission: ['admin.integration'],
|
||||||
|
},
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
Setting.create_if_not_exists(
|
||||||
|
title: 'Check_MK tolen',
|
||||||
|
name: 'check_mk_token',
|
||||||
|
area: 'Core',
|
||||||
|
description: 'Defines the Check_MK token for allowing updates.',
|
||||||
|
options: {},
|
||||||
|
state: SecureRandom.hex(16),
|
||||||
|
preferences: {
|
||||||
|
permission: ['admin.integration'],
|
||||||
|
},
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -2847,6 +2847,117 @@ Setting.create_if_not_exists(
|
||||||
},
|
},
|
||||||
frontend: false
|
frontend: false
|
||||||
)
|
)
|
||||||
|
Setting.create_if_not_exists(
|
||||||
|
title: 'Check_MK integration',
|
||||||
|
name: 'check_mk_integration',
|
||||||
|
area: 'Integration::Switch',
|
||||||
|
description: 'Defines if Check_MK (http://mathias-kettner.com/check_mk.html) is enabled or not.',
|
||||||
|
options: {
|
||||||
|
form: [
|
||||||
|
{
|
||||||
|
display: '',
|
||||||
|
null: true,
|
||||||
|
name: 'check_mk_integration',
|
||||||
|
tag: 'boolean',
|
||||||
|
options: {
|
||||||
|
true => 'yes',
|
||||||
|
false => 'no',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
state: false,
|
||||||
|
preferences: {
|
||||||
|
prio: 1,
|
||||||
|
permission: ['admin.integration'],
|
||||||
|
},
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
Setting.create_if_not_exists(
|
||||||
|
title: 'Group',
|
||||||
|
name: 'check_mk_group_id',
|
||||||
|
area: 'Integration::CheckMK',
|
||||||
|
description: 'Defines the group of created tickets.',
|
||||||
|
options: {
|
||||||
|
form: [
|
||||||
|
{
|
||||||
|
display: '',
|
||||||
|
null: false,
|
||||||
|
name: 'check_mk_group_id',
|
||||||
|
tag: 'select',
|
||||||
|
relation: 'Group',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
state: 1,
|
||||||
|
preferences: {
|
||||||
|
prio: 2,
|
||||||
|
permission: ['admin.integration'],
|
||||||
|
},
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
Setting.create_if_not_exists(
|
||||||
|
title: 'Auto close',
|
||||||
|
name: 'check_mk_auto_close',
|
||||||
|
area: 'Integration::CheckMK',
|
||||||
|
description: 'Defines if tickets should be closed if service is recovered.',
|
||||||
|
options: {
|
||||||
|
form: [
|
||||||
|
{
|
||||||
|
display: '',
|
||||||
|
null: true,
|
||||||
|
name: 'check_mk_auto_close',
|
||||||
|
tag: 'boolean',
|
||||||
|
options: {
|
||||||
|
true => 'yes',
|
||||||
|
false => 'no',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
state: true,
|
||||||
|
preferences: {
|
||||||
|
prio: 3,
|
||||||
|
permission: ['admin.integration'],
|
||||||
|
},
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
Setting.create_if_not_exists(
|
||||||
|
title: 'Auto close state',
|
||||||
|
name: 'check_mk_auto_close_state_id',
|
||||||
|
area: 'Integration::CheckMK',
|
||||||
|
description: 'Defines the state of auto closed tickets.',
|
||||||
|
options: {
|
||||||
|
form: [
|
||||||
|
{
|
||||||
|
display: '',
|
||||||
|
null: false,
|
||||||
|
name: 'check_mk_auto_close_state_id',
|
||||||
|
tag: 'select',
|
||||||
|
relation: 'TicketState',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
state: 4,
|
||||||
|
preferences: {
|
||||||
|
prio: 4,
|
||||||
|
permission: ['admin.integration'],
|
||||||
|
},
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
Setting.create_if_not_exists(
|
||||||
|
title: 'Check_MK tolen',
|
||||||
|
name: 'check_mk_token',
|
||||||
|
area: 'Core',
|
||||||
|
description: 'Defines the Check_MK token for allowing updates.',
|
||||||
|
options: {},
|
||||||
|
state: SecureRandom.hex(16),
|
||||||
|
preferences: {
|
||||||
|
permission: ['admin.integration'],
|
||||||
|
},
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'LDAP integration',
|
title: 'LDAP integration',
|
||||||
name: 'ldap_integration',
|
name: 'ldap_integration',
|
||||||
|
|
|
@ -242,7 +242,7 @@ returns
|
||||||
# update items
|
# update items
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
items_to_update.each { |_id, item|
|
items_to_update.each { |_id, item|
|
||||||
item.save
|
item.save!
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
270
test/controllers/integration_check_mk_controller_test.rb
Normal file
270
test/controllers/integration_check_mk_controller_test.rb
Normal file
|
@ -0,0 +1,270 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class IntegationCheckMkControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
setup do
|
||||||
|
token = SecureRandom.urlsafe_base64(16)
|
||||||
|
Setting.set('check_mk_token', token)
|
||||||
|
Setting.set('check_mk_integration', true)
|
||||||
|
end
|
||||||
|
|
||||||
|
test '01 without token' do
|
||||||
|
post '/api/v1/integration/check_mk/', {}
|
||||||
|
assert_response(404)
|
||||||
|
end
|
||||||
|
|
||||||
|
test '01 invalid token & enabled feature' do
|
||||||
|
post '/api/v1/integration/check_mk/invalid_token', {}
|
||||||
|
assert_response(422)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
assert_equal('Invalid token!', result['error'])
|
||||||
|
end
|
||||||
|
|
||||||
|
test '01 invalid token & disabled feature' do
|
||||||
|
Setting.set('check_mk_integration', false)
|
||||||
|
|
||||||
|
post '/api/v1/integration/check_mk/invalid_token', {}
|
||||||
|
assert_response(422)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
assert_equal('Feature is disable, please contact your admin to enable it!', result['error'])
|
||||||
|
end
|
||||||
|
|
||||||
|
test '02 ticket create & close' do
|
||||||
|
params = {
|
||||||
|
event_id: '123',
|
||||||
|
state: 'down',
|
||||||
|
host: 'some host',
|
||||||
|
service: 'some service',
|
||||||
|
}
|
||||||
|
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params
|
||||||
|
assert_response(200)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
|
||||||
|
assert(result['result'])
|
||||||
|
assert(result['ticket_id'])
|
||||||
|
assert(result['ticket_number'])
|
||||||
|
|
||||||
|
ticket = Ticket.find(result['ticket_id'])
|
||||||
|
assert_equal('new', ticket.state.name)
|
||||||
|
assert_equal(1, ticket.articles.count)
|
||||||
|
|
||||||
|
params = {
|
||||||
|
event_id: '123',
|
||||||
|
state: 'up',
|
||||||
|
host: 'some host',
|
||||||
|
service: 'some service',
|
||||||
|
}
|
||||||
|
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params
|
||||||
|
assert_response(200)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
|
||||||
|
assert(result['result'])
|
||||||
|
assert(result['ticket_ids'].include?(ticket.id))
|
||||||
|
|
||||||
|
ticket.reload
|
||||||
|
assert_equal('closed', ticket.state.name)
|
||||||
|
assert_equal(2, ticket.articles.count)
|
||||||
|
end
|
||||||
|
|
||||||
|
test '02 ticket create & create & auto close' do
|
||||||
|
params = {
|
||||||
|
event_id: '123',
|
||||||
|
state: 'down',
|
||||||
|
host: 'some host',
|
||||||
|
service: 'some service',
|
||||||
|
}
|
||||||
|
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params
|
||||||
|
assert_response(200)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
|
||||||
|
assert(result['result'])
|
||||||
|
assert(result['ticket_id'])
|
||||||
|
assert(result['ticket_number'])
|
||||||
|
|
||||||
|
ticket = Ticket.find(result['ticket_id'])
|
||||||
|
assert_equal('new', ticket.state.name)
|
||||||
|
assert_equal(1, ticket.articles.count)
|
||||||
|
|
||||||
|
params = {
|
||||||
|
event_id: '123',
|
||||||
|
state: 'down',
|
||||||
|
host: 'some host',
|
||||||
|
service: 'some service',
|
||||||
|
}
|
||||||
|
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params
|
||||||
|
assert_response(200)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
|
||||||
|
assert_equal('ticket already open, added note', result['result'])
|
||||||
|
assert(result['ticket_ids'].include?(ticket.id))
|
||||||
|
|
||||||
|
ticket.reload
|
||||||
|
assert_equal('new', ticket.state.name)
|
||||||
|
assert_equal(2, ticket.articles.count)
|
||||||
|
|
||||||
|
params = {
|
||||||
|
event_id: '123',
|
||||||
|
state: 'up',
|
||||||
|
host: 'some host',
|
||||||
|
service: 'some service',
|
||||||
|
}
|
||||||
|
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params
|
||||||
|
assert_response(200)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
|
||||||
|
assert(result['result'])
|
||||||
|
assert(result['ticket_ids'].include?(ticket.id))
|
||||||
|
|
||||||
|
ticket.reload
|
||||||
|
assert_equal('closed', ticket.state.name)
|
||||||
|
assert_equal(3, ticket.articles.count)
|
||||||
|
end
|
||||||
|
|
||||||
|
test '02 ticket close' do
|
||||||
|
params = {
|
||||||
|
event_id: '123',
|
||||||
|
state: 'up',
|
||||||
|
host: 'some host',
|
||||||
|
service: 'some service',
|
||||||
|
}
|
||||||
|
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params
|
||||||
|
assert_response(200)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
|
||||||
|
assert_equal('no open tickets found, ignore action', result['result'])
|
||||||
|
end
|
||||||
|
|
||||||
|
test '02 ticket create & create & no auto close' do
|
||||||
|
Setting.set('check_mk_auto_close', false)
|
||||||
|
params = {
|
||||||
|
event_id: '123',
|
||||||
|
state: 'down',
|
||||||
|
host: 'some host',
|
||||||
|
service: 'some service',
|
||||||
|
}
|
||||||
|
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params
|
||||||
|
assert_response(200)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
|
||||||
|
assert(result['result'])
|
||||||
|
assert(result['ticket_id'])
|
||||||
|
assert(result['ticket_number'])
|
||||||
|
|
||||||
|
ticket = Ticket.find(result['ticket_id'])
|
||||||
|
assert_equal('new', ticket.state.name)
|
||||||
|
assert_equal(1, ticket.articles.count)
|
||||||
|
|
||||||
|
params = {
|
||||||
|
event_id: '123',
|
||||||
|
state: 'down',
|
||||||
|
host: 'some host',
|
||||||
|
service: 'some service',
|
||||||
|
}
|
||||||
|
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params
|
||||||
|
assert_response(200)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
|
||||||
|
assert_equal('ticket already open, added note', result['result'])
|
||||||
|
assert(result['ticket_ids'].include?(ticket.id))
|
||||||
|
|
||||||
|
ticket.reload
|
||||||
|
assert_equal('new', ticket.state.name)
|
||||||
|
assert_equal(2, ticket.articles.count)
|
||||||
|
|
||||||
|
params = {
|
||||||
|
event_id: '123',
|
||||||
|
state: 'up',
|
||||||
|
host: 'some host',
|
||||||
|
service: 'some service',
|
||||||
|
}
|
||||||
|
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params
|
||||||
|
assert_response(200)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
|
||||||
|
assert_equal('ticket already open, added note', result['result'])
|
||||||
|
assert(result['ticket_ids'].include?(ticket.id))
|
||||||
|
|
||||||
|
ticket.reload
|
||||||
|
assert_equal('new', ticket.state.name)
|
||||||
|
assert_equal(3, ticket.articles.count)
|
||||||
|
end
|
||||||
|
|
||||||
|
test '02 ticket create & create & auto close - host only' do
|
||||||
|
params = {
|
||||||
|
event_id: '123',
|
||||||
|
state: 'down',
|
||||||
|
host: 'some host',
|
||||||
|
}
|
||||||
|
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params
|
||||||
|
assert_response(200)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
|
||||||
|
assert(result['result'])
|
||||||
|
assert(result['ticket_id'])
|
||||||
|
assert(result['ticket_number'])
|
||||||
|
|
||||||
|
ticket = Ticket.find(result['ticket_id'])
|
||||||
|
assert_equal('new', ticket.state.name)
|
||||||
|
assert_equal(1, ticket.articles.count)
|
||||||
|
|
||||||
|
params = {
|
||||||
|
event_id: '123',
|
||||||
|
state: 'down',
|
||||||
|
host: 'some host',
|
||||||
|
}
|
||||||
|
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params
|
||||||
|
assert_response(200)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
|
||||||
|
assert_equal('ticket already open, added note', result['result'])
|
||||||
|
assert(result['ticket_ids'].include?(ticket.id))
|
||||||
|
|
||||||
|
ticket.reload
|
||||||
|
assert_equal('new', ticket.state.name)
|
||||||
|
assert_equal(2, ticket.articles.count)
|
||||||
|
|
||||||
|
params = {
|
||||||
|
event_id: '123',
|
||||||
|
state: 'up',
|
||||||
|
host: 'some host',
|
||||||
|
}
|
||||||
|
post "/api/v1/integration/check_mk/#{Setting.get('check_mk_token')}", params
|
||||||
|
assert_response(200)
|
||||||
|
|
||||||
|
result = JSON.parse(@response.body)
|
||||||
|
assert_equal(Hash, result.class)
|
||||||
|
|
||||||
|
assert(result['result'])
|
||||||
|
assert(result['ticket_ids'].include?(ticket.id))
|
||||||
|
|
||||||
|
ticket.reload
|
||||||
|
assert_equal('closed', ticket.state.name)
|
||||||
|
assert_equal(3, ticket.articles.count)
|
||||||
|
end
|
||||||
|
end
|
|
@ -41,7 +41,6 @@ Comment: [] =
|
||||||
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
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['icinga'])
|
assert_not(ticket_p.preferences['icinga'])
|
||||||
|
|
||||||
# RBL check
|
# RBL check
|
||||||
|
@ -69,8 +68,6 @@ IPv4: 127.0.0.1="
|
||||||
ticket_0, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_0, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
assert_equal('new', ticket_0.state.name)
|
assert_equal('new', ticket_0.state.name)
|
||||||
assert(ticket_0.preferences)
|
assert(ticket_0.preferences)
|
||||||
assert(ticket_0.preferences['integration'])
|
|
||||||
assert_equal('icinga', ticket_0.preferences['integration'])
|
|
||||||
assert(ticket_0.preferences['icinga'])
|
assert(ticket_0.preferences['icinga'])
|
||||||
assert_equal('apn4711.dc.example.com (Display Name: "apn4711.dc.example.com")', ticket_0.preferences['icinga']['host'])
|
assert_equal('apn4711.dc.example.com (Display Name: "apn4711.dc.example.com")', ticket_0.preferences['icinga']['host'])
|
||||||
assert_equal('CHECK_RBL CRITICAL - apn4711.dc.example.com BLACKLISTED on 1 server of 38 (ix.dnsbl.example.com)', ticket_0.preferences['icinga']['info'])
|
assert_equal('CHECK_RBL CRITICAL - apn4711.dc.example.com BLACKLISTED on 1 server of 38 (ix.dnsbl.example.com)', ticket_0.preferences['icinga']['info'])
|
||||||
|
@ -102,8 +99,6 @@ IPv4: 127.0.0.1="
|
||||||
ticket_0_1, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_0_1, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
assert_equal('new', ticket_0_1.state.name)
|
assert_equal('new', ticket_0_1.state.name)
|
||||||
assert(ticket_0_1.preferences)
|
assert(ticket_0_1.preferences)
|
||||||
assert(ticket_0_1.preferences['integration'])
|
|
||||||
assert_equal('icinga', ticket_0_1.preferences['integration'])
|
|
||||||
assert(ticket_0_1.preferences['icinga'])
|
assert(ticket_0_1.preferences['icinga'])
|
||||||
assert_equal('apn4711.dc.example.com (Display Name: "apn4711.dc.example.com")', ticket_0_1.preferences['icinga']['host'])
|
assert_equal('apn4711.dc.example.com (Display Name: "apn4711.dc.example.com")', ticket_0_1.preferences['icinga']['host'])
|
||||||
assert_equal('CHECK_RBL CRITICAL - apn4711.dc.example.com BLACKLISTED on 1 server of 38 (ix.dnsbl.example.com)', ticket_0_1.preferences['icinga']['info'])
|
assert_equal('CHECK_RBL CRITICAL - apn4711.dc.example.com BLACKLISTED on 1 server of 38 (ix.dnsbl.example.com)', ticket_0_1.preferences['icinga']['info'])
|
||||||
|
@ -135,8 +130,6 @@ IPv4: 127.0.0.1="
|
||||||
ticket_0_2, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_0_2, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
assert_equal('closed', ticket_0_2.state.name)
|
assert_equal('closed', ticket_0_2.state.name)
|
||||||
assert(ticket_0_2.preferences)
|
assert(ticket_0_2.preferences)
|
||||||
assert(ticket_0_2.preferences['integration'])
|
|
||||||
assert_equal('icinga', ticket_0_2.preferences['integration'])
|
|
||||||
assert(ticket_0_2.preferences['icinga'])
|
assert(ticket_0_2.preferences['icinga'])
|
||||||
assert_equal('apn4711.dc.example.com (Display Name: "apn4711.dc.example.com")', ticket_0_2.preferences['icinga']['host'])
|
assert_equal('apn4711.dc.example.com (Display Name: "apn4711.dc.example.com")', ticket_0_2.preferences['icinga']['host'])
|
||||||
assert_equal('CHECK_RBL CRITICAL - apn4711.dc.example.com BLACKLISTED on 1 server of 38 (ix.dnsbl.example.com)', ticket_0_2.preferences['icinga']['info'])
|
assert_equal('CHECK_RBL CRITICAL - apn4711.dc.example.com BLACKLISTED on 1 server of 38 (ix.dnsbl.example.com)', ticket_0_2.preferences['icinga']['info'])
|
||||||
|
@ -173,8 +166,6 @@ Comment: [] =
|
||||||
ticket_1, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_1, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
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_equal('icinga', ticket_1.preferences['integration'])
|
|
||||||
assert(ticket_1.preferences['icinga'])
|
assert(ticket_1.preferences['icinga'])
|
||||||
assert_equal('host.internal.loc', ticket_1.preferences['icinga']['host'])
|
assert_equal('host.internal.loc', ticket_1.preferences['icinga']['host'])
|
||||||
assert_equal('CPU Load', ticket_1.preferences['icinga']['service'])
|
assert_equal('CPU Load', ticket_1.preferences['icinga']['service'])
|
||||||
|
@ -209,8 +200,6 @@ Comment: [] =
|
||||||
ticket_2, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_2, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
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_equal('icinga', ticket_2.preferences['integration'])
|
|
||||||
assert(ticket_2.preferences['icinga'])
|
assert(ticket_2.preferences['icinga'])
|
||||||
assert_equal('host.internal.loc', ticket_2.preferences['icinga']['host'])
|
assert_equal('host.internal.loc', ticket_2.preferences['icinga']['host'])
|
||||||
assert_equal('Disk Usage 123', ticket_2.preferences['icinga']['service'])
|
assert_equal('Disk Usage 123', ticket_2.preferences['icinga']['service'])
|
||||||
|
@ -246,8 +235,6 @@ Comment: [] =
|
||||||
ticket_1_1, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_1_1, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
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_equal('icinga', ticket_1_1.preferences['integration'])
|
|
||||||
assert(ticket_1_1.preferences['icinga'])
|
assert(ticket_1_1.preferences['icinga'])
|
||||||
assert_equal('host.internal.loc', ticket_1_1.preferences['icinga']['host'])
|
assert_equal('host.internal.loc', ticket_1_1.preferences['icinga']['host'])
|
||||||
assert_equal('CPU Load', ticket_1_1.preferences['icinga']['service'])
|
assert_equal('CPU Load', ticket_1_1.preferences['icinga']['service'])
|
||||||
|
@ -284,8 +271,6 @@ Comment: [] =
|
||||||
assert_equal(ticket_1.id, ticket_1_2.id)
|
assert_equal(ticket_1.id, ticket_1_2.id)
|
||||||
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_equal('icinga', ticket_1_2.preferences['integration'])
|
|
||||||
assert(ticket_1_2.preferences['icinga'])
|
assert(ticket_1_2.preferences['icinga'])
|
||||||
assert_equal('host.internal.loc', ticket_1_2.preferences['icinga']['host'])
|
assert_equal('host.internal.loc', ticket_1_2.preferences['icinga']['host'])
|
||||||
assert_equal('CPU Load', ticket_1_2.preferences['icinga']['service'])
|
assert_equal('CPU Load', ticket_1_2.preferences['icinga']['service'])
|
||||||
|
@ -318,8 +303,6 @@ Comment: [] =
|
||||||
ticket_3, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_3, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
assert_equal('new', ticket_3.state.name)
|
assert_equal('new', ticket_3.state.name)
|
||||||
assert(ticket_3.preferences)
|
assert(ticket_3.preferences)
|
||||||
assert(ticket_3.preferences['integration'])
|
|
||||||
assert_equal('icinga', ticket_3.preferences['integration'])
|
|
||||||
assert(ticket_3.preferences['icinga'])
|
assert(ticket_3.preferences['icinga'])
|
||||||
assert_equal('apn4711.dc.example.com', ticket_3.preferences['icinga']['host'])
|
assert_equal('apn4711.dc.example.com', ticket_3.preferences['icinga']['host'])
|
||||||
assert_nil(ticket_3.preferences['icinga']['service'])
|
assert_nil(ticket_3.preferences['icinga']['service'])
|
||||||
|
@ -354,8 +337,6 @@ Comment: [] =
|
||||||
assert_equal(ticket_3.id, ticket_3_1.id)
|
assert_equal(ticket_3.id, ticket_3_1.id)
|
||||||
assert_equal('closed', ticket_3_1.state.name)
|
assert_equal('closed', ticket_3_1.state.name)
|
||||||
assert(ticket_3_1.preferences)
|
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(ticket_3_1.preferences['icinga'])
|
||||||
assert_equal('apn4711.dc.example.com', ticket_3.preferences['icinga']['host'])
|
assert_equal('apn4711.dc.example.com', ticket_3.preferences['icinga']['host'])
|
||||||
assert_nil(ticket_3_1.preferences['icinga']['service'])
|
assert_nil(ticket_3_1.preferences['icinga']['service'])
|
||||||
|
|
|
@ -37,7 +37,6 @@ WARNING - load average: 3.44, 0.99, 0.35
|
||||||
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
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['nagios'])
|
assert_not(ticket_p.preferences['nagios'])
|
||||||
|
|
||||||
# matching sender - CPU Load/host.internal.loc
|
# matching sender - CPU Load/host.internal.loc
|
||||||
|
@ -67,8 +66,6 @@ WARNING - load average: 3.44, 0.99, 0.35
|
||||||
ticket_1, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_1, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
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_equal('nagios', ticket_1.preferences['integration'])
|
|
||||||
assert(ticket_1.preferences['nagios'])
|
assert(ticket_1.preferences['nagios'])
|
||||||
assert_equal('host.internal.loc', ticket_1.preferences['nagios']['host'])
|
assert_equal('host.internal.loc', ticket_1.preferences['nagios']['host'])
|
||||||
assert_equal('CPU Load', ticket_1.preferences['nagios']['service'])
|
assert_equal('CPU Load', ticket_1.preferences['nagios']['service'])
|
||||||
|
@ -101,8 +98,6 @@ WARNING - load average: 3.44, 0.99, 0.35
|
||||||
ticket_2, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_2, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
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_equal('nagios', ticket_2.preferences['integration'])
|
|
||||||
assert(ticket_2.preferences['nagios'])
|
assert(ticket_2.preferences['nagios'])
|
||||||
assert_equal('host.internal.loc', ticket_2.preferences['nagios']['host'])
|
assert_equal('host.internal.loc', ticket_2.preferences['nagios']['host'])
|
||||||
assert_equal('Disk Usage 123', ticket_2.preferences['nagios']['service'])
|
assert_equal('Disk Usage 123', ticket_2.preferences['nagios']['service'])
|
||||||
|
@ -136,8 +131,6 @@ WARNING - load average: 3.44, 0.99, 0.35
|
||||||
ticket_1_1, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_1_1, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
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_equal('nagios', ticket_1_1.preferences['integration'])
|
|
||||||
assert(ticket_1_1.preferences['nagios'])
|
assert(ticket_1_1.preferences['nagios'])
|
||||||
assert_equal('host.internal.loc', ticket_1_1.preferences['nagios']['host'])
|
assert_equal('host.internal.loc', ticket_1_1.preferences['nagios']['host'])
|
||||||
assert_equal('CPU Load', ticket_1_1.preferences['nagios']['service'])
|
assert_equal('CPU Load', ticket_1_1.preferences['nagios']['service'])
|
||||||
|
@ -170,8 +163,6 @@ Additional Info:
|
||||||
assert_equal(ticket_1.id, ticket_1_2.id)
|
assert_equal(ticket_1.id, ticket_1_2.id)
|
||||||
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_equal('nagios', ticket_1_2.preferences['integration'])
|
|
||||||
assert(ticket_1_2.preferences['nagios'])
|
assert(ticket_1_2.preferences['nagios'])
|
||||||
assert_equal('host.internal.loc', ticket_1_2.preferences['nagios']['host'])
|
assert_equal('host.internal.loc', ticket_1_2.preferences['nagios']['host'])
|
||||||
assert_equal('CPU Load', ticket_1_2.preferences['nagios']['service'])
|
assert_equal('CPU Load', ticket_1_2.preferences['nagios']['service'])
|
||||||
|
@ -204,8 +195,6 @@ Comment: [] =
|
||||||
ticket_3, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_3, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
assert_equal('new', ticket_3.state.name)
|
assert_equal('new', ticket_3.state.name)
|
||||||
assert(ticket_3.preferences)
|
assert(ticket_3.preferences)
|
||||||
assert(ticket_3.preferences['integration'])
|
|
||||||
assert_equal('nagios', ticket_3.preferences['integration'])
|
|
||||||
assert(ticket_3.preferences['nagios'])
|
assert(ticket_3.preferences['nagios'])
|
||||||
assert_equal('apn4711.dc.example.com', ticket_3.preferences['nagios']['host'])
|
assert_equal('apn4711.dc.example.com', ticket_3.preferences['nagios']['host'])
|
||||||
assert_nil(ticket_3.preferences['nagios']['service'])
|
assert_nil(ticket_3.preferences['nagios']['service'])
|
||||||
|
@ -240,8 +229,6 @@ Comment: [] =
|
||||||
assert_equal(ticket_3.id, ticket_3_1.id)
|
assert_equal(ticket_3.id, ticket_3_1.id)
|
||||||
assert_equal('closed', ticket_3_1.state.name)
|
assert_equal('closed', ticket_3_1.state.name)
|
||||||
assert(ticket_3_1.preferences)
|
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(ticket_3_1.preferences['nagios'])
|
||||||
assert_equal('apn4711.dc.example.com', ticket_3.preferences['nagios']['host'])
|
assert_equal('apn4711.dc.example.com', ticket_3.preferences['nagios']['host'])
|
||||||
assert_nil(ticket_3_1.preferences['nagios']['service'])
|
assert_nil(ticket_3_1.preferences['nagios']['service'])
|
||||||
|
|
Loading…
Reference in a new issue