sensu-plugins-log-pattern 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80637aee656f586af0f648d4a088b5a084ea9e16
4
- data.tar.gz: 309df90ec8a6ec62e59ef58c7b2e22cffdc67a75
3
+ metadata.gz: 4b1dd729d9737e2a1050c11f9767c50abf704aef
4
+ data.tar.gz: 9754ae63c71f3f56f179519d17e84f44f4a81e8d
5
5
  SHA512:
6
- metadata.gz: 93579e0ff5da9895016760109ce54e91439a0d35f173173bc5839b2969eb9b3ad60846da93adfcfba07e5d9a4fd1701d0fcdc756f9a1ac687795c23977c9ebb6
7
- data.tar.gz: 1682205c02cc12616c0c71746dbe13d42a500083b2f18ec6c5f8e94f2042caafd6a2a6d011939b70f52a9c23015fbabafe7e6f2403dc25335f944859d5f30f7b
6
+ metadata.gz: b4bb38b32f5caa1a261092ef080f88665cb2b5e1cf4018caf73200d5f10fee76c9f7c9f7933f78d2551eec5684746e70951d0a9d23d633ceb95cf53ba6ce95a9
7
+ data.tar.gz: 0e23df8a9787bf36fa026ae79d6a0126f7655602457730b8abd60398e7dcb2511c9bef2c46dd45855033f6015c213989a43def69802d374d4d5c74d417512ab3
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ ## [0.0.2] - 2016-01-06
9
+ ### Added
10
+ - Cursor should be reset to 0 when log files are rolled over
11
+
8
12
  ## [0.0.1] - 2016-01-06
9
13
  ### Added
10
14
  - Initial release
@@ -60,12 +60,14 @@ class CheckLogPattern < Sensu::Plugin::Check::CLI
60
60
  :description => "Warning if number of matches exceeds COUNT (default: 1)",
61
61
  :short => "-w <COUNT>",
62
62
  :long => "--warn <COUNT>",
63
+ :proc => proc(&:to_i),
63
64
  :default => 1
64
65
 
65
66
  option :crit,
66
67
  :description => "Critical if number of matches exceeds COUNT",
67
68
  :short => "-c <COUNT>",
68
69
  :long => "--crit <COUNT>",
70
+ :proc => proc(&:to_i),
69
71
  :default => nil
70
72
 
71
73
  def initialize()
@@ -99,17 +101,21 @@ class CheckLogPattern < Sensu::Plugin::Check::CLI
99
101
  hash = Digest::MD5.hexdigest("#{file}_#{config[:pattern]}")
100
102
  cursor_file = config[:state_dir] + "/" + hash + ".last_cursor"
101
103
 
104
+ fd = File.open(file)
105
+
102
106
  if File.exists?(cursor_file)
103
107
  last_cursor = File.read(cursor_file).chomp.to_i
108
+
109
+ # e.g. handle cases when files are rolled over
110
+ last_cursor = 0 unless fd.stat.size >= last_cursor
104
111
  else
105
112
  last_cursor = 0
106
113
  end
107
114
 
108
- fd = File.open(file)
109
115
  fd.seek(last_cursor, File::SEEK_SET) if last_cursor > 0
110
- bread = 0
116
+ b_read = 0
111
117
  fd.each_line do |line|
112
- bread += line.bytesize
118
+ b_read += line.bytesize
113
119
 
114
120
  str = config[:ignore_case] ? line.downcase : line
115
121
 
@@ -128,7 +134,7 @@ class CheckLogPattern < Sensu::Plugin::Check::CLI
128
134
  end
129
135
 
130
136
  # update cursor file
131
- File.open(cursor_file, 'w') { |f| f.write(last_cursor + bread) }
137
+ File.open(cursor_file, 'w') { |f| f.write(last_cursor + b_read) }
132
138
  end
133
139
 
134
140
  msg = []
@@ -2,7 +2,7 @@ module SensuPluginsLogPattern
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 1
5
+ PATCH = 2
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-log-pattern
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Cerutti