spec/localhost.rb in zabbixapi-0.4.1 vs spec/localhost.rb in zabbixapi-0.4.2
- old
+ new
@@ -1,9 +1,12 @@
require 'zabbixapi'
# settings
-api_url = 'http://localhost/api_jsonrpc.php'
+#api_url = 'http://zabbix/zabbix12/api_jsonrpc.php'
+api_url = 'http://zabbix/zabbix13/api_jsonrpc.php'
+#api_url = 'http://zabbix/zabbix20/api_jsonrpc.php'
+
api_login = 'Admin'
api_password = 'zabbix'
zbx = ZabbixApi.connect(
:url => api_url,
@@ -20,10 +23,12 @@
trigger = "trigger____1"
user = "user____1"
user2 = "user____2"
graph = "graph___a"
+puts "### Zabbix API server version #{zbx.server.version} ###"
+
describe ZabbixApi, "test_api" do
it "SERVER: Get version api" do
zbx.server.version.should be_kind_of(String)
end
@@ -82,11 +87,11 @@
zbx.items.create(
:description => item,
:key_ => "proc.num[aaa]",
:hostid => zbx.templates.get_id(:host => template),
:applications => [zbx.applications.get_id(:name => application)]
- )
+ ).should be_kind_of(Integer)
end
it "ITEM: Full info check" do
zbx.items.get_full_data(:description => item)[0]['itemid'].should be_kind_of(String)
end
@@ -100,10 +105,20 @@
:itemid => zbx.items.get_id(:description => item),
:status => 0
).should be_kind_of(Integer)
end
+ it "ITEM: Create or update" do
+ zbx.items.create_or_update(
+ :description => item,
+ :key_ => "proc.num[aaa]",
+ :type => 6,
+ :hostid => zbx.templates.get_id(:host => template),
+ :applications => [zbx.applications.get_id(:name => application)]
+ ).should be_kind_of(Integer)
+ end
+
it "ITEM: Get unknown" do
zbx.items.get_id(:description => "#{item}_____")
end
it "HOST: Create" do
@@ -112,10 +127,18 @@
:ip => "10.20.48.88",
:groups => [:groupid => zbx.hostgroups.get_id(:name => hostgroup)]
).should be_kind_of(Integer)
end
+ it "HOST: Update or create" do
+ zbx.hosts.create_or_update(
+ :host => host,
+ :ip => "10.20.48.89",
+ :groups => [:groupid => zbx.hostgroups.get_id(:name => hostgroup)]
+ ).should be_kind_of(Integer)
+ end
+
it "HOST: Find unknown" do
zbx.hosts.get_id(:host => "#{host}___").should be_kind_of(NilClass)
end
it "HOST: Find" do
@@ -133,19 +156,22 @@
zbx.templates.get_ids_by_host(
:hostids => [zbx.hosts.get_id(:host => host)]
).should be_kind_of(Array)
end
- it "HOSTS: Linked host with templates" do
- zbx.hosts.unlink_templates(
+ it "TEMPLATE: Linked hosts with templates" do
+ zbx.templates.mass_add(
:hosts_id => [zbx.hosts.get_id(:host => host)],
:templates_id => [zbx.templates.get_id(:host => template)]
).should be_kind_of(TrueClass)
end
- it "TEMPLATE: Unlink host from templates" do
-
+ it "TEMPLATE: Unlink hosts from templates" do
+ zbx.templates.mass_remove(
+ :hosts_id => [zbx.hosts.get_id(:host => host)],
+ :templates_id => [zbx.templates.get_id(:host => template)]
+ ).should be_kind_of(TrueClass)
end
it "TEMPLATE: Get all" do
zbx.templates.all.should be_kind_of(Hash)
end
@@ -178,13 +204,16 @@
:show_triggers => "0",
:name => graph,
:width => "900",
:height => "200"
).should be_kind_of(Integer)
- #
end
+ it "GRAPH: Find ugititems" do
+ zbx.graphs.get_items( zbx.graphs.get_id(:name => graph) )
+ end
+
it "GRAPH: Find" do
zbx.graphs.get_id( :name => graph ).should be_kind_of(Integer)
end
it "GRAPH: Update" do
@@ -193,9 +222,25 @@
:name => graph,
:hostid => zbx.hosts.get_id(:host => host)
),
:ymax_type => 1
).should be_kind_of(Integer)
+ end
+
+ it "GRAPH: Create or Update" do
+ gitems = {
+ :itemid => zbx.items.get_id(:description => item),
+ :calc_fnc => "3",
+ :type => "0",
+ :periods_cnt => "5"
+ }
+ zbx.graphs.create_or_update(
+ :gitems => [gitems],
+ :show_triggers => "1",
+ :name => graph,
+ :width => "900",
+ :height => "200"
+ ).should be_kind_of(Integer)
end
it "GRAPH: Delete" do
zbx.graphs.delete(zbx.graphs.get_id(:name => graph)).should be_kind_of(Integer)
end