zabbixapi 0.6.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +11 -6
  3. data/README.md +21 -25
  4. data/lib/zabbixapi.rb +23 -10
  5. data/lib/zabbixapi/{1.8/basic → basic}/basic_alias.rb +0 -0
  6. data/lib/zabbixapi/{1.8/basic → basic}/basic_func.rb +3 -3
  7. data/lib/zabbixapi/{1.8/basic → basic}/basic_init.rb +0 -0
  8. data/lib/zabbixapi/{2.0/basic → basic}/basic_logic.rb +3 -3
  9. data/lib/zabbixapi/{1.8/classes → classes}/applications.rb +0 -0
  10. data/lib/zabbixapi/{1.8/classes → classes}/errors.rb +0 -0
  11. data/lib/zabbixapi/{1.8/classes → classes}/graphs.rb +0 -0
  12. data/lib/zabbixapi/{2.0/classes → classes}/hostgroups.rb +0 -0
  13. data/lib/zabbixapi/{2.0/classes → classes}/hosts.rb +4 -0
  14. data/lib/zabbixapi/{2.0/classes → classes}/items.rb +8 -0
  15. data/lib/zabbixapi/{1.8/classes → classes}/mediatypes.rb +0 -0
  16. data/lib/zabbixapi/{2.0/classes → classes}/proxies.rb +0 -0
  17. data/lib/zabbixapi/{2.0/classes → classes}/screens.rb +1 -19
  18. data/lib/zabbixapi/{1.8/classes → classes}/server.rb +0 -0
  19. data/lib/zabbixapi/{2.0/classes → classes}/templates.rb +4 -4
  20. data/lib/zabbixapi/{1.8/classes → classes}/triggers.rb +0 -0
  21. data/lib/zabbixapi/{1.8/classes → classes}/unusable.rb +0 -0
  22. data/lib/zabbixapi/{2.0/classes → classes}/usergroups.rb +0 -12
  23. data/lib/zabbixapi/{2.0/classes → classes}/usermacros.rb +0 -0
  24. data/lib/zabbixapi/{2.0/classes → classes}/users.rb +2 -2
  25. data/lib/zabbixapi/version.rb +1 -1
  26. data/spec/application.rb +74 -0
  27. data/spec/basic_func.rb +4 -0
  28. data/spec/graph.rb +135 -0
  29. data/spec/host.rb +136 -0
  30. data/spec/hostgroup.rb +55 -0
  31. data/spec/item.rb +132 -0
  32. data/spec/mediatype.rb +47 -0
  33. data/spec/query.rb +13 -0
  34. data/spec/screen.rb +88 -0
  35. data/spec/server.rb +17 -0
  36. data/spec/spec_helper.rb +21 -0
  37. data/spec/template.rb +148 -0
  38. data/spec/trigger.rb +74 -0
  39. data/spec/user.rb +99 -0
  40. data/spec/usergroup.rb +69 -0
  41. data/zabbixapi.gemspec +3 -3
  42. metadata +52 -44
  43. data/lib/zabbixapi/1.8/basic/basic_logic.rb +0 -103
  44. data/lib/zabbixapi/1.8/classes/hostgroups.rb +0 -26
  45. data/lib/zabbixapi/1.8/classes/hosts.rb +0 -58
  46. data/lib/zabbixapi/1.8/classes/items.rb +0 -54
  47. data/lib/zabbixapi/1.8/classes/screens.rb +0 -101
  48. data/lib/zabbixapi/1.8/classes/templates.rb +0 -109
  49. data/lib/zabbixapi/1.8/classes/usergroups.rb +0 -82
  50. data/lib/zabbixapi/1.8/classes/users.rb +0 -32
  51. data/lib/zabbixapi/2.0/basic/basic_alias.rb +0 -21
  52. data/lib/zabbixapi/2.0/basic/basic_func.rb +0 -55
  53. data/lib/zabbixapi/2.0/basic/basic_init.rb +0 -33
  54. data/lib/zabbixapi/2.0/classes/applications.rb +0 -45
  55. data/lib/zabbixapi/2.0/classes/errors.rb +0 -15
  56. data/lib/zabbixapi/2.0/classes/graphs.rb +0 -66
  57. data/lib/zabbixapi/2.0/classes/mediatypes.rb +0 -31
  58. data/lib/zabbixapi/2.0/classes/server.rb +0 -12
  59. data/lib/zabbixapi/2.0/classes/triggers.rb +0 -67
  60. data/lib/zabbixapi/2.0/classes/unusable.rb +0 -10
  61. data/spec/localhost.rb +0 -514
  62. data/spec/run.rb +0 -486
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbixapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasiliev D.V.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-12 00:00:00.000000000 Z
12
+ date: 2014-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -47,48 +47,43 @@ files:
47
47
  - README.md
48
48
  - Rakefile
49
49
  - lib/zabbixapi.rb
50
- - lib/zabbixapi/1.8/basic/basic_alias.rb
51
- - lib/zabbixapi/1.8/basic/basic_func.rb
52
- - lib/zabbixapi/1.8/basic/basic_init.rb
53
- - lib/zabbixapi/1.8/basic/basic_logic.rb
54
- - lib/zabbixapi/1.8/classes/applications.rb
55
- - lib/zabbixapi/1.8/classes/errors.rb
56
- - lib/zabbixapi/1.8/classes/graphs.rb
57
- - lib/zabbixapi/1.8/classes/hostgroups.rb
58
- - lib/zabbixapi/1.8/classes/hosts.rb
59
- - lib/zabbixapi/1.8/classes/items.rb
60
- - lib/zabbixapi/1.8/classes/mediatypes.rb
61
- - lib/zabbixapi/1.8/classes/screens.rb
62
- - lib/zabbixapi/1.8/classes/server.rb
63
- - lib/zabbixapi/1.8/classes/templates.rb
64
- - lib/zabbixapi/1.8/classes/triggers.rb
65
- - lib/zabbixapi/1.8/classes/unusable.rb
66
- - lib/zabbixapi/1.8/classes/usergroups.rb
67
- - lib/zabbixapi/1.8/classes/users.rb
68
- - lib/zabbixapi/2.0/basic/basic_alias.rb
69
- - lib/zabbixapi/2.0/basic/basic_func.rb
70
- - lib/zabbixapi/2.0/basic/basic_init.rb
71
- - lib/zabbixapi/2.0/basic/basic_logic.rb
72
- - lib/zabbixapi/2.0/classes/applications.rb
73
- - lib/zabbixapi/2.0/classes/errors.rb
74
- - lib/zabbixapi/2.0/classes/graphs.rb
75
- - lib/zabbixapi/2.0/classes/hostgroups.rb
76
- - lib/zabbixapi/2.0/classes/hosts.rb
77
- - lib/zabbixapi/2.0/classes/items.rb
78
- - lib/zabbixapi/2.0/classes/mediatypes.rb
79
- - lib/zabbixapi/2.0/classes/proxies.rb
80
- - lib/zabbixapi/2.0/classes/screens.rb
81
- - lib/zabbixapi/2.0/classes/server.rb
82
- - lib/zabbixapi/2.0/classes/templates.rb
83
- - lib/zabbixapi/2.0/classes/triggers.rb
84
- - lib/zabbixapi/2.0/classes/unusable.rb
85
- - lib/zabbixapi/2.0/classes/usergroups.rb
86
- - lib/zabbixapi/2.0/classes/usermacros.rb
87
- - lib/zabbixapi/2.0/classes/users.rb
50
+ - lib/zabbixapi/basic/basic_alias.rb
51
+ - lib/zabbixapi/basic/basic_func.rb
52
+ - lib/zabbixapi/basic/basic_init.rb
53
+ - lib/zabbixapi/basic/basic_logic.rb
54
+ - lib/zabbixapi/classes/applications.rb
55
+ - lib/zabbixapi/classes/errors.rb
56
+ - lib/zabbixapi/classes/graphs.rb
57
+ - lib/zabbixapi/classes/hostgroups.rb
58
+ - lib/zabbixapi/classes/hosts.rb
59
+ - lib/zabbixapi/classes/items.rb
60
+ - lib/zabbixapi/classes/mediatypes.rb
61
+ - lib/zabbixapi/classes/proxies.rb
62
+ - lib/zabbixapi/classes/screens.rb
63
+ - lib/zabbixapi/classes/server.rb
64
+ - lib/zabbixapi/classes/templates.rb
65
+ - lib/zabbixapi/classes/triggers.rb
66
+ - lib/zabbixapi/classes/unusable.rb
67
+ - lib/zabbixapi/classes/usergroups.rb
68
+ - lib/zabbixapi/classes/usermacros.rb
69
+ - lib/zabbixapi/classes/users.rb
88
70
  - lib/zabbixapi/client.rb
89
71
  - lib/zabbixapi/version.rb
90
- - spec/localhost.rb
91
- - spec/run.rb
72
+ - spec/application.rb
73
+ - spec/basic_func.rb
74
+ - spec/graph.rb
75
+ - spec/host.rb
76
+ - spec/hostgroup.rb
77
+ - spec/item.rb
78
+ - spec/mediatype.rb
79
+ - spec/query.rb
80
+ - spec/screen.rb
81
+ - spec/server.rb
82
+ - spec/spec_helper.rb
83
+ - spec/template.rb
84
+ - spec/trigger.rb
85
+ - spec/user.rb
86
+ - spec/usergroup.rb
92
87
  - zabbixapi.gemspec
93
88
  homepage: https://github.com/express42/zabbixapi
94
89
  licenses:
@@ -115,6 +110,19 @@ signing_key:
115
110
  specification_version: 4
116
111
  summary: Realization for Zabbix API.
117
112
  test_files:
118
- - spec/localhost.rb
119
- - spec/run.rb
113
+ - spec/application.rb
114
+ - spec/basic_func.rb
115
+ - spec/graph.rb
116
+ - spec/host.rb
117
+ - spec/hostgroup.rb
118
+ - spec/item.rb
119
+ - spec/mediatype.rb
120
+ - spec/query.rb
121
+ - spec/screen.rb
122
+ - spec/server.rb
123
+ - spec/spec_helper.rb
124
+ - spec/template.rb
125
+ - spec/trigger.rb
126
+ - spec/user.rb
127
+ - spec/usergroup.rb
120
128
  has_rdoc:
@@ -1,103 +0,0 @@
1
- class ZabbixApi
2
- class Basic
3
-
4
- def create(data)
5
- log "[DEBUG] Call create with parametrs: #{data.inspect}"
6
-
7
- data_with_default = default_options.empty? ? data : merge_params(data)
8
- data_create = array_flag ? [data_with_default] : data_with_default
9
- result = @client.api_request(:method => "#{method_name}.create", :params => data_create)
10
- parse_keys result
11
- end
12
-
13
- def delete(data)
14
- log "[DEBUG] Call delete with parametrs: #{data.inspect}"
15
-
16
- data_delete = array_flag ? [data] : [key.to_sym => data]
17
- result = @client.api_request(:method => "#{method_name}.delete", :params => data_delete)
18
- parse_keys result
19
- end
20
-
21
- def create_or_update(data)
22
- log "[DEBUG] Call create_or_update with parametrs: #{data.inspect}"
23
-
24
- id = get_id(indentify.to_sym => data[indentify.to_sym])
25
- id ? update(data.merge(key.to_sym => id.to_s)) : create(data)
26
- end
27
-
28
- def update(data)
29
- log "[DEBUG] Call update with parametrs: #{data.inspect}"
30
-
31
- dump = {}
32
- item_id = data[key.to_sym].to_i
33
- dump_by_id(key.to_sym => data[key.to_sym]).each do |item|
34
- dump = symbolize_keys(item) if item[key].to_i == data[key.to_sym].to_i
35
- end
36
-
37
- if hash_equals?(dump, data)
38
- log "[DEBUG] Equal keys #{dump} and #{data}, skip update"
39
- item_id
40
- else
41
- data_update = array_flag ? [data] : data
42
- result = @client.api_request(:method => "#{method_name}.update", :params => data_update)
43
- parse_keys result
44
- end
45
-
46
- end
47
-
48
- def get_full_data(data)
49
- log "[DEBUG] Call get_full_data with parametrs: #{data.inspect}"
50
-
51
- @client.api_request(
52
- :method => "#{method_name}.get",
53
- :params => {
54
- :filter => {
55
- indentify.to_sym => data[indentify.to_sym]
56
- },
57
- :output => "extend"
58
- }
59
- )
60
- end
61
-
62
- def dump_by_id(data)
63
- log "[DEBUG] Call dump_by_id with parametrs: #{data.inspect}"
64
-
65
- @client.api_request(
66
- :method => "#{method_name}.get",
67
- :params => {
68
- :filter => {
69
- key.to_sym => data[key.to_sym]
70
- },
71
- :output => "extend"
72
- }
73
- )
74
- end
75
-
76
- def all
77
- result = {}
78
- @client.api_request(:method => "#{method_name}.get", :params => {:output => "extend"}).each do |item|
79
- result[item[indentify]] = item[key]
80
- end
81
- result
82
- end
83
-
84
- def get_id(data)
85
- log "[DEBUG] Call get_id with parametrs: #{data.inspect}"
86
-
87
- result = symbolize_keys( get_full_data(data) )
88
- id = nil
89
- result.each { |item| id = item[key.to_sym].to_i if item[indentify.to_sym] == data[indentify.to_sym] }
90
- id
91
- end
92
-
93
- def get_or_create(data)
94
- log "[DEBUG] Call get_or_create with parametrs: #{data.inspect}"
95
-
96
- unless (id = get_id(data))
97
- id = create(data)
98
- end
99
- id
100
- end
101
-
102
- end
103
- end
@@ -1,26 +0,0 @@
1
- class ZabbixApi
2
- class HostGroups < Basic
3
-
4
- def array_flag
5
- true
6
- end
7
-
8
- def method_name
9
- "hostgroup"
10
- end
11
-
12
- def indentify
13
- "name"
14
- end
15
-
16
- def key
17
- "groupid"
18
- end
19
-
20
- def delete(data)
21
- result = @client.api_request(:method => "hostgroup.delete", :params => [:groupid => data])
22
- result.empty? ? nil : result['groupids'][0].to_i
23
- end
24
-
25
- end
26
- end
@@ -1,58 +0,0 @@
1
- class ZabbixApi
2
- class Hosts < Basic
3
-
4
- def array_flag
5
- true
6
- end
7
-
8
- def method_name
9
- "host"
10
- end
11
-
12
- def indentify
13
- "host"
14
- end
15
-
16
- def default_options
17
- {
18
- :host => nil,
19
- :port => 10050,
20
- :status => 1,
21
- :useip => 1,
22
- :dns => '',
23
- :ip => '0.0.0.0',
24
- :proxy_hostid => 0,
25
- :groups => [],
26
- :useipmi => 0,
27
- :ipmi_ip => '',
28
- :ipmi_port => 623,
29
- :ipmi_authtype => 0,
30
- :ipmi_privilege => 0,
31
- :ipmi_username => '',
32
- :ipmi_password => ''
33
- }
34
- end
35
-
36
- def unlink_templates(data)
37
- result = @client.api_request(
38
- :method => "host.massRemove",
39
- :params => {
40
- :hostids => data[:hosts_id],
41
- :templates => data[:templates_id]
42
- }
43
- )
44
- case @client.api_version
45
- when "1.2"
46
- result ? true : false
47
- else
48
- result.empty? ? false : true
49
- end
50
- end
51
-
52
- def create_or_update(data)
53
- hostid = get_id(:host => data[:host])
54
- hostid ? update(data.merge(:hostid => hostid)) : create(data)
55
- end
56
-
57
- end
58
- end
@@ -1,54 +0,0 @@
1
- class ZabbixApi
2
- class Items < Basic
3
-
4
- def array_flag
5
- true
6
- end
7
-
8
- def method_name
9
- "item"
10
- end
11
-
12
- def indentify
13
- "description"
14
- end
15
-
16
- def default_options
17
- {
18
- :description => nil,
19
- :key_ => nil,
20
- :hostid => nil,
21
- :delay => 60,
22
- :history => 60,
23
- :status => 0,
24
- :type => 7,
25
- :snmp_community => '',
26
- :snmp_oid => '',
27
- :value_type => 3,
28
- :data_type => 0,
29
- :trapper_hosts => 'localhost',
30
- :snmp_port => 161,
31
- :units => '',
32
- :multiplier => 0,
33
- :delta => 0,
34
- :snmpv3_securityname => '',
35
- :snmpv3_securitylevel => 0,
36
- :snmpv3_authpassphrase => '',
37
- :snmpv3_privpassphrase => '',
38
- :formula => 0,
39
- :trends => 365,
40
- :logtimefmt => '',
41
- :valuemapid => 0,
42
- :delay_flex => '',
43
- :authtype => 0,
44
- :username => '',
45
- :password => '',
46
- :publickey => '',
47
- :privatekey => '',
48
- :params => '',
49
- :ipmi_sensor => ''
50
- }
51
- end
52
-
53
- end
54
- end
@@ -1,101 +0,0 @@
1
- class ZabbixApi
2
- class Screens < Basic
3
-
4
- # extracted from frontends/php/include/defines.inc.php
5
- #SCREEN_RESOURCE_GRAPH => 0,
6
- #SCREEN_RESOURCE_SIMPLE_GRAPH => 1,
7
- #SCREEN_RESOURCE_MAP => 2,
8
- #SCREEN_RESOURCE_PLAIN_TEXT => 3,
9
- #SCREEN_RESOURCE_HOSTS_INFO => 4,
10
- #SCREEN_RESOURCE_TRIGGERS_INFO => 5,
11
- #SCREEN_RESOURCE_SERVER_INFO => 6,
12
- #SCREEN_RESOURCE_CLOCK => 7,
13
- #SCREEN_RESOURCE_SCREEN => 8,
14
- #SCREEN_RESOURCE_TRIGGERS_OVERVIEW => 9,
15
- #SCREEN_RESOURCE_DATA_OVERVIEW => 10,
16
- #SCREEN_RESOURCE_URL => 11,
17
- #SCREEN_RESOURCE_ACTIONS => 12,
18
- #SCREEN_RESOURCE_EVENTS => 13,
19
- #SCREEN_RESOURCE_HOSTGROUP_TRIGGERS => 14,
20
- #SCREEN_RESOURCE_SYSTEM_STATUS => 15,
21
- #SCREEN_RESOURCE_HOST_TRIGGERS => 16
22
-
23
- def method_name
24
- "screen"
25
- end
26
-
27
- def indentify
28
- "name"
29
- end
30
-
31
- def delete(data)
32
- screen_name = data[:screen_name]
33
- screen_id = data[:screen_id]
34
-
35
- unless screen_name.nil?
36
- unless screen_name.instance_of?(Array)
37
- screen_id = get_id(:name => screen_name)
38
- else
39
- screen_id = []
40
- screen_name.each do |name|
41
- screen_id << get_id(:name => name)
42
- end
43
- end
44
- end
45
-
46
- unless screen_id.instance_of?(Array)
47
- screen_id = [screen_id, screen_id]
48
- end
49
-
50
- result = @client.api_request(:method => "screen.delete", :params => screen_id)
51
- result.empty? ? nil : result['screenids'][0].to_i
52
- end
53
-
54
- def get_or_create_for_host(data)
55
- screen_name = data[:screen_name]
56
- graphids = data[:graphids]
57
- screenitems = []
58
- hsize = data[:hsize] || 3
59
- valign = data[:valign] || 2
60
- halign = data[:halign] || 2
61
- rowspan = data[:rowspan] || 0
62
- colspan = data[:colspan] || 0
63
- height = data[:height] || 320 # default 320
64
- width = data[:width] || 200 # default 200
65
- vsize = data[:vsize] || (graphids.size/hsize).to_i
66
- screenid = get_id(:name => screen_name)
67
-
68
- if ((graphids.size/hsize) / 2) == 0
69
- vsize = data[:vsize] || (graphids.size/hsize).to_i
70
- else
71
- vsize = data[:vsize] || ((graphids.size/hsize)+1).to_i
72
- end
73
-
74
- unless screenid
75
- # Create screen
76
- graphids.each_with_index do |graphid, index|
77
- screenitems << {
78
- :resourcetype => 0,
79
- :resourceid => graphid,
80
- :x => (index % hsize).to_i,
81
- :y => (index % graphids.size/hsize).to_i,
82
- :valign => valign,
83
- :halign => halign,
84
- :rowspan => rowspan,
85
- :colspan => colspan,
86
- :height => height,
87
- :width => width
88
- }
89
- end
90
- screenid = create(
91
- :name => screen_name,
92
- :hsize => hsize,
93
- :vsize => vsize,
94
- :screenitems => screenitems
95
- )
96
- end
97
- screenid
98
- end
99
-
100
- end
101
- end