malsh 0.3.0 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/malsh/cli.rb +8 -4
- data/lib/malsh/notification/base.rb +4 -2
- data/lib/malsh/notification/slack.rb +7 -7
- data/lib/malsh/version.rb +1 -1
- data/lib/malsh.rb +17 -3
- data/malsh.gemspec +2 -2
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ba6b10739e65fa9b65e4cd60cd399ccdc4fc688d69bbaca61f0d032e9fd2c3d
|
4
|
+
data.tar.gz: 521295added941774b5ba85b0a2c3777747569552f5c94b6926259a050c812c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '050824909ff8d3d653b0e7a864b403002560386d217f02de354a6829d38890f439c2950bc6ac443bde5165e1ae0aed03097d91e604368af0acafc8f9158a417a'
|
7
|
+
data.tar.gz: 77b19f42a100da11c7e29c79f00a438bbe6488817f478be5b0fa9363cabab365415e810dc0d98ce0b310d033b10f563ad92b22e0d26e8416a5a86b24112711d6
|
data/lib/malsh/cli.rb
CHANGED
@@ -17,11 +17,15 @@ module Malsh
|
|
17
17
|
def retire
|
18
18
|
Malsh.init options
|
19
19
|
|
20
|
-
hosts = Parallel.map(Malsh.
|
21
|
-
|
22
|
-
|
20
|
+
hosts = Parallel.map(Malsh.hosts) do |h|
|
21
|
+
m = Malsh.host_metrics(
|
22
|
+
h.id,
|
23
|
+
Malsh.host_metric_names(h.id).first,
|
24
|
+
Time.now.to_i - 86400,
|
25
|
+
Time.now.to_i
|
26
|
+
)
|
27
|
+
h if (!m || (m["metrics"] && m["metrics"].size == 0)) && !(h["meta"].has_key?("cloud") && %w(elb rds cloudfront).include?(h["meta"]["cloud"]["provider"]))
|
23
28
|
end.flatten.compact
|
24
|
-
|
25
29
|
Malsh.notify_host("退役未了ホスト一覧", hosts)
|
26
30
|
end
|
27
31
|
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module Malsh::Notification
|
2
2
|
class Base
|
3
3
|
def self.notify_host(subject, hosts)
|
4
|
-
|
5
|
-
|
4
|
+
puts "#{subject}:"
|
5
|
+
hosts.map do |h|
|
6
|
+
puts "#{h.name}(#{h.roles.keys.join(",")})"
|
7
|
+
end if doit?
|
6
8
|
end
|
7
9
|
|
8
10
|
def self.notify_alert(subject, alerts)
|
@@ -5,7 +5,7 @@ module Malsh::Notification
|
|
5
5
|
return unless doit?
|
6
6
|
lists = if Malsh.options[:org]
|
7
7
|
hosts.map do |h|
|
8
|
-
"<https://mackerel.io/orgs/#{Malsh.options[:org]}/hosts/#{h.id}/-/setting|#{h.name}>"
|
8
|
+
"<https://mackerel.io/orgs/#{Malsh.options[:org]}/hosts/#{h.id}/-/setting|#{h.name}(#{h.roles.keys.join(",")})>"
|
9
9
|
end
|
10
10
|
else
|
11
11
|
hosts.map(&:name)
|
@@ -30,16 +30,16 @@ module Malsh::Notification
|
|
30
30
|
''
|
31
31
|
end
|
32
32
|
|
33
|
-
title = if alert
|
34
|
-
alert.monitor.name
|
35
|
-
else
|
33
|
+
title = if Malsh.alert_has_host?(alert)
|
36
34
|
alert.host.name
|
35
|
+
else
|
36
|
+
alert.monitor.name
|
37
37
|
end
|
38
38
|
|
39
|
-
author_name = if alert
|
40
|
-
''
|
41
|
-
else
|
39
|
+
author_name = if Malsh.alert_has_host?(alert)
|
42
40
|
alert.host.roles.map{|k, v| v.map{|r| "#{k}: #{r}"}}.flatten.join(" ")
|
41
|
+
else
|
42
|
+
''
|
43
43
|
end
|
44
44
|
|
45
45
|
attachments << {
|
data/lib/malsh/version.rb
CHANGED
data/lib/malsh.rb
CHANGED
@@ -51,10 +51,10 @@ module Malsh
|
|
51
51
|
|
52
52
|
def alerts()
|
53
53
|
@_alerts ||= Mackerel.alerts.map do |alert|
|
54
|
-
if alert
|
55
|
-
alert['monitor'] = Mackerel.monitor(alert.monitorId)
|
56
|
-
else
|
54
|
+
if alert_has_host?(alert)
|
57
55
|
alert['host'] = Malsh.host_by_id(alert.hostId)
|
56
|
+
else
|
57
|
+
alert['monitor'] = Mackerel.monitor(alert.monitorId)
|
58
58
|
end
|
59
59
|
alert
|
60
60
|
end
|
@@ -83,5 +83,19 @@ module Malsh
|
|
83
83
|
puts e
|
84
84
|
end
|
85
85
|
end
|
86
|
+
|
87
|
+
def host_metric_names(id)
|
88
|
+
begin
|
89
|
+
Mackerel.host_metric_names(id)
|
90
|
+
rescue => e
|
91
|
+
puts e
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def alert_has_host?(alert)
|
96
|
+
exclude_types = ['external', 'service']
|
97
|
+
return false if exclude_types.include?(alert.type)
|
98
|
+
true
|
99
|
+
end
|
86
100
|
end
|
87
101
|
end
|
data/malsh.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_dependency 'mackerel-rb'
|
27
27
|
spec.add_dependency 'slack-notifier'
|
28
28
|
spec.add_dependency 'parallel'
|
29
|
-
spec.add_development_dependency "bundler"
|
30
|
-
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "bundler"
|
30
|
+
spec.add_development_dependency "rake"
|
31
31
|
spec.add_development_dependency "rspec"
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: malsh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kazuhiko yamahsita
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -70,30 +70,30 @@ dependencies:
|
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,7 +141,7 @@ homepage: http://ten-snapon.com.
|
|
141
141
|
licenses:
|
142
142
|
- MIT
|
143
143
|
metadata: {}
|
144
|
-
post_install_message:
|
144
|
+
post_install_message:
|
145
145
|
rdoc_options: []
|
146
146
|
require_paths:
|
147
147
|
- lib
|
@@ -156,9 +156,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
159
|
-
|
160
|
-
|
161
|
-
signing_key:
|
159
|
+
rubygems_version: 3.1.6
|
160
|
+
signing_key:
|
162
161
|
specification_version: 4
|
163
162
|
summary: mackerel tools.
|
164
163
|
test_files: []
|