macklog 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 901c11b1c68baa1dbf06defee69bd4080b19a0d2
4
+ data.tar.gz: dbfa0eb4f272738fe1028b6f01e9f082537fde3b
5
+ SHA512:
6
+ metadata.gz: c12f8c1f354c687359319ff99e963c420eb5fa66c3935f382c56f9bbabd7ac2e76a5d6631f8338f2127c903c84dc9dfbbaf5abcd9477f90f5ef5aa87e53e90af
7
+ data.tar.gz: 4a9e1a3e9e49e64abaa3b70a85e754e4edc4b6ed05673c5fc9e50426c1260cfc0a92e04bc55fdd325452e4e4428cd28bf7c4ce4d64f2654877cf2054a43ae3e9
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ /test.*
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.6
5
+ - 2.2.2
6
+ addons:
7
+ code_climate:
8
+ repo_token: "e8ca1bd02a83946d3e1618a57c4cc5fb141c8288d0d246e8e6999c2314350baf"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in macklog.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ macklog (0.1.1)
5
+ thor
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ codeclimate-test-reporter (0.4.7)
11
+ simplecov (>= 0.7.1, < 1.0.0)
12
+ diff-lcs (1.2.5)
13
+ docile (1.1.5)
14
+ json (1.8.3)
15
+ rake (10.4.2)
16
+ rspec (3.3.0)
17
+ rspec-core (~> 3.3.0)
18
+ rspec-expectations (~> 3.3.0)
19
+ rspec-mocks (~> 3.3.0)
20
+ rspec-core (3.3.2)
21
+ rspec-support (~> 3.3.0)
22
+ rspec-expectations (3.3.1)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.3.0)
25
+ rspec-mocks (3.3.2)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.3.0)
28
+ rspec-support (3.3.0)
29
+ simplecov (0.10.0)
30
+ docile (~> 1.1.0)
31
+ json (~> 1.8)
32
+ simplecov-html (~> 0.10.0)
33
+ simplecov-html (0.10.0)
34
+ thor (0.19.1)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ bundler (~> 1.9)
41
+ codeclimate-test-reporter
42
+ macklog!
43
+ rake (~> 10.0)
44
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 kazuhiko yamahsita
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Macklog
2
+ [![Build Status](https://travis-ci.org/pyama86/macklog.svg?branch=master)](https://travis-ci.org/pyama86/macklog)
3
+
4
+ [![Code Climate](https://codeclimate.com/github/pyama86/macklog/badges/gpa.svg)](https://codeclimate.com/github/pyama86/macklog)
5
+
6
+
7
+ mackerelのログ監視プラグインです。
8
+ 指定したファイルに指定したワードが出力された場合、Criticalアラートを出力します。
9
+
10
+ ## Installation
11
+
12
+ ```ruby
13
+ gem 'macklog'
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ### mackerel-agent.conf
19
+ ```
20
+ [plugin.checks.http_fatal_error]
21
+ command = "macklog -f /var/log/httpd/error.log -w fatal -i"
22
+ ```
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it ( https://github.com/[my-github-username]/macklog/fork )
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ ENV['CODECLIMATE_REPO_TOKEN']="e8ca1bd02a83946d3e1618a57c4cc5fb141c8288d0d246e8e6999c2314350baf"
4
+ ENV['MALTCH_TEST'] = "true"
5
+ RSpec::Core::RakeTask.new("spec")
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "macklog"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/macklog ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'macklog'
4
+
5
+ Macklog::Cli.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ {
2
+ "result": {
3
+ "covered_percent": 93.48
4
+ }
5
+ }
@@ -0,0 +1,96 @@
1
+ {
2
+ "RSpec": {
3
+ "coverage": {
4
+ "/Users/yamashitakazuhiko/src/github.com/pyama86/macklog/lib/macklog.rb": [
5
+ 1,
6
+ 1,
7
+ 1,
8
+ 1,
9
+ null,
10
+ 1,
11
+ 1,
12
+ 1,
13
+ 1,
14
+ null
15
+ ],
16
+ "/Users/yamashitakazuhiko/src/github.com/pyama86/macklog/lib/macklog/cli.rb": [
17
+ 1,
18
+ null,
19
+ 1,
20
+ 1,
21
+ 1,
22
+ 1,
23
+ 1,
24
+ 1,
25
+ 1,
26
+ null,
27
+ null,
28
+ null,
29
+ null,
30
+ null,
31
+ null,
32
+ 6,
33
+ null,
34
+ 6,
35
+ 1,
36
+ 1,
37
+ null,
38
+ null,
39
+ 5,
40
+ null,
41
+ 5,
42
+ 2,
43
+ null,
44
+ null,
45
+ null,
46
+ 1,
47
+ 1,
48
+ 5,
49
+ null,
50
+ 2,
51
+ null,
52
+ 3,
53
+ null,
54
+ 5,
55
+ null,
56
+ null,
57
+ 1,
58
+ 2,
59
+ 2,
60
+ null,
61
+ 2,
62
+ 2,
63
+ 2,
64
+ null,
65
+ 0,
66
+ null,
67
+ null,
68
+ null,
69
+ 1,
70
+ 2,
71
+ 2,
72
+ null,
73
+ null,
74
+ null,
75
+ 1,
76
+ 3,
77
+ 3,
78
+ null,
79
+ 2,
80
+ null,
81
+ 1,
82
+ null,
83
+ 0,
84
+ null,
85
+ null,
86
+ 0,
87
+ null,
88
+ null,
89
+ null,
90
+ null,
91
+ null
92
+ ]
93
+ },
94
+ "timestamp": 1437383134
95
+ }
96
+ }
File without changes
data/exe/macklog ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "macklog"
data/lib/macklog.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'thor'
2
+ require 'pp'
3
+ require "macklog/version"
4
+ require "macklog/cli"
5
+
6
+ module Macklog
7
+ class Error < StandardError; end
8
+ class FileNotFound < Error; end
9
+ class MatchWord < Error; end
10
+ end
@@ -0,0 +1,75 @@
1
+ require 'macklog'
2
+
3
+ module Macklog
4
+ class Cli < Thor
5
+ desc "check", "check log"
6
+ option :file, :type => :string , :required => true, :aliases => '-f'
7
+ option :word , :type => :string , :required => true, :aliases => '-w'
8
+ option :ignorecase , :type => :boolean, :aliases => '-i'
9
+ def check
10
+ # exit code
11
+ # 0:OK
12
+ # 1:WARNING
13
+ # 2:CRITICAL
14
+ # 3:UNKNOWN
15
+
16
+ file_path = File.expand_path(options[:file])
17
+
18
+ unless File.exist?(file_path)
19
+ puts "#{file_path} not found!"
20
+ exit_status 3
21
+ end
22
+
23
+ result = log_search(file_path, options[:word] , options[:ignorecase])
24
+
25
+ if result && !notified?(file_path, result)
26
+ exit_status 2
27
+ end
28
+ end
29
+
30
+ no_tasks do
31
+ def log_search(file_path, word, ignore=nil)
32
+ result = case
33
+ when ignore
34
+ File.readlines(file_path).grep(/#{word}/i)
35
+ else
36
+ File.readlines(file_path).grep(/#{word}/)
37
+ end
38
+ result.last.chomp unless result.empty?
39
+ end
40
+
41
+ def notified?(file_path, record)
42
+ tmp_path = ENV["macklog_tmp"] ? ENV["macklog_tmp"] : "/tmp"
43
+ tmp_path << "/macklog_#{File.basename(file_path, '.*')}.tmp"
44
+
45
+ unless File.exist?(tmp_path) && File.readlines(tmp_path).map(&:chomp).include?(record)
46
+ append_alert_log(tmp_path, record)
47
+ false
48
+ else
49
+ true
50
+ end
51
+ end
52
+
53
+ def append_alert_log(tmp_path, record)
54
+ File.open(tmp_path, "a") do |file|
55
+ file.puts record
56
+ end
57
+ end
58
+
59
+ def exit_status(status)
60
+ if ENV["MALTCH_TEST"]
61
+ case status
62
+ when 2
63
+ raise(Macklog::MatchWord)
64
+ when 3
65
+ raise(Macklog::FileNotFound)
66
+ else
67
+ true
68
+ end
69
+ else
70
+ exit(status)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,10 @@
1
+ require 'thor'
2
+ require 'pp'
3
+ require "macklog/version"
4
+ require "macklog/cli"
5
+
6
+ module Macklog
7
+ class Error < StandardError; end
8
+ class FileNotFound < Error; end
9
+ class MatchWord < Error; end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Macklog
2
+ VERSION = "0.1.1"
3
+ end
data/macklog.gemspec ADDED
@@ -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 'macklog/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "macklog"
8
+ spec.version = Macklog::VERSION
9
+ spec.authors = ["kazuhiko yamahsita"]
10
+ spec.email = ["pyama@pepabo.com"]
11
+
12
+ spec.summary = %q{mackerel log watch plugin.}
13
+ spec.description = %q{mackerel log watch plugin }
14
+ spec.homepage = "http://tem-snapon.com"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "codeclimate-test-reporter"
26
+ spec.add_dependency "thor"
27
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: macklog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - kazuhiko yamahsita
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: codeclimate-test-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: 'mackerel log watch plugin '
84
+ email:
85
+ - pyama@pepabo.com
86
+ executables:
87
+ - macklog
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/macklog
100
+ - bin/setup
101
+ - coverage/.last_run.json
102
+ - coverage/.resultset.json
103
+ - coverage/.resultset.json.lock
104
+ - exe/macklog
105
+ - lib/macklog.rb
106
+ - lib/macklog/cli.rb
107
+ - lib/macklog/macklog.rb
108
+ - lib/macklog/version.rb
109
+ - macklog.gemspec
110
+ homepage: http://tem-snapon.com
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.4.6
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: mackerel log watch plugin.
134
+ test_files: []