tailnudge 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab69ad2210a335582f7fa11008dc199776e0dfdf
4
+ data.tar.gz: 054f6f3e889ce45b0bc0d50a3517b2ab32b51bed
5
+ SHA512:
6
+ metadata.gz: c81f070a7013d46549e220b8f1554473102436b12274c91cfb842989bb93265380b094092f2f3bb4fc72f96f1bf10a8163c6a39cd1af887478c93c450ef3b4df
7
+ data.tar.gz: 867cfb067b7b831e5bfb6f4b035a87712054a4f1b96c4a82d9e2163befbf8f957f70bf9d626d4e7fe885e23bc821c37a245cd22293f0c29ef85af9443137cf94
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1 @@
1
+ 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tailnudge.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,63 @@
1
+ # Tailnudge
2
+
3
+ Utility to send OSX notifications while tailing one or more files for
4
+ pattern matches.
5
+
6
+ Useful if you'd like to be notified when, eg, a log displays a
7
+ deprecation or error notice during development.
8
+
9
+ ## Installation
10
+
11
+
12
+ ```sh
13
+ $ gem install tailnudge
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ See:
19
+
20
+ ```sh
21
+ $ tailnudge help tail
22
+ ```
23
+
24
+ ## Examples
25
+
26
+ Tail a log and look for lines that include "DEPRECATION" or
27
+ "DEPRECATED", and play the "Tink" sound.
28
+
29
+ ```sh
30
+ $ tailnudge log/development.log -p deprecat -t 'My App' -s Tink
31
+ ```
32
+
33
+ Note that patterns are case-insensitive and that only one notification
34
+ per pattern will be displayed at a time (to prevent inadvertent event
35
+ flooding) unless you use the `--all`/`-a` option.
36
+
37
+ Notify Rails HTTP 200 request times, without throttling:
38
+
39
+ ```sh
40
+ $ tailnudge log/development.log -a -p 'Completed 200 OK in (\d+m?s)' -t 'Requests'
41
+ ```
42
+
43
+ Notify when HTTP 500 or 404 is encountered (but only show one 500/404
44
+ notication at a time; no `-a` option, and throttling is done per-pattern):
45
+
46
+ ```sh
47
+ $ tailnudge log/development.log -p 'Completed 500' 'Completed 404' -t 'HTTP 404/500'
48
+ ```
49
+
50
+ Notify when HTTP 5XX or 404 is encountered (but only show one 500 or
51
+ 404 at a time; no `-a` option, and throttling is done per-pattern):
52
+
53
+ ```sh
54
+ $ tailnudge log/development.log -p 'Completed [45]\d{2}' -t 'HTTP 4XX/5XX'
55
+ ```
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # -*- mode: ruby; -*-
4
+
5
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
6
+
7
+ require "tailnudge"
8
+
9
+ unless ARGV.empty? || %w(help tail).include?(ARGV[0])
10
+ ARGV.unshift('tail')
11
+ end
12
+
13
+ Tailnudge::CLI.start(ARGV)
@@ -0,0 +1,36 @@
1
+ require "eventmachine"
2
+ require "eventmachine-tail"
3
+ require "terminal-notifier"
4
+ require "thor"
5
+
6
+ module Tailnudge
7
+ autoload :VERSION, "tailnudge/version"
8
+ autoload :CLI, "tailnudge/cli"
9
+ autoload :Notification, "tailnudge/notification"
10
+ autoload :Reader, "tailnudge/reader"
11
+ autoload :Result, "tailnudge/result"
12
+
13
+ def self.configuration=(configuration = {})
14
+ # Patterns to match
15
+ self.patterns = configuration[:pattern]
16
+ # Basics
17
+ @configuration = configuration
18
+ end
19
+
20
+ def self.patterns=(patterns)
21
+ @patterns = Array(patterns).map { |pattern|
22
+ Regexp.new(pattern, Regexp::IGNORECASE)
23
+ }
24
+ end
25
+ class << self; attr_reader :patterns, :configuration; end
26
+
27
+ def self.run(paths = [], options)
28
+ self.configuration = options
29
+ EventMachine.run do
30
+ paths.each do |path|
31
+ EventMachine.file_tail(path, Reader)
32
+ end
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,36 @@
1
+ module Tailnudge
2
+
3
+ class CLI < Thor
4
+
5
+ method_option :all, {
6
+ aliases: %w(-a),
7
+ default: false,
8
+ desc: "Notify on every match (no throttling by pattern)"
9
+ }
10
+ method_option :title, {
11
+ aliases: %w(-t),
12
+ default: "tailnudge",
13
+ desc: "Title to use for notifications"
14
+ }
15
+ method_option :subtitle, desc: "Subtitle to use for notifications"
16
+ method_option :sound, {
17
+ lazy_default: 'default',
18
+ aliases: %w(-s),
19
+ desc: "Sound to play (listed in Sound Preferences, note they are case-sensitive)"
20
+ }
21
+ method_option :pattern, {
22
+ aliases: %w(-p --patterns),
23
+ type: :array,
24
+ required: true,
25
+ desc: "Regular expressions to match. Case-insensitive. Note that if a capture is present, only its contents will be used in the notification."
26
+ }
27
+ desc "tail FILE [MORE_FILES]", "Tail files for patterns"
28
+ def tail(files = [])
29
+ Tailnudge.run(Array(files), options)
30
+ end
31
+
32
+ default_task :tail
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,38 @@
1
+ module Tailnudge
2
+
3
+ class Notification
4
+
5
+ def self.create(result)
6
+ new(result).run
7
+ end
8
+
9
+ def initialize(result)
10
+ @result = result
11
+ end
12
+
13
+ def run
14
+ TerminalNotifier.notify(@result.message,
15
+ options)
16
+ end
17
+
18
+ private
19
+
20
+ def options
21
+ if Tailnudge.configuration[:all]
22
+ Tailnudge.configuration
23
+ else
24
+ # Throttling by group
25
+ Tailnudge.configuration.merge(group_id: group_id)
26
+ end
27
+ end
28
+
29
+ def group_id
30
+ [
31
+ Process.pid,
32
+ @result.pattern_id
33
+ ].join('-')
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,31 @@
1
+ module Tailnudge
2
+
3
+ class Reader < EventMachine::FileTail
4
+
5
+ def self.extract(line)
6
+ Tailnudge.patterns.each do |pattern|
7
+ match = pattern.match(line)
8
+ if match
9
+ return Result.new(match, line)
10
+ end
11
+ end
12
+ nil
13
+ end
14
+
15
+ def initialize(path, startpos=-1)
16
+ super(path, startpos)
17
+ @buffer = BufferedTokenizer.new
18
+ end
19
+
20
+ def receive_data(data)
21
+ @buffer.extract(data).each do |line|
22
+ result = self.class.extract(line)
23
+ if result
24
+ Notification.create(result)
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,20 @@
1
+ module Tailnudge
2
+
3
+ class Result
4
+
5
+ def initialize(match, text)
6
+ @match = match
7
+ @text = text
8
+ end
9
+
10
+ def message
11
+ @match[1] || @text
12
+ end
13
+
14
+ def pattern_id
15
+ @match.regexp.object_id
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,3 @@
1
+ module Tailnudge
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tailnudge/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tailnudge"
8
+ spec.version = Tailnudge::VERSION
9
+ spec.authors = ["Bruce Williams"]
10
+ spec.email = ["brwcodes@gmail.com"]
11
+ spec.summary = %q{Display OSX notification when a tailed file matches a pattern}
12
+ spec.description = %q{Tailnudge displays OS notifications when a tailed file matches a pattern; useful for being nudged more forcibly when you encounter deprecation, errors in log files.}
13
+ spec.homepage = "http://github.com/bruce/tailnudge"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "terminal-notifier"
22
+ spec.add_dependency "eventmachine-tail"
23
+ spec.add_dependency "thor"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.4"
26
+ spec.add_development_dependency "rake"
27
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tailnudge
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bruce Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: terminal-notifier
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: eventmachine-tail
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Tailnudge displays OS notifications when a tailed file matches a pattern;
84
+ useful for being nudged more forcibly when you encounter deprecation, errors in
85
+ log files.
86
+ email:
87
+ - brwcodes@gmail.com
88
+ executables:
89
+ - tailnudge
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".gitignore"
94
+ - ".ruby-version"
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/tailnudge
100
+ - lib/tailnudge.rb
101
+ - lib/tailnudge/cli.rb
102
+ - lib/tailnudge/notification.rb
103
+ - lib/tailnudge/reader.rb
104
+ - lib/tailnudge/result.rb
105
+ - lib/tailnudge/version.rb
106
+ - tailnudge.gemspec
107
+ homepage: http://github.com/bruce/tailnudge
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.2.0
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Display OSX notification when a tailed file matches a pattern
131
+ test_files: []