#!/usr/bin/env ruby require 'rubygems' require 'yaml' require 'getopt/std' require 'zabbixapi' opt = Getopt::Std.getopts("g:E:n:") group_name = opt["g"] zabbix_env = opt["E"] disk_name = opt["n"] template_name = "TMPL_iops_#{disk_name}" # read config config = YAML::load(open('./config.yml')) api_url = config[zabbix_env]["api_url"] api_login = config[zabbix_env]["api_login"] api_password = config[zabbix_env]["api_password"] # Esablish new connection zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password) # Create new template p " * Creating template #{template_name}." g_id = zbx.add_or_get_group(group_name) options = { 'groups' => [ g_id.to_i ], 'host' => template_name } t_id = zbx.add_or_get_template(options) # Create application #{app_name} app_name = "iops_#{disk_name}" p " ** Create application #{app_name}." application = { 'hostid' => t_id.to_i, 'name' => app_name } a_id = zbx.add_or_get_application(t_id, application) # 'reads for #{disk_name}' options = { 'description' => "iops read #{disk_name}", 'key_' => "vfs.dev.read[#{disk_name}]", 'hostid' => t_id.to_i, 'applications' => [ a_id.to_i ], 'history' => 7, 'trends' => 30, 'delay' => 60, 'value_type' => 0 } p " ** Add 'vfs.dev.read[#{disk_name}]' to #{template_name}." reads_id = zbx.add_or_get_item(t_id, options) # 'writes for #{disk_name}' options = { 'description' => "iops writes #{disk_name}", 'key_' => "vfs.dev.write[#{disk_name}]", 'hostid' => t_id.to_i, 'applications' => [ a_id.to_i ], 'history' => 7, 'trends' => 30, 'delay' => 60, 'value_type' => 0 } p " ** Add 'vfs.dev.write[#{disk_name}]' to #{template_name}." writes_id = zbx.add_or_get_item(t_id, options) # TRIGGERS options = { 'description' => "read on #{disk_name} is too big", 'expression' => "{#{template_name}:vfs.dev.read[#{disk_name}].last(0)}>100", 'priority' => 2, # warning 'templateid' => 0, 'comments' => "too many reads on #{disk_name} (warning)", 'type' => 0, 'status' => '0' } p " ** Add '#{disk_name} reads' trigger'" tr_id = zbx.add_or_get_trigger(t_id, options) options = { 'description' => "write on #{disk_name} is too big", 'expression' => "{#{template_name}:vfs.dev.write[#{disk_name}].last(0)}>300", 'priority' => 2, # warning 'templateid' => 0, 'comments' => "too many writes on #{disk_name} (warning)", 'type' => 0, 'status' => '0' } p " ** Add '#{disk_name} writes' trigger'" tr_id = zbx.add_or_get_trigger(t_id, options) # GRAPHS options = { 'gitems' => [ { "itemid" => reads_id, "drawtype" => "0", "sortorder" => "0", "color" => "AA0000", "yaxisside" => "0", "calc_fnc" => "2", "type" => "0", "periods_cnt" => "5" }, { "itemid" => writes_id, "drawtype" => "0", "sortorder" => "0", "color" => "009900", "yaxisside" => "0", "calc_fnc" => "2", "type" => "0", "periods_cnt" => "5" } ], "show_triggers" => "1", "name" => "IOPS graph", "width" => "900", "height" => "200", "templateid" => "0" } p " ** Add 'IOPS graph'" g_id = zbx.add_or_get_graph(t_id, options)