Improved otrs import.
This commit is contained in:
parent
6d49496446
commit
697db3839f
6 changed files with 128 additions and 39 deletions
|
@ -38,7 +38,7 @@ add a new history entry for an object
|
||||||
def self.add(data)
|
def self.add(data)
|
||||||
|
|
||||||
# return if we run import mode
|
# return if we run import mode
|
||||||
return if Setting.get('import_mode')
|
return if Setting.get('import_mode') && !data[:id]
|
||||||
|
|
||||||
# lookups
|
# lookups
|
||||||
if data[:history_type]
|
if data[:history_type]
|
||||||
|
|
|
@ -6,7 +6,7 @@ class SchedulerUpdate < ActiveRecord::Migration
|
||||||
Scheduler.reset_column_information
|
Scheduler.reset_column_information
|
||||||
Scheduler.create_or_update(
|
Scheduler.create_or_update(
|
||||||
:name => 'Import OTRS diff load',
|
:name => 'Import OTRS diff load',
|
||||||
:method => 'Import::OTRS.diff_worker',
|
:method => 'Import::OTRS2.diff_worker',
|
||||||
:period => 60 * 3,
|
:period => 60 * 3,
|
||||||
:prio => 1,
|
:prio => 1,
|
||||||
:active => true,
|
:active => true,
|
||||||
|
|
|
@ -11,7 +11,7 @@ module Auth::Otrs
|
||||||
return false if endpoint == 'http://otrs_host/otrs'
|
return false if endpoint == 'http://otrs_host/otrs'
|
||||||
|
|
||||||
# connect to OTRS
|
# connect to OTRS
|
||||||
result = Import::OTRS.auth( username, password )
|
result = Import::OTRS2.auth( username, password )
|
||||||
return false if !result
|
return false if !result
|
||||||
return false if !result['groups_ro']
|
return false if !result['groups_ro']
|
||||||
return false if !result['groups_rw']
|
return false if !result['groups_rw']
|
||||||
|
|
|
@ -79,8 +79,10 @@ module Import::OTRS2
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.post(data)
|
def self.post(data, url = nil)
|
||||||
url = Setting.get('import_otrs_endpoint')
|
if !url
|
||||||
|
url = Setting.get('import_otrs_endpoint')
|
||||||
|
end
|
||||||
data['Key'] = Setting.get('import_otrs_endpoint_key')
|
data['Key'] = Setting.get('import_otrs_endpoint_key')
|
||||||
puts 'POST: ' + url
|
puts 'POST: ' + url
|
||||||
response = UserAgent.request(
|
response = UserAgent.request(
|
||||||
|
@ -116,8 +118,69 @@ module Import::OTRS2
|
||||||
JSON.parse( data )
|
JSON.parse( data )
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.load( object, limit = '', offset = '' )
|
=begin
|
||||||
request_json( ";Subaction=Export;Object=#{object};Limit=#{limit};Offset=#{offset}", 1 )
|
|
||||||
|
start auth on OTRS - just for experimental reasons
|
||||||
|
|
||||||
|
result = auth(username, password)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
{ ..user structure.. }
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def self.auth(username, password)
|
||||||
|
url = Setting.get('import_otrs_endpoint')
|
||||||
|
url.gsub!('ZammadMigrator', 'ZammadSSO')
|
||||||
|
response = post( { :Action => 'ZammadSSO', :Subaction => 'Auth', :User => username, :Pw => password }, url )
|
||||||
|
return if !response
|
||||||
|
return if !response.success?
|
||||||
|
|
||||||
|
result = json(response)
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
|
|
||||||
|
request session data - just for experimental reasons
|
||||||
|
|
||||||
|
result = session(session_id)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
{ ..session structure.. }
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def self.session(session_id)
|
||||||
|
url = Setting.get('import_otrs_endpoint')
|
||||||
|
url.gsub!('ZammadMigrator', 'ZammadSSO')
|
||||||
|
response = post( { :Action => 'ZammadSSO', :Subaction => 'SessionCheck', :SessionID => session_id }, url )
|
||||||
|
return if !response
|
||||||
|
return if !response.success?
|
||||||
|
result = json(response)
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
|
|
||||||
|
load objects from otrs
|
||||||
|
|
||||||
|
result = load('SysConfig')
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
[
|
||||||
|
{ ..object1.. },
|
||||||
|
{ ..object2.. },
|
||||||
|
{ ..object3.. },
|
||||||
|
]
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def self.load( object, limit = '', offset = '', diff = 0 )
|
||||||
|
request_json( ";Subaction=Export;Object=#{object};Limit=#{limit};Offset=#{offset};Diff=#{diff}", 1 )
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
@ -313,7 +376,6 @@ module Import::OTRS2
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
_ticket_result(records, locks)
|
_ticket_result(records, locks)
|
||||||
#sleep 1
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,43 +404,58 @@ module Import::OTRS2
|
||||||
end
|
end
|
||||||
|
|
||||||
# create states
|
# create states
|
||||||
state
|
states = load('State')
|
||||||
|
state(states)
|
||||||
|
|
||||||
# create priorities
|
# create priorities
|
||||||
priority
|
priorities = load('Priority')
|
||||||
|
priority(priorities)
|
||||||
|
|
||||||
# create groups
|
# create groups
|
||||||
ticket_group
|
queues = load('Queue')
|
||||||
|
ticket_group(queues)
|
||||||
|
|
||||||
|
# get agents groups
|
||||||
|
groups = load('Group')
|
||||||
|
|
||||||
|
# get agents roles
|
||||||
|
roles = load('Role')
|
||||||
|
|
||||||
# create agents
|
# create agents
|
||||||
user
|
users = load('User')
|
||||||
|
user(users, groups, roles, queues)
|
||||||
|
|
||||||
|
# create organizations
|
||||||
|
organizations = load('Customer')
|
||||||
|
organization(organizations)
|
||||||
|
|
||||||
|
# get changed tickets
|
||||||
self.ticket_diff
|
self.ticket_diff
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.ticket_diff
|
||||||
|
count = 0
|
||||||
|
run = true
|
||||||
|
steps = 20
|
||||||
|
locks = { :User => {} }
|
||||||
|
while run
|
||||||
|
count += steps
|
||||||
|
puts "loading... diff ..."
|
||||||
|
offset = count-steps
|
||||||
|
if offset != 0
|
||||||
|
offset = count - steps + 1
|
||||||
|
end
|
||||||
|
records = load( 'Ticket', steps, count-steps, 1 )
|
||||||
|
if !records || !records[0]
|
||||||
|
puts "... no more work."
|
||||||
|
run = false
|
||||||
|
next
|
||||||
|
end
|
||||||
|
_ticket_result(records, locks)
|
||||||
|
end
|
||||||
|
|
||||||
def self.ticket_diff()
|
|
||||||
url = "public.pl?Action=Export;Type=TicketDiff;Limit=30"
|
|
||||||
response = request( url )
|
|
||||||
return if !response
|
|
||||||
return if !response.success?
|
|
||||||
result = json(response)
|
|
||||||
self._ticket_result(result)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.ticket(ticket_ids)
|
|
||||||
url = "public.pl?Action=Export;Type=Ticket;"
|
|
||||||
ticket_ids.each {|ticket_id|
|
|
||||||
url = url + "TicketID=#{CGI::escape ticket_id};"
|
|
||||||
}
|
|
||||||
response = request( url )
|
|
||||||
return if !response
|
|
||||||
return if !response.success?
|
|
||||||
|
|
||||||
result = json(response)
|
|
||||||
self._ticket_result(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self._ticket_result(result, locks)
|
def self._ticket_result(result, locks)
|
||||||
|
@ -595,10 +672,11 @@ module Import::OTRS2
|
||||||
end
|
end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#puts "HS: #{record['History'].inspect}"
|
||||||
record['History'].each { |history|
|
record['History'].each { |history|
|
||||||
if history['HistoryType'] == 'NewTicket'
|
if history['HistoryType'] == 'NewTicket'
|
||||||
History.add(
|
puts "HS.add( #{history.inspect} )"
|
||||||
|
res = History.add(
|
||||||
:id => history['HistoryID'],
|
:id => history['HistoryID'],
|
||||||
:o_id => history['TicketID'],
|
:o_id => history['TicketID'],
|
||||||
:history_type => 'created',
|
:history_type => 'created',
|
||||||
|
@ -606,6 +684,7 @@ module Import::OTRS2
|
||||||
:created_at => history['CreateTime'],
|
:created_at => history['CreateTime'],
|
||||||
:created_by_id => history['CreateBy']
|
:created_by_id => history['CreateBy']
|
||||||
)
|
)
|
||||||
|
puts "res #{res.inspect}"
|
||||||
end
|
end
|
||||||
if history['HistoryType'] == 'StateUpdate'
|
if history['HistoryType'] == 'StateUpdate'
|
||||||
data = history['Name']
|
data = history['Name']
|
||||||
|
|
|
@ -10,7 +10,8 @@ module Sso::Otrs
|
||||||
return false if !params['SessionID']
|
return false if !params['SessionID']
|
||||||
|
|
||||||
# connect to OTRS
|
# connect to OTRS
|
||||||
result = Import::OTRS.session( params['SessionID'] )
|
result = Import::OTRS2.session( params['SessionID'] )
|
||||||
|
|
||||||
return false if !result
|
return false if !result
|
||||||
return false if !result['groups_ro']
|
return false if !result['groups_ro']
|
||||||
return false if !result['groups_rw']
|
return false if !result['groups_rw']
|
||||||
|
@ -18,8 +19,10 @@ module Sso::Otrs
|
||||||
|
|
||||||
user = User.where( :login => result['user']['UserLogin'], :active => true ).first
|
user = User.where( :login => result['user']['UserLogin'], :active => true ).first
|
||||||
|
|
||||||
# sync / check permissions
|
if !user
|
||||||
Import::OTRS.permission_sync( user, result, config_item )
|
Rails.logger.notice "No such user #{result['user']['UserLogin']}, requested for SSO!"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
return user
|
return user
|
||||||
end
|
end
|
||||||
|
|
|
@ -83,6 +83,8 @@ returns
|
||||||
:code => 0,
|
:code => 0,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
raise "Unknown method '#{options[:method]}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
if !response
|
if !response
|
||||||
|
@ -107,7 +109,12 @@ returns
|
||||||
:success => false,
|
:success => false,
|
||||||
:code => response.code,
|
:code => response.code,
|
||||||
)
|
)
|
||||||
|
when Net::HTTPInternalServerError
|
||||||
|
return Result.new(
|
||||||
|
:error => "Server Error: #{response.inspect}!",
|
||||||
|
:success => false,
|
||||||
|
:code => response.code,
|
||||||
|
)
|
||||||
when Net::HTTPRedirection
|
when Net::HTTPRedirection
|
||||||
raise "Too many redirections for the original URL, halting." if count <= 0
|
raise "Too many redirections for the original URL, halting." if count <= 0
|
||||||
url = response["location"]
|
url = response["location"]
|
||||||
|
@ -123,7 +130,7 @@ returns
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
raise "Unknown method '#{option[:method]}'"
|
raise "Unable to proccess http call '#{response.inspect}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.ftp(uri,options)
|
def self.ftp(uri,options)
|
||||||
|
|
Loading…
Reference in a new issue