Improved logging.

This commit is contained in:
Martin Edenhofer 2015-05-05 10:11:31 +02:00
parent 08f2c924ef
commit cf3e6274d0
5 changed files with 40 additions and 44 deletions

View file

@ -207,8 +207,6 @@ Style/RedundantSelf:
Enabled: false Enabled: false
Style/Next: Style/Next:
Enabled: false Enabled: false
Rails/Output:
Enabled: false
Lint/UselessAccessModifier: Lint/UselessAccessModifier:
Enabled: false Enabled: false
Style/CommentIndentation: Style/CommentIndentation:

View file

@ -77,7 +77,7 @@ class Store
# remove from old provider # remove from old provider
adapter_source.delete( item.sha ) adapter_source.delete( item.sha )
logger.info "NOTICE: Moved file #{item.sha} from #{source} to #{target}" logger.info "Moved file #{item.sha} from #{source} to #{target}"
} }
true true
end end

View file

@ -45,7 +45,7 @@ class Store::Provider::File
# read file from fs # read file from fs
def self.read_from_fs(sha) def self.read_from_fs(sha)
Rails.logger.info "read from fs #{ get_locaton(sha) }" Rails.logger.debug "read from fs #{ get_locaton(sha) }"
if !File.exist?( get_locaton(sha) ) if !File.exist?( get_locaton(sha) )
raise "ERROR: No such file #{ get_locaton(sha) }" raise "ERROR: No such file #{ get_locaton(sha) }"
end end
@ -66,7 +66,7 @@ class Store::Provider::File
# install file # install file
permission = '600' permission = '600'
if !File.exist?( get_locaton(sha) ) if !File.exist?( get_locaton(sha) )
Rails.logger.info "storge write '#{ get_locaton(sha) }' (#{permission})" Rails.logger.debug "storge write '#{ get_locaton(sha) }' (#{permission})"
file = File.new( get_locaton(sha), 'wb' ) file = File.new( get_locaton(sha), 'wb' )
file.write( data ) file.write( data )
file.close file.close

View file

@ -3,7 +3,7 @@ end
module Import::OTRS module Import::OTRS
def self.request(part) def self.request(part)
url = Setting.get('import_otrs_endpoint') + '/' + part + ';Key=' + Setting.get('import_otrs_endpoint_key') url = Setting.get('import_otrs_endpoint') + '/' + part + ';Key=' + Setting.get('import_otrs_endpoint_key')
puts 'GET: ' + url Rails.logger.info 'GET: ' + url
response = UserAgent.request( response = UserAgent.request(
url, url,
{ {
@ -12,7 +12,7 @@ module Import::OTRS
}, },
) )
if !response.success? if !response.success?
puts "ERROR: #{response.error}" Rails.logger.info "ERROR: #{response.error}"
return return
end end
response response
@ -20,7 +20,7 @@ module Import::OTRS
def self.post(base, data) def self.post(base, data)
url = Setting.get('import_otrs_endpoint') + '/' + base url = Setting.get('import_otrs_endpoint') + '/' + base
data['Key'] = Setting.get('import_otrs_endpoint_key') data['Key'] = Setting.get('import_otrs_endpoint_key')
puts 'POST: ' + url Rails.logger.info 'POST: ' + url
response = UserAgent.request( response = UserAgent.request(
url, url,
{ {
@ -31,7 +31,7 @@ module Import::OTRS
}, },
) )
if !response.success? if !response.success?
puts "ERROR: #{response.error}" Rails.logger.info "ERROR: #{response.error}"
return return
end end
response response
@ -110,7 +110,7 @@ module Import::OTRS
end end
def self.start def self.start
puts 'Start import...' Rails.logger.info 'Start import...'
# # set system in import mode # # set system in import mode
# Setting.set('import_mode', true) # Setting.set('import_mode', true)
@ -150,14 +150,14 @@ module Import::OTRS
(1..thread_count).each {|thread| (1..thread_count).each {|thread|
threads[thread] = Thread.new { threads[thread] = Thread.new {
sleep thread * 3 sleep thread * 3
puts "Started import thread# #{thread} ..." Rails.logger.info "Started import thread# #{thread} ..."
run = true run = true
while run while run
ticket_ids = result.pop(20) ticket_ids = result.pop(20)
if !ticket_ids.empty? if !ticket_ids.empty?
self.ticket(ticket_ids) self.ticket(ticket_ids)
else else
puts "... thread# #{thread}, no more work." Rails.logger.info "... thread# #{thread}, no more work."
run = false run = false
end end
end end
@ -176,7 +176,7 @@ module Import::OTRS
end end
def self.diff def self.diff
puts 'Start diff...' Rails.logger.info 'Start diff...'
# check if system is in import mode # check if system is in import mode
if !Setting.get('import_mode') if !Setting.get('import_mode')
@ -222,7 +222,7 @@ module Import::OTRS
end end
def self._ticket_result(result) def self._ticket_result(result)
# puts result.inspect # Rails.logger.info result.inspect
map = { map = {
Ticket: { Ticket: {
Changed: :updated_at, Changed: :updated_at,
@ -283,12 +283,12 @@ module Import::OTRS
ticket_new[value] = record['Ticket'][key.to_s] ticket_new[value] = record['Ticket'][key.to_s]
end end
} }
# puts key.to_s # Rails.logger.info key.to_s
# puts value.to_s # Rails.logger.info value.to_s
#puts 'new ticket data ' + ticket_new.inspect #Rails.logger.info 'new ticket data ' + ticket_new.inspect
# check if state already exists # check if state already exists
ticket_old = Ticket.where( id: ticket_new[:id] ).first ticket_old = Ticket.where( id: ticket_new[:id] ).first
#puts 'TICKET OLD ' + ticket_old.inspect #Rails.logger.info 'TICKET OLD ' + ticket_old.inspect
# find user # find user
if ticket_new[:owner] if ticket_new[:owner]
user = User.lookup( login: ticket_new[:owner] ) user = User.lookup( login: ticket_new[:owner] )
@ -310,13 +310,13 @@ module Import::OTRS
else else
ticket_new[:customer_id] = 1 ticket_new[:customer_id] = 1
end end
# puts 'ttt' + ticket_new.inspect # Rails.logger.info 'ttt' + ticket_new.inspect
# set state types # set state types
if ticket_old if ticket_old
puts "update Ticket.find(#{ticket_new[:id]})" Rails.logger.info "update Ticket.find(#{ticket_new[:id]})"
ticket_old.update_attributes(ticket_new) ticket_old.update_attributes(ticket_new)
else else
puts "add Ticket.find(#{ticket_new[:id]})" Rails.logger.info "add Ticket.find(#{ticket_new[:id]})"
ticket = Ticket.new(ticket_new) ticket = Ticket.new(ticket_new)
ticket.id = ticket_new[:id] ticket.id = ticket_new[:id]
ticket.save ticket.save
@ -412,14 +412,14 @@ module Import::OTRS
end end
article_new.delete( :type ) article_new.delete( :type )
article_old = Ticket::Article.where( id: article_new[:id] ).first article_old = Ticket::Article.where( id: article_new[:id] ).first
#puts 'ARTICLE OLD ' + article_old.inspect #Rails.logger.info 'ARTICLE OLD ' + article_old.inspect
# set state types # set state types
if article_old if article_old
puts "update Ticket::Article.find(#{article_new[:id]})" Rails.logger.info "update Ticket::Article.find(#{article_new[:id]})"
# puts article_new.inspect # Rails.logger.info article_new.inspect
article_old.update_attributes(article_new) article_old.update_attributes(article_new)
else else
puts "add Ticket::Article.find(#{article_new[:id]})" Rails.logger.info "add Ticket::Article.find(#{article_new[:id]})"
article = Ticket::Article.new(article_new) article = Ticket::Article.new(article_new)
article.id = article_new[:id] article.id = article_new[:id]
article.save article.save
@ -428,8 +428,8 @@ module Import::OTRS
} }
record['History'].each { |history| record['History'].each { |history|
# puts '-------' # Rails.logger.info '-------'
# puts history.inspect # Rails.logger.info history.inspect
if history['HistoryType'] == 'NewTicket' if history['HistoryType'] == 'NewTicket'
History.add( History.add(
id: history['HistoryID'], id: history['HistoryID'],
@ -457,7 +457,7 @@ module Import::OTRS
to_id = state_to.id to_id = state_to.id
end end
end end
# puts "STATE UPDATE (#{history['HistoryID']}): -> #{from}->#{to}" # Rails.logger.info "STATE UPDATE (#{history['HistoryID']}): -> #{from}->#{to}"
History.add( History.add(
id: history['HistoryID'], id: history['HistoryID'],
o_id: history['TicketID'], o_id: history['TicketID'],
@ -545,7 +545,7 @@ module Import::OTRS
return if !response.success? return if !response.success?
result = json(response) result = json(response)
# puts result.inspect # Rails.logger.info result.inspect
map = { map = {
ChangeTime: :updated_at, ChangeTime: :updated_at,
CreateTime: :created_at, CreateTime: :created_at,
@ -578,7 +578,7 @@ module Import::OTRS
# check if state already exists # check if state already exists
state_old = Ticket::State.where( id: state_new[:id] ).first state_old = Ticket::State.where( id: state_new[:id] ).first
# puts 'st: ' + state['TypeName'] # Rails.logger.info 'st: ' + state['TypeName']
# set state types # set state types
if state['TypeName'] == 'pending auto' if state['TypeName'] == 'pending auto'
@ -587,7 +587,7 @@ module Import::OTRS
state_type = Ticket::StateType.where( name: state['TypeName'] ).first state_type = Ticket::StateType.where( name: state['TypeName'] ).first
state_new[:state_type_id] = state_type.id state_new[:state_type_id] = state_type.id
if state_old if state_old
# puts 'TS: ' + state_new.inspect # Rails.logger.info 'TS: ' + state_new.inspect
state_old.update_attributes(state_new) state_old.update_attributes(state_new)
else else
state = Ticket::State.new(state_new) state = Ticket::State.new(state_new)
@ -705,7 +705,7 @@ module Import::OTRS
} }
result.each { |user| result.each { |user|
# puts 'USER: ' + user.inspect # Rails.logger.info 'USER: ' + user.inspect
_set_valid(user) _set_valid(user)
role = Role.lookup( name: 'Agent' ) role = Role.lookup( name: 'Agent' )
@ -727,13 +727,13 @@ module Import::OTRS
# set state types # set state types
if user_old if user_old
puts "update User.find(#{user_new[:id]})" Rails.logger.info "update User.find(#{user_new[:id]})"
# puts 'Update User' + user_new.inspect # Rails.logger.info 'Update User' + user_new.inspect
user_new.delete( :role_ids ) user_new.delete( :role_ids )
user_old.update_attributes(user_new) user_old.update_attributes(user_new)
else else
puts "add User.find(#{user_new[:id]})" Rails.logger.info "add User.find(#{user_new[:id]})"
# puts 'Add User' + user_new.inspect # Rails.logger.info 'Add User' + user_new.inspect
user = User.new(user_new) user = User.new(user_new)
user.id = user_new[:id] user.id = user_new[:id]
user.save user.save
@ -745,7 +745,7 @@ module Import::OTRS
count = 0 count = 0
while done == false while done == false
sleep 2 sleep 2
puts "Count=#{count};Offset=#{count}" Rails.logger.info "Count=#{count};Offset=#{count}"
response = request( "public.pl?Action=Export;Type=Customer;Count=100;Offset=#{count}" ) response = request( "public.pl?Action=Export;Type=Customer;Count=100;Offset=#{count}" )
return if !response return if !response
count = count + 3000 count = count + 3000
@ -798,12 +798,12 @@ module Import::OTRS
# set state types # set state types
if user_old if user_old
puts "update User.find(#{user_new[:id]})" Rails.logger.info "update User.find(#{user_new[:id]})"
# puts 'Update User' + user_new.inspect # Rails.logger.info 'Update User' + user_new.inspect
user_old.update_attributes(user_new) user_old.update_attributes(user_new)
else else
# puts 'Add User' + user_new.inspect # Rails.logger.info 'Add User' + user_new.inspect
puts "add User.find(#{user_new[:id]})" Rails.logger.info "add User.find(#{user_new[:id]})"
user = User.new(user_new) user = User.new(user_new)
user.save user.save
end end

View file

@ -797,7 +797,6 @@ module Import::OTRS2
# check if state already exists # check if state already exists
state_old = Ticket::State.where( id: state_new[:id] ).first state_old = Ticket::State.where( id: state_new[:id] ).first
# puts 'st: ' + state['TypeName']
# set state types # set state types
if state['TypeName'] == 'pending auto' if state['TypeName'] == 'pending auto'
@ -806,7 +805,6 @@ module Import::OTRS2
state_type = Ticket::StateType.where( name: state['TypeName'] ).first state_type = Ticket::StateType.where( name: state['TypeName'] ).first
state_new[:state_type_id] = state_type.id state_new[:state_type_id] = state_type.id
if state_old if state_old
# puts 'TS: ' + state_new.inspect
state_old.update_attributes(state_new) state_old.update_attributes(state_new)
else else
state = Ticket::State.new(state_new) state = Ticket::State.new(state_new)
@ -1185,7 +1183,7 @@ module Import::OTRS2
# log # log
def self.log(message) def self.log(message)
thread_no = Thread.current[:thread_no] || '-' thread_no = Thread.current[:thread_no] || '-'
puts "#{Time.new.to_s}/thread##{thread_no}: #{message}" Rails.logger.info "thread##{thread_no}: #{message}"
end end
# set translate valid ids to active = true|false # set translate valid ids to active = true|false