Skip to content

Commit

Permalink
graph and trigger prototypes; split enums into their own file; item p…
Browse files Browse the repository at this point in the history
…rototype cleanup
  • Loading branch information
andrewGarson committed Jun 21, 2013
1 parent 1aa8bd3 commit 8539dd0
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 208 deletions.
227 changes: 39 additions & 188 deletions libraries/chef_zabbix_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def symbolize(options)

class << self


def find_hostgroup_ids(connection, hostgroup)
group_id_request = {
:method => "hostgroup.get",
Expand Down Expand Up @@ -153,6 +152,30 @@ def find_lld_rule_ids(connection, template_id, key)
connection.query(request)
end

def find_trigger_ids(connection, description)
request = {
:method => "trigger.get",
:params => {
:search => {
:description => description
}
}
}
connection.query(request)
end

def find_trigger_prototype_ids(connection, description)
request = {
:method => "trigger.get",
:params => {
:search => {
:description => description
}
}
}
connection.query(request)
end

def find_item_ids(connection, template_id, key, name=nil)
request = {
:method => "item.get",
Expand All @@ -172,21 +195,22 @@ def find_item_ids(connection, template_id, key, name=nil)
connection.query(request)
end

def find_item_prototype_ids(connection, template_id, discovery_rule_id, key)
def find_item_prototype_ids(connection, template_id, key, discovery_rule_id=nil)
request = {
:method => "itemprototype.get",
:params => {
:discoveryids => discovery_rule_id,
:templateids => template_id,
:search => {
:key_ => key
}
}
}
if discovery_rule_id
request[:params][:discoveryids] = discovery_rule_id
end
connection.query(request)
end


def find_item_ids_on_host(connection, host, key)
request = {
:method => "item.get",
Expand All @@ -197,11 +221,7 @@ def find_item_ids_on_host(connection, host, key)
}
}
}
Chef::Log.info("CHICKEN")
Chef::Log.info(request)
res = connection.query(request)
Chef::Log.info(res)
res
connection.query(request)
end

def find_graph_ids(connection, name)
Expand All @@ -215,187 +235,18 @@ def find_graph_ids(connection, name)
}
connection.query(request)
end
end

module Enumeration
class << self
def included(base)
base.extend(ClassMethods)
base.send(:include, ClassMethods)
end

def extended(base)
base.send(:include, ClassMethods)
end
end

module ClassMethods
attr_reader :enumeration_values
def enum(name, val)
@enumeration_values ||= {}
@enumeration_values[name] ||= new(val)
# The better solution would be to just call define_singleton_method
# but that doesn't work in 1.8.x and we want 1.8.x compatibility
eigen_class = class << self; self; end
eigen_class.send(:define_method, name) do
@enumeration_values[name]
end
end
def find_graph_prototype_ids(connection, name)
request = {
:method => "graphprototype.get",
:params => {
:filter => {
:name => name
}
}
}
connection.query(request)
end

attr_reader :value
def initialize(value)
@value = value
end
end

class AuthType
include Enumeration
enum :password, 0
enum :private_key, 1
end

class DataType
include Enumeration
enum :decimal, 0
enum :octal, 1
enum :hexidecimal, 2
enum :boolean, 3
end

class Delta
include Enumeration
enum :as_is, 0
enum :speed_per_second, 1
enum :simple_change, 2
end

class SNMPV3_SecurityLevel
include Enumeration
enum :no_auth_no_priv, 0
enum :auth_no_priv, 1
enum :auth_priv, 2
end

class ItemType
include Enumeration
enum :zabbix_agent, 0
enum :snmp_v1_agent, 1
enum :zabbix_trapper, 2
enum :simple_check, 3
enum :snmp_v2_agent, 4
enum :zabbix_internal, 5
enum :snmp_v3_agent, 6
enum :zabbix_agent_active_check, 7
enum :zabbix_aggregate, 8
enum :web_item, 9
enum :externali_check , 10
enum :database_monitor, 11
enum :ipmi_agent, 12
enum :ssh_agent, 13
enum :telnet_agent, 14
enum :calculated, 15
enum :jmx_agent, 16
enum :snmp_trap, 17
end

class ItemValueType
include Enumeration
enum :float, 0
enum :character, 1
enum :log, 2
enum :unsigned, 3
enum :text, 4
end

class TriggerPriority
include Enumeration

enum :not_classified, 0
enum :information, 1
enum :warning, 2
enum :average, 3
enum :high, 4
enum :disaster, 5
end

class ItemStatus
include Enumeration
enum :enabled, 0
enum :disabled, 1
enum :not_supported, 2
end

class TriggerStatus
include Enumeration
enum :active, 0
enum :disabled, 1
end

class TriggerType
include Enumeration
enum :normal, 0
enum :multiple, 1
end

class GraphItemCalcFunction
include Enumeration
enum :min, 1
enum :max, 2
enum :average, 4
enum :all, 7
end

class GraphItemType
include Enumeration
enum :simple, 0
enum :aggregated, 1
enum :graph, 2
end

class GraphType
include Enumeration
enum :normal, 0
enum :stacked, 1
enum :pie, 2
enum :exploded, 3
end

class GraphAxisType
include Enumeration
enum :calculated, 0
enum :fixed, 1
# TODO: Update the graph provider to do an update after it has created
# all of its item so that you can map an item id and support this value
#enum :item, 2
end

class IPMIAuthType
include Enumeration
enum :default, -1
enum :none, 0
enum :md2, 1
enum :md5, 2
enum :straight, 3
enum :oem, 4
enum :rmcp_plus, 5
end

class IPMIPrivilege
include Enumeration
enum :callback, 1
enum :user, 2
enum :operator, 3
enum :admin, 4
enum :oem, 5
end

class HostInterfaceType
include Enumeration
enum :agent, 1
enum :snmp, 2
enum :ipmi, 3
enum :jmx, 4
end
end
end
Expand Down
Loading

0 comments on commit 8539dd0

Please sign in to comment.