#!/usr/bin/env ruby require 'rubygems' require 'getopt/std' require 'yaml' require 'zabbixapi' opt = Getopt::Std.getopts("g:E:") group_name = opt["g"] zabbix_env = opt["E"] template_name = "TMPL_ipmi_cpufan_sensor" app_name = "cpufan_sensor" disaster_rpm = '5000.000' # 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 = "ipmi_cpufan_sensor" p " ** Create application #{app_name}." application = { 'hostid' => t_id.to_i, 'name' => app_name } a_id = zbx.add_or_get_application(t_id, application) # 'mpeg2lander signal quality' options = { 'description' => "Fan6/CPU sensor RPM", 'key_' => "cpufansensor", 'hostid' => t_id.to_i, 'applications' => [ a_id.to_i ], 'history' => 7, 'trends' => 30, 'delay' => 60, 'value_type' => 0 } p " ** Add 'cpufansensor' to #{template_name}." sensor_item_id = zbx.add_or_get_item(t_id, options) # TRIGGER # cpufan disaster (high threshold) options = { 'description' => "Cpufan sensor RPM", 'expression' => "{#{template_name}:cpufansensor.last(0)}>#{disaster_rpm}", 'priority' => 5, # disaster 'templateid' => 0, 'comments' => "Cpufan sensor (Disaster)", 'type' => 0, 'status' => '0' } p " ** Add 'cpufan sensor disaster' trigger" tr_id = zbx.add_or_get_trigger(t_id, options) # TODO: create low_threshold trigger # Author: something # Today we can't create it, because on some servers incorrectly # connected cable to the sensor # GRAPH options = { 'gitems' => [ { "itemid" => sensor_item_id, "drawtype" => "0", "sortorder" => "0", "color" => "AA0000", "yaxisside" => "0", "calc_fnc" => "2", "type" => "0", "periods_cnt" => "5" } ], "show_triggers" => "1", "name" => "Fan6/CPU sensor RPM data from ipmitool", "width" => "900", "height" => "200", "templateid" => "0" } g_id = zbx.add_or_get_graph(t_id, options)