zinv 0.1.4 → 0.2.0
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.
- checksums.yaml +5 -5
- data/CHANGELOG +0 -0
- data/exe/zinv.rb +31 -43
- data/lib/zinv/version.rb +1 -1
- data/zinv.gemspec +5 -5
- metadata +27 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 163b830fb516b396c3728b88f1e331a005a14baed783df3dcd2381714746b4ac
|
4
|
+
data.tar.gz: af33e4686ed1feaf9a283a17f11b50064dbd8df6806488bf076723217142b8e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16af76981bea37da7d01baa2cfa6407242f1acb43e6cb5cd5d7cee47042828569ae3d7e4d9486e451d52a7d8db280d687d52a572e9e776f1bfd9e81d58ee2eb7
|
7
|
+
data.tar.gz: f4cd51c4369503021fb887640a1a83643c17f24f265fead6e33fa7e4311260af509f6afa341bf6f53ebf3ca994184b94cc802638e7467fd557dc66302f6a0f09
|
data/CHANGELOG
ADDED
File without changes
|
data/exe/zinv.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require '
|
2
|
+
require 'zabbix/api'
|
3
3
|
require 'json'
|
4
|
-
require '
|
5
|
-
require '
|
4
|
+
require 'optimist'
|
5
|
+
require 'amazing_print'
|
6
6
|
require 'set'
|
7
7
|
require 'yaml'
|
8
8
|
|
@@ -11,10 +11,9 @@ require 'yaml'
|
|
11
11
|
# ansible-playbook to have hosts not yet in zabbix listed in inventory
|
12
12
|
runtimehostvar = 'ZINV_ADD_HOSTS'
|
13
13
|
|
14
|
-
opts =
|
14
|
+
opts = Optimist::options do
|
15
15
|
opt :list, "List entire inventory" # required by ansible
|
16
16
|
opt :host, "List a single host", :type => :string # required by ansible
|
17
|
-
opt :debug, "Debugging verbosity"
|
18
17
|
opt :groups, "Dump groups list"
|
19
18
|
opt :templates, "Dump templates list"
|
20
19
|
end
|
@@ -62,23 +61,18 @@ if opts[:host]
|
|
62
61
|
end
|
63
62
|
|
64
63
|
# Connect to zabbix.
|
65
|
-
zbx =
|
66
|
-
|
67
|
-
|
68
|
-
:
|
69
|
-
:
|
64
|
+
zbx = Zabbix::Api::Client.new(url: ENV['ZINV_ZABBIX_URL'])
|
65
|
+
|
66
|
+
zbx.login(
|
67
|
+
user: ENV['ZINV_ZABBIX_USER'],
|
68
|
+
pass: ENV['ZINV_ZABBIX_PASS'],
|
70
69
|
)
|
71
70
|
|
72
71
|
|
73
72
|
# Get all the root template objects
|
74
|
-
roottemplates = zbx.
|
75
|
-
:
|
76
|
-
|
77
|
-
:filter => {
|
78
|
-
:host => roottemplatenames
|
79
|
-
}
|
80
|
-
}
|
81
|
-
)
|
73
|
+
roottemplates = zbx.template.get(
|
74
|
+
filter: { host: roottemplatenames }
|
75
|
+
).collect
|
82
76
|
|
83
77
|
|
84
78
|
ansibletemplates = roottemplates # This list is used by host gathering logic later on
|
@@ -87,7 +81,7 @@ prevchunk = roottemplates # this is for the "walking the tree" logic
|
|
87
81
|
|
88
82
|
# Set up template groups for the root templates
|
89
83
|
prevchunk.each {|template|
|
90
|
-
name = template
|
84
|
+
name = template.name.gsub(/[ ]/,'_')
|
91
85
|
if not ansibletemplategroups.has_key?(name)
|
92
86
|
ansibletemplategroups[name] = {'hosts' => Set.new}
|
93
87
|
end
|
@@ -96,11 +90,8 @@ prevchunk.each {|template|
|
|
96
90
|
# Find all templates that derive from the root ones, adding to ansibletemplates
|
97
91
|
# and ansibletemplategroups as we go
|
98
92
|
begin
|
99
|
-
nextchunk = zbx.
|
100
|
-
:
|
101
|
-
:params => {
|
102
|
-
:parentTemplateids => prevchunk.collect {|each| each['templateid']}
|
103
|
-
}
|
93
|
+
nextchunk = zbx.template.get(
|
94
|
+
parentTemplateids: prevchunk.collect {|each| each['templateid']}
|
104
95
|
)
|
105
96
|
nextchunk.each {|template|
|
106
97
|
name = template['name'].gsub(/[ ]/,'_')
|
@@ -127,21 +118,17 @@ ansiblehostgroups['New_Hosts'] = {'hosts' => newhostnamelist}
|
|
127
118
|
metadata = Hash.new
|
128
119
|
|
129
120
|
|
121
|
+
|
130
122
|
# Gather all the hosts that use the templates we've collected. We'll put them in
|
131
123
|
# two types of hashes: host group hashes and template group hashes.
|
132
|
-
zbx.
|
124
|
+
zbx.hostgroup.get().each { |hostgroup|
|
133
125
|
hostlist = Array.new
|
134
126
|
# Gather hosts using our templates, ensuring we also grab inventory for this host
|
135
|
-
hosts = zbx.
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
:selectParentTemplates => [
|
141
|
-
'name'
|
142
|
-
],
|
143
|
-
:selectInventory => 'extend'
|
144
|
-
}
|
127
|
+
hosts = zbx.host.get(
|
128
|
+
groupids: [hostgroup.groupid],
|
129
|
+
templateids: ansibletemplates.collect {|each| each['templateid']},
|
130
|
+
selectParentTemplates: [ 'name' ],
|
131
|
+
selectInventory: 'extend'
|
145
132
|
)
|
146
133
|
|
147
134
|
# For each host we've collected, add it to each group it belongs in (both host and template),
|
@@ -150,12 +137,12 @@ zbx.hostgroups.all.each { |name,id|
|
|
150
137
|
hosts.each { |host|
|
151
138
|
# You can put the string DONOTMANAGE anywhere in the zabbix host description
|
152
139
|
# If you do that the node in question will be excluded from inventory
|
153
|
-
if host
|
154
|
-
hostlist.push(host
|
155
|
-
host
|
140
|
+
if host.description !~ /DONOTMANAGE/
|
141
|
+
hostlist.push(host.host)
|
142
|
+
host.parentTemplates.each { |template|
|
156
143
|
templatename = template['name'].gsub(/[ ]/,'_')
|
157
144
|
if ansibletemplategroups.has_key?(templatename)
|
158
|
-
ansibletemplategroups[templatename]['hosts'].add(host
|
145
|
+
ansibletemplategroups[templatename]['hosts'].add(host.name)
|
159
146
|
end
|
160
147
|
}
|
161
148
|
# If you need to define host variables, in the zabbix host definition select "Inventory" and put yaml in the Notes field.
|
@@ -165,11 +152,11 @@ zbx.hostgroups.all.each { |name,id|
|
|
165
152
|
# ereiamjh: The ghost in the machine
|
166
153
|
# youshouldwatch: Brazil
|
167
154
|
#
|
168
|
-
if host.
|
155
|
+
if host.respond_to?(:inventory) and host.inventory.class == Hash and host.inventory.has_key?('notes') and host.inventory['notes'].size > 0
|
169
156
|
begin
|
170
|
-
metadata[host
|
157
|
+
metadata[host.name] = YAML.load(host.inventory['notes'])
|
171
158
|
rescue Exception => e
|
172
|
-
puts "Error parsing inventory notes field for host #{host
|
159
|
+
puts "Error parsing inventory notes field for host #{host.name} - SKIPPING"
|
173
160
|
ap e
|
174
161
|
end
|
175
162
|
end
|
@@ -178,11 +165,12 @@ zbx.hostgroups.all.each { |name,id|
|
|
178
165
|
}
|
179
166
|
|
180
167
|
if hostlist.size > 0
|
181
|
-
ansiblehostgroups[name.gsub(/[ ]/,'_')] = {'hosts'=>hostlist}
|
168
|
+
ansiblehostgroups[hostgroup.name.gsub(/[ ]/,'_')] = {'hosts'=>hostlist}
|
182
169
|
ansiblehostgroups['All_Hosts']['hosts'].merge(hostlist) # probably don't need this
|
183
170
|
end
|
184
171
|
}
|
185
172
|
|
173
|
+
|
186
174
|
# These are just for more informative dumps...
|
187
175
|
hostgroupcount = ansiblehostgroups.keys.size
|
188
176
|
if opts[:groups]
|
data/lib/zinv/version.rb
CHANGED
data/zinv.gemspec
CHANGED
@@ -26,9 +26,9 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
|
-
spec.add_development_dependency "bundler"
|
30
|
-
spec.add_development_dependency "rake"
|
31
|
-
spec.add_runtime_dependency "
|
32
|
-
spec.add_runtime_dependency "
|
33
|
-
spec.add_runtime_dependency "
|
29
|
+
spec.add_development_dependency "bundler"
|
30
|
+
spec.add_development_dependency "rake"
|
31
|
+
spec.add_runtime_dependency "zabbix-api-simple"
|
32
|
+
spec.add_runtime_dependency "optimist"
|
33
|
+
spec.add_runtime_dependency "amazing_print"
|
34
34
|
end
|
metadata
CHANGED
@@ -1,85 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zinv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Parker
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: zabbix-api-simple
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: optimist
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: amazing_print
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
description:
|
84
84
|
email:
|
85
85
|
- david.parker _AT_ nsight.com
|
@@ -88,6 +88,7 @@ executables:
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
+
- CHANGELOG
|
91
92
|
- CODE_OF_CONDUCT.md
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE
|
@@ -120,8 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
121
|
- !ruby/object:Gem::Version
|
121
122
|
version: '0'
|
122
123
|
requirements: []
|
123
|
-
|
124
|
-
rubygems_version: 2.6.11
|
124
|
+
rubygems_version: 3.1.6
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: Ansible dynamic inventory script for hosts monitored by zabbix
|