sensu-plugins-logs 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ca00d7419177ed84a34e3bd7b9d302e108bb126
4
- data.tar.gz: 920733496f7eed50cba97b593df62f39c4eaf0da
3
+ metadata.gz: 929c81f862960a2e581bf3e46e6bb2128612ff7d
4
+ data.tar.gz: defbc634359dbba7c00af2b90d2b61c44c67ef1d
5
5
  SHA512:
6
- metadata.gz: 377795148728c7bd23665e28a0f0b090f3b1ae0d6dba29c73421762dcf539f5dba34d53d60872c2f029c7d5fcc3c3e2a225c893800a03f7d5fa4b953c192254f
7
- data.tar.gz: a493f106877b0a25dcc0e9b0e4c430a1f528174667b1071a10c5c7d452297ac14a9c3b41b6660709ec805f022279950ec5a03c0277f7735f032c4a65c4fffe8d
6
+ metadata.gz: d805b4d8b93e77d0f3f065eb6d781e0d749c3691b3ddc416a42388c28d8ad143fd267d7dd02a44e99071f2090cd8f3258785111d28965220b746a8f1f14ed8a2
7
+ data.tar.gz: 1c884973770d313379614cbc0a4374e65d2ba899b9117953f0300d4f271a1782b539e6f75b6f1658a987420b4276525e97303528c6d02844f52e95e56baac7e0
data/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4
4
  This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
5
 
6
6
  ## [Unreleased]
7
+ ## [1.1.0] - 2017-05-20
8
+ ### Added
9
+ - Add `return-length` option to support custom length for returned matched lines
10
+ - Add `log-pattern` option to support read and match against whole log entry instead of single line
7
11
 
8
12
  ## [1.0.0] - 2017-03-07
9
13
  ### Fixed
@@ -36,7 +40,9 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
36
40
  ### Added
37
41
  - initial release
38
42
 
39
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-logs/compare/1.0.0...HEAD
43
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-logs/compare/1.1.0...HEAD
44
+ [1.1.0]: https://github.com/sensu-plugins/sensu-plugins-logs/compare/1.0.0...1.1.0
45
+ [0.0.4]:
40
46
  [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-logs/compare/0.0.4...1.0.0
41
47
  [0.0.4]: https://github.com/sensu-plugins/sensu-plugins-logs/compare/0.0.3...0.0.4
42
48
  [0.0.3]: https://github.com/sensu-plugins/sensu-plugins-logs/compare/0.0.2...0.0.3
data/bin/check-log.rb CHANGED
@@ -57,6 +57,21 @@ class CheckLog < Sensu::Plugin::Check::CLI
57
57
  short: '-q PAT',
58
58
  long: '--pattern PAT'
59
59
 
60
+ # this check currently makes no attempt to try to save you from
61
+ # a bad regex such as being unbound. Regexes ending in anything like:
62
+ # `.*`, `.+`, `[0-9-A-Z-a-z]+`, etc. Having regex without a real
63
+ # boundry could force the entire log file into memory at once rather
64
+ # line by line and could have signifigant performance impact. Please
65
+ # if you are going to use this please make sure you have log rotation
66
+ # set up and test your regex to make sure that it will catch what
67
+ # you want. I would reccomend placing several log examples into
68
+ # something like http://regexr.com/ and ensure that your regex properly
69
+ # catches the boundries. You have been warned.
70
+ option :log_pattern,
71
+ description: 'The log format of each log entry',
72
+ short: '-l PAT',
73
+ long: '--log-pattern PAT'
74
+
60
75
  option :exclude,
61
76
  description: 'Pattern to exclude from matching',
62
77
  short: '-E PAT',
@@ -106,6 +121,13 @@ class CheckLog < Sensu::Plugin::Check::CLI
106
121
  boolean: true,
107
122
  default: false
108
123
 
124
+ option :return_content_length,
125
+ description: 'Matched line length',
126
+ short: '-L N',
127
+ long: '--return-length N',
128
+ proc: proc(&:to_i),
129
+ default: 250
130
+
109
131
  def run
110
132
  unknown 'No log file specified' unless config[:log_file] || config[:file_pattern]
111
133
  unknown 'No pattern specified' unless config[:pattern]
@@ -180,6 +202,10 @@ class CheckLog < Sensu::Plugin::Check::CLI
180
202
  @log.seek(@bytes_to_skip, File::SEEK_SET) if @bytes_to_skip > 0
181
203
  # #YELLOW
182
204
  @log.each_line do |line|
205
+ if config[:log_pattern]
206
+ line = get_log_entry(line)
207
+ end
208
+
183
209
  line = line.encode('UTF-8', invalid: :replace, replace: '')
184
210
  bytes_read += line.bytesize
185
211
  if config[:case_insensitive]
@@ -188,7 +214,7 @@ class CheckLog < Sensu::Plugin::Check::CLI
188
214
  m = line.match(config[:pattern]) unless line.match(config[:exclude])
189
215
  end
190
216
  if m
191
- accumulative_error += "\n" + line.slice(0, 250)
217
+ accumulative_error += "\n" + line.slice(0..config[:return_content_length])
192
218
  if m[1]
193
219
  if config[:crit] && m[1].to_i > config[:crit]
194
220
  n_crits += 1
@@ -210,4 +236,20 @@ class CheckLog < Sensu::Plugin::Check::CLI
210
236
  end
211
237
  [n_warns, n_crits, accumulative_error]
212
238
  end
239
+
240
+ def get_log_entry(first_line)
241
+ log_entry = [first_line]
242
+
243
+ @log.each_line do |line|
244
+ if !line.match(config[:log_pattern])
245
+ log_entry.push(line)
246
+ else
247
+ @log.pos = @log.pos - line.bytesize if line
248
+ break
249
+ end
250
+ end
251
+
252
+ log_entry = log_entry.join('')
253
+ log_entry
254
+ end
213
255
  end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsLogs
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-08 00:00:00.000000000 Z
11
+ date: 2017-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin