Skip to content

Commit

Permalink
Merge pull request sensu#336 from jmherbst/master
Browse files Browse the repository at this point in the history
Added option to specify encoding page for check-log.rb
  • Loading branch information
nstielau committed Nov 6, 2013
2 parents 89c609d + 0183eb8 commit 235c972
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion plugins/logging/check-log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class CheckLog < Sensu::Plugin::Check::CLI
:short => '-q PAT',
:long => '--pattern PAT'

option :encoding,
:description => "Explicit encoding page to read log file with",
:short => '-e ENCODING-PAGE',
:long => '--encoding ENCODING-PAGE'

option :warn,
:description => "Warning level if pattern has a group",
:short => '-w N',
Expand Down Expand Up @@ -114,7 +119,14 @@ def run

def open_log(log_file)
state_dir = config[:state_auto] || config[:state_dir]
@log = File.open(log_file)

# Opens file using optional encoding page. ex: 'iso8859-1'
if config[:encoding]
@log = File.open(log_file, "r:#{config[:encoding]}")
else
@log = File.open(log_file)
end

@state_file = File.join(state_dir, File.expand_path(log_file))
@bytes_to_skip = begin
File.open(@state_file) do |file|
Expand Down

0 comments on commit 235c972

Please sign in to comment.