icinga-powershell-plugins
icinga-powershell-plugins copied to clipboard
Feature/Enhancement: Invoke-IcingaCheckDirectory - add possibility to check for pattern in file
Sometimes it's not enough only for check for file size, creation/modify date etc. from files in a directory. Therefore it is sometimes necessary to additionally search for a file content (pattern). It would be great to have such a possibility with an additional parameter.
Because I forked the check already for us with such a new param, I will create a PR with this change.
PR https://github.com/Icinga/icinga-powershell-plugins/pull/292
For some reasons signing the CLA is at the moment not possible. So I post a possible solution/idea here:
First it would need a new provider function to check the file content. e.g.
function Get-IcingaDirectoryContainPattern
{
param (
[string]$ContainPattern,
$DirectoryData
)
$DirectoryData = ($DirectoryData | Where-Object {Select-String -Pattern $ContainPattern -Path $_.Fullname})
return $DirectoryData;
}
After, the function Get-IcingaDirectoryAll()
needs a new parameter like
[string]$FileContainPattern
and then in the code must be added something like this to filter again the the file list
if ([string]::IsNullOrEmpty($FileContainPattern) -eq $FALSE) {
$DirectoryData = (Get-IcingaDirectoryContainPattern -ContainPattern $FileContainPattern -DirectoryData $DirectoryData);
}
At least the Code from Invoke-IcingaCheckDirectory
must be expand also with a parameter and pass this to the function call Get-IcingaDirectoryAll
.
That's just a suggestion. Maybe you have a better idea.
ref/NC/761567