zabbix_vhost 0.1.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 +7 -0
- data/.gitignore +50 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/cli +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/zabbix_agent.conf +2 -0
- data/docs/zbx_export_templates.xml +271 -0
- data/lib/zabbix_vhost/cli.rb +37 -0
- data/lib/zabbix_vhost/config.rb +124 -0
- data/lib/zabbix_vhost/version.rb +3 -0
- data/lib/zabbix_vhost.rb +6 -0
- data/zabbix_vhost.gemspec +29 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: adefef1aaf7a63743df0fa9c7c26fa868cc0d647
|
4
|
+
data.tar.gz: 0077dfc9c1e162dd70c357f753f36066cefbb1d5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c99783b8e5c7bb63a226a77971648e3b77fffbba85c0d3e6e5c62f6b7d71f6d10f5e44a6f5e02ec70669d64cacd5aaf6e61c9c4dfaf5be527eea4994d6c59bc4
|
7
|
+
data.tar.gz: 4b1e13d46e44d6f9f94ce8c98846c1803b6e5175a07f03000e4ca8cb9265528e07cba7c23eba34a7799398707c93e87d3bab39c6d7072065944d53500c41add2
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
|
10
|
+
# rspec failure tracking
|
11
|
+
.rspec_status
|
12
|
+
|
13
|
+
*.gem
|
14
|
+
*.rbc
|
15
|
+
/.config
|
16
|
+
/coverage/
|
17
|
+
/InstalledFiles
|
18
|
+
/pkg/
|
19
|
+
/spec/reports/
|
20
|
+
/spec/examples.txt
|
21
|
+
/test/tmp/
|
22
|
+
/test/version_tmp/
|
23
|
+
/tmp/
|
24
|
+
|
25
|
+
## Specific to RubyMotion:
|
26
|
+
.dat*
|
27
|
+
.repl_history
|
28
|
+
build/
|
29
|
+
|
30
|
+
## Documentation cache and generated files:
|
31
|
+
/.yardoc/
|
32
|
+
/_yardoc/
|
33
|
+
/doc/
|
34
|
+
/rdoc/
|
35
|
+
|
36
|
+
## Environment normalisation:
|
37
|
+
/vendor/bundle
|
38
|
+
/lib/bundler/man/
|
39
|
+
|
40
|
+
# for a library or gem, you might want to ignore these files since the code is
|
41
|
+
# intended to run in multiple environments; otherwise, check them in:
|
42
|
+
# Gemfile.lock
|
43
|
+
# .ruby-version
|
44
|
+
# .ruby-gemset
|
45
|
+
|
46
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
47
|
+
.rvmrc
|
48
|
+
|
49
|
+
|
50
|
+
test_apache_configs
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
zabbix_vhost (0.1.0)
|
5
|
+
thor
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
rake (10.5.0)
|
12
|
+
rspec (3.7.0)
|
13
|
+
rspec-core (~> 3.7.0)
|
14
|
+
rspec-expectations (~> 3.7.0)
|
15
|
+
rspec-mocks (~> 3.7.0)
|
16
|
+
rspec-core (3.7.1)
|
17
|
+
rspec-support (~> 3.7.0)
|
18
|
+
rspec-expectations (3.7.0)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.7.0)
|
21
|
+
rspec-mocks (3.7.0)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.7.0)
|
24
|
+
rspec-support (3.7.1)
|
25
|
+
thor (0.20.0)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.16)
|
32
|
+
rake (~> 10.0)
|
33
|
+
rspec (~> 3.0)
|
34
|
+
zabbix_vhost!
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Marino Bonetti
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# ZabbixVhost
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zabbix_vhost`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'zabbix_vhost'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install zabbix_vhost
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Copiare nella cartella di zabbix agent il file di configurazione per il parametro di autodiscovery,
|
26
|
+
configurando la chiamata allo script per l'autodiscovery dei domini e per le chiamate alla richiesta
|
27
|
+
informazioni di dominio
|
28
|
+
|
29
|
+
Importare il template di zabbix
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
TODO: Write usage instructions here
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zabbix_vhost.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/cli
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "zabbix_vhost"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,271 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<zabbix_export>
|
3
|
+
<version>3.2</version>
|
4
|
+
<date>2018-05-30T14:01:10Z</date>
|
5
|
+
<groups>
|
6
|
+
<group>
|
7
|
+
<name>01 - Web site</name>
|
8
|
+
</group>
|
9
|
+
<group>
|
10
|
+
<name>Discovered hosts</name>
|
11
|
+
</group>
|
12
|
+
<group>
|
13
|
+
<name>Linux servers</name>
|
14
|
+
</group>
|
15
|
+
</groups>
|
16
|
+
<templates>
|
17
|
+
<template>
|
18
|
+
<template>Template App VHosts</template>
|
19
|
+
<name>Template App VHosts</name>
|
20
|
+
<description>Autodiscover hosts on server</description>
|
21
|
+
<groups>
|
22
|
+
<group>
|
23
|
+
<name>01 - Web site</name>
|
24
|
+
</group>
|
25
|
+
<group>
|
26
|
+
<name>Discovered hosts</name>
|
27
|
+
</group>
|
28
|
+
<group>
|
29
|
+
<name>Linux servers</name>
|
30
|
+
</group>
|
31
|
+
</groups>
|
32
|
+
<applications>
|
33
|
+
<application>
|
34
|
+
<name>HostingCondiviso</name>
|
35
|
+
</application>
|
36
|
+
</applications>
|
37
|
+
<items/>
|
38
|
+
<discovery_rules>
|
39
|
+
<discovery_rule>
|
40
|
+
<name>Vhosts</name>
|
41
|
+
<type>0</type>
|
42
|
+
<snmp_community/>
|
43
|
+
<snmp_oid/>
|
44
|
+
<key>vhosts.domains_autodiscovery</key>
|
45
|
+
<delay>3600</delay>
|
46
|
+
<status>0</status>
|
47
|
+
<allowed_hosts/>
|
48
|
+
<snmpv3_contextname/>
|
49
|
+
<snmpv3_securityname/>
|
50
|
+
<snmpv3_securitylevel>0</snmpv3_securitylevel>
|
51
|
+
<snmpv3_authprotocol>0</snmpv3_authprotocol>
|
52
|
+
<snmpv3_authpassphrase/>
|
53
|
+
<snmpv3_privprotocol>0</snmpv3_privprotocol>
|
54
|
+
<snmpv3_privpassphrase/>
|
55
|
+
<delay_flex/>
|
56
|
+
<params/>
|
57
|
+
<ipmi_sensor/>
|
58
|
+
<authtype>0</authtype>
|
59
|
+
<username/>
|
60
|
+
<password/>
|
61
|
+
<publickey/>
|
62
|
+
<privatekey/>
|
63
|
+
<port/>
|
64
|
+
<filter>
|
65
|
+
<evaltype>0</evaltype>
|
66
|
+
<formula/>
|
67
|
+
<conditions/>
|
68
|
+
</filter>
|
69
|
+
<lifetime>30</lifetime>
|
70
|
+
<description/>
|
71
|
+
<item_prototypes>
|
72
|
+
<item_prototype>
|
73
|
+
<name>Alias {#DOMAIN}</name>
|
74
|
+
<type>0</type>
|
75
|
+
<snmp_community/>
|
76
|
+
<multiplier>0</multiplier>
|
77
|
+
<snmp_oid/>
|
78
|
+
<key>vhosts.domain_data[{#DOMAIN},server_alias]</key>
|
79
|
+
<delay>3600</delay>
|
80
|
+
<history>10</history>
|
81
|
+
<trends>0</trends>
|
82
|
+
<status>1</status>
|
83
|
+
<value_type>4</value_type>
|
84
|
+
<allowed_hosts/>
|
85
|
+
<units/>
|
86
|
+
<delta>0</delta>
|
87
|
+
<snmpv3_contextname/>
|
88
|
+
<snmpv3_securityname/>
|
89
|
+
<snmpv3_securitylevel>0</snmpv3_securitylevel>
|
90
|
+
<snmpv3_authprotocol>0</snmpv3_authprotocol>
|
91
|
+
<snmpv3_authpassphrase/>
|
92
|
+
<snmpv3_privprotocol>0</snmpv3_privprotocol>
|
93
|
+
<snmpv3_privpassphrase/>
|
94
|
+
<formula>1</formula>
|
95
|
+
<delay_flex/>
|
96
|
+
<params/>
|
97
|
+
<ipmi_sensor/>
|
98
|
+
<data_type>0</data_type>
|
99
|
+
<authtype>0</authtype>
|
100
|
+
<username/>
|
101
|
+
<password/>
|
102
|
+
<publickey/>
|
103
|
+
<privatekey/>
|
104
|
+
<port/>
|
105
|
+
<description/>
|
106
|
+
<inventory_link>0</inventory_link>
|
107
|
+
<applications>
|
108
|
+
<application>
|
109
|
+
<name>HostingCondiviso</name>
|
110
|
+
</application>
|
111
|
+
</applications>
|
112
|
+
<valuemap/>
|
113
|
+
<logtimefmt/>
|
114
|
+
<application_prototypes/>
|
115
|
+
</item_prototype>
|
116
|
+
<item_prototype>
|
117
|
+
<name>SSL active {#DOMAIN}</name>
|
118
|
+
<type>0</type>
|
119
|
+
<snmp_community/>
|
120
|
+
<multiplier>0</multiplier>
|
121
|
+
<snmp_oid/>
|
122
|
+
<key>vhosts.domain_data[{#DOMAIN},ssl_active]</key>
|
123
|
+
<delay>3600</delay>
|
124
|
+
<history>10</history>
|
125
|
+
<trends>365</trends>
|
126
|
+
<status>0</status>
|
127
|
+
<value_type>3</value_type>
|
128
|
+
<allowed_hosts/>
|
129
|
+
<units/>
|
130
|
+
<delta>0</delta>
|
131
|
+
<snmpv3_contextname/>
|
132
|
+
<snmpv3_securityname/>
|
133
|
+
<snmpv3_securitylevel>0</snmpv3_securitylevel>
|
134
|
+
<snmpv3_authprotocol>0</snmpv3_authprotocol>
|
135
|
+
<snmpv3_authpassphrase/>
|
136
|
+
<snmpv3_privprotocol>0</snmpv3_privprotocol>
|
137
|
+
<snmpv3_privpassphrase/>
|
138
|
+
<formula>1</formula>
|
139
|
+
<delay_flex/>
|
140
|
+
<params/>
|
141
|
+
<ipmi_sensor/>
|
142
|
+
<data_type>3</data_type>
|
143
|
+
<authtype>0</authtype>
|
144
|
+
<username/>
|
145
|
+
<password/>
|
146
|
+
<publickey/>
|
147
|
+
<privatekey/>
|
148
|
+
<port/>
|
149
|
+
<description/>
|
150
|
+
<inventory_link>0</inventory_link>
|
151
|
+
<applications>
|
152
|
+
<application>
|
153
|
+
<name>HostingCondiviso</name>
|
154
|
+
</application>
|
155
|
+
</applications>
|
156
|
+
<valuemap>
|
157
|
+
<name>YES|NO</name>
|
158
|
+
</valuemap>
|
159
|
+
<logtimefmt/>
|
160
|
+
<application_prototypes/>
|
161
|
+
</item_prototype>
|
162
|
+
<item_prototype>
|
163
|
+
<name>Days valid SSL {#DOMAIN}</name>
|
164
|
+
<type>0</type>
|
165
|
+
<snmp_community/>
|
166
|
+
<multiplier>0</multiplier>
|
167
|
+
<snmp_oid/>
|
168
|
+
<key>vhosts.domain_data[{#DOMAIN},ssl_until_days]</key>
|
169
|
+
<delay>3600</delay>
|
170
|
+
<history>10</history>
|
171
|
+
<trends>365</trends>
|
172
|
+
<status>0</status>
|
173
|
+
<value_type>3</value_type>
|
174
|
+
<allowed_hosts/>
|
175
|
+
<units>days</units>
|
176
|
+
<delta>0</delta>
|
177
|
+
<snmpv3_contextname/>
|
178
|
+
<snmpv3_securityname/>
|
179
|
+
<snmpv3_securitylevel>0</snmpv3_securitylevel>
|
180
|
+
<snmpv3_authprotocol>0</snmpv3_authprotocol>
|
181
|
+
<snmpv3_authpassphrase/>
|
182
|
+
<snmpv3_privprotocol>0</snmpv3_privprotocol>
|
183
|
+
<snmpv3_privpassphrase/>
|
184
|
+
<formula>1</formula>
|
185
|
+
<delay_flex/>
|
186
|
+
<params/>
|
187
|
+
<ipmi_sensor/>
|
188
|
+
<data_type>0</data_type>
|
189
|
+
<authtype>0</authtype>
|
190
|
+
<username/>
|
191
|
+
<password/>
|
192
|
+
<publickey/>
|
193
|
+
<privatekey/>
|
194
|
+
<port/>
|
195
|
+
<description>numero di giorni di validità del certificato</description>
|
196
|
+
<inventory_link>0</inventory_link>
|
197
|
+
<applications>
|
198
|
+
<application>
|
199
|
+
<name>HostingCondiviso</name>
|
200
|
+
</application>
|
201
|
+
</applications>
|
202
|
+
<valuemap/>
|
203
|
+
<logtimefmt/>
|
204
|
+
<application_prototypes/>
|
205
|
+
</item_prototype>
|
206
|
+
</item_prototypes>
|
207
|
+
<trigger_prototypes>
|
208
|
+
<trigger_prototype>
|
209
|
+
<expression>{Template App VHosts:vhosts.domain_data[{#DOMAIN},ssl_until_days].last()}<2 and {Template App VHosts:vhosts.domain_data[{#DOMAIN},ssl_active].last()}=1</expression>
|
210
|
+
<recovery_mode>0</recovery_mode>
|
211
|
+
<recovery_expression/>
|
212
|
+
<name>Certificato {#DOMAIN} SSL scade domani</name>
|
213
|
+
<correlation_mode>0</correlation_mode>
|
214
|
+
<correlation_tag/>
|
215
|
+
<url/>
|
216
|
+
<status>0</status>
|
217
|
+
<priority>4</priority>
|
218
|
+
<description>Attivo nel momento che il certificato scade il giorno sucessivo</description>
|
219
|
+
<type>0</type>
|
220
|
+
<manual_close>0</manual_close>
|
221
|
+
<dependencies/>
|
222
|
+
<tags/>
|
223
|
+
</trigger_prototype>
|
224
|
+
<trigger_prototype>
|
225
|
+
<expression>{Template App VHosts:vhosts.domain_data[{#DOMAIN},ssl_active].last()}=1 and {Template App VHosts:vhosts.domain_data[{#DOMAIN},ssl_until_days].last()}<30</expression>
|
226
|
+
<recovery_mode>0</recovery_mode>
|
227
|
+
<recovery_expression/>
|
228
|
+
<name>Certificato {#DOMAIN} SSL scade in 30 giorni</name>
|
229
|
+
<correlation_mode>0</correlation_mode>
|
230
|
+
<correlation_tag/>
|
231
|
+
<url/>
|
232
|
+
<status>0</status>
|
233
|
+
<priority>2</priority>
|
234
|
+
<description>Attivo nel momento che il certificato scade entro 30 giorni</description>
|
235
|
+
<type>0</type>
|
236
|
+
<manual_close>0</manual_close>
|
237
|
+
<dependencies/>
|
238
|
+
<tags/>
|
239
|
+
</trigger_prototype>
|
240
|
+
</trigger_prototypes>
|
241
|
+
<graph_prototypes/>
|
242
|
+
<host_prototypes/>
|
243
|
+
</discovery_rule>
|
244
|
+
</discovery_rules>
|
245
|
+
<httptests/>
|
246
|
+
<macros>
|
247
|
+
<macro>
|
248
|
+
<macro>{$DOMAIN}</macro>
|
249
|
+
<value>Dominio</value>
|
250
|
+
</macro>
|
251
|
+
</macros>
|
252
|
+
<templates/>
|
253
|
+
<screens/>
|
254
|
+
</template>
|
255
|
+
</templates>
|
256
|
+
<value_maps>
|
257
|
+
<value_map>
|
258
|
+
<name>YES|NO</name>
|
259
|
+
<mappings>
|
260
|
+
<mapping>
|
261
|
+
<value>0</value>
|
262
|
+
<newvalue>NO</newvalue>
|
263
|
+
</mapping>
|
264
|
+
<mapping>
|
265
|
+
<value>1</value>
|
266
|
+
<newvalue>YES</newvalue>
|
267
|
+
</mapping>
|
268
|
+
</mappings>
|
269
|
+
</value_map>
|
270
|
+
</value_maps>
|
271
|
+
</zabbix_export>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'json'
|
3
|
+
require_relative './config'
|
4
|
+
module ZabbixVhost
|
5
|
+
class CLI < Thor
|
6
|
+
|
7
|
+
|
8
|
+
desc "autodiscover PATH", "Autodiscover Vhost in absolute path"
|
9
|
+
def autodiscover(path)
|
10
|
+
|
11
|
+
|
12
|
+
configurations = ZabbixVhost::Config.dir_reader(path)
|
13
|
+
|
14
|
+
|
15
|
+
data = configurations.collect do |c|
|
16
|
+
{
|
17
|
+
"{#DOMAIN}" => c.server_name
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
print JSON.generate({data: data})
|
22
|
+
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
desc "get_domain_data PATH DOMAIN FUNCTION", "Get a information from the Vhost configuration find in the PATH"
|
28
|
+
|
29
|
+
def get_domain_data(path,domain,function)
|
30
|
+
|
31
|
+
c = ZabbixVhost::Config.find_in_dir(path, domain)
|
32
|
+
|
33
|
+
print c.send(function)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module ZabbixVhost
|
2
|
+
class Config
|
3
|
+
|
4
|
+
attr_accessor :file_path
|
5
|
+
|
6
|
+
attr_reader :server_alias, :server_name
|
7
|
+
|
8
|
+
def initialize(f)
|
9
|
+
|
10
|
+
@file_path = f
|
11
|
+
@server_alias = []
|
12
|
+
@server_name = nil
|
13
|
+
@ssl_active = nil
|
14
|
+
parse
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse
|
19
|
+
@config_content = File.read(@file_path)
|
20
|
+
## Controlliamo se siamo in apache
|
21
|
+
if_apache do
|
22
|
+
@server_name = @config_content.match(/ServerName (?<server_name>.*)/)[:server_name]
|
23
|
+
|
24
|
+
if @config_content.match(/ServerAlias/)
|
25
|
+
@server_alias = @config_content.match(/ServerAlias (?<names>.*)/)[:names].split(" ")
|
26
|
+
end
|
27
|
+
|
28
|
+
@ssl_active = !@config_content.match(/443/).nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
if @ssl_active
|
32
|
+
@ssl_data = read_ssl_data
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def self.dir_reader(path)
|
38
|
+
configuration_files = Dir.glob("#{path}/*")
|
39
|
+
|
40
|
+
configurations = []
|
41
|
+
|
42
|
+
configuration_files.each do |f|
|
43
|
+
|
44
|
+
if File.file?(f)
|
45
|
+
cfg = self.new(f)
|
46
|
+
configurations << cfg
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
configurations
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Cerca il dominio all'interno della cartella
|
56
|
+
def self.find_in_dir(path, domain)
|
57
|
+
dir_reader(path).select {|c| c.server_name == domain}.first
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def if_apache
|
62
|
+
if @config_content.match(/ServerName/)
|
63
|
+
yield
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def ssl_active
|
68
|
+
@ssl_active ? 1 : 0
|
69
|
+
end
|
70
|
+
|
71
|
+
def ssl_until_days
|
72
|
+
return nil unless @ssl_data
|
73
|
+
@ssl_data[:days_until]
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def read_ssl_data
|
80
|
+
|
81
|
+
if @ssl_active
|
82
|
+
begin
|
83
|
+
require "socket"
|
84
|
+
require "openssl"
|
85
|
+
|
86
|
+
host = @server_name
|
87
|
+
|
88
|
+
# Il codice commentato si occupa di verificare veramente il certificato. non ci interessa in questo momento
|
89
|
+
# ssl_context = OpenSSL::SSL::SSLContext.new
|
90
|
+
# ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
91
|
+
#
|
92
|
+
# cert_store = OpenSSL::X509::Store.new
|
93
|
+
# cert_store.set_default_paths
|
94
|
+
# ssl_context.cert_store = cert_store
|
95
|
+
|
96
|
+
tcp_client = TCPSocket.new(host, 443)
|
97
|
+
# ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_client, ssl_context)
|
98
|
+
ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_client)
|
99
|
+
|
100
|
+
|
101
|
+
ssl_client.hostname = host
|
102
|
+
ssl_client.connect
|
103
|
+
cert = OpenSSL::X509::Certificate.new(ssl_client.peer_cert)
|
104
|
+
ssl_client.sysclose
|
105
|
+
tcp_client.close
|
106
|
+
|
107
|
+
certprops = OpenSSL::X509::Name.new(cert.issuer).to_a
|
108
|
+
issuer = certprops.select {|name, data, type| name == "O"}.first[1]
|
109
|
+
{
|
110
|
+
valid_on: cert.not_before,
|
111
|
+
valid_until: cert.not_after,
|
112
|
+
days_until: (cert.not_after - Time.now).to_i / 86400,
|
113
|
+
issuer: issuer
|
114
|
+
# valid: (ssl_client.verify_result == 0)
|
115
|
+
}
|
116
|
+
rescue Exception => e
|
117
|
+
puts "PROBLEMI ELABORAZIONE #{@server_name} SSL #{e.message} - "
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
data/lib/zabbix_vhost.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "zabbix_vhost/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zabbix_vhost"
|
8
|
+
spec.version = ZabbixVhost::VERSION
|
9
|
+
spec.authors = ["Marino Bonetti"]
|
10
|
+
spec.email = ["marinobonetti@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Virtual Hosts - Autodiscovery - Zabbix}
|
13
|
+
spec.description = %q{Gem to parse information about VHost and make possible of autodiscovery with zabbix and collect information about virtual hosts}
|
14
|
+
spec.homepage = "https://github.com/ArchimediaZerogroup/zabbix_vhost"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "thor"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zabbix_vhost
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marino Bonetti
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Gem to parse information about VHost and make possible of autodiscovery
|
70
|
+
with zabbix and collect information about virtual hosts
|
71
|
+
email:
|
72
|
+
- marinobonetti@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/cli
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- docs/zabbix_agent.conf
|
89
|
+
- docs/zbx_export_templates.xml
|
90
|
+
- lib/zabbix_vhost.rb
|
91
|
+
- lib/zabbix_vhost/cli.rb
|
92
|
+
- lib/zabbix_vhost/config.rb
|
93
|
+
- lib/zabbix_vhost/version.rb
|
94
|
+
- zabbix_vhost.gemspec
|
95
|
+
homepage: https://github.com/ArchimediaZerogroup/zabbix_vhost
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.5.2
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Virtual Hosts - Autodiscovery - Zabbix
|
119
|
+
test_files: []
|