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

Support for searching pattern in file #292

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/plugins/05-Invoke-IcingaCheckDirectory.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ No special permissions required.
| CreationYoungerThan | String | false | | String that expects input format like "20d", which translates to 20 days. Allowed units: ms, s, m, h, d, w, M, y. Thereby all files which have a creation date younger then 20 days are considered within the check. |
| FileSizeGreaterThan | String | false | | String that expects input format like "20MB", which translates to the filze size 20 MB. Allowed units: B, KB, MB, GB, TB. Thereby all files with a size of 20 MB or larger are considered within the check. |
| FileSizeSmallerThan | String | false | | String that expects input format like "5MB", which translates to the filze size 5 MB. Allowed units: B, KB, MB, GB, TB. Thereby all files with a size of 5 MB or less are considered within the check. |
| FileSizeContainPattern | String | false | | String pattern which a file should contain |
| Verbosity | Int32 | false | 0 | Changes the behavior of the plugin output which check states are printed: 0 (default): Only service checks/packages with state not OK will be printed 1: Only services with not OK will be printed including OK checks of affected check packages including Package config 2: Everything will be printed regardless of the check state 3: Identical to Verbose 2, but prints in addition the check package configuration e.g (All must be [OK]) |
| NoPerfData | SwitchParameter | false | False | |
| ThresholdInterval | String | | | Change the value your defined threshold checks against from the current value to a collected time threshold of the Icinga for Windows daemon, as described [here](https://icinga.com/docs/icinga-for-windows/latest/doc/service/10-Register-Service-Checks/). An example for this argument would be 1m or 15m which will use the average of 1m or 15m for monitoring. |
Expand Down
5 changes: 4 additions & 1 deletion plugins/Invoke-IcingaCheckDirectory.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@
String that expects input format like "5MB", which translates to the filze size 5 MB. Allowed units: B, KB, MB, GB, TB.

Thereby all files with a size of 5 MB or less are considered within the check.
.PARAMETER FileContainPattern
String Pattern which a file should contain
.PARAMETER Verbosity
Changes the behavior of the plugin output which check states are printed:
0 (default): Only service checks/packages with state not OK will be printed
Expand Down Expand Up @@ -189,6 +191,7 @@ function Invoke-IcingaCheckDirectory()
[string]$CreationYoungerThan,
[string]$FileSizeGreaterThan,
[string]$FileSizeSmallerThan,
[string]$FileContainPattern,
[ValidateSet(0, 1, 2, 3)]
[int]$Verbosity = 0,
[switch]$NoPerfData = $FALSE
Expand All @@ -198,7 +201,7 @@ function Invoke-IcingaCheckDirectory()
-ChangeYoungerThan $ChangeYoungerThan -ChangeOlderThan $ChangeOlderThan `
-CreationYoungerThan $CreationYoungerThan -CreationOlderThan $CreationOlderThan `
-CreationTimeEqual $CreationTimeEqual -ChangeTimeEqual $ChangeTimeEqual `
-FileSizeGreaterThan $FileSizeGreaterThan -FileSizeSmallerThan $FileSizeSmallerThan;
-FileSizeGreaterThan $FileSizeGreaterThan -FileSizeSmallerThan $FileSizeSmallerThan -FileContainPattern $FileContainPattern;

$DirectoryCheck = New-IcingaCheckPackage -Name ([string]::Format('Directory Check: "{0}"', $Path)) -OperatorAnd -Verbose $Verbosity -AddSummaryHeader;

Expand Down
18 changes: 17 additions & 1 deletion provider/directory/Icinga_Provider_Directory.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function Get-IcingaDirectoryAll()
[string]$CreationOlderThan,
[string]$CreationYoungerThan,
[string]$FileSizeGreaterThan,
[string]$FileSizeSmallerThan
[string]$FileSizeSmallerThan,
[string]$FileContainPattern,
);

if ([string]::IsNullOrEmpty($Path)) {
Expand Down Expand Up @@ -66,6 +67,9 @@ function Get-IcingaDirectoryAll()
if ([string]::IsNullOrEmpty($FileSizeSmallerThan) -eq $FALSE) {
$DirectoryData = (Get-IcingaDirectorySizeSmallerThan -FileSizeSmallerThan $FileSizeSmallerThan -DirectoryData $DirectoryData);
}
if ([string]::IsNullOrEmpty($FileContainPattern) -eq $FALSE) {
$DirectoryData = (Get-IcingaDirectoryContainPattern -ContainPattern $FileContainPattern -DirectoryData $DirectoryData);
}

foreach ($entry in $DirectoryData) {
if ((Get-Item $entry.FullName) -Is [System.IO.DirectoryInfo]) {
Expand Down Expand Up @@ -263,3 +267,15 @@ function Get-IcingaDirectoryCreationTimeEqual()

return $DirectoryData;
}

function Get-IcingaDirectoryContainPattern
{
param (
[string]$ContainPattern,
$DirectoryData
)

$DirectoryData = ($DirectoryData | Where-Object {Select-String -Pattern $ContainPattern -Path $_.Fullname})

return $DirectoryData;
}