lognotifier 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lognotifier/application.rb +28 -22
- data/lib/lognotifier/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f9f4a3327765327d119256598ade5ecd51d1132
|
4
|
+
data.tar.gz: ccd651ccf1e69da2cd0a0ac9078e31711a8645fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3af867267545bd579ddb121a071c126b087c8c0d7e959617fc60ae150c14000eeb740c1d11af543dd4024df95a54941480ea112bbd58b62f0003d64aa5580930
|
7
|
+
data.tar.gz: d423343495bcef574eb9c2ec8da6c51cbba7859da7013caeeb39a5370e80a8c526d0d83b61a2a606e8232f685d7a591a5aa1e801f4131e0e51dd23ce41c73c40
|
@@ -1,18 +1,15 @@
|
|
1
1
|
module Lognotifier
|
2
|
-
|
3
2
|
class Application
|
4
|
-
|
5
|
-
CONFIG_FILE = "/etc/lognotifier.yaml"
|
3
|
+
CONFIG_FILE = '/etc/lognotifier.yaml'
|
6
4
|
@config = nil
|
7
5
|
@logger = nil
|
8
6
|
|
9
7
|
def initialize
|
10
|
-
|
11
8
|
# Load configuration:
|
12
9
|
begin
|
13
|
-
@config = YAML
|
10
|
+
@config = YAML.load(File.read CONFIG_FILE)
|
14
11
|
rescue => e
|
15
|
-
puts
|
12
|
+
puts 'Error at opening config file, error was:'
|
16
13
|
puts e.message
|
17
14
|
exit 1
|
18
15
|
end
|
@@ -21,13 +18,11 @@ module Lognotifier
|
|
21
18
|
@logger = Logger.new @config['logfile']
|
22
19
|
|
23
20
|
# Main exec loop
|
24
|
-
|
25
|
-
|
21
|
+
run
|
26
22
|
end
|
27
23
|
|
28
24
|
def run
|
29
|
-
|
30
|
-
@logger.info "Starting lognotifierd"
|
25
|
+
@logger.info 'Starting lognotifierd'
|
31
26
|
|
32
27
|
threads = []
|
33
28
|
@config['pagerduty'].each do |conf|
|
@@ -50,26 +45,37 @@ module Lognotifier
|
|
50
45
|
@logger.error "ERROR WAS: #{e.message}"
|
51
46
|
Thread.exit
|
52
47
|
end
|
53
|
-
|
54
|
-
|
48
|
+
|
49
|
+
# Seek to the end of the file and watch for changes
|
50
|
+
file.seek(0, IO::SEEK_END)
|
51
|
+
queue = INotify::Notifier.new
|
52
|
+
|
53
|
+
# previous to nil to record the previous line
|
54
|
+
previous = nil
|
55
|
+
|
56
|
+
# Watch for modified actions, read the content and alert if match
|
57
|
+
# When alerting also send the previous line if available
|
55
58
|
queue.watch(filename, :modify) do
|
56
59
|
content = file.read
|
57
60
|
config['patterns'].each do |pattern|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
next unless content.match(/#{pattern["regex"]}/)
|
62
|
+
message = ''
|
63
|
+
message += previous.chomp + ' | ' unless previous.nil? || previous == content
|
64
|
+
message += content.chomp
|
65
|
+
begin
|
66
|
+
pagerduty.trigger("#{pattern['prefix']} #{message}")
|
67
|
+
@logger.info("ALERT TRIGGERD - #{pattern['prefix']}: #{message}")
|
68
|
+
rescue => e
|
69
|
+
@logger.error("FAILED TO SEND ALERT: #{pattern['prefix']} #{message}")
|
70
|
+
@logger.error("Error: #{e.message}")
|
66
71
|
end
|
67
72
|
end
|
73
|
+
previous = content
|
68
74
|
end
|
69
|
-
queue.run
|
75
|
+
queue.run
|
70
76
|
end
|
71
77
|
end
|
72
|
-
threads.each
|
78
|
+
threads.each(&:join)
|
73
79
|
end
|
74
80
|
end
|
75
81
|
end
|
data/lib/lognotifier/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lognotifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Breinlinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.4.8
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: Parse logs and notify to pagerduty on patter match
|