malsh 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: 347a943b1a31d9e96ce868829ed7244ee1f9b7e4
4
- data.tar.gz: d8292cf71492b05ec754738f8674af60160c806d
3
+ metadata.gz: 858533993fc700f1d6b4fc20d5d5c441ae037f0f
4
+ data.tar.gz: 15bdd45140ce7f0fb3faadbd94da1cf051886f45
5
5
  SHA512:
6
- metadata.gz: 8063808bd39e8639033f6586ea3df71dd820221e228e9c6cb6ca937fc2c41ebed7df0de82e8a0b0fb23936836516ffe78030cd376315862302aa74b16eddd47e
7
- data.tar.gz: 27656b665489d656235323d93015cb915e8c212646510885f4f66c555288ddf9669e51b98dbfb9f84fb028ed18b46cb89c49b7554ac727cc91efc227716971b7
6
+ metadata.gz: a5bbf854b5e324f132626028a63d1d0487f361463d8c7045be77b6e95cb7c7eb7cf7f5f29b45eee34df931e59996dfdeef48bc3533d69b7de93a4b488e5974e7
7
+ data.tar.gz: 2acfb0ef1aa9e8558f18b62b05cb4717300fb32c50e72158e7c2b7fa9658aa40aa753b34127cc5bbef8dca695654feb8dda3df76c1ddcb89410b02ec508cbffc
data/lib/malsh/cli.rb CHANGED
@@ -8,6 +8,7 @@ module Malsh
8
8
  class_option :slack_user, :type => :string, :aliases => :su
9
9
  class_option :api_key, :type => :string, :aliases => :k
10
10
  class_option :subject, :type => :string, :aliases => :s
11
+ class_option :org, :type => :string, :aliases => :o
11
12
  class_option :invert_match, :type => :array, :aliases => :v
12
13
  class_option :invert_role, :type => :array, :aliases => :r
13
14
  class_option :regexp,:type => :array, :aliases => :e
@@ -16,23 +17,23 @@ module Malsh
16
17
  def retire
17
18
  Malsh.init options
18
19
 
19
- host_names = Parallel.map(Malsh.metrics('memory.used')) do|memory|
20
+ hosts = Parallel.map(Malsh.metrics('memory.used')) do|memory|
20
21
  host = Malsh.host_by_id memory.first
21
- host.name if (!memory.last["memory.used"].respond_to?(:value) || !memory.last["memory.used"].value)
22
+ host if (!memory.last["memory.used"].respond_to?(:value) || !memory.last["memory.used"].value)
22
23
  end.flatten.compact
23
24
 
24
- Malsh.notify("退役未了ホスト一覧", host_names)
25
+ Malsh.notify("退役未了ホスト一覧", hosts)
25
26
  end
26
27
 
27
28
  desc 'maverick', 'check no role'
28
29
  def maverick
29
30
  Malsh.init options
30
31
 
31
- host_names = Parallel.map(Malsh.hosts) do |h|
32
- h.name if h.roles.keys.size < 1
32
+ hosts = Parallel.map(Malsh.hosts) do |h|
33
+ h if h.roles.keys.size < 1
33
34
  end.flatten.compact
34
35
 
35
- Malsh.notify("ロール無所属ホスト一覧", host_names)
36
+ Malsh.notify("ロール無所属ホスト一覧", hosts)
36
37
  end
37
38
 
38
39
  desc 'search', 'search hosts'
@@ -41,14 +42,13 @@ module Malsh
41
42
  option :memory_threshold, :type => :numeric, :aliases => :m
42
43
  option :status, :type => :string, :aliases => :st
43
44
  def search
44
- _host_names = {}
45
45
  Malsh.init options
46
46
  o = options[:status] ? { status: options[:status] } : {}
47
47
  hosts = Malsh.hosts(o)
48
48
  Object.const_get("Malsh::HostMetrics").constants.each do |c|
49
49
  hosts = Object.const_get("Malsh::HostMetrics::#{c}").check(hosts)
50
50
  end
51
- Malsh.notify("ホスト一覧", hosts.compact.map {|h| h["name"]})
51
+ Malsh.notify("ホスト一覧", hosts.compact)
52
52
  end
53
53
 
54
54
  map %w[--version -v] => :__print_version
@@ -1,7 +1,8 @@
1
1
  module Malsh::Notification
2
2
  class Base
3
3
  def self.notify(subject, hosts)
4
- puts "#{subject}: \n#{hosts.join("\n")}" if hosts.size > 0 && doit?
4
+ names = hosts.map(&:name)
5
+ puts "#{subject}: \n#{names.join("\n")}" if names.size > 0 && doit?
5
6
  end
6
7
 
7
8
  def self.doit?
@@ -3,8 +3,15 @@ module Malsh::Notification
3
3
  class Slack < Base
4
4
  def self.notify(subject, hosts)
5
5
  return unless doit?
6
+ lists = if Malsh.options[:org]
7
+ hosts.map do |h|
8
+ "<https://mackerel.io/orgs/#{Malsh.options[:org]}/hosts/#{h.id}/-/setting|#{h.name}>"
9
+ end
10
+ else
11
+ hosts.map(&:name)
12
+ end
6
13
  note = {
7
- text: hosts.join("\n"),
14
+ text: lists.join("\n"),
8
15
  color: "warning"
9
16
  }
10
17
  notifier.ping "*#{subject}*", attachments: [note]
data/lib/malsh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Malsh
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kazuhiko yamahsita
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-07 00:00:00.000000000 Z
11
+ date: 2017-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
- rubygems_version: 2.4.8
160
+ rubygems_version: 2.5.2
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: mackerel tools.