Hey there!
I have an InSpec control, which is executed against remote hosts. What I want to achieve is to check the modification time of all the files in a specific location. Works fine on localhost. However, when running against a remote system, the log file arrays are evaluated locally, which means InSpec looks into the directories on the localhost, fills the arrays and then tries to access all the files on the remote hosts. Some of them exist, but most of them don't so I get a bunch of errors. Is this intended? And how can I achieve that the arrays are filled with actual values on the remote host?
I already tried to put the first to lines into the control, directly before the forEach loop, did not help.
Any ideas? Help would be much appreciated!
nginx_log_files = Dir["/var/log/nginx/."]
mysql_log_files = Dir["/var/log/mysql/."]
control:
control 'testcase-19-os' do
impact 1.0
title 'Log files'
desc 'Check whether log file modification time is <30 days'
nginx_log_files.each do |path|
describe file(path) do
its('mtime') { should >= Time.now.to_i - 30246060 }
end
end
mysql_log_files.each do |path|
describe file(path) do
its('mtime') { should >= Time.now.to_i - 30246060 }
end
end
end
output:
× testcase-19-os: Log files (13 failed)
× File /var/log/nginx/error.log.1 mtime should >= 1546180951
undefined method >=' for nil:NilClass × File /var/log/nginx/access.log mtime should >= 1546180951 undefined method
>=' for nil:NilClass
× File /var/log/nginx/error.log mtime should >= 1546180951
undefined method >=' for nil:NilClass × File /var/log/nginx/access.log.2.gz mtime should >= 1546180951 undefined method
>=' for nil:NilClass
× File /var/log/nginx/access.log.1 mtime should >= 1546180951
undefined method >=' for nil:NilClass ✔ File /var/log/mysql/error.log.5.gz mtime should >= 1546180951 × File /var/log/mysql/mysql.log.1.gz mtime should >= 1546180952 undefined method
>=' for nil:NilClass
File /var/log/mysql/error.log.1.gz mtime should >= 1546180952
× File /var/log/mysql/mysql.log mtime should >= 1546180952
undefined method >=' for nil:NilClass × File /var/log/mysql/mysql-slow.log.2.gz mtime should >= 1546180952 undefined method
>=' for nil:NilClass
× File /var/log/mysql/mysql-slow.log.3.gz mtime should >= 1546180952
undefined method >=' for nil:NilClass × File /var/log/mysql/mysql.log.2.gz mtime should >= 1546180952 undefined method
>=' for nil:NilClass
× File /var/log/mysql/mysql.log.3.gz mtime should >= 1546180952
undefined method >=' for nil:NilClass ✔ File /var/log/mysql/error.log.2.gz mtime should >= 1546180952 ✔ File /var/log/mysql/error.log.3.gz mtime should >= 1546180953 × File /var/log/mysql/mysql-slow.log.1.gz mtime should >= 1546180953 undefined method
>=' for nil:NilClass
File /var/log/mysql/error.log.7.gz mtime should >= 1546180953
File /var/log/mysql/error.log mtime should >= 1546180953
× File /var/log/mysql/mysql-slow.log mtime should >= 1546180953
undefined method `>=' for nil:NilClass
File /var/log/mysql/error.log.4.gz mtime should >= 1546180953