Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supported seeking over log lines which contain multibyte characters. #1238

Closed
wants to merge 1 commit into from

Conversation

metheglin
Copy link

If a log has multibyte, check-log.rb unexpectedly behaves because String#size doesn't tell byte size but the number of characters.
However, ruby 1.8.6 or lower doesn't seem to support bytesize method. I wonder whether I should support lower version.

■Before Fixing
※The string "TEST" is multibyte alphabets

% echo 0 > /var/cache/check-log/default/tmp/test.log
% echo "TEST" > /tmp/test.log
% ./check-log.rb -f /tmp/test.log -q 'test' -e 'UTF-8'
CheckLog OK: 0 warnings, 0 criticals for pattern test.
% cat /var/cache/check-log/default/tmp/test.log
5
% echo "test" >> /tmp/test.log
% ./check-log.rb -f /tmp/test.log -q 'test' -e 'UTF-8'
Check failed to run: invalid byte sequence in UTF-8, ["./check-log.rb:188:in `match'", "./check-log.rb:188:in `match'", "./check-log.rb:188:in `block in search_log'", "./check-log.rb:183:in `each_line'", "./check-log.rb:183:in `search_log'", "./check-log.rb:135:in `block in run'", "./check-log.rb:129:in `each'", "./check-log.rb:129:in `run'", "/usr/local/ruby-2.1.6/lib/ruby/gems/2.1.0/gems/sensu-plugin-1.1.0/lib/sensu-plugin/cli.rb:56:in `block in <class:CLI>'"]

■After Fixing
※The string "TEST" is multibyte alphabets

% echo 0 > /var/cache/check-log/default/tmp/test.log
% echo "TEST" > /tmp/test.log
% ./check-log.rb -f /tmp/test.log -q 'test' -e 'UTF-8'
CheckLog OK: 0 warnings, 0 criticals for pattern test.
% cat /var/cache/check-log/default/tmp/test.log
13
% echo "test" >> /tmp/test.log
% ./check-log.rb -f /tmp/test.log -q 'test' -e 'UTF-8'
CheckLog CRITICAL: 0 warnings, 1 criticals for pattern test.
% cat /var/cache/check-log/default/tmp/test.log
18

@analytically
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants