lib/zabbixapi/classes/graphs.rb in zabbixapi-4.1.0 vs lib/zabbixapi/classes/graphs.rb in zabbixapi-4.1.1
- old
+ new
@@ -22,16 +22,16 @@
# @return [Hash]
def get_full_data(data)
log "[DEBUG] Call get_full_data with parametrs: #{data.inspect}"
@client.api_request(
- :method => "#{method_name}.get",
- :params => {
- :search => {
- indentify.to_sym => data[indentify.to_sym],
+ method: "#{method_name}.get",
+ params: {
+ search: {
+ indentify.to_sym => data[indentify.to_sym]
},
- :output => 'extend',
+ output: 'extend'
}
)
end
# Get Graph ids for Host from Zabbix API
@@ -39,51 +39,41 @@
# @param data [Hash] Should include host value to query for matching graphs
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
# @return [Array] Returns array of Graph ids
def get_ids_by_host(data)
- ids = []
- graphs = {}
-
result = @client.api_request(
- :method => 'graph.get',
- :params => {
- :filter => {
- :host => data[:host],
+ method: 'graph.get',
+ params: {
+ filter: {
+ host: data[:host]
},
- :output => 'extend',
+ output: 'extend'
}
)
- result.each do |graph|
+ result.map do |graph|
num = graph['graphid']
name = graph['name']
- graphs[name] = num
filter = data[:filter]
- if filter.nil?
- ids.push(graphs[name])
- elsif /#{filter}/ =~ name
- ids.push(graphs[name])
- end
- end
-
- ids
+ num if filter.nil? || /#{filter}/ =~ name
+ end.compact
end
# Get Graph Item object using Zabbix API
#
# @param data [Hash] Needs to include graphids to properly identify Graph Items via Zabbix API
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
# @return [Hash]
def get_items(data)
@client.api_request(
- :method => 'graphitem.get',
- :params => {
- :graphids => [data],
- :output => 'extend',
+ method: 'graphitem.get',
+ params: {
+ graphids: [data],
+ output: 'extend'
}
)
end
# Get or Create Graph object using Zabbix API
@@ -93,11 +83,11 @@
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
# @return [Integer] Zabbix object id
def get_or_create(data)
log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
- unless (id = get_id(:name => data[:name], :templateid => data[:templateid]))
+ unless (id = get_id(name: data[:name], templateid: data[:templateid]))
id = create(data)
end
id
end
@@ -107,11 +97,11 @@
# @param data [Hash] Needs to include name and templateid to properly identify Graphs via Zabbix API
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
# @return [Integer] Zabbix object id
def create_or_update(data)
- graphid = get_id(:name => data[:name], :templateid => data[:templateid])
- graphid ? _update(data.merge(:graphid => graphid)) : create(data)
+ graphid = get_id(name: data[:name], templateid: data[:templateid])
+ graphid ? _update(data.merge(graphid: graphid)) : create(data)
end
def _update(data)
data.delete(:name)
update(data)