zabbix_conf 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 31cb3ac40dd62bc0f18ec65991d3f0a3de415c95
4
+ data.tar.gz: f30ac7bb33c44a8537aa9f694abc0099eae5c739
5
+ SHA512:
6
+ metadata.gz: 1e05b93678cc7903e2c8c742c59fd80edbfa2197e182a5ce2ffe4e1381d1aa9cefdb9ffd544ee9a9674430f9df90c76b5b97da89159239677cee6523a7b0cae4
7
+ data.tar.gz: 781fca7c479ac113a99fd1572b34fb955668fd75fb6004c1f655cf9e9a4f28e772ad0fa86aa221014f6b0ec3741a84fc40a577de51043de9b1279f4a83f117db
@@ -0,0 +1,27 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+
24
+ .ruby-*
25
+
26
+ conf/
27
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zabbix_conf.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Cevaris
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ # Zabbix Configuration
2
+
3
+ ## File based configuration for Zabbix
4
+
5
+ #### Example configuration file
6
+ ```
7
+ [server]
8
+ fqdn = server.example.com
9
+ ip = 192.168.10.50
10
+ pass = zabbix
11
+ user = admin
12
+
13
+ [agent]
14
+ fqdn = agent.example.com
15
+ ip = 192.168.10.60
16
+ hostgroup = localGroup
17
+ template = Template OS Linux
18
+ ```
19
+
20
+ #### Execute Agent configuration
21
+ ```
22
+ zabconf -c /etc/zabbix/agent.ini
23
+ ```
24
+
25
+ #### Required Gems
26
+ - zabbixapi
27
+ - inifile
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'inifile'
5
+ require 'optparse'
6
+
7
+ require 'zabbix_conf'
8
+
9
+ # sync global stdout
10
+ STDOUT.sync = true
11
+
12
+ def execute(options={}, config={})
13
+ server = config[:server]
14
+ agent = config[:agent]
15
+
16
+ zabconf = ZabbixConf::Configure.new
17
+
18
+ if !agent.empty? && !server.empty?
19
+ zabconf.config_agent(options, config)
20
+ end
21
+
22
+ # if server
23
+ # zabconf.config_server(options, config)
24
+ # end
25
+
26
+ end
27
+
28
+ def validate_inifile(agent={}, server={})
29
+ errors = []
30
+
31
+ unless server.empty?
32
+ errors << 'Missing server fqdn' if server['fqdn'].nil?
33
+ errors << 'Missing server ip' if server['ip'].nil?
34
+ errors << 'Missing server password' if server['pass'].nil?
35
+ errors << 'Missing server username' if server['user'].nil?
36
+ end
37
+ unless agent.empty?
38
+ errors << 'Missing agent fqdn' if agent['fqdn'].nil?
39
+ errors << 'Missing agent ip' if agent['ip'].nil?
40
+ end
41
+
42
+ return errors, {:agent => agent, :server => server}
43
+ end
44
+
45
+
46
+ def validate_args(optparse, options)
47
+ begin
48
+ optparse.parse!
49
+ required = [:config_path]
50
+ missing = required.select{ |param| options[param].nil? }
51
+ if not missing.empty?
52
+ puts "Missing options: #{missing.join(', ')}"
53
+ puts optparse
54
+ exit
55
+ end
56
+
57
+ # Check if config exists, else throw error
58
+ raise Errno::ENOENT.new options[:config_path] unless File.exists?(options[:config_path])
59
+
60
+ # Validate ini file
61
+ ini_data = IniFile.load(options[:config_path])
62
+ errors, args = validate_inifile(ini_data['agent'],ini_data['server'])
63
+ raise "Configuration Error\n #{errors.join("\n")}" unless errors.empty?
64
+
65
+ # All is valid, return arguments
66
+ args
67
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
68
+ puts $!.to_s
69
+ puts optparse
70
+ exit
71
+ end
72
+ end
73
+
74
+
75
+ options = {}
76
+
77
+ optparse = OptionParser.new do|opts|
78
+ opts.banner = "Usage: zabconf [options] --config-path=FILE"
79
+
80
+ options[:verbose] = false
81
+ opts.on( '-v', '--verbose', 'Output more information' ) do
82
+ options[:verbose] = true
83
+ end
84
+
85
+ opts.on( '-c', '--config-path FILE', 'Path to config file' ) do |value|
86
+ options[:config_path] = value
87
+ end
88
+
89
+ opts.on( '-h', '--help', 'Display this screen' ) do
90
+ puts opts
91
+ exit
92
+ end
93
+ end
94
+
95
+ # Execute script if valid args
96
+ config = validate_args(optparse, options)
97
+ execute(options, config) if config
98
+
@@ -0,0 +1,11 @@
1
+ [server]
2
+ fqdn = server.example.com
3
+ ip = 192.168.10.50
4
+ pass = zabbix
5
+ user = admin
6
+
7
+ [agent]
8
+ fqdn = agent.example.com
9
+ ip = 192.168.10.60
10
+ hostgroup = localGroup
11
+ template = Template OS Linux
@@ -0,0 +1,5 @@
1
+ [server]
2
+ ip = 192.168.10.50
3
+ fqdn = server.example.com
4
+ pass = zabbix
5
+ user = admin
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+
3
+ require 'zabbixapi'
4
+ require 'timeout'
5
+
6
+ require "zabbix_conf/version"
7
+ require "zabbix_conf/enums"
8
+ require "zabbix_conf/configure"
9
+
10
+ module ZabbixConf
11
+ end
@@ -0,0 +1,89 @@
1
+ module ZabbixConf
2
+ class Configure
3
+ def zab_client(config={})
4
+ server = config[:server]
5
+ agent = config[:agent]
6
+ server_url = "http://#{server['ip']}/zabbix/api_jsonrpc.php"
7
+
8
+ Timeout::timeout(TIMEOUT) {
9
+ ZabbixApi.connect(
10
+ :url => server_url,
11
+ :user => server['user'],
12
+ :password => server['pass']
13
+ )
14
+ }
15
+ end
16
+
17
+ def get_template(client, config={})
18
+ server = config[:server]
19
+ agent = config[:agent]
20
+
21
+ Timeout::timeout(TIMEOUT) {
22
+ client.templates.get_id(:host => agent['template'])
23
+ }
24
+ end
25
+
26
+ def create_hostgroup(client, config={})
27
+ server = config[:server]
28
+ agent = config[:agent]
29
+
30
+ Timeout::timeout(TIMEOUT) {
31
+ client.hostgroups.get_or_create(:name => agent['hostgroup'])
32
+ }
33
+ end
34
+
35
+ def add_tempalte_to_host(client, config={})
36
+ server = config[:server]
37
+ agent = config[:agent]
38
+
39
+ template_ids = [get_template(client, config)]
40
+
41
+ Timeout::timeout(TIMEOUT) {
42
+ client.templates.mass_add(
43
+ :hosts_id => [client.hosts.get_id(:host => agent['fqdn'])],
44
+ :templates_id => template_ids
45
+ )
46
+ }
47
+ end
48
+
49
+ def create_host(client, config={})
50
+ server = config[:server]
51
+ agent = config[:agent]
52
+
53
+ hostgroup = create_hostgroup(client, config)
54
+
55
+ Timeout::timeout(TIMEOUT) {
56
+ client.hosts.create_or_update(
57
+ :host => agent['fqdn'],
58
+ :interfaces => [{
59
+ :type => TYPE_AGENT,
60
+ :main => YES,
61
+ :ip => agent['ip'],
62
+ :dns => agent['fqdn'],
63
+ :port => AGENT_PORT,
64
+ :useip => YES
65
+ }],
66
+ :groups => [:groupid => hostgroup]
67
+ )
68
+ }
69
+ end
70
+
71
+
72
+ def config_server(options={}, config={})
73
+ server = config[:server]
74
+ agent = config[:agent]
75
+
76
+ end
77
+
78
+ def config_agent(options={}, config={})
79
+ server = config[:server]
80
+ agent = config[:agent]
81
+
82
+ zbx = zab_client(config)
83
+ host = create_host(zbx, config)
84
+ add_tempalte_to_host(zbx, config)
85
+
86
+ puts 'Done configuring agent'
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,15 @@
1
+ module ZabbixConf
2
+ TIMEOUT = 10
3
+
4
+ TYPE_AGENT = 1
5
+ TYPE_SNMP = 2
6
+ TYPE_IPMI = 3
7
+ TYPE_JMX = 4
8
+
9
+ YES = 1
10
+ NO = 0
11
+
12
+ AGENT_PORT = 10050
13
+
14
+ TEMPLATE_LINUX = 10001
15
+ end
@@ -0,0 +1,3 @@
1
+ module ZabbixConf
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zabbix_conf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "zabbix_conf"
8
+ spec.version = ZabbixConf::VERSION
9
+ spec.authors = ["cevaris"]
10
+ spec.email = ["cevaris@gmail.com"]
11
+ spec.summary = %q{File based configuration for Zabbix.}
12
+ spec.description = %q{Ini configuration files are parsed to configure a Zabbix server via the zabbixapi ruby gem.}
13
+ spec.homepage = "https://github.com/cevaris/zabbix-conf/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+ spec.executables = ["zabconf"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "zabbixapi"
25
+ spec.add_development_dependency "inifile"
26
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zabbix_conf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - cevaris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2014-07-17 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ version_requirements: &id001 !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: "1.6"
21
+ prerelease: false
22
+ requirement: *id001
23
+ type: :development
24
+ - !ruby/object:Gem::Dependency
25
+ name: rake
26
+ version_requirements: &id002 !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - &id003
29
+ - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ prerelease: false
33
+ requirement: *id002
34
+ type: :development
35
+ - !ruby/object:Gem::Dependency
36
+ name: zabbixapi
37
+ version_requirements: &id004 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - *id003
40
+ prerelease: false
41
+ requirement: *id004
42
+ type: :development
43
+ - !ruby/object:Gem::Dependency
44
+ name: inifile
45
+ version_requirements: &id005 !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - *id003
48
+ prerelease: false
49
+ requirement: *id005
50
+ type: :development
51
+ description: Ini configuration files are parsed to configure a Zabbix server via the zabbixapi ruby gem.
52
+ email:
53
+ - cevaris@gmail.com
54
+ executables:
55
+ - zabconf
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - .gitignore
62
+ - Gemfile
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - bin/zabconf
67
+ - examples/agent.ini
68
+ - examples/server.ini
69
+ - lib/zabbix_conf.rb
70
+ - lib/zabbix_conf/configure.rb
71
+ - lib/zabbix_conf/enums.rb
72
+ - lib/zabbix_conf/version.rb
73
+ - zabbix_conf.gemspec
74
+ homepage: https://github.com/cevaris/zabbix-conf/
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+
79
+ post_install_message:
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - *id003
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - *id003
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.14
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: File based configuration for Zabbix.
97
+ test_files: []
98
+