sensu-plugin 2.6.0 → 2.6.1
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/sensu-plugin.rb +1 -1
 - data/lib/sensu-plugin/utils.rb +4 -0
 - data/test/handle_api_request_test.rb +8 -2
 - 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: b1dfcce5f32c8ed80fd9da0ff34dfac0b6b3a999
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 19da9ae23b0a0706f05c84ffb50ad4415433c383
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 3eb2f697572579bf4af26638f38a1e849ca873150412ccff731f6f770f4342b5d98919c4b7bc6bcd0a9c488c938ebd67e042bfd143dcc3c157084a6a7cf4789a
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 0bb69e9bb18ddf8eaea85f5f07643ff45cc230b4ca2510e84814c20dd7b1f87f52c6ea524cd62d5f7a06c11b2f835d90dcb45d8338e25780455cadb592ff7c62
         
     | 
    
        data/lib/sensu-plugin.rb
    CHANGED
    
    
    
        data/lib/sensu-plugin/utils.rb
    CHANGED
    
    | 
         @@ -115,7 +115,11 @@ module Sensu 
     | 
|
| 
       115 
115 
     | 
    
         
             
                        unknown("Non-OK response from API query: #{get_uri(query_path)}")
         
     | 
| 
       116 
116 
     | 
    
         
             
                      end
         
     | 
| 
       117 
117 
     | 
    
         
             
                      data = JSON.parse(response.body)
         
     | 
| 
      
 118 
     | 
    
         
            +
                      # when the data is empty, we have hit the end
         
     | 
| 
       118 
119 
     | 
    
         
             
                      break if data.empty?
         
     | 
| 
      
 120 
     | 
    
         
            +
                      # If API lacks pagination support, it will
         
     | 
| 
      
 121 
     | 
    
         
            +
                      # return same data on subsequent iterations
         
     | 
| 
      
 122 
     | 
    
         
            +
                      break if results.any? { |r| r == data }
         
     | 
| 
       119 
123 
     | 
    
         
             
                      results << data
         
     | 
| 
       120 
124 
     | 
    
         
             
                      offset += limit
         
     | 
| 
       121 
125 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -33,11 +33,17 @@ class TestHandleAPIRequest < MiniTest::Test 
     | 
|
| 
       33 
33 
     | 
    
         
             
              end
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
              def test_http_paginated_get
         
     | 
| 
      
 36 
     | 
    
         
            +
                result_two = sample_check_result.dup
         
     | 
| 
      
 37 
     | 
    
         
            +
                result_two[:client] = 'haproxy01'
         
     | 
| 
      
 38 
     | 
    
         
            +
                result_two[:name]   = 'check_haproxy'
         
     | 
| 
      
 39 
     | 
    
         
            +
                result_two[:output] = 'haproxy is fubar'
         
     | 
| 
      
 40 
     | 
    
         
            +
                result_two[:status] = 2
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
       36 
42 
     | 
    
         
             
                stub_request(:get, 'http://127.0.0.1:4567/results?limit=1&offset=0')
         
     | 
| 
       37 
43 
     | 
    
         
             
                  .to_return(status: 200, headers: {}, body: JSON.dump([sample_check_result]))
         
     | 
| 
       38 
44 
     | 
    
         | 
| 
       39 
45 
     | 
    
         
             
                stub_request(:get, 'http://127.0.0.1:4567/results?limit=1&offset=1')
         
     | 
| 
       40 
     | 
    
         
            -
                  .to_return(status: 200, headers: {}, body: JSON.dump([ 
     | 
| 
      
 46 
     | 
    
         
            +
                  .to_return(status: 200, headers: {}, body: JSON.dump([result_two]))
         
     | 
| 
       41 
47 
     | 
    
         | 
| 
       42 
48 
     | 
    
         
             
                stub_request(:get, 'http://127.0.0.1:4567/results?limit=1&offset=2')
         
     | 
| 
       43 
49 
     | 
    
         
             
                  .to_return(status: 200, headers: {}, body: JSON.dump([]))
         
     | 
| 
         @@ -46,7 +52,7 @@ class TestHandleAPIRequest < MiniTest::Test 
     | 
|
| 
       46 
52 
     | 
    
         
             
                response = handler.paginated_get('/results', 'limit' => 1)
         
     | 
| 
       47 
53 
     | 
    
         | 
| 
       48 
54 
     | 
    
         
             
                # we expect the combined results to be an array containing two instances of the sample check result
         
     | 
| 
       49 
     | 
    
         
            -
                combined_results = JSON.parse("[ #{JSON.dump(sample_check_result)} , #{JSON.dump( 
     | 
| 
      
 55 
     | 
    
         
            +
                combined_results = JSON.parse("[ #{JSON.dump(sample_check_result)} , #{JSON.dump(result_two)} ]")
         
     | 
| 
       50 
56 
     | 
    
         
             
                assert_equal(response, combined_results)
         
     | 
| 
       51 
57 
     | 
    
         
             
              end
         
     | 
| 
       52 
58 
     | 
    
         |