malsh 0.3.5 → 0.3.7

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: ac84ac7dfd01868083d18c3e6be4fecba347d7a748e96033bc49e6b2d0b25c35
4
- data.tar.gz: 88e91d32de344e8416c57d0e86bb8983a67db9c46d9e4639ff6402648694f238
3
+ metadata.gz: d2921c475fe2f506e5112d5516ce9edd3dced93b747d54e201e75b501ce08e07
4
+ data.tar.gz: 667793ad29f16f1f5da072262f7a20ae568e991cf893ac4acff1ab5eec4bf945
5
5
  SHA512:
6
- metadata.gz: 11cab119d65d791bfa156646c3891795af92125f62095694e9edbcfd53efc16a403505876d6941aaa1228d310cecdb888a437f904e879a4ea36f3e1760c8ee03
7
- data.tar.gz: 15b728424b65bb9080773210f4737e45416a7b00f6cc2c3036060df061115d6ee489801f79859788f87fcbec8007566a920d3b8103637fafdad2ed6bfbe63b98
6
+ metadata.gz: ef60cccc6ff2ed471f23b2abb54e4976f405f9e923eab9e6c2f52d8dcb44c7abe82f63628d4ff568664ec3cc4a4d77a517a5ea22acde800fc0b5902747600eac
7
+ data.tar.gz: dbd026c600590927df289db850dc278a9698b2296b91b9a295848978eb975adc93d648b86d034073a1cced56f6b9e37bdbd69ccac7793b84325dbeb626906608
data/lib/malsh/cli.rb CHANGED
@@ -1,17 +1,16 @@
1
1
  require 'malsh'
2
2
  require 'parallel'
3
- require 'pp'
4
3
  module Malsh
5
4
  class CLI < Thor
6
- class_option :slack_webhook, :type => :string, :aliases => :sw
7
- class_option :slack_channel, :type => :string, :aliases => :sc
8
- class_option :slack_user, :type => :string, :aliases => :su
9
- class_option :api_key, :type => :string, :aliases => :k
10
- class_option :subject, :type => :string, :aliases => :s
11
- class_option :org, :type => :string, :aliases => :o
12
- class_option :invert_match, :type => :array, :aliases => :v
13
- class_option :invert_role, :type => :array, :aliases => :r
14
- class_option :regexp,:type => :array, :aliases => :e
5
+ class_option :slack_webhook, type: :string, aliases: :sw
6
+ class_option :slack_channel, type: :string, aliases: :sc
7
+ class_option :slack_user, type: :string, aliases: :su
8
+ class_option :api_key, type: :string, aliases: :k
9
+ class_option :subject, type: :string, aliases: :s
10
+ class_option :org, type: :string, aliases: :o
11
+ class_option :invert_match, type: :array, aliases: :v
12
+ class_option :invert_role, type: :array, aliases: :r
13
+ class_option :regexp, type: :array, aliases: :e
15
14
 
16
15
  desc 'retire', 'check forget retire host'
17
16
  def retire
@@ -21,12 +20,13 @@ module Malsh
21
20
  m = Malsh.host_metrics(
22
21
  h.id,
23
22
  Malsh.host_metric_names(h.id).first,
24
- Time.now.to_i - 86400,
23
+ Time.now.to_i - 86_400,
25
24
  Time.now.to_i
26
25
  )
27
- h if (!m || (m["metrics"] && m["metrics"].size == 0)) && !(h["meta"].has_key?("cloud") && %w(elb rds cloudfront).include?(h["meta"]["cloud"]["provider"]))
26
+ h if (!m || (m['metrics'] && m['metrics'].size == 0)) &&
27
+ !(h['meta'].has_key?('cloud') && %w[elb rds cloudfront kubernetes].include?(h['meta']['cloud']['provider']))
28
28
  end.flatten.compact
29
- Malsh.notify_host("退役未了ホスト一覧", hosts)
29
+ Malsh.notify_host('退役未了ホスト一覧', hosts)
30
30
  end
31
31
 
32
32
  desc 'maverick', 'check no role'
@@ -37,22 +37,22 @@ module Malsh
37
37
  h if h.roles.keys.size < 1
38
38
  end.flatten.compact
39
39
 
40
- Malsh.notify_host("ロール無所属ホスト一覧", hosts)
40
+ Malsh.notify_host('ロール無所属ホスト一覧', hosts)
41
41
  end
42
42
 
43
43
  desc 'search', 'search hosts'
44
- option :past_date , :type => :numeric, :aliases => :p
45
- option :cpu_threshold, :type => :numeric, :aliases => :c
46
- option :memory_threshold, :type => :numeric, :aliases => :m
47
- option :status, :type => :string, :aliases => :st
44
+ option :past_date, type: :numeric, aliases: :p
45
+ option :cpu_threshold, type: :numeric, aliases: :c
46
+ option :memory_threshold, type: :numeric, aliases: :m
47
+ option :status, type: :string, aliases: :st
48
48
  def search
49
49
  Malsh.init options
50
50
  o = options[:status] ? { status: options[:status] } : {}
51
51
  hosts = Malsh.hosts(o)
52
- Object.const_get("Malsh::HostMetrics").constants.each do |c|
52
+ Object.const_get('Malsh::HostMetrics').constants.each do |c|
53
53
  hosts = Object.const_get("Malsh::HostMetrics::#{c}").check(hosts)
54
54
  end
55
- Malsh.notify_host("ホスト一覧", hosts.compact)
55
+ Malsh.notify_host('ホスト一覧', hosts.compact)
56
56
  end
57
57
 
58
58
  desc 'alert', 'list alerts'
@@ -63,7 +63,7 @@ module Malsh
63
63
  end
64
64
 
65
65
  map %w[--version -v] => :__print_version
66
- desc "--version, -v", "print the version"
66
+ desc '--version, -v', 'print the version'
67
67
  def __print_version
68
68
  puts Malsh::VERSION
69
69
  end
data/lib/malsh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Malsh
2
- VERSION = "0.3.5"
2
+ VERSION = '0.3.7'
3
3
  end
data/lib/malsh.rb CHANGED
@@ -1,9 +1,9 @@
1
- require "malsh/version"
1
+ require 'malsh/version'
2
2
  require 'thor'
3
3
  require 'mackerel-rb'
4
- require "malsh/cli"
5
- require "malsh/notification"
6
- require "malsh/host_metrics"
4
+ require 'malsh/cli'
5
+ require 'malsh/notification'
6
+ require 'malsh/host_metrics'
7
7
 
8
8
  module Malsh
9
9
  class << self
@@ -19,7 +19,7 @@ module Malsh
19
19
  end
20
20
  end
21
21
 
22
- def options(ops=nil)
22
+ def options(ops = nil)
23
23
  @_options = ops if ops
24
24
  @_options
25
25
  end
@@ -38,9 +38,9 @@ module Malsh
38
38
 
39
39
  def hosts(options = {})
40
40
  @_hosts ||= Mackerel.hosts(options).reject do |h|
41
- Malsh.options[:invert_match] && Malsh.options[:invert_match].find {|v| host_name(h).match(/#{v}/) }
41
+ Malsh.options[:invert_match] && Malsh.options[:invert_match].find { |v| host_name(h).match(/#{v}/) }
42
42
  end.reject do |h|
43
- Malsh.options[:regexp] && Malsh.options[:regexp].all? {|r| !host_name(h).match(/#{r}/)}
43
+ Malsh.options[:regexp] && Malsh.options[:regexp].all? { |r| !host_name(h).match(/#{r}/) }
44
44
  end.reject do |h|
45
45
  Malsh.options[:invert_role] && Malsh.options[:invert_role].find do |r|
46
46
  service, role = r.split(/:/)
@@ -49,7 +49,7 @@ module Malsh
49
49
  end
50
50
  end
51
51
 
52
- def alerts()
52
+ def alerts
53
53
  @_alerts ||= Mackerel.alerts.map do |alert|
54
54
  if alert_has_host?(alert)
55
55
  alert['host'] = Malsh.host_by_id(alert.hostId)
@@ -71,30 +71,27 @@ module Malsh
71
71
  def metrics(name)
72
72
  hash = {}
73
73
  hosts.map(&:id).each_slice(200) do |ids|
74
- hash.merge!(Mackerel.latest_tsdb({hostId: ids, name: name}))
74
+ hash.merge!(Mackerel.latest_tsdb({ hostId: ids, name: name }))
75
75
  end
76
76
  hash
77
77
  end
78
78
 
79
79
  def host_metrics(id, name, from, to)
80
- begin
81
- Mackerel.host_metrics(id, name: name, from: from, to: to)
82
- rescue => e
83
- puts e
84
- end
80
+ Mackerel.host_metrics(id, name: name, from: from, to: to)
81
+ rescue StandardError => e
82
+ puts e
85
83
  end
86
84
 
87
85
  def host_metric_names(id)
88
- begin
89
- Mackerel.host_metric_names(id)
90
- rescue => e
91
- puts e
92
- end
86
+ Mackerel.host_metric_names(id)
87
+ rescue StandardError => e
88
+ puts e
93
89
  end
94
90
 
95
91
  def alert_has_host?(alert)
96
- exclude_types = ['external', 'service']
92
+ exclude_types = %w[external service expression]
97
93
  return false if exclude_types.include?(alert.type)
94
+
98
95
  true
99
96
  end
100
97
  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.5
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - kazuhiko yamahsita
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-13 00:00:00.000000000 Z
11
+ date: 2023-09-08 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.1.6
159
+ rubygems_version: 3.3.26
160
160
  signing_key:
161
161
  specification_version: 4
162
162
  summary: mackerel tools.