malsh 0.3.1 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '04893527ed6c71386b40145b68b31ae4bacce444e5d3edce147327789b18349b'
4
- data.tar.gz: 1ef47a2b0df230ca310900b2036c3ea63ca8ce4f4058e572f9c3154069142563
3
+ metadata.gz: ac84ac7dfd01868083d18c3e6be4fecba347d7a748e96033bc49e6b2d0b25c35
4
+ data.tar.gz: 88e91d32de344e8416c57d0e86bb8983a67db9c46d9e4639ff6402648694f238
5
5
  SHA512:
6
- metadata.gz: ea062a8de9ff0d9b425b042b7aff1bb1bbaf43bc4aad3c9f020a936496f07cece395ccb1d0fd4c15fb90789437c95933d0d5287a34f897e43c4339978d394d1c
7
- data.tar.gz: 7fbc8dc08cee0e942531086f53640653ca4cf27b7a66b0e836fa19396ae6a53cb20d1466f50ca5c6cb2725031b7541f430b2b2c00d5efd1b08d7acb4e551d021
6
+ metadata.gz: 11cab119d65d791bfa156646c3891795af92125f62095694e9edbcfd53efc16a403505876d6941aaa1228d310cecdb888a437f904e879a4ea36f3e1760c8ee03
7
+ data.tar.gz: 15b728424b65bb9080773210f4737e45416a7b00f6cc2c3036060df061115d6ee489801f79859788f87fcbec8007566a920d3b8103637fafdad2ed6bfbe63b98
data/lib/malsh/cli.rb CHANGED
@@ -24,7 +24,7 @@ module Malsh
24
24
  Time.now.to_i - 86400,
25
25
  Time.now.to_i
26
26
  )
27
- h if !m || m["metrics"].size == 0
27
+ h if (!m || (m["metrics"] && m["metrics"].size == 0)) && !(h["meta"].has_key?("cloud") && %w(elb rds cloudfront).include?(h["meta"]["cloud"]["provider"]))
28
28
  end.flatten.compact
29
29
  Malsh.notify_host("退役未了ホスト一覧", hosts)
30
30
  end
@@ -1,18 +1,19 @@
1
1
  module Malsh::Notification
2
2
  class Base
3
3
  def self.notify_host(subject, hosts)
4
- names = hosts.map(&:name)
5
- puts "#{subject}: \n#{names.join("\n")}" if names.size > 0 && doit?
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)
9
11
  puts "#{subject}: "
10
12
  alerts.each do |alert|
11
- title = case alert.type
12
- when 'external'
13
- alert.monitor.name
14
- else
13
+ title = if Malsh.alert_has_host?(alert)
15
14
  alert.host.name
15
+ else
16
+ alert.monitor.name
16
17
  end
17
18
  puts "#{title}: #{alert.message}"
18
19
  end
@@ -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.type == 'external'
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.type == 'external'
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
@@ -1,3 +1,3 @@
1
1
  module Malsh
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.5"
3
3
  end
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.type == 'external'
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
@@ -91,5 +91,11 @@ module Malsh
91
91
  puts e
92
92
  end
93
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
94
100
  end
95
101
  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.1
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - kazuhiko yamahsita
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-15 00:00:00.000000000 Z
11
+ date: 2021-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  requirements: []
159
- rubygems_version: 3.0.6
159
+ rubygems_version: 3.1.6
160
160
  signing_key:
161
161
  specification_version: 4
162
162
  summary: mackerel tools.