lognotifier 0.0.4 → 0.0.5

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: c35eacd8647646f1b1476934575254f39cbd5613
4
- data.tar.gz: 1dfe2b4c94ce3537157b81b563165e6828e9de5a
3
+ metadata.gz: 2f9f4a3327765327d119256598ade5ecd51d1132
4
+ data.tar.gz: ccd651ccf1e69da2cd0a0ac9078e31711a8645fd
5
5
  SHA512:
6
- metadata.gz: 4a1e0f8a50e45ec87236a1c59c0ae3f89af1df88fbe7162c302b2031b77aa2e9cf61db6c64105758f2a27c591fa91fb6cf3c58ddccb6ccf7a9f99f9be151279d
7
- data.tar.gz: d08fce50463aad57f9112ba4997e92acfef409c50eabaec6212b9183bfb37a939f757fd540c3470543d24214d5326d2235911ac13b7bd87223cf60a2b1b782de
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::load(File.read CONFIG_FILE)
10
+ @config = YAML.load(File.read CONFIG_FILE)
14
11
  rescue => e
15
- puts "Error at opening config file, error was:"
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
- self.run
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
- file.seek(0,IO::SEEK_END)
54
- queue = INotify::Notifier.new
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
- if content.match(/#{pattern["regex"]}/)
59
- begin
60
- pagerduty.trigger("#{pattern["prefix"]} #{content}")
61
- @logger.info("ALERT TRIGGERD: #{pattern["prefix"]} #{content}" )
62
- rescue => e
63
- @logger.error("FAILED TO SEND ALERT: #{pattern["prefix"]} #{content}" )
64
- @logger.error("Error: #{e.message.to_s}" )
65
- end
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 {|t| t.join}
78
+ threads.each(&:join)
73
79
  end
74
80
  end
75
81
  end
@@ -1,3 +1,3 @@
1
1
  module Lognotifier
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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
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: 2014-10-08 00:00:00.000000000 Z
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.2.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