zabbixapi 0.1.6.1 → 0.1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -20,7 +20,7 @@ You can:
20
20
  "dns" => 'my.example.com',
21
21
  "host" => 'my.example.com',
22
22
  "useip" => 1,
23
- "groups" => ['some_group']
23
+ "groups" => [get_group_id('some_group')]
24
24
  }
25
25
  if zbx.create_host(host_options)
26
26
  puts zbx.get_host_id('my.example.com')
@@ -15,7 +15,7 @@ module Zabbix
15
15
  end
16
16
 
17
17
  def group_exist?(pattern)
18
- group_id = get_groups_id(pattern)
18
+ group_id = get_group_id(pattern)
19
19
  group_id ? true : false
20
20
  end
21
21
 
@@ -30,7 +30,7 @@ module Zabbix
30
30
  'ipmi_username' => '',
31
31
  'ipmi_password' => ''
32
32
  }
33
- host_options['groups'].nil? || host_options['groups'].map! { |group_id| {'groupid' => get_group_id(group_id)} }
33
+ host_options['groups'].nil? || host_options['groups'].map! { |group_id| {'groupid' => group_id} }
34
34
  host = merge_opt(host_default, host_options)
35
35
  message = {
36
36
  'method' => 'host.create',
@@ -0,0 +1,52 @@
1
+ module Zabbix
2
+ class ZabbixApi
3
+
4
+ def get_mediatype_id(mediatype)
5
+ message = {
6
+ 'method' => 'mediatype.get',
7
+ 'params' => {
8
+ 'search' => {
9
+ 'description' => mediatype
10
+ },
11
+ 'output' => 'extend',
12
+ }
13
+ }
14
+ response = send_request(message)
15
+ response.empty? ? nil : response[0]['mediatypeid'].to_i
16
+ end
17
+
18
+ def add_mediatype(mediatype_options)
19
+ mediatype_default = {
20
+ 'type' => '0',
21
+ 'description' => '',
22
+ 'smtp_server' => '',
23
+ 'smtp_helo' => '',
24
+ 'smtp_email' => '',
25
+ 'exec_path' => '',
26
+ 'gsm_modem' => '',
27
+ 'username' => '',
28
+ 'passwd' => ''
29
+ }
30
+ mediatype = merge_opt(mediatype_default, mediatype_options)
31
+ message = {
32
+ 'method' => 'mediatype.create',
33
+ 'params' => mediatype
34
+ }
35
+ response = send_request(message)
36
+ response.empty? ? nil : response['mediatypeids'][0].to_i
37
+ end
38
+
39
+ def delete_mediatype(mediatype)
40
+ mediatype_id = get_mediatype_id(mediatype)
41
+ message = {
42
+ 'method' => 'mediatype.delete',
43
+ 'params' =>
44
+ [mediatype_id]
45
+ }
46
+ response = send_request(message)
47
+ response ? true : false
48
+ end
49
+
50
+ end
51
+ end
52
+
data/lib/zabbixapi.rb CHANGED
@@ -8,3 +8,4 @@ require 'zabbixapi/screen'
8
8
  require 'zabbixapi/template'
9
9
  require 'zabbixapi/trigger'
10
10
  require 'zabbixapi/usermacro'
11
+ require 'zabbixapi/mediatype'
data/spec/item.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  require 'zabbixapi'
2
2
  require 'json'
3
3
 
4
- #require 'webmock/rspec'
5
- #include WebMock::API
6
-
7
4
  # settings
8
5
  api_url = 'http://zabbix.local/api_jsonrpc.php'
9
6
  api_login = 'Admin'
@@ -44,7 +41,7 @@ end
44
41
  # 04. Delete group
45
42
  describe Zabbix::ZabbixApi, "delete_group" do
46
43
  it "Delete some group" do
47
- result = zbx.delete_group('some_group')
44
+ result = zbx.delete_group(zbx.get_group_id'some_group')
48
45
  end
49
46
  end
50
47
 
@@ -54,3 +51,24 @@ describe Zabbix::ZabbixApi, "delete_host" do
54
51
  result = zbx.delete_host('my.example.com')
55
52
  end
56
53
  end
54
+
55
+ # 06. Mediatype create
56
+ mediatype_options = {
57
+ 'type' => '0',
58
+ 'description' => 'example_mediatype',
59
+ 'smtp_server' => 'test.company.com',
60
+ 'smtp_helo' => 'test.company.com',
61
+ 'smtp_email' => 'test@test.company.com',
62
+ }
63
+ describe Zabbix::ZabbixApi, "create_mediatype" do
64
+ it "Create mediatype" do
65
+ result = zbx.add_mediatype(mediatype_options)
66
+ end
67
+ end
68
+
69
+ # 07. Mediatype delete
70
+ describe Zabbix::ZabbixApi, "create_mediatype" do
71
+ it "Delete mediatype" do
72
+ result = zbx.delete_mediatype('example_mediatype')
73
+ end
74
+ end
data/zabbixapi.gemspec CHANGED
@@ -4,7 +4,7 @@ require 'rake'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
 
7
- spec.version = '0.1.6.1'
7
+ spec.version = '0.1.6.2'
8
8
  spec.name = 'zabbixapi'
9
9
  spec.summary = 'Ruby module for work with zabbix api.'
10
10
 
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.1.6.1
4
+ version: 0.1.6.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-07 00:00:00.000000000 Z
12
+ date: 2012-10-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Ruby module for work with zabbix api v1.8.
15
15
  email: vadv.mkn@gmail.com
@@ -25,6 +25,7 @@ files:
25
25
  - lib/zabbixapi/group.rb
26
26
  - lib/zabbixapi/host.rb
27
27
  - lib/zabbixapi/item.rb
28
+ - lib/zabbixapi/mediatype.rb
28
29
  - lib/zabbixapi/screen.rb
29
30
  - lib/zabbixapi/template.rb
30
31
  - lib/zabbixapi/trigger.rb
@@ -64,4 +65,3 @@ signing_key:
64
65
  specification_version: 3
65
66
  summary: Ruby module for work with zabbix api.
66
67
  test_files: []
67
- has_rdoc: true