13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/zabbix-ruby-client/plugin_base.rb', line 13
def getline(file, pattern=false)
if File.readable? file
File.open(file,'r') do |f|
f.each do |l|
line = l.strip
if pattern
if Regexp.new(pattern).match line
Log.debug "File #{file}: #{line}"
return line
end
else
return line
end
end
end
Log.warn "File #{file}: pattern \"#{pattern}\" not found."
false
else
if File.file? file
Log.error "File not readable: #{file}"
else
Log.error "File not found: #{file}"
end
false
end
end
|