sensu-plugins-http-boutetnico 1.1.0 → 1.2.0
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/bin/metrics-http-json.rb +33 -16
 - data/lib/sensu-plugins-http/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 614d08b1f3e1c9b2d460ea354358ef70e2f64ae8
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 2f362017637e487505175c01b059b8762c09e13e
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 0ebcb58029ff428cd41bc33047f967682a8f4589ad01862e9b0a187187aa821f649a253c127f296bd988b45c0f1885674a19c8da84206edc028b22247b91de89
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 46138a93ec92ded1c134e48519ebcd3cc3879e4e1bd9b4b066d9e251da58fcd16cf5a4c7c4b9b680aca3982993c3fc53b8ed25d6d9b3a9c597b12e03db8a752b
         
     | 
    
        data/bin/metrics-http-json.rb
    CHANGED
    
    | 
         @@ -1,6 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #! /usr/bin/env ruby
         
     | 
| 
       2 
     | 
    
         
            -
            # 
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 2 
     | 
    
         
            +
            #
         
     | 
| 
       4 
3 
     | 
    
         
             
            #   metrics-http-json.rb
         
     | 
| 
       5 
4 
     | 
    
         
             
            #
         
     | 
| 
       6 
5 
     | 
    
         
             
            # DESCRIPTION:
         
     | 
| 
         @@ -17,7 +16,9 @@ 
     | 
|
| 
       17 
16 
     | 
    
         
             
            #   gem: rest-client
         
     | 
| 
       18 
17 
     | 
    
         
             
            #
         
     | 
| 
       19 
18 
     | 
    
         
             
            # USAGE:
         
     | 
| 
       20 
     | 
    
         
            -
            #    
     | 
| 
      
 19 
     | 
    
         
            +
            #   ./metrics-http-json.rb -u 'https://user:password@127.0.0.1:443
         
     | 
| 
      
 20 
     | 
    
         
            +
            #
         
     | 
| 
      
 21 
     | 
    
         
            +
            #   ./metrics-http-json.rb -u 'http://127.0.0.1:8080/jolokia/read/com\
         
     | 
| 
       21 
22 
     | 
    
         
             
            #   .mchange.v2.c3p0:name=datasource,type=PooledDataSource' -s hostname.c3p0\
         
     | 
| 
       22 
23 
     | 
    
         
             
            #    -m 'Connections::numConnections,BusyConnections::numBusyConnections'\
         
     | 
| 
       23 
24 
     | 
    
         
             
            #    -o 'value'
         
     | 
| 
         @@ -56,9 +57,10 @@ class HttpJsonGraphite < Sensu::Plugin::Metric::CLI::Graphite 
     | 
|
| 
       56 
57 
     | 
    
         
             
                     default: Socket.gethostname.to_s
         
     | 
| 
       57 
58 
     | 
    
         | 
| 
       58 
59 
     | 
    
         
             
              option :metric,
         
     | 
| 
       59 
     | 
    
         
            -
                     description: 'Metric/JSON key pair ex:Connections::numConnections',
         
     | 
| 
      
 60 
     | 
    
         
            +
                     description: 'Optional Metric/JSON key pair ex:Connections::numConnections',
         
     | 
| 
       60 
61 
     | 
    
         
             
                     short: '-m METRIC::JSONKEY',
         
     | 
| 
       61 
     | 
    
         
            -
                     long: '--metric METRIC::JSONKEY'
         
     | 
| 
      
 62 
     | 
    
         
            +
                     long: '--metric METRIC::JSONKEY',
         
     | 
| 
      
 63 
     | 
    
         
            +
                     default: nil
         
     | 
| 
       62 
64 
     | 
    
         | 
| 
       63 
65 
     | 
    
         
             
              option :headers,
         
     | 
| 
       64 
66 
     | 
    
         
             
                     description: 'Additional HTTP request headers to send. Example: Authorization:XYZ,User-Agent:ABC',
         
     | 
| 
         @@ -82,6 +84,16 @@ class HttpJsonGraphite < Sensu::Plugin::Metric::CLI::Graphite 
     | 
|
| 
       82 
84 
     | 
    
         
             
                     long: '--debug',
         
     | 
| 
       83 
85 
     | 
    
         
             
                     default: false
         
     | 
| 
       84 
86 
     | 
    
         | 
| 
      
 87 
     | 
    
         
            +
              def deep_value(hash, scheme = '')
         
     | 
| 
      
 88 
     | 
    
         
            +
                hash.each do |key, value|
         
     | 
| 
      
 89 
     | 
    
         
            +
                  if value.is_a?(Hash)
         
     | 
| 
      
 90 
     | 
    
         
            +
                    deep_value(value, "#{scheme}.#{key}")
         
     | 
| 
      
 91 
     | 
    
         
            +
                  else
         
     | 
| 
      
 92 
     | 
    
         
            +
                    output "#{scheme}.#{key}", value
         
     | 
| 
      
 93 
     | 
    
         
            +
                  end
         
     | 
| 
      
 94 
     | 
    
         
            +
                end
         
     | 
| 
      
 95 
     | 
    
         
            +
              end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
       85 
97 
     | 
    
         
             
              def run
         
     | 
| 
       86 
98 
     | 
    
         
             
                puts "args config: #{config}" if config[:debug]
         
     | 
| 
       87 
99 
     | 
    
         | 
| 
         @@ -110,22 +122,27 @@ class HttpJsonGraphite < Sensu::Plugin::Metric::CLI::Graphite 
     | 
|
| 
       110 
122 
     | 
    
         
             
                  )
         
     | 
| 
       111 
123 
     | 
    
         | 
| 
       112 
124 
     | 
    
         
             
                  puts "Http response: #{r}" if config[:debug]
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
                   
     | 
| 
       115 
     | 
    
         
            -
                     
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
                     
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                  if config[:metric].nil?
         
     | 
| 
      
 127 
     | 
    
         
            +
                    deep_value(::JSON.parse(r), scheme)
         
     | 
| 
      
 128 
     | 
    
         
            +
                  else
         
     | 
| 
      
 129 
     | 
    
         
            +
                    metric_pair_array = metric_pair_input.split(/,/)
         
     | 
| 
      
 130 
     | 
    
         
            +
                    metric_pair_array.each do |m|
         
     | 
| 
      
 131 
     | 
    
         
            +
                      metric, attribute = m.to_s.split(/::/)
         
     | 
| 
      
 132 
     | 
    
         
            +
                      puts "metric: #{metric}, attribute: #{attribute}" if config[:debug]
         
     | 
| 
      
 133 
     | 
    
         
            +
                      unless object.nil?
         
     | 
| 
      
 134 
     | 
    
         
            +
                        ::JSON.parse(r)[object].each do |k, v|
         
     | 
| 
      
 135 
     | 
    
         
            +
                          if k == attribute
         
     | 
| 
      
 136 
     | 
    
         
            +
                            output([scheme, metric].join('.'), v)
         
     | 
| 
      
 137 
     | 
    
         
            +
                          end
         
     | 
| 
      
 138 
     | 
    
         
            +
                        end
         
     | 
| 
      
 139 
     | 
    
         
            +
                      end
         
     | 
| 
      
 140 
     | 
    
         
            +
                      ::JSON.parse(r).each do |k, v|
         
     | 
| 
       119 
141 
     | 
    
         
             
                        if k == attribute
         
     | 
| 
       120 
142 
     | 
    
         
             
                          output([scheme, metric].join('.'), v)
         
     | 
| 
       121 
143 
     | 
    
         
             
                        end
         
     | 
| 
       122 
144 
     | 
    
         
             
                      end
         
     | 
| 
       123 
145 
     | 
    
         
             
                    end
         
     | 
| 
       124 
     | 
    
         
            -
                    ::JSON.parse(r).each do |k, v|
         
     | 
| 
       125 
     | 
    
         
            -
                      if k == attribute
         
     | 
| 
       126 
     | 
    
         
            -
                        output([scheme, metric].join('.'), v)
         
     | 
| 
       127 
     | 
    
         
            -
                      end
         
     | 
| 
       128 
     | 
    
         
            -
                    end
         
     | 
| 
       129 
146 
     | 
    
         
             
                  end
         
     | 
| 
       130 
147 
     | 
    
         
             
                rescue Errno::ECONNREFUSED
         
     | 
| 
       131 
148 
     | 
    
         
             
                  critical "#{config[:url]} is not responding"
         
     |