Sha256: 7b87c972b5fbb67eb446b9d30c8a59a4c847f9c7fcda176b6f6d7be8e957ee21

Contents?: true

Size: 1.58 KB

Versions: 5

Compression:

Stored size: 1.58 KB

Contents

#!/usr/bin/env ruby

require 'rubygems'
require 'getopt/std'
require 'yaml'
require 'zabbixapi'

opt = Getopt::Std.getopts("g:i:E:")

group_name = opt["g"]
zabbix_env = opt["E"]

template_name = "TMPL_ntp"
app_name = "NTP"

# 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}
p " ** Create application #{app_name}."
application = {
  'hostid' => t_id.to_i,
  'name' => app_name
}
a_id = zbx.add_or_get_application(t_id, application)

# 'ntpd process exists'
options = {
  'description' => "ntpd process exists",
  'key_' => "proc.num[ntpd]",
  'hostid' => t_id.to_i,
  'applications' => [ a_id.to_i ],
  'history' => 7,
  'trends' => 30,
  'delay' => 120,
  'value_type' => 0
}
p " ** Add 'ntpd process exists' to #{template_name}."
item_id = zbx.add_or_get_item(t_id, options)

# TRIGGERS
options = {
  'description' => "ntpd process exists",
  'expression' => "{#{template_name}:proc.num[ntpd].last(0)}<1",
  'priority' => 5, # disaster
  'templateid' => 0,
  'comments' => "ntpd process exists (disaster)",
  'type' => 0,
  'status' => '0'
}

p " ** Add 'ntpd process exists' trigger"
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_ntp
zabbixapi-0.2.0 examples/zabbix_ntp
zabbixapi-0.1.9 examples/zabbix_ntp
zabbixapi-0.1.8 examples/zabbix_ntp
zabbixapi-0.1.7 examples/zabbix_ntp