kapacitor-ruby 1.0.3 → 1.0.8
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 +5 -5
- data/lib/kapacitor/client.rb +78 -66
- data/lib/kapacitor/version.rb +1 -1
- metadata +6 -7
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: b992f75fe340aaeb410f88845f8b0cf22f404a68f2407920450aeb8f81a749cc
         | 
| 4 | 
            +
              data.tar.gz: 0f86926ff9b4354aa26f34cb82dbdcc48678dd9cf89f7b3a7b4161573d0b1265
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 5766810cf37cf0f73c05085e5dc0e2698f2439a48b065a8c78b0dd1516ea08d5597cfd5ddc8b266f56ee175f0627ac7667f3fa9ac2b515406efb7343862cbc6d
         | 
| 7 | 
            +
              data.tar.gz: e2e22bb48e84baf6803fa099364991221fb5f0c1d4746a38811d9fc88e208c98b6ba312eb226f27b5a4f4011580da787bb9885ddca86f43202affd92f77de6b5
         | 
    
        data/lib/kapacitor/client.rb
    CHANGED
    
    | @@ -13,7 +13,7 @@ module Kapacitor | |
| 13 13 | 
             
                # @param url [String] Kapacitor REST API's URL (defaults to `http://localhost:9092`)
         | 
| 14 14 | 
             
                # @param version [Integer] API version (defaults to `v1preview`)
         | 
| 15 15 | 
             
                #
         | 
| 16 | 
            -
                def initialize(url: 'http://localhost:9092/kapacitor', version: ' | 
| 16 | 
            +
                def initialize(url: 'http://localhost:9092/kapacitor', version: 'v1')
         | 
| 17 17 | 
             
                  @http = HTTPClient.new
         | 
| 18 18 | 
             
                  @url = [url, version].join('/')
         | 
| 19 19 | 
             
                end
         | 
| @@ -61,6 +61,15 @@ module Kapacitor | |
| 61 61 | 
             
                  api_delete(endpoint: "templates/#{id}")
         | 
| 62 62 | 
             
                end
         | 
| 63 63 |  | 
| 64 | 
            +
                # Retrieve Kapacitor topic
         | 
| 65 | 
            +
                #
         | 
| 66 | 
            +
                # @return [List[String]] List of topics
         | 
| 67 | 
            +
                #
         | 
| 68 | 
            +
                def topics()
         | 
| 69 | 
            +
                  res = api_get(endpoint: "alerts/topics")
         | 
| 70 | 
            +
                  return res['topics'].map { |v| v['id'] }
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
             | 
| 64 73 | 
             
                # Retrieve Kapacitor templates
         | 
| 65 74 | 
             
                #
         | 
| 66 75 | 
             
                # @param offset [Integer] Offset count for paginating through templates
         | 
| @@ -89,7 +98,7 @@ module Kapacitor | |
| 89 98 | 
             
                def define_task(id:, dbrps:, **opts)
         | 
| 90 99 | 
             
                  if (opts[:template_id].nil? && opts[:type].nil? && opts[:script].nil?) || (opts[:template_id] && (opts[:type] || opts[:script]))
         | 
| 91 100 | 
             
                    raise ArgumentError, "Must specify either a Template ID or a script and type"
         | 
| 92 | 
            -
                  elsif opts[ | 
| 101 | 
            +
                  elsif opts[:template_id].nil? && (opts[:type].nil? || opts[:script].nil?)
         | 
| 93 102 | 
             
                    raise ArgumentError, "Must specify both task type and script when not using a Template ID"
         | 
| 94 103 | 
             
                  end
         | 
| 95 104 |  | 
| @@ -130,7 +139,7 @@ module Kapacitor | |
| 130 139 | 
             
                  req['type'] = opts[:type] if opts[:type]
         | 
| 131 140 | 
             
                  req['dbrps'] = opts[:dbrps] if opts[:dbrps]
         | 
| 132 141 | 
             
                  req['script'] = opts[:script] if opts[:script]
         | 
| 133 | 
            -
                  req['status'] =  | 
| 142 | 
            +
                  req['status'] = 'disabled'
         | 
| 134 143 | 
             
                  req['vars'] = opts[:vars] if opts[:vars]
         | 
| 135 144 |  | 
| 136 145 | 
             
                  if opts[:type]
         | 
| @@ -142,6 +151,12 @@ module Kapacitor | |
| 142 151 | 
             
                  end
         | 
| 143 152 |  | 
| 144 153 | 
             
                  api_patch(endpoint: "tasks/#{id}", data: req) unless req.empty?
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                  if opts[:status] == 'enabled'
         | 
| 156 | 
            +
                    req['status'] = opts[:status] if opts[:status]
         | 
| 157 | 
            +
                    api_patch(endpoint: "tasks/#{id}", data: req) unless req.empty?
         | 
| 158 | 
            +
                  end
         | 
| 159 | 
            +
             | 
| 145 160 | 
             
                end
         | 
| 146 161 |  | 
| 147 162 | 
             
                # Delete a Kapacitor task
         | 
| @@ -179,20 +194,17 @@ module Kapacitor | |
| 179 194 | 
             
                #
         | 
| 180 195 | 
             
                # @param id [String] Handler ID
         | 
| 181 196 | 
             
                # @param topic [String] Topic name
         | 
| 182 | 
            -
                # @param  | 
| 197 | 
            +
                # @param kind [String] Kind of handler
         | 
| 198 | 
            +
                # @param match [String] Lambda expression
         | 
| 199 | 
            +
                # @param options [Hash] Handler options
         | 
| 183 200 | 
             
                #
         | 
| 184 | 
            -
                def define_topic_handler(id:, topic:,  | 
| 185 | 
            -
                  req = { | 
| 186 | 
            -
             | 
| 187 | 
            -
             | 
| 188 | 
            -
                   | 
| 189 | 
            -
                   | 
| 190 | 
            -
             | 
| 191 | 
            -
                  actions.each do |action|
         | 
| 192 | 
            -
                    raise ArgumentError, "Missing required kind attribute for action #{action}"
         | 
| 193 | 
            -
                  end
         | 
| 194 | 
            -
             | 
| 195 | 
            -
                  req['actions'] = actions
         | 
| 201 | 
            +
                def define_topic_handler(id:, topic:, kind:, match: nil, options: {})
         | 
| 202 | 
            +
                  req = {
         | 
| 203 | 
            +
                    'id': id,
         | 
| 204 | 
            +
                    'kind': kind
         | 
| 205 | 
            +
                  }
         | 
| 206 | 
            +
                  req['match'] = match unless match.nil?
         | 
| 207 | 
            +
                  req['options'] = options
         | 
| 196 208 | 
             
                  api_post(endpoint: "alerts/topics/#{topic}/handlers", data: req)
         | 
| 197 209 | 
             
                end
         | 
| 198 210 |  | 
| @@ -200,15 +212,17 @@ module Kapacitor | |
| 200 212 | 
             
                #
         | 
| 201 213 | 
             
                # @param id [String] Handler ID
         | 
| 202 214 | 
             
                # @param topic [String] Topic name
         | 
| 203 | 
            -
                # @param  | 
| 215 | 
            +
                # @param kind [String] Kind of handler
         | 
| 216 | 
            +
                # @param match [String] Lambda expression
         | 
| 217 | 
            +
                # @param options [Hash] Handler options
         | 
| 204 218 | 
             
                #
         | 
| 205 | 
            -
                def update_topic_handler(id:, topic:,  | 
| 206 | 
            -
                  req = { | 
| 207 | 
            -
             | 
| 208 | 
            -
             | 
| 209 | 
            -
                   | 
| 210 | 
            -
             | 
| 211 | 
            -
                  req[' | 
| 219 | 
            +
                def update_topic_handler(id:, topic:, kind:, match: nil, options: nil)
         | 
| 220 | 
            +
                  req = {
         | 
| 221 | 
            +
                    'id': id,
         | 
| 222 | 
            +
                    'kind': kind
         | 
| 223 | 
            +
                  }
         | 
| 224 | 
            +
                  req['match'] = match unless match.nil?
         | 
| 225 | 
            +
                  req['options'] = options unless options.nil?
         | 
| 212 226 | 
             
                  api_put(endpoint: "alerts/topics/#{topic}/handlers/#{id}", data: req) unless req.empty?
         | 
| 213 227 | 
             
                end
         | 
| 214 228 |  | 
| @@ -240,14 +254,14 @@ private | |
| 240 254 | 
             
                def api_get(endpoint:, query: nil)
         | 
| 241 255 | 
             
                  begin
         | 
| 242 256 | 
             
                    resp = self.http.get([self.url, endpoint].join('/'), query, {'Content-type' => 'application/json', 'Accept' => 'application/json'})
         | 
| 243 | 
            -
                     | 
| 244 | 
            -
                       | 
| 245 | 
            -
             | 
| 246 | 
            -
                       | 
| 247 | 
            -
             | 
| 248 | 
            -
             | 
| 249 | 
            -
             | 
| 250 | 
            -
                      raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason} | 
| 257 | 
            +
                    begin
         | 
| 258 | 
            +
                      data = JSON.parse(resp.body) unless resp.body.empty?
         | 
| 259 | 
            +
                    rescue JSON::ParserError
         | 
| 260 | 
            +
                      raise Exception, "Failed to decode response message"
         | 
| 261 | 
            +
                    end
         | 
| 262 | 
            +
                    if resp.status != 200
         | 
| 263 | 
            +
                      error = data.include?('error') ? data['error'] : data.inspect if data
         | 
| 264 | 
            +
                      raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
         | 
| 251 265 | 
             
                    end
         | 
| 252 266 | 
             
                  rescue
         | 
| 253 267 | 
             
                    raise Exception, "Failed to execute GET request to Kapacitor REST API (#{$!})"
         | 
| @@ -264,14 +278,14 @@ private | |
| 264 278 | 
             
                def api_post(endpoint:, data:)
         | 
| 265 279 | 
             
                  begin
         | 
| 266 280 | 
             
                    resp = self.http.post([self.url, endpoint].join('/'), data.to_json, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
         | 
| 267 | 
            -
                     | 
| 268 | 
            -
                       | 
| 269 | 
            -
             | 
| 270 | 
            -
                       | 
| 271 | 
            -
             | 
| 272 | 
            -
             | 
| 273 | 
            -
             | 
| 274 | 
            -
                      raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason} | 
| 281 | 
            +
                    begin
         | 
| 282 | 
            +
                      data = JSON.parse(resp.body) unless resp.body.empty?
         | 
| 283 | 
            +
                    rescue JSON::ParserError
         | 
| 284 | 
            +
                      raise Exception, "Failed to decode response message"
         | 
| 285 | 
            +
                    end
         | 
| 286 | 
            +
                    if resp.status != 200
         | 
| 287 | 
            +
                      error = data.include?('error') ? data['error'] : data.inspect if data
         | 
| 288 | 
            +
                      raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
         | 
| 275 289 | 
             
                    end
         | 
| 276 290 | 
             
                  rescue
         | 
| 277 291 | 
             
                    raise Exception, "Failed to execute POST request to Kapacitor REST API (#{$!})"
         | 
| @@ -287,16 +301,14 @@ private | |
| 287 301 | 
             
                def api_delete(endpoint:)
         | 
| 288 302 | 
             
                  begin
         | 
| 289 303 | 
             
                    resp = self.http.delete([self.url, endpoint].join('/'), {'Content-type' => 'application/json', 'Accept' => 'application/json'})
         | 
| 290 | 
            -
                     | 
| 291 | 
            -
                       | 
| 292 | 
            -
             | 
| 293 | 
            -
             | 
| 294 | 
            -
             | 
| 295 | 
            -
             | 
| 296 | 
            -
             | 
| 297 | 
            -
                       | 
| 298 | 
            -
                    else
         | 
| 299 | 
            -
                      raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason})"
         | 
| 304 | 
            +
                    begin
         | 
| 305 | 
            +
                      data = JSON.parse(resp.body) unless resp.body.empty?
         | 
| 306 | 
            +
                    rescue JSON::ParserError
         | 
| 307 | 
            +
                      raise Exception, "Failed to decode response message"
         | 
| 308 | 
            +
                    end
         | 
| 309 | 
            +
                    if resp.status != 204
         | 
| 310 | 
            +
                      error = data.include?('error') ? data['error'] : data.inspect if data
         | 
| 311 | 
            +
                      raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
         | 
| 300 312 | 
             
                    end
         | 
| 301 313 | 
             
                  rescue
         | 
| 302 314 | 
             
                    raise Exception, "Failed to execute DELETE request to Kapacitor REST API (#{$!})"
         | 
| @@ -313,14 +325,14 @@ private | |
| 313 325 | 
             
                def api_patch(endpoint:, data:)
         | 
| 314 326 | 
             
                  begin
         | 
| 315 327 | 
             
                    resp = self.http.patch([self.url, endpoint].join('/'), data.to_json, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
         | 
| 316 | 
            -
                     | 
| 317 | 
            -
                       | 
| 318 | 
            -
             | 
| 319 | 
            -
                       | 
| 320 | 
            -
             | 
| 321 | 
            -
             | 
| 322 | 
            -
             | 
| 323 | 
            -
                      raise Exception, "Query returned a non successful HTTP code ( | 
| 328 | 
            +
                    begin
         | 
| 329 | 
            +
                      data = JSON.parse(resp.body) unless resp.body.empty?
         | 
| 330 | 
            +
                    rescue JSON::ParserError
         | 
| 331 | 
            +
                      raise Exception, "Failed to decode response message"
         | 
| 332 | 
            +
                    end
         | 
| 333 | 
            +
                    if resp.status != 200
         | 
| 334 | 
            +
                      error = data.include?('error') ? data['error'] : data.inspect if data
         | 
| 335 | 
            +
                      raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
         | 
| 324 336 | 
             
                    end
         | 
| 325 337 | 
             
                  rescue
         | 
| 326 338 | 
             
                    raise Exception, "Failed to execute PATCH request to Kapacitor REST API (#{$!})"
         | 
| @@ -337,14 +349,14 @@ private | |
| 337 349 | 
             
                def api_put(endpoint:, data:)
         | 
| 338 350 | 
             
                  begin
         | 
| 339 351 | 
             
                    resp = self.http.put([self.url, endpoint].join('/'), data.to_json, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
         | 
| 340 | 
            -
                     | 
| 341 | 
            -
                       | 
| 342 | 
            -
             | 
| 343 | 
            -
                       | 
| 344 | 
            -
             | 
| 345 | 
            -
             | 
| 346 | 
            -
             | 
| 347 | 
            -
                      raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason} | 
| 352 | 
            +
                    begin
         | 
| 353 | 
            +
                      data = JSON.parse(resp.body) unless resp.body.empty?
         | 
| 354 | 
            +
                    rescue JSON::ParserError
         | 
| 355 | 
            +
                      raise Exception, "Failed to decode response message"
         | 
| 356 | 
            +
                    end
         | 
| 357 | 
            +
                    if resp.status != 200
         | 
| 358 | 
            +
                      error = data.include?('error') ? data['error'] : data.inspect if data
         | 
| 359 | 
            +
                      raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
         | 
| 348 360 | 
             
                    end
         | 
| 349 361 | 
             
                  rescue
         | 
| 350 362 | 
             
                    raise Exception, "Failed to execute PUT request to Kapacitor REST API (#{$!})"
         | 
    
        data/lib/kapacitor/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: kapacitor-ruby
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.8
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Matteo Cerutti
         | 
| 8 | 
            -
            autorequire: | 
| 8 | 
            +
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2020-12-11 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: httpclient
         | 
| @@ -52,7 +52,7 @@ homepage: https://github.com/m4ce/kapacitor-ruby | |
| 52 52 | 
             
            licenses:
         | 
| 53 53 | 
             
            - Apache 2.0
         | 
| 54 54 | 
             
            metadata: {}
         | 
| 55 | 
            -
            post_install_message: | 
| 55 | 
            +
            post_install_message:
         | 
| 56 56 | 
             
            rdoc_options: []
         | 
| 57 57 | 
             
            require_paths:
         | 
| 58 58 | 
             
            - lib
         | 
| @@ -67,9 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 67 67 | 
             
                - !ruby/object:Gem::Version
         | 
| 68 68 | 
             
                  version: '0'
         | 
| 69 69 | 
             
            requirements: []
         | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
            signing_key: 
         | 
| 70 | 
            +
            rubygems_version: 3.0.1
         | 
| 71 | 
            +
            signing_key:
         | 
| 73 72 | 
             
            specification_version: 4
         | 
| 74 73 | 
             
            summary: Ruby client library that allows to interact with the Kapacitor JSON REST
         | 
| 75 74 | 
             
              API
         |