Skip to content

Commit

Permalink
Fix 'crit' and 'warn' flags being ignored in search_log
Browse files Browse the repository at this point in the history
  • Loading branch information
avifried1 authored and majormoses committed May 21, 2017
1 parent 192c07d commit ff1d387
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)

## [Unreleased]
### Changed
- `check-log.rb`: Fix 'crit' and 'warn' flags being ignored in search_log

## [1.1.0] - 2017-05-20
### Added
- Add `return-length` option to support custom length for returned matched lines
Expand Down
20 changes: 7 additions & 13 deletions bin/check-log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def search_log
bytes_read = 0
n_warns = 0
n_crits = 0
n_matched = 0
accumulative_error = ''

@log.seek(@bytes_to_skip, File::SEEK_SET) if @bytes_to_skip > 0
Expand All @@ -215,21 +216,14 @@ def search_log
end
if m
accumulative_error += "\n" + line.slice(0..config[:return_content_length])
if m[1]
if config[:crit] && m[1].to_i > config[:crit]
n_crits += 1
elsif config[:warn] && m[1].to_i > config[:warn]
n_warns += 1
end
else
if config[:only_warn] # rubocop:disable Style/IfInsideElse
n_warns += 1
else
n_crits += 1
end
end
n_matched += 1
end
end
if !config[:only_warn] && config[:crit] && n_matched >= config[:crit]
n_crits = n_matched
elsif config[:warn] && n_matched >= config[:warn]
n_warns = n_matched
end
FileUtils.mkdir_p(File.dirname(@state_file))
File.open(@state_file, 'w') do |file|
file.write(@bytes_to_skip + bytes_read)
Expand Down

0 comments on commit ff1d387

Please sign in to comment.