Projet

Général

Profil

Révision b0b39b01

IDb0b39b018e200cd0b771675fd0a6489f6ee9f045
Parent 26c29daa
Enfant 809639ab

Ajouté par Lars Kruse il y a plus de 5 ans

Ruby plugins: apply style changes as suggested by "rubocop --fix-layout"

Voir les différences:

plugins/ejabberd/ejabberd_scanlog
28 28
$debug_mode = ARGV.first == 'debug'
29 29

  
30 30
if $debug_mode
31
	log_info = DEFAULT_CACHE
31
  log_info = DEFAULT_CACHE
32 32
else
33
	begin
34
		log_info = YAML.load IO.read(CACHE_FILE)
35
	rescue
36
		log_info = DEFAULT_CACHE
37
	end
38

  
39
	if File.size(LOG_FILE) < log_info[:start]
40
		# logrotate?
41
		log_info = DEFAULT_CACHE
42
	end
33
  begin
34
    log_info = YAML.load IO.read(CACHE_FILE)
35
  rescue
36
    log_info = DEFAULT_CACHE
37
  end
38

  
39
  if File.size(LOG_FILE) < log_info[:start]
40
    # logrotate?
41
    log_info = DEFAULT_CACHE
42
  end
43 43
end
44 44

  
45 45
if ARGV.first == 'reset'
46
	log_info = { :start => File.size(LOG_FILE)-1 }
47
	puts 'Log reset'
46
  log_info = { :start => File.size(LOG_FILE) - 1 }
47
  puts 'Log reset'
48 48
end
49 49

  
50 50
new_data = ''
51 51
File.open(LOG_FILE, 'rb') do |flog|
52
	flog.seek(log_info[:start])
53
	new_data = flog.read
52
  flog.seek(log_info[:start])
53
  new_data = flog.read
54 54
end
55 55

  
56 56
KNOWN_LOG_TYPES = [
57
	# each element is an instance of Array. 1st item: error description, others: text to search log for
58
	['EJAB-1482 Crash when waiting for item',
59
		['wait_for_']],
60
	['EJAB-1483 ODBC sup failure (wrong PID?)',
61
 		['ejabberd_odbc_sup']],
62
	['EJAB-1483 ODBC sup wrong PID failure echo',
63
		["mod_pubsub_odbc,'-unsubscribe"]],
64
	['DNS failure',
65
		['You should check your DNS configuration']],
66
	['Database unavailable/too slow',
67
		['Database was not available or too slow']],
68
	['State machine terminated: timeout',
69
		['State machine',
70
		'terminating',
71
		'Reason for',
72
		'timeout']],
73
	['The auth module returned an error',
74
		['The authentication module',
75
		'returned an error']],
76
	['MySQL disconnected',
77
		['mysql',
78
		'Received unknown signal, exiting']],
79
	['Connecting to MySQL: failed',
80
		['mysql',
81
		'Failed connecting to']],
82
	['Timeout while running a hook',
83
		['ejabberd_hooks',
84
		'timeout']],
85
	['SQL transaction restarts exceeded',
86
		['SQL transaction restarts exceeded']],
87
	['Unexpected info',
88
		['nexpected info']],
89
	['Other sql_cmd timeout',
90
		['sql_cmd']],
91
	['System limit hit: ports', # check with length(erlang:ports())., set in ejabberdctl config file
92
		['system_limit',
93
		'open_port']],
94
	['Other system limit hit', # processes? check with erlang:system_info(process_count)., erlang:system_info(process_limit)., set in ejabberdctl cfg
95
		['system_limit']],
96
	['Generic server terminating',
97
		['Generic server',
98
		'terminating']],
99
	['Mnesia table shrinked',
100
		['shrinking table']],
101
	['Admin access failed',
102
		['Access of',
103
		'failed with error']],
104
	['MySQL sock timedout',
105
		['mysql_',
106
		': Socket',
107
		'timedout']],
108
	['Configuration error',
109
		['{badrecord,config}']],
110
	['Strange vCard error (vhost)',
111
		['error found when trying to get the vCard']],
112
	['Mnesia is overloaded',
113
		['Mnesia is overloaded']],
114
	['MySQL: init failed recv data',
115
		['mysql_conn: init failed receiving data']],
116
	['TCP Error',
117
		['Failed TCP']]
57
  # each element is an instance of Array. 1st item: error description, others: text to search log for
58
  ['EJAB-1482 Crash when waiting for item',
59
   ['wait_for_']],
60
  ['EJAB-1483 ODBC sup failure (wrong PID?)',
61
   ['ejabberd_odbc_sup']],
62
  ['EJAB-1483 ODBC sup wrong PID failure echo',
63
   ["mod_pubsub_odbc,'-unsubscribe"]],
64
  ['DNS failure',
65
   ['You should check your DNS configuration']],
66
  ['Database unavailable/too slow',
67
   ['Database was not available or too slow']],
68
  ['State machine terminated: timeout',
69
   ['State machine',
70
    'terminating',
71
    'Reason for',
72
    'timeout']],
73
  ['The auth module returned an error',
74
   ['The authentication module',
75
    'returned an error']],
76
  ['MySQL disconnected',
77
   ['mysql',
78
    'Received unknown signal, exiting']],
79
  ['Connecting to MySQL: failed',
80
   ['mysql',
81
    'Failed connecting to']],
82
  ['Timeout while running a hook',
83
   ['ejabberd_hooks',
84
    'timeout']],
85
  ['SQL transaction restarts exceeded',
86
   ['SQL transaction restarts exceeded']],
87
  ['Unexpected info',
88
   ['nexpected info']],
89
  ['Other sql_cmd timeout',
90
   ['sql_cmd']],
91
  ['System limit hit: ports', # check with length(erlang:ports())., set in ejabberdctl config file
92
   ['system_limit',
93
    'open_port']],
94
  ['Other system limit hit', # processes? check with erlang:system_info(process_count)., erlang:system_info(process_limit)., set in ejabberdctl cfg
95
   ['system_limit']],
96
  ['Generic server terminating',
97
   ['Generic server',
98
    'terminating']],
99
  ['Mnesia table shrinked',
100
   ['shrinking table']],
101
  ['Admin access failed',
102
   ['Access of',
103
    'failed with error']],
104
  ['MySQL sock timedout',
105
   ['mysql_',
106
    ': Socket',
107
    'timedout']],
108
  ['Configuration error',
109
   ['{badrecord,config}']],
110
  ['Strange vCard error (vhost)',
111
   ['error found when trying to get the vCard']],
112
  ['Mnesia is overloaded',
113
   ['Mnesia is overloaded']],
114
  ['MySQL: init failed recv data',
115
   ['mysql_conn: init failed receiving data']],
116
  ['TCP Error',
117
   ['Failed TCP']]
118 118
]
119 119

  
120 120
def log_type(text)
121
	KNOWN_LOG_TYPES.find_index { |entry|
122
		entry[1].all? { |substr| text.include? substr }
123
	}
121
  KNOWN_LOG_TYPES.find_index { |entry|
122
    entry[1].all? { |substr| text.include? substr }
123
  }
124 124
end
125 125

  
126 126
new_data.split("\n=").each { |report|
127
	next if report.empty?
128
	report =~ /\A(\w+) REPORT==== (.*) ===\n(.*)\z/m
129
	type, time, text = $1, $2, $3
130
	next unless type and time and text
131

  
132
	log_info[type] = (log_info[type] || 0) + 1
133
	if sub_type = log_type(text)
134
		log_info[sub_type] = (log_info[sub_type] || 0) + 1
135
	elsif $debug_mode
136
		warn "Unparsed log entry #{type}: #{text} at #{time}"
137
	end
127
  next if report.empty?
128

  
129
  report =~ /\A(\w+) REPORT==== (.*) ===\n(.*)\z/m
130
  type, time, text = $1, $2, $3
131
  next unless type and time and text
132

  
133
  log_info[type] = (log_info[type] || 0) + 1
134
  if sub_type = log_type(text)
135
    log_info[sub_type] = (log_info[sub_type] || 0) + 1
136
  elsif $debug_mode
137
    warn "Unparsed log entry #{type}: #{text} at #{time}"
138
  end
138 139
}
139 140

  
140 141
log_info[:start] += new_data.size
141 142
File.open(CACHE_FILE, 'w') { |f| f.write log_info.to_yaml } unless $debug_mode
142 143

  
143 144
if ARGV.first == 'config'
144
	puts <<CONFIG
145
graph_title Ejabberd Log
146
graph_vlabel total
147
graph_category chat
148
graph_args -l 0
149
CONFIG
145
  puts <<~CONFIG
146
    graph_title Ejabberd Log
147
    graph_vlabel total
148
    graph_category chat
149
    graph_args -l 0
150
  CONFIG
150 151
end
151 152

  
152 153
(KNOWN_LOG_TYPES + %w(ERROR WARNING INFO DEBUG)).each.with_index { |log_type, index|
153
	label, index = if log_type.is_a? Array
154
					   [log_type.first, index]
155
				   else
156
					   [log_type, log_type]
157
				   end
158
	if ARGV.first == 'config'
159
		puts "T#{index}.label #{label}"
160
		puts "T#{index}.draw LINE"
161
	else
162
		puts "T#{index}.value #{log_info[index] or 0}"
163
	end
154
  label, index = if log_type.is_a? Array
155
                   [log_type.first, index]
156
                 else
157
                   [log_type, log_type]
158
           end
159
  if ARGV.first == 'config'
160
    puts "T#{index}.label #{label}"
161
    puts "T#{index}.draw LINE"
162
  else
163
    puts "T#{index}.value #{log_info[index] or 0}"
164
  end
164 165
}

Formats disponibles : Unified diff