malsh 0.3.5 → 0.3.6
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 +4 -4
 - data/lib/malsh/version.rb +1 -1
 - data/lib/malsh.rb +17 -20
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 496b75cce4bfa94893f699050d52c6eb43b56cf3863fd9f0bfe0e07748961b8d
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 84f4216c6c2e56b81332d2a777b6953413f43a09a5216ad0a5aaed1a14421271
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: bf1876097f304d5a5a6736f24c474de58beab2609f70c5ba4a9d955fb6e2183a53f48f86aaf8e067979cac67f495fbce2147d3b110bec460aa5f920ffc874df3
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: cf51581d01a034a937bd46fa5b80336d247713185e05806b5444e0137fee4d485af18f2171bf4038c94bd678b013461a3a582db89865343fe0c591af2e7cc79d
         
     | 
    
        data/lib/malsh/version.rb
    CHANGED
    
    
    
        data/lib/malsh.rb
    CHANGED
    
    | 
         @@ -1,9 +1,9 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require  
     | 
| 
      
 1 
     | 
    
         
            +
            require 'malsh/version'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'thor'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'mackerel-rb'
         
     | 
| 
       4 
     | 
    
         
            -
            require  
     | 
| 
       5 
     | 
    
         
            -
            require  
     | 
| 
       6 
     | 
    
         
            -
            require  
     | 
| 
      
 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 
     | 
    
         
            -
                   
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
                   
     | 
| 
       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 
     | 
    
         
            -
                   
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
                   
     | 
| 
       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 = [ 
     | 
| 
      
 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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.6
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - kazuhiko yamahsita
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2022-07-25 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. 
     | 
| 
      
 159 
     | 
    
         
            +
            rubygems_version: 3.3.3
         
     | 
| 
       160 
160 
     | 
    
         
             
            signing_key:
         
     | 
| 
       161 
161 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       162 
162 
     | 
    
         
             
            summary: mackerel tools.
         
     |