Sha256: bf57878516f724d6a9e3fb4d9dc6889951234bbd5ce98d6e79ceae25b0398c7e

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

class ZabbixApi
  class Triggers

    def initialize(client)
      @client = client
    end

    def create(data)
      result = @client.api_request(:method => "trigger.create", :params => [data])
      result.empty? ? nil : result['triggerids'][0].to_i
    end

    def add(data)
      create(data)
    end

    def delete(data)
      result = @client.api_request(:method => "trigger.delete", :params => [data])
      result.empty? ? nil : result['triggerids'][0].to_i
    end

    def destroy(data)
      delete(data)
    end

    def update(data)
      result = @client.api_request(:method => "trigger.update", :params => data)
      result.empty? ? nil : result['triggerids'][0].to_i
    end

    def create_or_update(data)
      triggerid = get_id(:description => data[:description], :templateid => data[:templateid])
      triggerid ? update(data.merge(:triggerid => triggerid)) : create(data)
    end

    def get_full_data(data)
      @client.api_request(:method => "trigger.get", :params => {:filter => data, :output => "extend"})
    end

    def get_id(data)
      result = get_full_data(data)
      triggerid = nil
      result.each { |template| triggerid = template['triggerid'].to_i if template['name'] == data[:name] }
      triggerid
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zabbixapi-0.5.0 lib/zabbixapi/triggers.rb
zabbixapi-0.5.0b6 lib/zabbixapi/triggers.rb
zabbixapi-0.5.0b5 lib/zabbixapi/triggers.rb
zabbixapi-0.5.0b4 lib/zabbixapi/triggers.rb