icinga-powershell-plugins icon indicating copy to clipboard operation
icinga-powershell-plugins copied to clipboard

Feature/Enhancement: Invoke-IcingaCheckDirectory - add possibility to check for pattern in file

Open stevie-sy opened this issue 2 years ago • 3 comments

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.

stevie-sy avatar Mar 30 '22 08:03 stevie-sy

PR https://github.com/Icinga/icinga-powershell-plugins/pull/292

stevie-sy avatar Mar 30 '22 09:03 stevie-sy

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.

stevie-sy avatar Aug 17 '22 16:08 stevie-sy

ref/NC/761567

tbauriedel avatar Sep 09 '22 09:09 tbauriedel