Skip to content

Commit 4facac6

Browse files
committed
test(inspec): add tests for packages, config files & services
1 parent f0f1563 commit 4facac6

File tree

3 files changed

+174
-0
lines changed

3 files changed

+174
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# frozen_string_literal: true
2+
3+
control 'zabbix agent configuration' do
4+
title 'should match desired lines'
5+
6+
describe file('/etc/zabbix/zabbix_agentd.conf') do
7+
it { should be_file }
8+
it { should be_owned_by 'root' }
9+
it { should be_grouped_into 'root' }
10+
its('mode') { should cmp '0644' }
11+
its('content') { should include 'Server=localhost' }
12+
its('content') { should include 'ListenPort=10050' }
13+
its('content') { should include 'ListenIP=0.0.0.0' }
14+
its('content') { should include 'ServerActive=localhost' }
15+
its('content') do
16+
should include(
17+
'HostMetadata=c9767034-22c6-4d3d-a886-5fcaf1386b77'
18+
)
19+
end
20+
its('content') { should include 'Include=/etc/zabbix/zabbix_agentd.d/' }
21+
its('content') do
22+
should include(
23+
'UserParameter=net.ping[*],/usr/bin/fping -q -c3 $1 2>&1 | '\
24+
'sed \'s,.*/\([0-9.]*\)/.*,\1,\''
25+
)
26+
end
27+
its('content') do
28+
should include(
29+
'UserParameter=custom.vfs.dev.discovery,/usr/local/bin/dev-discovery.sh'
30+
)
31+
end
32+
end
33+
end
34+
35+
control 'zabbix server configuration' do
36+
title 'should match desired lines'
37+
38+
server_file_group = 'zabbix'
39+
server_file_mode = '0640'
40+
setting_dbsocket = '/var/lib/mysql/mysql.sock'
41+
case platform[:family]
42+
when 'debian'
43+
server_file_group = 'root'
44+
server_file_mode = '0644'
45+
setting_dbsocket = '/var/run/mysqld/mysqld.sock'
46+
when 'fedora'
47+
server_file_group = 'zabbixsrv'
48+
end
49+
50+
# TODO: Conditional content to consider for inclusion below
51+
# 'ExternalScripts=/usr/lib/zabbix/externalscripts' (fedora only)
52+
# 'FpingLocation=/usr/sbin/fping' (not debian)
53+
# 'Fping6Location=/usr/sbin/fping6' (not debian)
54+
55+
# Note: The file below is a symlink to `/etc/zabbix_server.conf` on Fedora
56+
describe file('/etc/zabbix/zabbix_server.conf') do
57+
it { should be_file }
58+
it { should be_owned_by 'root' }
59+
it { should be_grouped_into server_file_group }
60+
its('mode') { should cmp server_file_mode }
61+
its('content') { should include 'ListenPort=10051' }
62+
its('content') { should include '# Mandatory: no' }
63+
its('content') { should include 'DBHost=localhost' }
64+
its('content') { should include '# Database user. Ignored for SQLite.' }
65+
its('content') { should include 'DBUser=zabbixuser' }
66+
its('content') { should include 'DBPassword=zabbixpass' }
67+
its('content') { should include setting_dbsocket }
68+
its('content') { should include 'ListenIP=0.0.0.0' }
69+
end
70+
end
71+
72+
control 'zabbix web configuration' do
73+
title 'should match desired lines'
74+
75+
describe file('/etc/zabbix/web/zabbix.conf.php') do
76+
it { should be_file }
77+
it { should be_owned_by 'root' }
78+
it { should be_grouped_into 'root' }
79+
its('mode') { should cmp '0644' }
80+
its('content') { should include 'global $DB;' }
81+
its('content') { should match(/\$DB\["TYPE"\].*=.*\'MYSQL\';/) }
82+
its('content') { should match(/\$DB\["SERVER"\].*=.*\'localhost';/) }
83+
its('content') { should match(/\$DB\["PORT"\].*=.*\'0\';/) }
84+
its('content') { should match(/\$DB\["DATABASE"\].*=.*\'zabbix\';/) }
85+
its('content') { should match(/\$DB\["USER"\].*=.*\'zabbixuser\';/) }
86+
its('content') { should match(/\$DB\["PASSWORD"\].*=.*\'zabbixpass\';/) }
87+
its('content') { should match(/\$DB\["SCHEMA"\].*=.*\'\';/) }
88+
its('content') { should match(/\$ZBX_SERVER.*=.*\'localhost\';/) }
89+
its('content') { should match(/\$ZBX_SERVER_PORT.*=.*\'10051\';/) }
90+
its('content') do
91+
should match(/\$ZBX_SERVER_NAME.*=.*\'Zabbix installed with saltstack\';/)
92+
end
93+
its('content') { should match(/\$IMAGE_FORMAT_DEFAULT.*=.*IMAGE_FORMAT_PNG;/) }
94+
end
95+
end
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# frozen_string_literal: true
2+
3+
pkg_agent = 'zabbix-agent'
4+
pkg_server = 'zabbix-server-mysql'
5+
pkg_web =
6+
case platform[:family]
7+
when 'debian'
8+
'zabbix-frontend-php'
9+
else
10+
'zabbix-web-mysql'
11+
end
12+
version =
13+
case platform[:name]
14+
when 'debian'
15+
if os[:release].start_with?('10')
16+
'1:4.4.0-1+buster'
17+
elsif os[:release].start_with?('9')
18+
'1:4.4.0-1+stretch'
19+
elsif os[:release].start_with?('8')
20+
'1:4.4.0-1+jessie'
21+
end
22+
when 'ubuntu'
23+
if os[:release].start_with?('18')
24+
'1:4.4.0-1+bionic'
25+
elsif os[:release].start_with?('16')
26+
'1:4.4.0-1+xenial'
27+
end
28+
when 'centos'
29+
if os[:release].start_with?('8')
30+
'4.4.0-1.el8'
31+
elsif os[:release].start_with?('7')
32+
'4.4.0-1.el7'
33+
elsif os[:release].start_with?('6')
34+
'4.4.0-1.el6'
35+
end
36+
when 'fedora'
37+
if os[:release].start_with?('30')
38+
'4.0.11-1.fc30'
39+
elsif os[:release].start_with?('29')
40+
'3.0.28-1.fc29'
41+
end
42+
end
43+
44+
control 'zabbix packages' do
45+
title 'should be installed'
46+
47+
[
48+
pkg_agent,
49+
pkg_server,
50+
pkg_web
51+
].each do |p|
52+
describe package(p) do
53+
it { should be_installed }
54+
its('version') { should eq version }
55+
end
56+
end
57+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
control 'zabbix service' do
4+
impact 0.5
5+
title 'should be running and enabled'
6+
7+
# Note: Checking the service for `zabbix-server` is not working yet on Fedora
8+
services =
9+
case platform[:name]
10+
when 'fedora'
11+
%w[zabbix-agent]
12+
else
13+
%w[zabbix-agent zabbix-server]
14+
end
15+
16+
services.each do |s|
17+
describe service(s) do
18+
it { should be_enabled }
19+
it { should be_running }
20+
end
21+
end
22+
end

0 commit comments

Comments
 (0)