Class: Zabbix::ZabbixApi
- Inherits:
-
Object
- Object
- Zabbix::ZabbixApi
- Defined in:
- lib/zabbixapi/base.rb,
lib/zabbixapi/host.rb,
lib/zabbixapi/item.rb,
lib/zabbixapi/graph.rb,
lib/zabbixapi/group.rb,
lib/zabbixapi/screen.rb,
lib/zabbixapi/trigger.rb,
lib/zabbixapi/template.rb,
lib/zabbixapi/mediatype.rb,
lib/zabbixapi/usermacro.rb,
lib/zabbixapi/application.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
Instance Method Summary collapse
- #add_application(app_options) ⇒ Object
- #add_graph(graph) ⇒ Object
- #add_graph_to_screen(screen_id, graph_id, x, y) ⇒ Object
- #add_group(groupname) ⇒ Object
- #add_host(host_options) ⇒ Object
- #add_host_to_group(host_id, group_id) ⇒ Object
- #add_item(item) ⇒ Object
- #add_macro(host_id, macro_name, macro_value) ⇒ Object
- #add_mediatype(mediatype_options) ⇒ Object
- #add_screen(screen_name, hsize, vsize) ⇒ Object
- #add_template(template_options) ⇒ Object
- #add_trigger(trigger) ⇒ Object
- #auth ⇒ Object
- #del_all_graphs_from_screen(screen_id) ⇒ Object
- #delete_group(groupname) ⇒ Object
- #delete_host(hostname) ⇒ Object
-
#delete_item(item_ids) ⇒ Object
Don’t work with api < 1.8.4.
- #delete_mediatype(mediatype) ⇒ Object
- #do_request(message) ⇒ Object
- #get_graph_id(host_id, graph_name) ⇒ Object
- #get_graphs(host_id) ⇒ Object
- #get_group_id(pattern) ⇒ Object
- #get_host_id(hostname) ⇒ Object
- #get_item_id(host_id, item_name) ⇒ Object
- #get_macro(host_id, macro_name) ⇒ Object
- #get_mediatype_id(mediatype) ⇒ Object
- #get_screen_graph_ids(screen_id) ⇒ Object
- #get_screen_id(screen_name) ⇒ Object
- #get_screen_parameter(screen_name, param_name) ⇒ Object
- #get_template_id(template_name) ⇒ Object
- #get_template_ids_by_host(host_id) ⇒ Object
- #get_templates ⇒ Object
- #get_trigger_id(host_id, trigger_name) ⇒ Object
- #get_triggers_by_host(host_id) ⇒ Object
- #group_exist?(pattern) ⇒ Boolean
-
#initialize(api_url, api_user, api_password) ⇒ ZabbixApi
constructor
A new instance of ZabbixApi.
- #item_exist?(host_id, item_name) ⇒ Boolean
- #link_templates_with_hosts(templates_id, hosts_id) ⇒ Object
-
#merge_opt(a, b) ⇒ Object
Utils.
- #send_request(message) ⇒ Object
- #set_macro_value(host_id, macro_name, macro_value) ⇒ Object
- #set_screen_parameter(screen_id, param_name, param_value) ⇒ Object
- #unlink_templates_from_hosts(templates_id, hosts_id) ⇒ Object
- #update_host(host_id, host_options) ⇒ Object
- #update_item(item_id, options) ⇒ Object
- #update_trigger_status(trigger_id, status) ⇒ Object
Constructor Details
#initialize(api_url, api_user, api_password) ⇒ ZabbixApi
Returns a new instance of ZabbixApi.
28 29 30 31 32 33 34 |
# File 'lib/zabbixapi/base.rb', line 28 def initialize (api_url, api_user, api_password) @api_url = api_url @api_user = api_user @api_password = api_password @debug = false # Disable debug by default end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
26 27 28 |
# File 'lib/zabbixapi/base.rb', line 26 def debug @debug end |
Instance Method Details
#add_application(app_options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/zabbixapi/application.rb', line 4 def add_application() = { 'hostid' => nil, 'name' => nil } application = merge_opt(, ) = { 'method' => 'application.create', 'params' => application } responce = send_request() responce.empty? ? nil : responce['applicationids'][0].to_i end |
#add_graph(graph) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/zabbixapi/graph.rb', line 4 def add_graph(graph) = { 'method' => 'graph.create', 'params' => graph } response = send_request() return 0 end |
#add_graph_to_screen(screen_id, graph_id, x, y) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/zabbixapi/screen.rb', line 76 def add_graph_to_screen(screen_id, graph_id, x, y) = { 'method' => 'screen.addItems', 'params' => { 'screenids' => [screen_id], 'screenitems' => [ { 'resourcetype' => 'graph', 'resourceid' => graph_id, 'width' => '800', 'height' => '200', 'x' => x, 'y' => y, 'valign' => 'Middle', 'halign' => 'Centre', 'colspan' => '0', 'rowspan' => '0', 'elements' => '0', 'dynamic' => '0', 'url' => '0', 'style' => '0' } ] } } response = send_request() return response end |
#add_group(groupname) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/zabbixapi/group.rb', line 22 def add_group(groupname) = { 'method' => 'hostgroup.create', 'params' => { 'name' => groupname } } response = send_request() response ? response['groupids'][0].to_i : nil end |
#add_host(host_options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/zabbixapi/host.rb', line 15 def add_host() host_default = { 'host' => nil, 'port' => 10050, 'status' => 0, 'useip' => 0, 'dns' => '', 'ip' => '0.0.0.0', 'proxy_hostid' => 0, 'groups' => [], 'useipmi' => 0, 'ipmi_ip' => '', 'ipmi_port' => 623, 'ipmi_authtype' => 0, 'ipmi_privilege' => 0, 'ipmi_username' => '', 'ipmi_password' => '' } ['groups'].nil? || ['groups'].map! { |group_id| {'groupid' => group_id} } host = merge_opt(host_default, ) = { 'method' => 'host.create', 'params' => host } response = send_request() response.empty? ? nil : response['hostids'][0].to_i end |
#add_host_to_group(host_id, group_id) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/zabbixapi/group.rb', line 45 def add_host_to_group(host_id, group_id) = { 'method' => 'hostgroup.massAdd', 'params' => { 'groups' => [group_id], 'hosts' => [host_id] } } response = send_request() response.empty? ? false : true end |
#add_item(item) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/zabbixapi/item.rb', line 4 def add_item(item) # Default item options # See: http://www.zabbix.com/documentation/1.8/api/item ## Item types (see ./frontends/php/include/defines.inc.php in zabbix source) # ITEM_TYPE_ZABBIX 0 # ITEM_TYPE_SNMPV1 1 # ITEM_TYPE_TRAPPER 2 # ITEM_TYPE_SIMPLE 3 # ITEM_TYPE_SNMPV2C 4 # ITEM_TYPE_INTERNAL 5 # ITEM_TYPE_SNMPV3 6 # ITEM_TYPE_ZABBIX_ACTIVE 7 # ITEM_TYPE_AGGREGATE 8 # ITEM_TYPE_HTTPTEST 9 # ITEM_TYPE_EXTERNAL 10 # ITEM_TYPE_DB_MONITOR 11 # ITEM_TYPE_IPMI 12 # ITEM_TYPE_SSH 13 # ITEM_TYPE_TELNET 14 # ITEM_TYPE_CALCULATED 15 = { 'description' => nil, 'key_' => nil, 'hostid' => nil, 'delay' => 60, 'history' => 60, 'status' => 0, 'type' => 7, 'snmp_community' => '', 'snmp_oid' => '', 'value_type' => 3, 'data_type' => 0, 'trapper_hosts' => 'localhost', 'snmp_port' => 161, 'units' => '', 'multiplier' => 0, 'delta' => 0, 'snmpv3_securityname' => '', 'snmpv3_securitylevel' => 0, 'snmpv3_authpassphrase' => '', 'snmpv3_privpassphrase' => '', 'formula' => 0, 'trends' => 365, 'logtimefmt' => '', 'valuemapid' => 0, 'delay_flex' => '', 'authtype' => 0, 'username' => '', 'password' => '', 'publickey' => '', 'privatekey' => '', 'params' => '', 'ipmi_sensor' => '', 'applications' => '', 'templateid' => 0 } .merge!(item) = { 'method' => 'item.create', 'params' => [] } response = send_request() response.empty? ? nil : response['itemids'][0] end |
#add_macro(host_id, macro_name, macro_value) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/zabbixapi/usermacro.rb', line 4 def add_macro(host_id, macro_name, macro_value) = { 'method' => 'Usermacro.create', 'params' => { 'hostid' => host_id, 'macro' => macro_name, 'value' => macro_value } } response = send_request() hostmacroids == response['hostmacroids'] ? hostmacroids : nil end |
#add_mediatype(mediatype_options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zabbixapi/mediatype.rb', line 18 def add_mediatype() mediatype_default = { 'type' => '0', 'description' => '', 'smtp_server' => '', 'smtp_helo' => '', 'smtp_email' => '', 'exec_path' => '', 'gsm_modem' => '', 'username' => '', 'passwd' => '' } mediatype = merge_opt(mediatype_default, ) = { 'method' => 'mediatype.create', 'params' => mediatype } response = send_request() response.empty? ? nil : response['mediatypeids'][0].to_i end |
#add_screen(screen_name, hsize, vsize) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/zabbixapi/screen.rb', line 105 def add_screen(screen_name, hsize, vsize) = { 'method' => 'screen.create', 'params' => { 'name' => screen_name, 'hsize' => hsize, 'vsize' => vsize } } response = send_request() response.empty? ? nil : response['screenids'][0] end |
#add_template(template_options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/zabbixapi/template.rb', line 4 def add_template() template_default = { 'host' => nil, 'groups' => [], } ['groups'].map! { |group_id| {'groupid' => group_id} } template = merge_opt(template_default, ) = { 'method' => 'template.create', 'params' => template } response = send_request() response.empty? ? nil : response['templateids'][0].to_i end |
#add_trigger(trigger) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/zabbixapi/trigger.rb', line 4 def add_trigger(trigger) = { 'method' => 'trigger.create', 'params' => [trigger] } response = send_request() response.empty? ? nil : response['triggerids'][0] end |
#auth ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/zabbixapi/base.rb', line 106 def auth() = { 'auth' => nil, 'method' => 'user.authenticate', 'params' => { 'user' => @api_user, 'password' => @api_password, '0' => '0' } } do_request() end |
#del_all_graphs_from_screen(screen_id) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/zabbixapi/screen.rb', line 65 def del_all_graphs_from_screen(screen_id) = { 'method' => 'screen.deleteItems', 'params' => { 'screenids' => [screen_id], } } response = send_request() response ? response : nil end |
#delete_group(groupname) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/zabbixapi/group.rb', line 33 def delete_group(groupname) group_id = get_group_id(groupname) = { 'method' => 'hostgroup.delete', 'params' => { 'groupid' => group_id } } response = send_request() response ? response['groupids'][0].to_i : nil end |
#delete_host(hostname) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/zabbixapi/host.rb', line 56 def delete_host(hostname) host_id = get_host_id(hostname) = { 'method' => 'host.delete', 'params' => { 'hostid' => host_id } } send_request() end |
#delete_item(item_ids) ⇒ Object
Don’t work with api < 1.8.4
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/zabbixapi/item.rb', line 104 def delete_item(item_ids) if item_ids.kind_of? Array = { 'method' => 'item.delete', 'params' => item_ids } elsif item_ids.kind_of? Fixnum or item_ids.kind_of? String = { 'method' => 'item.delete', 'params' => [item_ids] } else raise Zabbix::ArgumentError.new("Zabbix::ZabbixApi.delete_item() argument error. item_ids => #{item_ids.inspect}") end response = send_request() if response.empty? result = nil else response['itemids'].count == 1 ? result = response['itemids'][0] : result = response['itemids'] end return result end |
#delete_mediatype(mediatype) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/zabbixapi/mediatype.rb', line 39 def delete_mediatype(mediatype) mediatype_id = get_mediatype_id(mediatype) = { 'method' => 'mediatype.delete', 'params' => [mediatype_id] } response = send_request() response ? true : false end |
#do_request(message) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/zabbixapi/base.rb', line 36 def do_request() id = rand 100_000 ['id'] = id ['jsonrpc'] = '2.0' = JSON.generate() uri = URI.parse(@api_url) http = Net::HTTP.new(uri.host, uri.port) if uri.scheme == "https" http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end request = Net::HTTP::Post.new(uri.request_uri) request.add_field('Content-Type', 'application/json-rpc') request.body=() begin puts "[ZBXAPI] : INFO : Do request. Body => #{request.body}" if @debug response = http.request(request) rescue ::SocketError => e puts "[ZBXAPI] : ERROR : SocketError => #{e.}" if @debug raise Zabbix::SocketError.new(e.) end if @debug puts "[ZBXAPI] : INFO : Response start" puts response puts "[ZBXAPI] : INFO : Response end" end if response.code != "200" raise Zabbix::ResponseCodeError.new("Responce code from [" + @api_url + "] is #{response.code}") end response_body_hash = JSON.parse(response.body) if @debug puts "[ZBXAPI] : INFO : Response body" puts response_body_hash.inspect end if error = response_body_hash['error'] = error['message'] error_data = error['data'] error_code = error['code'] = "Code: [" + error_code.to_s + "]. Message: [" + +\ "]. Data: [" + error_data + "]." case error_code.to_s when '-32602' raise Zabbix::AlreadyExist.new() else raise Zabbix::ResponseError.new() end end return response_body_hash['result'] end |
#get_graph_id(host_id, graph_name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/zabbixapi/graph.rb', line 13 def get_graph_id(host_id, graph_name) = { 'method' => 'graph.get', 'params' => { 'filter' => { 'name' => graph_name, 'hostid' => host_id } } } response = send_request() response.empty? ? nil : response[0]['graphid'] end |
#get_graphs(host_id) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/zabbixapi/graph.rb', line 27 def get_graphs(host_id) = { 'method' => 'graph.get', 'params' => { 'extendoutput' => '1', 'filter' => { 'hostid' => host_id } } } response = send_request() if response.empty? result = nil else result = {} response.each() do |graph| graph_id = graph['graphid'] graph_name = graph['name'] result[graph_id] = graph_name end end return result end |
#get_group_id(pattern) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/zabbixapi/group.rb', line 4 def get_group_id(pattern) = { 'method' => 'hostgroup.get', 'params' => { 'filter' => { 'name' => pattern } } } response = send_request() response.empty? ? nil : response[0]['groupid'] end |
#get_host_id(hostname) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/zabbixapi/host.rb', line 43 def get_host_id(hostname) = { 'method' => 'host.get', 'params' => { 'filter' => { 'host' => hostname } } } response = send_request() response.empty? ? nil : response[0]['hostid'].to_i end |
#get_item_id(host_id, item_name) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/zabbixapi/item.rb', line 69 def get_item_id(host_id, item_name) = { 'method' => 'item.get', 'params' => { 'filter' => { 'hostid' => host_id, 'description' => item_name } } } response = send_request() response.empty? ? nil : response[0]['itemid'] end |
#get_macro(host_id, macro_name) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/zabbixapi/usermacro.rb', line 17 def get_macro(host_id, macro_name) = { 'method' => 'Usermacro.get', 'params' => { 'hostids' => host_id, 'macros' => macro_name, 'extendoutput' => '1' } } response = send_request() if response.empty? result = nil else if hostmacroid == response[0]['hostmacroid'] macro_id = hostmacroid macro_value = response[0]['value'] result = { 'id' => macro_id, 'value' => macro_value } else result = nil end end return result end |
#get_mediatype_id(mediatype) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/zabbixapi/mediatype.rb', line 4 def get_mediatype_id(mediatype) = { 'method' => 'mediatype.get', 'params' => { 'search' => { 'description' => mediatype }, 'output' => 'extend', } } response = send_request() response.empty? ? nil : response[0]['mediatypeid'].to_i end |
#get_screen_graph_ids(screen_id) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/zabbixapi/screen.rb', line 31 def get_screen_graph_ids(screen_id) = { 'method' => 'screen.get', 'params' => { 'extendoutput' => '1', 'select_screenitems' => '1', 'screenids' => [screen_id] } } response = send_request() if response.empty? result = nil else result = [] screenitems = response[0]['screenitems'] screenitems.each() do |item| result << item['resourceid'] if item['resourcetype'].to_i == 0 end end return result end |
#get_screen_id(screen_name) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/zabbixapi/screen.rb', line 4 def get_screen_id(screen_name) = { 'method' => 'screen.get', 'params' => { 'filter' => { 'name' => screen_name } } } response = send_request() response.empty? ? nil : response[0]['screenid'] end |
#get_screen_parameter(screen_name, param_name) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/zabbixapi/screen.rb', line 17 def get_screen_parameter(screen_name, param_name) = { 'method' => 'screen.get', 'params' => { 'extendoutput' => '1', 'filter' => { 'name' => screen_name } } } response = send_request() response.empty? ? nil : response[0][param_name] end |
#get_template_id(template_name) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/zabbixapi/template.rb', line 65 def get_template_id(template_name) = { 'method' => 'template.get', 'params' => { 'filter' => { 'host' => template_name } } } response = send_request() response.empty? ? nil : response.keys[0] end |
#get_template_ids_by_host(host_id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/zabbixapi/template.rb', line 19 def get_template_ids_by_host(host_id) = { 'method' => 'template.get', 'params' => { 'hostids' => [host_id] } } response = send_request() if response.empty? result = nil else result = [] response.each_key() do |template_id| result << template_id end end return result end |
#get_templates ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/zabbixapi/template.rb', line 38 def get_templates() = { 'method' => 'template.get', 'params' => { 'extendoutput' => '0' } } response = send_request() if response.empty? result = nil else result = {} if response.kind_of? Hash template_ids = response.keys() template_ids.each() do |template_id| template_name = response[template_id]['host'] result[template_id] = template_name end elsif response.kind_of? Array response.each do |template_info| result[template_info['hostid']] = template_info['host'] end end end return result end |
#get_trigger_id(host_id, trigger_name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/zabbixapi/trigger.rb', line 13 def get_trigger_id(host_id, trigger_name) = { 'method' => 'trigger.get', 'params' => { 'filter' => { 'hostid' => host_id, 'description' => trigger_name } } } response = send_request() response.empty? ? nil : response[0]['triggerid'] end |
#get_triggers_by_host(host_id) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/zabbixapi/trigger.rb', line 27 def get_triggers_by_host(host_id) = { 'method' => 'trigger.get', 'params' => { 'filter' => { 'hostid' => host_id, }, 'extendoutput' => '1' } } response = send_request() if response.empty? result = {} else result = {} response.each do |trigger| trigger_id = trigger['triggerid'] description = trigger['description'] result[trigger_id] = description end end return result end |
#group_exist?(pattern) ⇒ Boolean
17 18 19 20 |
# File 'lib/zabbixapi/group.rb', line 17 def group_exist?(pattern) group_id = get_group_id(pattern) group_id ? true : false end |
#item_exist?(host_id, item_name) ⇒ Boolean
83 84 85 86 87 88 89 90 91 |
# File 'lib/zabbixapi/item.rb', line 83 def item_exist?(host_id, item_name) item_id = get_item_id(host_id, item_name) if item_id result = true else result = false end return result end |
#link_templates_with_hosts(templates_id, hosts_id) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/zabbixapi/template.rb', line 78 def link_templates_with_hosts(templates_id, hosts_id) templates_id.class == Array ? = templates_id : = [templates_id] hosts_id.class == Array ? = hosts_id : = [hosts_id] = { 'method' => 'template.massAdd', 'params' => { 'hosts' => .map { |t| {"hostid" => t} }, 'templates' => .map { |t| {"templateid" => t} } } } response = send_request() return response end |
#merge_opt(a, b) ⇒ Object
Utils.
121 122 123 124 125 126 127 128 129 |
# File 'lib/zabbixapi/base.rb', line 121 def merge_opt(a, b) c = {} b.each_pair do |key, value| if a.has_key?(key) then c[key] = value end end return a.merge(c) end |
#send_request(message) ⇒ Object
101 102 103 104 |
# File 'lib/zabbixapi/base.rb', line 101 def send_request() ['auth'] = auth() do_request() end |
#set_macro_value(host_id, macro_name, macro_value) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/zabbixapi/usermacro.rb', line 45 def set_macro_value(host_id, macro_name, macro_value) = { 'method' => 'usermacro.updateValue', 'params' => { 'hostid' => host_id, 'macro' => macro_name, 'value' => macro_value } } response = send_request() return true end |
#set_screen_parameter(screen_id, param_name, param_value) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/zabbixapi/screen.rb', line 53 def set_screen_parameter(screen_id, param_name, param_value) = { 'method' => 'screen.update', 'params' => { param_name => param_value, 'screenid' => screen_id } } response = send_request() response.empty? ? false : true end |
#unlink_templates_from_hosts(templates_id, hosts_id) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/zabbixapi/template.rb', line 92 def unlink_templates_from_hosts(templates_id, hosts_id) templates_id.class == Array ? = templates_id : = [templates_id] hosts_id.class == Array ? = hosts_id : = [hosts_id] = { 'method' => 'template.massRemove', 'params' => { 'hostids' => , 'templateids' => , 'force' => '1' } } response = send_request() return response end |
#update_host(host_id, host_options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/zabbixapi/host.rb', line 4 def update_host(host_id, ) host = host['hostid'] = host_id = { 'method' => 'host.update', 'params' => host } responce = send_request() responce.empty? ? nil : responce['hostids'][0].to_i end |
#update_item(item_id, options) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/zabbixapi/item.rb', line 93 def update_item(item_id, ) ["item_id"] = { 'method' => 'item.update', 'params' => } response = send_request() response.empty? ? nil : response['itemids'][0] end |
#update_trigger_status(trigger_id, status) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/zabbixapi/trigger.rb', line 51 def update_trigger_status(trigger_id, status) = { 'method' => 'trigger.update_status', 'params' => { 'triggerid' => trigger_id, 'status' => status } } response = send_request() response.empty? ? nil : response['triggerids'][0] end |