macklog 0.1.4 → 0.2.0

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: a62fda172422a1b1139963a312898ac0f630159b
4
- data.tar.gz: 93cce5305c530eb41283a5aaa2bf594c9d3f111a
3
+ metadata.gz: 22fe76b55d8c6450f3e716762e69f4c5b8636cf9
4
+ data.tar.gz: 0b995005bfaedede0731ff180d06ddc0c78cb6cc
5
5
  SHA512:
6
- metadata.gz: 04d1ff56fafb4e2b4adff8f8590e9fa906baccba03b0787c5fa8341585d7e26a2ed4e31a97d8033eac4098a727d278b03adca332c569c73be64fbd04e5cd11c4
7
- data.tar.gz: 500d341e87ed5c77bda24669238abaec1fd8eaaf0ea804c3ed76702b6d1b3ceff00c0be2821f81b89b47294c279efe93f5bd0f1efb98845c400cb9d937884702
6
+ metadata.gz: 3cea8c1711ad4402114474f59ed5f6134d0ebb481f73b9202996af51fd079b2e917b9cf3a420d090f952f60e07335c0b2e2b90ebe8bcdc9d09db7ce0a5a8a0c7
7
+ data.tar.gz: a2e6dfb20e815c3490142d7c8166194ac3f7933332581aa094768f08281db68942548b5d4d18a51f47aa2538dd2a9a829d376728b483df69ebaf3776a41566f7
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  /test.*
2
2
  /pkg
3
+ /Gemfile.lock
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- macklog (0.1.4)
4
+ macklog (0.2.0)
5
5
  thor
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
 
7
7
  mackerelのログ監視プラグインです。
8
- 指定したファイルに指定したワードが出力された場合、Criticalアラートを出力します。
8
+ 指定したファイルに指定したワードが出力された場合、アラートを出力します。
9
9
 
10
10
  ## Installation
11
11
 
12
12
  ```ruby
13
- gem 'macklog'
13
+ gem install macklog
14
14
  ```
15
15
 
16
16
  ## Usage
@@ -24,7 +24,8 @@ command = "macklog -f /var/log/httpd/error.log -w fatal -i"
24
24
  ### options
25
25
  ```
26
26
  -f : 対象ファイル
27
- -w : 対象キーワード
27
+ -w : warningキーワード
28
+ -c : criticalキーワード
28
29
  -i : 大文字小文字を区別しない
29
30
  ```
30
31
 
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "result": {
3
- "covered_percent": 93.48
3
+ "covered_percent": 94.23
4
4
  }
5
5
  }
@@ -11,6 +11,7 @@
11
11
  1,
12
12
  1,
13
13
  1,
14
+ 1,
14
15
  null
15
16
  ],
16
17
  "/Users/yamashitakazuhiko/src/github.com/pyama86/macklog/lib/macklog/cli.rb": [
@@ -23,61 +24,65 @@
23
24
  1,
24
25
  1,
25
26
  1,
27
+ 1,
26
28
  null,
27
29
  null,
28
30
  null,
29
31
  null,
30
32
  null,
31
33
  null,
32
- 6,
34
+ 10,
33
35
  null,
34
- 6,
36
+ 10,
35
37
  1,
36
38
  1,
37
39
  null,
38
- null,
39
- 5,
40
- null,
40
+ 9,
41
41
  5,
42
- 2,
43
- null,
44
- null,
45
42
  null,
46
43
  1,
47
44
  1,
48
- 5,
45
+ 1,
46
+ 11,
47
+ 11,
49
48
  null,
50
- 2,
51
49
  null,
52
- 3,
50
+ 1,
51
+ 11,
53
52
  null,
54
53
  5,
55
54
  null,
55
+ 6,
56
+ null,
57
+ 11,
58
+ null,
56
59
  null,
57
60
  1,
58
- 2,
59
- 2,
61
+ 6,
62
+ 6,
60
63
  null,
61
- 2,
62
- 2,
63
- 2,
64
+ 6,
65
+ 6,
66
+ 6,
64
67
  null,
65
68
  0,
66
69
  null,
67
70
  null,
68
71
  null,
69
72
  1,
70
- 2,
71
- 2,
73
+ 6,
74
+ 6,
72
75
  null,
73
76
  null,
74
77
  null,
75
78
  1,
76
- 3,
77
- 3,
79
+ 7,
80
+ 7,
78
81
  null,
79
82
  2,
80
83
  null,
84
+ 4,
85
+ null,
81
86
  1,
82
87
  null,
83
88
  0,
@@ -91,6 +96,6 @@
91
96
  null
92
97
  ]
93
98
  },
94
- "timestamp": 1437383134
99
+ "timestamp": 1438087132
95
100
  }
96
101
  }
@@ -6,5 +6,6 @@ require "macklog/cli"
6
6
  module Macklog
7
7
  class Error < StandardError; end
8
8
  class FileNotFound < Error; end
9
- class MatchWord < Error; end
9
+ class Critical < Error; end
10
+ class Warning < Error; end
10
11
  end
@@ -4,7 +4,8 @@ module Macklog
4
4
  class Cli < Thor
5
5
  desc "check", "check log"
6
6
  option :file, :type => :string , :required => true, :aliases => '-f'
7
- option :word , :type => :string , :required => true, :aliases => '-w'
7
+ option :critical, :type => :string, :aliases => '-c'
8
+ option :warning, :type => :string, :aliases => '-w'
8
9
  option :ignorecase , :type => :boolean, :aliases => '-i'
9
10
  def check
10
11
  # exit code
@@ -19,15 +20,16 @@ module Macklog
19
20
  puts "#{file_path} not found!"
20
21
  exit_status 3
21
22
  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
23
+ check_log(file_path, options[:critical], 2, options[:ignorecase]) if options[:critical]
24
+ check_log(file_path, options[:warning], 1, options[:ignorecase]) if options[:warning]
28
25
  end
29
26
  default_task :check
30
27
  no_tasks do
28
+ def check_log(file_path, word, status, ignore)
29
+ result = log_search(file_path, word, ignore)
30
+ exit_status status if result && !notified?(file_path, result)
31
+ end
32
+
31
33
  def log_search(file_path, word, ignore=nil)
32
34
  result = case
33
35
  when ignore
@@ -59,8 +61,10 @@ module Macklog
59
61
  def exit_status(status)
60
62
  if ENV["MALTCH_TEST"]
61
63
  case status
64
+ when 1
65
+ raise(Macklog::Warning)
62
66
  when 2
63
- raise(Macklog::MatchWord)
67
+ raise(Macklog::Critical)
64
68
  when 3
65
69
  raise(Macklog::FileNotFound)
66
70
  else
@@ -1,3 +1,3 @@
1
1
  module Macklog
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macklog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kazuhiko yamahsita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-20 00:00:00.000000000 Z
11
+ date: 2015-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler