Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stevie-sy opened this issue Mar 30, 2022 · 3 comments

Comments

@stevie-sy
Copy link

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
Copy link
Author

PR #292

@stevie-sy
Copy link
Author

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.

@tbauriedel
Copy link
Member

ref/NC/761567

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants