zabbixapi 0.1.6.4 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'getopt/std'
5
+ require 'yaml'
6
+ require 'zabbixapi'
7
+
8
+ opt = Getopt::Std.getopts("g:i:E:")
9
+
10
+ group_name = opt["g"]
11
+ zabbix_env = opt["E"]
12
+
13
+ template_name = "TMPL_pgsql"
14
+ app_name = "PostgreSQL"
15
+
16
+ # read config
17
+ config = YAML::load(open('./config.yml'))
18
+
19
+ api_url = config[zabbix_env]["api_url"]
20
+ api_login = config[zabbix_env]["api_login"]
21
+ api_password = config[zabbix_env]["api_password"]
22
+
23
+ # Esablish new connection
24
+ zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
25
+
26
+ # Create new template
27
+ p " * Creating template #{template_name}."
28
+ g_id = zbx.add_or_get_group(group_name)
29
+
30
+ options = {
31
+ 'groups' => [ g_id.to_i ],
32
+ 'host' => template_name
33
+ }
34
+
35
+ t_id = zbx.add_or_get_template(options)
36
+
37
+ # Create application #{app_name}
38
+ p " ** Create application #{app_name}."
39
+ application = {
40
+ 'hostid' => t_id.to_i,
41
+ 'name' => app_name
42
+ }
43
+ a_id = zbx.add_or_get_application(t_id, application)
44
+
45
+ # 'postgres process exists'
46
+ options = {
47
+ 'description' => "postgres process exists",
48
+ 'key_' => "proc.num[postgres]",
49
+ 'hostid' => t_id.to_i,
50
+ 'applications' => [ a_id.to_i ],
51
+ 'history' => 7,
52
+ 'trends' => 30,
53
+ 'delay' => 120,
54
+ 'value_type' => 0
55
+ }
56
+ p " ** Add 'postgres process exists' to #{template_name}."
57
+ item_id = zbx.add_or_get_item(t_id, options)
58
+
59
+ # 'active connections count'
60
+ options = {
61
+ 'description' => "postgres active connections count",
62
+ 'key_' => "pgsql.connection_count[]",
63
+ 'hostid' => t_id.to_i,
64
+ 'applications' => [ a_id.to_i ],
65
+ 'history' => 7,
66
+ 'trends' => 30,
67
+ 'delay' => 120,
68
+ 'value_type' => 0
69
+ }
70
+ p " ** Add 'postgres active connections count' to #{template_name}."
71
+ item_id = zbx.add_or_get_item(t_id, options)
72
+
73
+ # 'test connect'
74
+ options = {
75
+ 'description' => "postgres test connect",
76
+ 'key_' => "pgsql.test_connect[]",
77
+ 'hostid' => t_id.to_i,
78
+ 'applications' => [ a_id.to_i ],
79
+ 'history' => 7,
80
+ 'trends' => 30,
81
+ 'delay' => 120,
82
+ 'value_type' => 0
83
+ }
84
+ p " ** Add 'postgres test connect' to #{template_name}."
85
+ item_id = zbx.add_or_get_item(t_id, options)
86
+
87
+ # TRIGGERS
88
+ options = {
89
+ 'description' => "postgres process exists",
90
+ 'expression' => "{#{template_name}:proc.num[postgres].last(0)}<1",
91
+ 'priority' => 5, # disaster
92
+ 'templateid' => 0,
93
+ 'comments' => "postgres process exists (disaster)",
94
+ 'type' => 0,
95
+ 'status' => '0'
96
+ }
97
+
98
+ p " ** Add 'postgres process exists' trigger"
99
+ tr_id = zbx.add_or_get_trigger(t_id, options)
100
+
101
+ options = {
102
+ 'description' => "postgres test connect",
103
+ 'expression' => "{#{template_name}:pgsql.test_connect[].last(0)}#0",
104
+ 'priority' => 5, # disaster
105
+ 'templateid' => 0,
106
+ 'comments' => "postgres test connect (disaster)",
107
+ 'type' => 0,
108
+ 'status' => '0'
109
+ }
110
+
111
+ p " ** Add 'postgres test connect' trigger"
112
+ tr_id = zbx.add_or_get_trigger(t_id, options)
113
+
114
+ options = {
115
+ 'description' => "postgres connection count",
116
+ 'expression' => "{#{template_name}:pgsql.connection_count[].last(0)}>700",
117
+ 'priority' => 5, # disaster
118
+ 'templateid' => 0,
119
+ 'comments' => "postgres connection count (disaster)",
120
+ 'type' => 0,
121
+ 'status' => '0'
122
+ }
123
+
124
+ p " ** Add 'postgres connection count' trigger"
125
+ tr_id = zbx.add_or_get_trigger(t_id, options)
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'getopt/std'
5
+ require 'yaml'
6
+ require 'zabbixapi'
7
+
8
+ opt = Getopt::Std.getopts("g:i:E:")
9
+
10
+ group_name = opt["g"]
11
+ zabbix_env = opt["E"]
12
+
13
+ template_name = "TMPL_zabbix_server"
14
+ app_name = "zabbix_server"
15
+
16
+ # read config
17
+ config = YAML::load(open('./config.yml'))
18
+
19
+ api_url = config[zabbix_env]["api_url"]
20
+ api_login = config[zabbix_env]["api_login"]
21
+ api_password = config[zabbix_env]["api_password"]
22
+
23
+ # Esablish new connection
24
+ zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
25
+
26
+ # Create new template
27
+ p " * Creating template #{template_name}."
28
+ g_id = zbx.add_or_get_group(group_name)
29
+
30
+ options = {
31
+ 'groups' => [ g_id.to_i ],
32
+ 'host' => template_name
33
+ }
34
+
35
+ t_id = zbx.add_or_get_template(options)
36
+
37
+ # Create application #{app_name}
38
+ p " ** Create application #{app_name}."
39
+ application = {
40
+ 'hostid' => t_id.to_i,
41
+ 'name' => app_name
42
+ }
43
+ a_id = zbx.add_or_get_application(t_id, application)
44
+
45
+ # 'zabbix_server process exists'
46
+ options = {
47
+ 'description' => "zabbix_server process exists",
48
+ 'key_' => "proc.num[zabbix_server]",
49
+ 'hostid' => t_id.to_i,
50
+ 'applications' => [ a_id.to_i ],
51
+ 'history' => 7,
52
+ 'trends' => 30,
53
+ 'delay' => 120,
54
+ 'value_type' => 0
55
+ }
56
+ p " ** Add 'zabbix_server process exists' to #{template_name}."
57
+ item_id = zbx.add_or_get_item(t_id, options)
58
+
59
+ # TRIGGERS
60
+ options = {
61
+ 'description' => "zabbix_server process exists",
62
+ 'expression' => "{#{template_name}:proc.num[zabbix_server].last(0)}<1",
63
+ 'priority' => 5, # disaster
64
+ 'templateid' => 0,
65
+ 'comments' => "zabbix_server process exists (disaster)",
66
+ 'type' => 0,
67
+ 'status' => '0'
68
+ }
69
+
70
+ p " ** Add 'zabbix_server process exists' trigger"
71
+ tr_id = zbx.add_or_get_trigger(t_id, options)
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'yaml'
5
+ require 'getopt/std'
6
+ require 'zabbixapi'
7
+
8
+ opt = Getopt::Std.getopts("g:E:n:t:")
9
+
10
+ group_name = opt["g"]
11
+ zabbix_env = opt["E"]
12
+ disk_name = opt["n"]
13
+ parameter_name = opt["t"]
14
+
15
+ template_name = "TMPL_#{parameter_name}_#{disk_name}"
16
+
17
+ # read config
18
+ config = YAML::load(open('./config.yml'))
19
+
20
+ api_url = config[zabbix_env]["api_url"]
21
+ api_login = config[zabbix_env]["api_login"]
22
+ api_password = config[zabbix_env]["api_password"]
23
+
24
+ # Esablish new connection
25
+ zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
26
+
27
+ # Create new template
28
+ p " * Creating template #{template_name}."
29
+ g_id = zbx.add_or_get_group(group_name)
30
+
31
+ options = {
32
+ 'groups' => [ g_id.to_i ],
33
+ 'host' => template_name
34
+ }
35
+
36
+ t_id = zbx.add_or_get_template(options)
37
+
38
+ # Create application #{app_name}
39
+ app_name = "#{parameter_name}_#{disk_name}"
40
+ p " ** Create application #{app_name}."
41
+ application = {
42
+ 'hostid' => t_id.to_i,
43
+ 'name' => app_name
44
+ }
45
+ a_id = zbx.add_or_get_application(t_id, application)
46
+
47
+ # '#{parameter_name} for #{disk_name}'
48
+ options = {
49
+ 'description' => "#{parameter_name} for #{disk_name}",
50
+ 'key_' => "smart.state[#{disk_name},#{parameter_name}]",
51
+ 'hostid' => t_id.to_i,
52
+ 'applications' => [ a_id.to_i ],
53
+ 'history' => 7,
54
+ 'trends' => 30,
55
+ 'delay' => 60,
56
+ 'value_type' => 0
57
+ }
58
+ p " ** Add '#{parameter_name} for #{disk_name}' to #{template_name}."
59
+ param_id = zbx.add_or_get_item(t_id, options)
60
+
61
+ # TRIGGERS
62
+ options = {
63
+ 'description' => "Change of #{parameter_name} on #{disk_name} is too big",
64
+ 'expression' => "{#{template_name}:smart.state[#{disk_name},#{parameter_name}].abschange(0)}>10",
65
+ 'priority' => 2, # warning
66
+ 'templateid' => 0,
67
+ 'comments' => "too many reads on #{disk_name} (warning)",
68
+ 'type' => 0,
69
+ 'status' => '0'
70
+ }
71
+ p " ** Add '#{parameter_name} on #{disk_name}' trigger'"
72
+ tr_id = zbx.add_or_get_trigger(t_id, options)
73
+
74
+ # GRAPHS
75
+ options = {
76
+ 'gitems' => [
77
+ "itemid" => param_id,
78
+ "drawtype" => "0",
79
+ "sortorder" => "0",
80
+ "color" => "AA0000",
81
+ "yaxisside" => "0",
82
+ "calc_fnc" => "2",
83
+ "type" => "0",
84
+ "periods_cnt" => "5"
85
+ ],
86
+ "show_triggers" => "1",
87
+ "name" => "#{parameter_name} graph",
88
+ "width" => "900",
89
+ "height" => "200",
90
+ "templateid" => "0"
91
+ }
92
+
93
+ p " ** Add '#{parameter_name} graph'"
94
+ g_id = zbx.add_or_get_graph(t_id, options)
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'getopt/std'
5
+ require 'yaml'
6
+ require 'zabbixapi'
7
+
8
+ opt = Getopt::Std.getopts("g:i:E:")
9
+
10
+ group_name = opt["g"]
11
+ zabbix_env = opt["E"]
12
+
13
+ template_name = "TMPL_ssh"
14
+ app_name = "SSH"
15
+
16
+ # read config
17
+ config = YAML::load(open('./config.yml'))
18
+
19
+ api_url = config[zabbix_env]["api_url"]
20
+ api_login = config[zabbix_env]["api_login"]
21
+ api_password = config[zabbix_env]["api_password"]
22
+
23
+ # Esablish new connection
24
+ zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
25
+
26
+ # Create new template
27
+ p " * Creating template #{template_name}."
28
+ g_id = zbx.add_or_get_group(group_name)
29
+
30
+ options = {
31
+ 'groups' => [ g_id.to_i ],
32
+ 'host' => template_name
33
+ }
34
+
35
+ t_id = zbx.add_or_get_template(options)
36
+
37
+ # Create application #{app_name}
38
+ p " ** Create application #{app_name}."
39
+ application = {
40
+ 'hostid' => t_id.to_i,
41
+ 'name' => app_name
42
+ }
43
+ a_id = zbx.add_or_get_application(t_id, application)
44
+
45
+ # 'sshd process exists'
46
+ options = {
47
+ 'description' => "sshd process exists",
48
+ 'key_' => "proc.num[sshd]",
49
+ 'hostid' => t_id.to_i,
50
+ 'applications' => [ a_id.to_i ],
51
+ 'history' => 7,
52
+ 'trends' => 30,
53
+ 'delay' => 120,
54
+ 'value_type' => 0
55
+ }
56
+ p " ** Add 'sshd process exists' to #{template_name}."
57
+ item_id = zbx.add_or_get_item(t_id, options)
58
+
59
+ # TRIGGERS
60
+ options = {
61
+ 'description' => "sshd process exists",
62
+ 'expression' => "{#{template_name}:proc.num[sshd].last(0)}<1",
63
+ 'priority' => 5, # disaster
64
+ 'templateid' => 0,
65
+ 'comments' => "sshd process exists (disaster)",
66
+ 'type' => 0,
67
+ 'status' => '0'
68
+ }
69
+
70
+ p " ** Add 'sshd process exists' trigger"
71
+ tr_id = zbx.add_or_get_trigger(t_id, options)
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'getopt/std'
5
+ require 'yaml'
6
+ require 'zabbixapi'
7
+
8
+ opt = Getopt::Std.getopts("g:E:")
9
+
10
+ group_name = opt["g"]
11
+ zabbix_env = opt["E"]
12
+
13
+ template_name = "TMPL_varnish"
14
+ app_name = "Varnish"
15
+
16
+ # read config
17
+ config = YAML::load(open('./config.yml'))
18
+
19
+ api_url = config[zabbix_env]["api_url"]
20
+ api_login = config[zabbix_env]["api_login"]
21
+ api_password = config[zabbix_env]["api_password"]
22
+
23
+ # Esablish new connection
24
+ zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
25
+
26
+ # Create new template
27
+ p " * Creating template #{template_name}."
28
+ g_id = zbx.add_or_get_group(group_name)
29
+
30
+ options = {
31
+ 'groups' => [ g_id.to_i ],
32
+ 'host' => template_name
33
+ }
34
+
35
+ t_id = zbx.add_or_get_template(options)
36
+
37
+ # Create application #{app_name}
38
+ p " ** Create application #{app_name}."
39
+ application = {
40
+ 'hostid' => t_id.to_i,
41
+ 'name' => app_name
42
+ }
43
+ a_id = zbx.add_or_get_application(t_id, application)
44
+
45
+ # 'varnish service status'
46
+ options = {
47
+ 'description' => "varnish service status",
48
+ 'key_' => "runit_service[varnish]",
49
+ 'hostid' => t_id.to_i,
50
+ 'applications' => [ a_id.to_i ],
51
+ 'history' => 7,
52
+ 'trends' => 30,
53
+ 'delay' => 60,
54
+ 'value_type' => 0
55
+ }
56
+ p " ** Add 'varnish service status' to #{template_name}."
57
+ item_id = zbx.add_or_get_item(t_id, options)
58
+
59
+ # TRIGGERS
60
+ options = {
61
+ 'description' => "varnish service status",
62
+ 'expression' => "{#{template_name}:runit_service[varnish].last(0)}#0",
63
+ 'priority' => 5, # disaster
64
+ 'templateid' => 0,
65
+ 'comments' => "varnish service status (disaster)",
66
+ 'type' => 0,
67
+ 'status' => '0'
68
+ }
69
+
70
+ p " ** Add 'varnish service status' trigger"
71
+ tr_id = zbx.add_or_get_trigger(t_id, options)
data/lib/zabbixapi.rb CHANGED
@@ -9,3 +9,4 @@ require 'zabbixapi/template'
9
9
  require 'zabbixapi/trigger'
10
10
  require 'zabbixapi/usermacro'
11
11
  require 'zabbixapi/mediatype'
12
+ require 'zabbixapi/maintenance'
@@ -11,8 +11,8 @@ module Zabbix
11
11
  'method' => 'application.create',
12
12
  'params' => application
13
13
  }
14
- responce = send_request(message)
15
- responce.empty? ? nil : responce['applicationids'][0].to_i
14
+ response = send_request(message)
15
+ response.empty? ? nil : response['applicationids'][0].to_i
16
16
  end
17
17
 
18
18
  def add_or_get_application(host_id, app_options)