2019-10-29 04:01:38 -04:00
|
|
|
Import-IcingaLib provider\directory;
|
2019-10-28 11:10:27 -04:00
|
|
|
|
|
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Checks how many files are in a directory.
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
Invoke-IcingaCheckDirectory returns either 'OK', 'WARNING' or 'CRITICAL', based on the thresholds set.
|
|
|
|
|
e.g 'C:\Users\Icinga\Backup' contains 200 files, WARNING is set to 150, CRITICAL is set to 300. In this case the check will return CRITICAL
|
|
|
|
|
More Information on https://github.com/LordHepipud/icinga-module-windows
|
|
|
|
|
.FUNCTIONALITY
|
|
|
|
|
This module is intended to be used to check how many files and directories are within are specified path.
|
|
|
|
|
Based on the thresholds set the status will change between 'OK', 'WARNING' or 'CRITICAL'. The function will return one of these given codes.
|
|
|
|
|
.EXAMPLE
|
2019-10-29 04:01:38 -04:00
|
|
|
PS>Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -Warning 20 -Critical 30 -Verbose 3
|
2019-10-28 11:10:27 -04:00
|
|
|
[OK]: Check package "C:\Users\Icinga\Downloads" is [OK] (Match All)
|
|
|
|
|
\_ [OK]: C:\Users\Icinga\Downloads is 19
|
|
|
|
|
.EXAMPLE
|
2019-10-29 04:01:38 -04:00
|
|
|
PS>Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -Warning 20 -Critical 30 -Verbose 3
|
2019-10-28 11:10:27 -04:00
|
|
|
[WARNING]: Check package "C:\Users\Icinga\Downloads" is [WARNING] (Match All)
|
|
|
|
|
\_ [WARNING]: C:\Users\Icinga\Downloads is 24
|
|
|
|
|
.EXAMPLE
|
2019-10-29 04:01:38 -04:00
|
|
|
PS>Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -Warning 20 -Critical 30 -Verbose 3 -YoungerThen 20d -OlderThen 10d
|
2019-10-28 11:10:27 -04:00
|
|
|
[OK]: Check package "C:\Users\Icinga\Downloads" is [OK] (Match All)
|
|
|
|
|
\_ [OK]: C:\Users\Icinga\Downloads is 1
|
|
|
|
|
.EXAMPLE
|
2019-10-29 04:01:38 -04:00
|
|
|
PS>Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -FileNames "*.txt","*.sql" -Warning 20 -Critical 30 -Verbose 3
|
2019-10-28 11:10:27 -04:00
|
|
|
[OK]: Check package "C:\Users\Icinga\Downloads" is [OK] (Match All)
|
|
|
|
|
\_ [OK]: C:\Users\Icinga\Downloads is 4
|
2019-10-29 04:01:38 -04:00
|
|
|
.PARAMETER Warning
|
2019-10-28 11:10:27 -04:00
|
|
|
Used to specify a Warning threshold. In this case an integer value.
|
2019-10-29 04:01:38 -04:00
|
|
|
.PARAMETER Critical
|
2019-10-28 11:10:27 -04:00
|
|
|
Used to specify a Critical threshold. In this case an integer value.
|
|
|
|
|
.PARAMETER Path
|
|
|
|
|
Used to specify a path.
|
|
|
|
|
e.g. 'C:\Users\Icinga\Downloads'
|
|
|
|
|
.PARAMETER FileNames
|
|
|
|
|
Used to specify an array of filenames or expressions to match against.
|
|
|
|
|
|
2019-10-29 04:01:38 -04:00
|
|
|
e.g '*.txt', '*.sql' # Fiends all files ending with .txt and .sql
|
2019-10-28 11:10:27 -04:00
|
|
|
.PARAMETER Recurse
|
|
|
|
|
A switch, which can be set to filter through directories recursively.
|
|
|
|
|
.PARAMETER YoungerThen
|
2019-10-29 04:01:38 -04:00
|
|
|
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 younger then 20 days are considered within the check
|
2019-10-28 11:10:27 -04:00
|
|
|
.PARAMETER OlderThen
|
2019-10-29 04:01:38 -04:00
|
|
|
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 older then 20 days are considered within the check
|
2019-10-28 11:10:27 -04:00
|
|
|
.INPUTS
|
|
|
|
|
System.String
|
|
|
|
|
.OUTPUTS
|
|
|
|
|
System.String
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/LordHepipud/icinga-module-windows
|
|
|
|
|
.NOTES
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
function Invoke-IcingaCheckDirectory()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[string]$Path,
|
|
|
|
|
[array]$FileNames,
|
|
|
|
|
[switch]$Recurse,
|
2019-10-29 04:01:38 -04:00
|
|
|
[int]$Critical,
|
|
|
|
|
[int]$Warning,
|
2019-10-28 11:10:27 -04:00
|
|
|
[string]$YoungerThen,
|
|
|
|
|
[string]$OlderThen,
|
|
|
|
|
[int]$Verbose
|
|
|
|
|
);
|
|
|
|
|
|
2019-10-29 04:01:38 -04:00
|
|
|
$DirectoryData = Get-IcingaDirectoryAll -Path $Path -FileNames $FileNames `
|
|
|
|
|
-Recurse $Recurse -YoungerThen $YoungerThen -OlderThen $OlderThen;
|
|
|
|
|
$DirectoryCheck = New-IcingaCheck -Name $Path -Value $DirectoryData.Count -NoPerfData;
|
2019-10-28 11:10:27 -04:00
|
|
|
|
|
|
|
|
$DirectoryCheck.WarnOutOfRange(
|
2019-10-29 04:01:38 -04:00
|
|
|
($Warning)
|
2019-10-28 11:10:27 -04:00
|
|
|
).CritOutOfRange(
|
2019-10-29 04:01:38 -04:00
|
|
|
($Critical)
|
2019-10-28 11:10:27 -04:00
|
|
|
) | Out-Null;
|
|
|
|
|
|
|
|
|
|
$DirectoryPackage = New-IcingaCheckPackage -Name $Path -OperatorAnd -Checks $DirectoryCheck -Verbose $Verbose;
|
|
|
|
|
|
|
|
|
|
return (New-IcingaCheckresult -Check $DirectoryPackage -NoPerfData $TRUE -Compile);
|
|
|
|
|
}
|