#!/usr/bin/env ruby require 'rubygems' require 'getopt/std' require 'yaml' require 'zabbixapi' opt = Getopt::Std.getopts("m:g:E:") mount_point = opt["m"] group_name = opt["g"] zabbix_env = opt["E"] if ( mount_point == "/" ) template_name = "TMPL_Filesystem_root" app_name = "Filesystem_root" else mount_point = mount_point.sub(/\/$/, "") template_name = "TMPL_Filesystem" + mount_point.gsub(/\//, "_") app_name = "Filesystem" + mount_point.gsub(/\//, "_") end # 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.get_group_id(group_name) options = { 'groups' => [ g_id.to_i ], 'host' => template_name } t_id = zbx.add_template(options) # Create application #{app_name} p " ** Create application #{app_name}." application = { 'hostid' => t_id.to_i, 'name' => app_name } a_id = zbx.add_application(application) # Total disk space on #{mount_point} options = { 'description' => "Total disk space on #{mount_point}", 'key_' => "vfs.fs.size[#{mount_point},total]", 'hostid' => t_id.to_i, 'applications' => [ a_id.to_i ], 'units' => 'B', 'history' => 7, 'trends' => 30, 'delay' => 600, 'value_type' => 0 } p " ** Add 'Total disk space on #{mount_point}' to #{template_name}." total_in_b_item_id = zbx.add_item(options) # Used disk space on #{mount_point} options = { 'description' => "Used disk space on #{mount_point}", 'key_' => "vfs.fs.size[#{mount_point},used]", 'hostid' => t_id.to_i, 'applications' => [ a_id.to_i ], 'units' => 'B', 'history' => 7, 'trends' => 30, 'delay' => 60, 'value_type' => 0 } p " ** Add 'Used disk space on #{mount_point}' to #{template_name}." used_in_b_item_id = zbx.add_item(options) # Use disk space on #{mount_point} in % options = { 'description' => "Used disk space on #{mount_point} in %", 'key_' => "vfs.fs.size[#{mount_point},pused]", 'hostid' => t_id.to_i, 'applications' => [ a_id.to_i ], 'history' => 7, 'trends' => 30, 'delay' => 60, 'value_type' => 0 } p " ** Add 'Used disk space on #{mount_point} in %' to #{template_name}." i_id = zbx.add_item(options) # Free disk space on #{mount_point} options = { 'description' => "Free disk space on #{mount_point}", 'type' => '15', # calculated 'key_' => "vfs.fs.size[#{mount_point},free]", 'params' => "last(\"vfs.fs.size[#{mount_point},total]\") - last(\"vfs.fs.size[#{mount_point},used]\")", 'hostid' => t_id.to_i, 'applications' => [ a_id.to_i ], 'units' => 'B', 'history' => 7, 'trends' => 30, 'delay' => 60, 'value_type' => 0 } p " ** Add 'Free disk space on #{mount_point}' to #{template_name}." i_id = zbx.add_item(options) # Free disk space on #{mount_point} in % options = { 'description' => "Free disk space on #{mount_point} in %", 'type' => '15', # calculated 'key_' => "vfs.fs.size[#{mount_point},pfree]", 'params' => "100 - last(\"vfs.fs.size[#{mount_point},pused]\")", 'hostid' => t_id.to_i, 'applications' => [ a_id.to_i ], 'history' => 7, 'trends' => 30, 'delay' => 60, 'value_type' => 0 } p " ** Add 'Free disk space on #{mount_point} in %' to #{template_name}." i_id = zbx.add_item(options) # Free number of inodes on #{mount_point} options = { 'description' => "Free number of inodes on #{mount_point}", 'key_' => "vfs.fs.inode[#{mount_point},free]", 'hostid' => t_id.to_i, 'applications' => [ a_id.to_i ], 'units' => '', 'history' => 7, 'trends' => 30, 'delay' => 60, 'value_type' => 0 } p " ** Add 'Free number of inodes on #{mount_point}' to #{template_name}." i_id = zbx.add_item(options) # Free number of inodes on #{mount_point} in % options = { 'description' => "Free number of inodes on #{mount_point} in %", 'key_' => "vfs.fs.inode[#{mount_point},pfree]", 'hostid' => t_id.to_i, 'applications' => [ a_id.to_i ], 'history' => 7, 'trends' => 30, 'delay' => 60, 'value_type' => 0 } p " ** Add 'Free number of inodes on #{mount_point} in %' to #{template_name}." i_id = zbx.add_item(options) ## TRIGGERS options = { 'description' => "Free disk space on #{mount_point}", 'expression' => "{#{template_name}:vfs.fs.size[#{mount_point},pfree].last(0)}<15", 'priority' => 2, # warning 'templateid' => 0, 'comments' => "Free disk space on #{mount_point} (warning)", 'type' => 0, 'status' => '0' } p " ** Add 'Free disk space on #{mount_point} warning trigger'" tr_id = zbx.add_trigger(options) options = { 'description' => "Free disk space on #{mount_point}", 'expression' => "{#{template_name}:vfs.fs.size[#{mount_point},pfree].last(0)}<10", 'priority' => 5, # Disaster 'templateid' => 0, 'comments' => "Free disk space on #{mount_point} (disaster)", 'type' => 0, 'status' => 0 } p " ** Add 'Free disk space on #{mount_point} disaster trigger'" tr_id = zbx.add_trigger(options) options = { 'description' => "Free inodes on #{mount_point}", 'expression' => "{#{template_name}:vfs.fs.inode[#{mount_point},pfree].last(0)}<15", 'priority' => 2, # warning 'templateid' => '0', 'comments' => "Free disk inodes on #{mount_point} (warning)", 'type' => 0, 'status' => '0' } p " ** Add 'Free inodes on #{mount_point} warning trigger'" tr_id = zbx.add_trigger(options) options = { 'description' => "Free inodes on #{mount_point}", 'expression' => "{#{template_name}:vfs.fs.inode[#{mount_point},pfree].last(0)}<10", 'priority' => 5, #disaster 'templateid' => '0', 'comments' => "Free disk inodes on #{mount_point} (disaster)", 'type' => 0, 'status' => '0' } p " ** Add 'Free inodes on #{mount_point} disaster trigger'" tr_id = zbx.add_trigger(options) options = { 'gitems' => [ { "itemid" => total_in_b_item_id, "drawtype" => "0", "sortorder" => "0", "color" => "AA0000", "yaxisside" => "0", "calc_fnc" => "2", "type" => "0", "periods_cnt" => "5" }, { "itemid" => used_in_b_item_id, "drawtype" => "0", "sortorder" => "0", "color" => "009900", "yaxisside" => "0", "calc_fnc" => "2", "type" => "0", "periods_cnt" => "5" } ], "show_triggers" => "1", "name" => "Disk space on #{mount_point}", "width" => "900", "height" => "200", "templateid" => "0" } p " ** Add 'Disk space on #{mount_point} graph'" g_id = zbx.add_graph(options)