sensu-plugins-log-pattern 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/bin/check-log-pattern.rb +10 -4
- data/lib/sensu-plugins-log-pattern/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b1dd729d9737e2a1050c11f9767c50abf704aef
|
4
|
+
data.tar.gz: 9754ae63c71f3f56f179519d17e84f44f4a81e8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4bb38b32f5caa1a261092ef080f88665cb2b5e1cf4018caf73200d5f10fee76c9f7c9f7933f78d2551eec5684746e70951d0a9d23d633ceb95cf53ba6ce95a9
|
7
|
+
data.tar.gz: 0e23df8a9787bf36fa026ae79d6a0126f7655602457730b8abd60398e7dcb2511c9bef2c46dd45855033f6015c213989a43def69802d374d4d5c74d417512ab3
|
data/CHANGELOG.md
CHANGED
@@ -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
|
data/bin/check-log-pattern.rb
CHANGED
@@ -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
|
-
|
116
|
+
b_read = 0
|
111
117
|
fd.each_line do |line|
|
112
|
-
|
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 +
|
137
|
+
File.open(cursor_file, 'w') { |f| f.write(last_cursor + b_read) }
|
132
138
|
end
|
133
139
|
|
134
140
|
msg = []
|