Sha256: 9c0eaeb4b6939112fd5ba374fa36145b40358ecb5c8bc5610ac6fb79ec7e2c71

Contents?: true

Size: 1.68 KB

Versions: 5

Compression:

Stored size: 1.68 KB

Contents

#!/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"]
raid_name = opt["n"]

template_name = "TMPL_mdadm_#{raid_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 = "mdadm_#{raid_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)

# 'state of #{raid_name}'
options = {
  'description' => "state of #{raid_name}",
  'key_' => "mdadm.state[#{raid_name}]",
  'hostid' => t_id.to_i,
  'applications' => [ a_id.to_i ],
  'history' => 7,
  'trends' => 30,
  'delay' => 60,
  'value_type' => 0
}
p " ** Add 'mdadm.state[#{raid_name}]' to #{template_name}."
item_id = zbx.add_or_get_item(t_id, options)

# TRIGGERS
options = {
  'description' => "#{raid_name} is faulty",
  'expression' => "{#{template_name}:mdadm.state[#{raid_name}].last(0)}>0",
  'priority' => 5, # disaster
  'templateid' => 0,
  'comments' => "#{raid_name} is faulty (disaster)",
  'type' => 0,
  'status' => '0'
}

p " ** Add '#{raid_name} disaster' trigger'"
zbx.debug = true
tr_id = zbx.add_or_get_trigger(t_id, options)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
zabbixapi-0.3.0 examples/zabbix_mdadm
zabbixapi-0.2.0 examples/zabbix_mdadm
zabbixapi-0.1.9 examples/zabbix_mdadm
zabbixapi-0.1.8 examples/zabbix_mdadm
zabbixapi-0.1.7 examples/zabbix_mdadm