Skip to content
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
4 changes: 4 additions & 0 deletions doc/31-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic

[Issue and PRs](https://github.com/Icinga/icinga-powershell-plugins/milestone/22)

### Enhancements

* [#450](https://github.com/Icinga/icinga-powershell-plugins/pull/450) Adds support for access time to `Invoke-IcingaCheckDirectory`

## 1.13.1 (2025-05-08)

### Breaking Changes
Expand Down
76 changes: 39 additions & 37 deletions doc/plugins/05-Invoke-IcingaCheckDirectory.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

Checks for amount of files within a directory depending on the set filters

Invoke-IcingaCheckDirectory will check within a specific directory for files matching the set filter criteria.
It allows to filter for files with a specific size, modification date, name or file ending.
By using the Warning or Critical threshold you can then set on when the check will be set to 'WARNING' or 'CRITICAL'.

Based on the provided filters, the plugin will return the amount of files found matching those filters.
Invoke-IcingaCheckDirectory will check within a specific directory for files matching the set filter criteria.
It allows to filter for files with a specific size, modification date, name or file ending.
By using the Warning or Critical threshold you can then set on when the check will be set to 'WARNING' or 'CRITICAL'.
Based on the provided filters, the plugin will return the amount of files found matching those filters.
More Information on https://github.com/Icinga/icinga-powershell-plugins

## Permissions
Expand Down Expand Up @@ -40,7 +40,9 @@ No special permissions required.
| CreationTimeEqual | String | false | | String that expects input format like "20d", which translates to 20 days. Allowed units: ms, s, m, h, d, w, M, y.<br /> <br /> Thereby all files which have been created 20 days ago are considered within the check. |
| CreationOlderThan | String | false | | String that expects input format like "20d", which translates to 20 days. Allowed units: ms, s, m, h, d, w, M, y.<br /> <br /> Thereby all files which have a creation date older then 20 days are considered within the check. |
| 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.<br /> <br /> 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.<br /> <br /> Thereby all files with a size of 20 MB or larger are considered within the check. |
| AccessYoungerThan | String | false | String that expects input format like "20d", which translates to 20 days. Allowed units: ms, s, m, h, d, w, M, y.<br /> <br /> Thereby all files which have a access date younger then 20 days
| 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.<br /> <br /> Thereby all files with a size of 20 MB or larger are are considered within the check. |
| AccessOlderThan | String | false | | String that expects input format like "20d", which translates to 20 days. Allowed units: ms, s, m, h, d, w, M, y.<br /> <br /> Thereby all files which have a access date older then 20 days 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.<br /> <br /> Thereby all files with a size of 5 MB or less are considered within the check. |
| Verbosity | Int32 | false | 0 | Changes the behavior of the plugin output which check states are printed:<br /> 0 (default): Only service checks/packages with state not OK will be printed<br /> 1: Only services with not OK will be printed including OK checks of affected check packages including Package config<br /> 2: Everything will be printed regardless of the check state<br /> 3: Identical to Verbose 2, but prints in addition the check package configuration e.g (All must be [OK]) |
| NoPerfData | SwitchParameter | false | False | |
Expand All @@ -57,13 +59,13 @@ Invoke-IcingaCheckDirectory -Path 'C:\Users\Icinga\Downloads' -Warning 20 -Criti
### Example Output 1

```powershell
[CRITICAL] Directory Check: "C:\Users\Icinga\Downloads": 1 Critical 5 Ok [CRITICAL] File Count (33) (All must be [OK])
\_ [OK] Average File Size: 76.94MiB
\_ [CRITICAL] File Count: 33 is greater than threshold 30
\_ [OK] Folder Count: 1
\_ [OK] Largest File Size: 1.07GiB
\_ [OK] Smallest File Size: 0B
\_ [OK] Total Size: 2.48GiB
[CRITICAL] Directory Check: "C:\Users\Icinga\Downloads": 1 Critical 5 Ok [CRITICAL] File Count (33) (All must be [OK])
\_ [OK] Average File Size: 76.94MiB
\_ [CRITICAL] File Count: 33 is greater than threshold 30
\_ [OK] Folder Count: 1
\_ [OK] Largest File Size: 1.07GiB
\_ [OK] Smallest File Size: 0B
\_ [OK] Total Size: 2.48GiB
| 'average_file_size'=80677000B;; 'folder_count'=1;; 'total_size'=2662341000B;; 'largest_file_size'=1149023000B;; 'file_count'=33;20;30 'smallest_file_size'=0B;;
```

Expand All @@ -76,13 +78,13 @@ Invoke-IcingaCheckDirectory -Path 'C:\Users\Icinga\Downloads' -Warning 20 -Criti
### Example Output 2

```powershell
[WARNING] Directory Check: "C:\Users\Icinga\Downloads": 1 Warning 5 Ok [WARNING] File Count (22) (All must be [OK])
\_ [OK] Average File Size: 738.29KiB
\_ [WARNING] File Count: 22 is greater than threshold 20
\_ [OK] Folder Count: 0
\_ [OK] Largest File Size: 4.23MiB
\_ [OK] Smallest File Size: 0B
\_ [OK] Total Size: 15.86MiB
[WARNING] Directory Check: "C:\Users\Icinga\Downloads": 1 Warning 5 Ok [WARNING] File Count (22) (All must be [OK])
\_ [OK] Average File Size: 738.29KiB
\_ [WARNING] File Count: 22 is greater than threshold 20
\_ [OK] Folder Count: 0
\_ [OK] Largest File Size: 4.23MiB
\_ [OK] Smallest File Size: 0B
\_ [OK] Total Size: 15.86MiB
| 'average_file_size'=756008B;; 'folder_count'=0;; 'total_size'=16632180B;; 'largest_file_size'=4439043B;; 'file_count'=22;20;30 'smallest_file_size'=0B;;
```

Expand All @@ -95,13 +97,13 @@ Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -Warning 20 -Criti
### Example Output 3

```powershell
[OK] Directory Check: "C:\Users\Icinga\Downloads": 6 Ok (All must be [OK])
\_ [OK] Average File Size: 359.40MiB
\_ [OK] File Count: 7
\_ [OK] Folder Count: 1
\_ [OK] Largest File Size: 1.07GiB
\_ [OK] Smallest File Size: 0B
\_ [OK] Total Size: 2.46GiB
[OK] Directory Check: "C:\Users\Icinga\Downloads": 6 Ok (All must be [OK])
\_ [OK] Average File Size: 359.40MiB
\_ [OK] File Count: 7
\_ [OK] Folder Count: 1
\_ [OK] Largest File Size: 1.07GiB
\_ [OK] Smallest File Size: 0B
\_ [OK] Total Size: 2.46GiB
| 'average_file_size'=376853700B;; 'folder_count'=1;; 'total_size'=2637976000B;; 'largest_file_size'=1149023000B;; 'file_count'=7;20;30 'smallest_file_size'=0B;;
```

Expand All @@ -114,13 +116,13 @@ Invoke-IcingaCheckDirectory -Path 'C:\Users\Icinga\Downloads' -Warning 20 -Criti
### Example Output 4

```powershell
[OK] Directory Check: "C:\Users\Icinga\Downloads": 6 Ok (All must be [OK])
\_ [OK] Average File Size: 210.57MiB
\_ [OK] File Count: 12
\_ [OK] Folder Count: 0
\_ [OK] Largest File Size: 1.07GiB
\_ [OK] Smallest File Size: 0B
\_ [OK] Total Size: 2.47GiB
[OK] Directory Check: "C:\Users\Icinga\Downloads": 6 Ok (All must be [OK])
\_ [OK] Average File Size: 210.57MiB
\_ [OK] File Count: 12
\_ [OK] Folder Count: 0
\_ [OK] Largest File Size: 1.07GiB
\_ [OK] Smallest File Size: 0B
\_ [OK] Total Size: 2.47GiB
| 'average_file_size'=220801200B;; 'folder_count'=0;; 'total_size'=2649615000B;; 'largest_file_size'=1149023000B;; 'file_count'=12;20;30 'smallest_file_size'=0B;;
```

Expand All @@ -133,9 +135,9 @@ Invoke-IcingaCheckDirectory -Path 'C:\Users\Icinga\Downloads' -Warning 20 -Criti
### Example Output 5

```powershell
[CRITICAL] Directory Check: "C:\Users\Icinga\Downloads": 1 Critical 1 Warning 4 Ok [CRITICAL] File Count (33) [WARNING] Total Size (2.48GiB)
\_ [CRITICAL] File Count: 33 is greater than threshold 30
\_ [WARNING] Total Size: 2.48GiB is greater than threshold 2.00GiB
[CRITICAL] Directory Check: "C:\Users\Icinga\Downloads": 1 Critical 1 Warning 4 Ok [CRITICAL] File Count (33) [WARNING] Total Size (2.48GiB)
\_ [CRITICAL] File Count: 33 is greater than threshold 30
\_ [WARNING] Total Size: 2.48GiB is greater than threshold 2.00GiB
| 'average_file_size'=80677000B;; 'folder_count'=1;; 'total_size'=2662341000B;2147484000; 'largest_file_size'=1149023000B;; 'file_count'=33;20;30 'smallest_file_size'=0B;;
```

Expand Down
11 changes: 11 additions & 0 deletions plugins/Invoke-IcingaCheckDirectory.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@
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 older then 20 days are considered within the check.
.PARAMETER AccessYoungerThan
String in the format like "20d" (allowed units: ms, s, m, h, d, w, M, y).

Only considers files/folders whose last access time is newer than the given period.
.PARAMETER AccessOlderThan
String in the format like "20d" (allowed units: ms, s, m, h, d, w, M, y).

Only considers files/folders whose last access time is older than the given period.
.PARAMETER ChangeTimeEqual
String that expects input format like "20d", which translates to 20 days. Allowed units: ms, s, m, h, d, w, M, y.

Expand Down Expand Up @@ -187,6 +195,8 @@ function Invoke-IcingaCheckDirectory()
[string]$CreationTimeEqual,
[string]$CreationOlderThan,
[string]$CreationYoungerThan,
[string]$AccessYoungerThan,
[string]$AccessOlderThan,
[string]$FileSizeGreaterThan,
[string]$FileSizeSmallerThan,
[ValidateSet(0, 1, 2, 3)]
Expand All @@ -198,6 +208,7 @@ function Invoke-IcingaCheckDirectory()
-ChangeYoungerThan $ChangeYoungerThan -ChangeOlderThan $ChangeOlderThan `
-CreationYoungerThan $CreationYoungerThan -CreationOlderThan $CreationOlderThan `
-CreationTimeEqual $CreationTimeEqual -ChangeTimeEqual $ChangeTimeEqual `
-AccessYoungerThan $AccessYoungerThan -AccessOlderThan $AccessOlderThan `
-FileSizeGreaterThan $FileSizeGreaterThan -FileSizeSmallerThan $FileSizeSmallerThan;

$DirectoryCheck = New-IcingaCheckPackage -Name ([string]::Format('Directory Check: "{0}"', $Path)) -OperatorAnd -Verbose $Verbosity -AddSummaryHeader;
Expand Down
34 changes: 34 additions & 0 deletions provider/directory/Icinga_Provider_Directory.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function Get-IcingaDirectoryAll()
[string]$CreationTimeEqual,
[string]$CreationOlderThan,
[string]$CreationYoungerThan,
[string]$AccessYoungerThan,
[string]$AccessOlderThan,
[string]$FileSizeGreaterThan,
[string]$FileSizeSmallerThan
);
Expand Down Expand Up @@ -60,6 +62,12 @@ function Get-IcingaDirectoryAll()
$DirectoryData = Get-IcingaDirectoryCreationYoungerThan -CreationYoungerThan $CreationYoungerThan -DirectoryData $DirectoryData;
}
}
if ([string]::IsNullOrEmpty($AccessOlderThan) -eq $FALSE) {
$DirectoryData = Get-IcingaDirectoryAccessOlderThan -AccessOlderThan $AccessOlderThan -DirectoryData $DirectoryData;
}
if ([string]::IsNullOrEmpty($AccessYoungerThan) -eq $FALSE) {
$DirectoryData = Get-IcingaDirectoryAccessYoungerThan -AccessYoungerThan $AccessYoungerThan -DirectoryData $DirectoryData;
}
if ([string]::IsNullOrEmpty($FileSizeGreaterThan) -eq $FALSE) {
$DirectoryData = (Get-IcingaDirectorySizeGreaterThan -FileSizeGreaterThan $FileSizeGreaterThan -DirectoryData $DirectoryData);
}
Expand Down Expand Up @@ -241,6 +249,32 @@ function Get-IcingaDirectoryCreationYoungerThan()
return $DirectoryData;
}


function Get-IcingaDirectoryAccessOlderThan()
{
param (
[string]$AccessOlderThan,
$DirectoryData
)
$AccessOlderThan = Set-NumericNegative (ConvertTo-Seconds $AccessOlderThan);
$DirectoryData = ($DirectoryData | Where-Object {$_.LastAccessTime -lt (Get-Date).AddSeconds($AccessOlderThan)})

return $DirectoryData;
}


function Get-IcingaDirectoryAccessYoungerThan()
{
param (
[string]$AccessYoungerThan,
$DirectoryData
)
$AccessYoungerThan = Set-NumericNegative (ConvertTo-Seconds $AccessYoungerThan);
$DirectoryData = ($DirectoryData | Where-Object {$_.LastAccessTime -gt (Get-Date).AddSeconds($AccessYoungerThan)})

return $DirectoryData;
}

function Get-IcingaDirectoryCreationOlderThan()
{
param (
Expand Down