|
| 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 |
0 commit comments