mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Merge branch 'snapshot' of https://github.com/LordHepipud/icinga-module-windows into snapshot
This commit is contained in:
commit
8ff8a58733
3 changed files with 210 additions and 46 deletions
|
|
@ -19,7 +19,7 @@ Import-IcingaLib provider\directory;
|
|||
[WARNING]: Check package "C:\Users\Icinga\Downloads" is [WARNING] (Match All)
|
||||
\_ [WARNING]: C:\Users\Icinga\Downloads is 24
|
||||
.EXAMPLE
|
||||
PS>Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -Warning 20 -Critical 30 -Verbosity 3 -YoungerThen 20d -OlderThen 10d
|
||||
PS>Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -Warning 20 -Critical 30 -Verbosity 3 -ChangeYoungerThen 20d -ChangeOlderThen 10d
|
||||
[OK]: Check package "C:\Users\Icinga\Downloads" is [OK] (Match All)
|
||||
\_ [OK]: C:\Users\Icinga\Downloads is 1
|
||||
.EXAMPLE
|
||||
|
|
@ -39,14 +39,34 @@ Import-IcingaLib provider\directory;
|
|||
e.g '*.txt', '*.sql' # Fiends all files ending with .txt and .sql
|
||||
.PARAMETER Recurse
|
||||
A switch, which can be set to filter through directories recursively.
|
||||
.PARAMETER YoungerThen
|
||||
.PARAMETER ChangeYoungerThen
|
||||
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
|
||||
.PARAMETER OlderThen
|
||||
Thereby all files which have a change date younger then 20 days are considered within the check.
|
||||
.PARAMETER ChangeOlderThen
|
||||
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
|
||||
Thereby all files which have a change date older then 20 days are considered within the check.
|
||||
.PARAMETER CreationYoungerThen
|
||||
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.
|
||||
.PARAMETER CreationOlderThen
|
||||
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 ChangeTimeEqual
|
||||
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 been changed 20 days ago are considered within the check.
|
||||
|
||||
.PARAMETER CreationTimeEqual
|
||||
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 been created 20 days ago are considered within the check.
|
||||
|
||||
|
||||
.INPUTS
|
||||
System.String
|
||||
.OUTPUTS
|
||||
|
|
@ -64,8 +84,12 @@ function Invoke-IcingaCheckDirectory()
|
|||
[switch]$Recurse,
|
||||
$Critical = $null,
|
||||
$Warning = $null,
|
||||
[string]$YoungerThan,
|
||||
[string]$OlderThan,
|
||||
[string]$ChangeTimeEqual,
|
||||
[string]$ChangeYoungerThan,
|
||||
[string]$ChangeOlderThan,
|
||||
[string]$CreationTimeEqual,
|
||||
[string]$CreationOlderThan,
|
||||
[string]$CreationYoungerThan,
|
||||
[string]$FileSizeGreaterThan,
|
||||
[string]$FileSizeSmallerThan,
|
||||
[ValidateSet(0, 1, 2, 3)]
|
||||
|
|
@ -73,9 +97,10 @@ function Invoke-IcingaCheckDirectory()
|
|||
[switch]$NoPerfData
|
||||
);
|
||||
|
||||
$DirectoryData = Get-IcingaDirectoryAll -Path $Path -FileNames $FileNames `
|
||||
-Recurse $Recurse -YoungerThan $YoungerThan -OlderThan $OlderThan `
|
||||
-FileSizeGreaterThan $FileSizeGreaterThan -FileSizeSmallerThan $FileSizeSmallerThan;
|
||||
$DirectoryData = Get-IcingaDirectoryAll -Path $Path -FileNames $FileNames -Recurse $Recurse `
|
||||
-ChangeYoungerThan $ChangeYoungerThan -ChangeOlderThan $ChangeOlderThan `
|
||||
-CreationYoungerThan $CreationYoungerThan -CreationOlderThan $CreationOlderThan `
|
||||
-CreationTimeEqual $CreationTimeEqual -ChangeTimeEqual $ChangeTimeEqual;
|
||||
$DirectoryCheck = New-IcingaCheck -Name 'File Count' -Value $DirectoryData.Count;
|
||||
|
||||
$DirectoryCheck.WarnOutOfRange(
|
||||
|
|
|
|||
|
|
@ -37,12 +37,14 @@ function Invoke-IcingaCheckService()
|
|||
[ValidateSet('Stopped', 'StartPending', 'StopPending', 'Running', 'ContinuePending', 'PausePending', 'Paused')]
|
||||
[string]$Status = 'Running',
|
||||
[ValidateSet(0, 1, 2, 3)]
|
||||
[int]$Verbosity = 0
|
||||
[int]$Verbosity = 0,
|
||||
[switch]$NoPerfData
|
||||
);
|
||||
|
||||
$ServicesPackage = New-IcingaCheckPackage -Name 'Services' -OperatorAnd -Verbose $Verbosity;
|
||||
$ServicesPackage = New-IcingaCheckPackage -Name 'Services' -OperatorAnd -Verbose $Verbosity;
|
||||
$ServicesCountPackage = New-IcingaCheckPackage -Name 'Count Services' -OperatorAnd -Verbose $Verbosity -Hidden;
|
||||
|
||||
if ($Service.Count -ne 1) {
|
||||
[int]$StoppedCount,[int]$StartPendingCount,[int]$StopPendingCount,[int]$RunningCount,[int]$ContinuePendingCount,[int]$PausePendingCount,[int]$PausedCount,[int]$ServicesCounted = 0
|
||||
foreach ($services in $Service) {
|
||||
$IcingaCheck = $null;
|
||||
|
||||
|
|
@ -50,22 +52,41 @@ function Invoke-IcingaCheckService()
|
|||
$ServiceName = Get-IcingaServiceCheckName -ServiceInput $services -Service $FoundService;
|
||||
$ConvertedStatus = ConvertTo-ServiceStatusCode -Status $Status;
|
||||
$StatusRaw = $FoundService.Values.configuration.Status.raw;
|
||||
|
||||
|
||||
$IcingaCheck = New-IcingaCheck -Name $ServiceName -Value $StatusRaw -ObjectExists $FoundService -Translation $ProviderEnums.ServiceStatusName;
|
||||
$IcingaCheck.CritIfNotMatch($ConvertedStatus) | Out-Null;
|
||||
$ServicesPackage.AddCheck($IcingaCheck)
|
||||
|
||||
switch($StatusRaw) {
|
||||
{1 -contains $_} { $StoppedCount++; $ServicesCounted++}
|
||||
{2 -contains $_} { $StartPendingCount++; $ServicesCounted++}
|
||||
{3 -contains $_} { $StopPendingCount++; $ServicesCounted++}
|
||||
{4 -contains $_} { $RunningCount++; $ServicesCounted++}
|
||||
{5 -contains $_} { $ContinuePendingCount++; $ServicesCounted++}
|
||||
{6 -contains $_} { $PausePendingCount++; $ServicesCounted++}
|
||||
{7 -contains $_} { $PausedCount++; $ServicesCounted++}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$IcingaStopped = New-IcingaCheck -Name 'stopped services' -Value $StoppedCount;
|
||||
$IcingaStartPending = New-IcingaCheck -Name 'pending started services' -Value $StartPendingCount;
|
||||
$IcingaStopPending = New-IcingaCheck -Name 'pending stopped services' -Value $StopPendingCount;
|
||||
$IcingaRunning = New-IcingaCheck -Name 'running services' -Value $RunningCount;
|
||||
$IcingaContinuePending = New-IcingaCheck -Name 'pending continued services' -Value $ContinuePendingCount;
|
||||
$IcingaPausePending = New-IcingaCheck -Name 'pending paused services' -Value $PausePendingCount;
|
||||
$IcingaPaused = New-IcingaCheck -Name 'paused services' -Value $PausePendingCount;
|
||||
|
||||
$IcingaCount = New-IcingaCheck -Name 'service count' -Value $ServicesCounted;
|
||||
|
||||
$FoundService = Get-IcingaServices -Service $Service;
|
||||
$ServiceName = Get-IcingaServiceCheckName -ServiceInput $Service -Service $FoundService;
|
||||
$IntStatus = ConvertTo-ServiceStatusCode -Status $Status;
|
||||
$StatusRaw = $FoundService.Values.configuration.Status.raw;
|
||||
$ServicesCountPackage.AddCheck($IcingaStopped)
|
||||
$ServicesCountPackage.AddCheck($IcingaStartPending)
|
||||
$ServicesCountPackage.AddCheck($IcingaStopPending)
|
||||
$ServicesCountPackage.AddCheck($IcingaRunning)
|
||||
$ServicesCountPackage.AddCheck($IcingaContinuePending)
|
||||
$ServicesCountPackage.AddCheck($IcingaPausePending)
|
||||
$ServicesCountPackage.AddCheck($IcingaPaused)
|
||||
|
||||
$IcingaCheck = New-IcingaCheck -Name $ServiceName -Value $StatusRaw -ObjectExists $FoundService -Translation $ProviderEnums.ServiceStatusName;
|
||||
$IcingaCheck.CritIfNotMatch($IntStatus) | Out-Null;
|
||||
$ServicesPackage.AddCheck($IcingaCheck);
|
||||
$ServicesCountPackage.AddCheck($IcingaCount)
|
||||
$ServicesPackage.AddCheck($ServicesCountPackage)
|
||||
|
||||
}
|
||||
return (New-IcingaCheckResult -Name 'Services' -Check $ServicesPackage -NoPerfData $TRUE -Compile);
|
||||
return (New-IcingaCheckResult -Name 'Services' -Check $ServicesPackage -NoPerfData $NoPerfData -Compile);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,44 +6,58 @@ function Get-IcingaDirectoryAll()
|
|||
[string]$Path,
|
||||
[array]$FileNames,
|
||||
[bool]$Recurse,
|
||||
[string]$YoungerThan,
|
||||
[string]$OlderThan,
|
||||
[string]$ChangeTimeEqual,
|
||||
[string]$ChangeYoungerThan,
|
||||
[string]$ChangeOlderThan,
|
||||
[string]$CreationTimeEqual,
|
||||
[string]$CreationOlderThan,
|
||||
[string]$CreationYoungerThan,
|
||||
[string]$FileSizeGreaterThan,
|
||||
[string]$FileSizeSmallerThan
|
||||
);
|
||||
|
||||
if ($Recurse -eq $TRUE) {
|
||||
$DirectoryData = Get-ChildItem -Recurse -Path $Path -Include $FileNames;
|
||||
$DirectoryData = Get-IcingaDirectoryRecurse -Path $Path -FileNames $FileNames;
|
||||
} else {
|
||||
$DirectoryData = Get-ChildItem -Path $Path -Include $FileNames;
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrEmpty($OlderThan) -eq $FALSE -And [string]::IsNullOrEmpty($YoungerThan) -eq $FALSE) {
|
||||
$OlderThan = Set-NumericNegative (ConvertTo-Seconds $OlderThan);
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.LastWriteTime -lt (Get-Date).AddSeconds($OlderThan)})
|
||||
$YoungerThan = Set-NumericNegative (ConvertTo-Seconds $YoungerThan);
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.LastWriteTime -gt (Get-Date).AddSeconds($YoungerThan)})
|
||||
} elseif ([string]::IsNullOrEmpty($OlderThan) -eq $FALSE) {
|
||||
$OlderThan = Set-NumericNegative (ConvertTo-Seconds $OlderThan);
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.LastWriteTime -lt (Get-Date).AddSeconds($OlderThan)})
|
||||
} elseif ([string]::IsNullOrEmpty($YoungerThan) -eq $FALSE) {
|
||||
$YoungerThan = Set-NumericNegative (ConvertTo-Seconds $YoungerThan);
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.LastWriteTime -gt ((Get-Date).AddSeconds($YoungerThan))})
|
||||
$DirectoryData = Get-IcingaDirectory -Path $Path -FileNames $FileNames;
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrEmpty($ChangeTimeEqual) -eq $FALSE) {
|
||||
$DirectoryData = Get-IcingaDirectoryChangeTimeEqual -ChangeTimeEqual $ChangeTimeEqual -DirectoryData $DirectoryData;
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrEmpty($CreationTimeEqual) -eq $FALSE) {
|
||||
$DirectoryData = Get-IcingaDirectoryCreationTimeEqual -CreationTimeEqual $CreationTimeEqual -DirectoryData $DirectoryData;
|
||||
}
|
||||
|
||||
If ([string]::IsNullOrEmpty($ChangeTimeEqual) -eq $TRUE -Or [string]::IsNullOrEmpty($CreationTimeEqual) -eq $TRUE) {
|
||||
if ([string]::IsNullOrEmpty($ChangeOlderThan) -eq $FALSE) {
|
||||
$DirectoryData = Get-IcingaDirectoryChangeOlderThan -ChangeOlderThan $ChangeOlderThan -DirectoryData $DirectoryData;
|
||||
}
|
||||
if ([string]::IsNullOrEmpty($ChangeYoungerThan) -eq $FALSE) {
|
||||
$DirectoryData = Get-IcingaDirectoryChangeYoungerThan -ChangeYoungerThan $ChangeYoungerThan -DirectoryData $DirectoryData;
|
||||
}
|
||||
if ([string]::IsNullOrEmpty($CreationOlderThan) -eq $FALSE) {
|
||||
$DirectoryData = Get-IcingaDirectoryCreationOlderThan -CreationOlderThan $CreationOlderThan -DirectoryData $DirectoryData;
|
||||
}
|
||||
if ([string]::IsNullOrEmpty($CreationYoungerThan) -eq $FALSE) {
|
||||
$DirectoryData = Get-IcingaDirectoryCreationYoungerThan -CreationYoungerThan $CreationYoungerThan -DirectoryData $DirectoryData;
|
||||
}
|
||||
}
|
||||
if ([string]::IsNullOrEmpty($FileSizeGreaterThan) -eq $FALSE) {
|
||||
$FileSizeGreaterThanValue = (Convert-Bytes $FileSizeGreaterThan -Unit B).value
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.Length -gt $FileSizeGreaterThanValue})
|
||||
$DirectoryData = (Get-IcingaDirectorySizeGreaterThan -FileSizeGreaterThan $FileSizeGreaterThan -DirectoryData $DirectoryData);
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrEmpty($FileSizeSmallerThan) -eq $FALSE) {
|
||||
$FileSizeSmallerThanValue = (Convert-Bytes $FileSizeSmallerThan -Unit B).value
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.Length -gt $FileSizeSmallerThanValue})
|
||||
$DirectoryData = (Get-IcingaDirectorySizeSmallerThan -FileSizeSmallerThan $FileSizeSmallerThan -DirectoryData $DirectoryData);
|
||||
}
|
||||
|
||||
return $DirectoryData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
# RECURSE
|
||||
|
||||
function Get-IcingaDirectory()
|
||||
{
|
||||
param(
|
||||
|
|
@ -65,5 +79,109 @@ function Get-IcingaDirectoryRecurse()
|
|||
|
||||
$DirectoryData = Get-ChildItem -Recurse -Include $FileNames -Path $Path;
|
||||
|
||||
return $DirectoryData;
|
||||
}
|
||||
|
||||
# FILE SIZE
|
||||
|
||||
function Get-IcingaDirectorySizeGreaterThan()
|
||||
{
|
||||
param(
|
||||
[string]$FileSizeGreaterThan,
|
||||
$DirectoryData
|
||||
);
|
||||
$FileSizeGreaterThanValue = (Convert-Bytes $FileSizeGreaterThan -Unit B).value
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.Length -gt $FileSizeGreaterThanValue})
|
||||
|
||||
return $DirectoryData;
|
||||
}
|
||||
|
||||
function Get-IcingaDirectorySizeSmallerThan()
|
||||
{
|
||||
param(
|
||||
[string]$FileSizeSmallerThan,
|
||||
$DirectoryData
|
||||
);
|
||||
$FileSizeSmallerThanValue = (Convert-Bytes $FileSizeSmallerThan -Unit B).value
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.Length -gt $FileSizeSmallerThanValue})
|
||||
|
||||
return $DirectoryData;
|
||||
}
|
||||
|
||||
# TIME BASED CHANGE
|
||||
|
||||
function Get-IcingaDirectoryChangeOlderThan()
|
||||
{
|
||||
param (
|
||||
[string]$ChangeOlderThan,
|
||||
$DirectoryData
|
||||
)
|
||||
$ChangeOlderThan = Set-NumericNegative (ConvertTo-Seconds $ChangeOlderThan);
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.LastWriteTime -lt (Get-Date).AddSeconds($ChangeOlderThan)})
|
||||
|
||||
return $DirectoryData;
|
||||
}
|
||||
|
||||
function Get-IcingaDirectoryChangeYoungerThan()
|
||||
{
|
||||
param (
|
||||
[string]$ChangeYoungerThan,
|
||||
$DirectoryData
|
||||
)
|
||||
$ChangeYoungerThan = Set-NumericNegative (ConvertTo-Seconds $ChangeYoungerThan);
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.LastWriteTime -gt (Get-Date).AddSeconds($ChangeYoungerThan)})
|
||||
|
||||
return $DirectoryData;
|
||||
}
|
||||
|
||||
function Get-IcingaDirectoryChangeTimeEqual()
|
||||
{
|
||||
param (
|
||||
[string]$ChangeTimeEqual,
|
||||
$DirectoryData
|
||||
)
|
||||
$ChangeTimeEqual = Set-NumericNegative (ConvertTo-Seconds $ChangeTimeEqual);
|
||||
$ChangeTimeEqual = (Get-Date).AddSeconds($ChangeTimeEqual);
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.LastWriteTime.Day -eq $ChangeTimeEqual.Day -And $_.LastWriteTime.Month -eq $ChangeTimeEqual.Month -And $_.LastWriteTime.Year -eq $ChangeTimeEqual.Year})
|
||||
|
||||
return $DirectoryData;
|
||||
}
|
||||
|
||||
# TIME BASED CREATION
|
||||
|
||||
function Get-IcingaDirectoryCreationYoungerThan()
|
||||
{
|
||||
param (
|
||||
[string]$CreationYoungerThan,
|
||||
$DirectoryData
|
||||
)
|
||||
$CreationYoungerThan = Set-NumericNegative (ConvertTo-Seconds $CreationYoungerThan);
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.CreationTime -gt (Get-Date).AddSeconds($CreationYoungerThan)})
|
||||
|
||||
return $DirectoryData;
|
||||
}
|
||||
|
||||
function Get-IcingaDirectoryCreationOlderThan()
|
||||
{
|
||||
param (
|
||||
[string]$CreationOlderThan,
|
||||
$DirectoryData
|
||||
)
|
||||
$CreationOlderThan = Set-NumericNegative (ConvertTo-Seconds $CreationOlderThan);
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.CreationTime -lt (Get-Date).AddSeconds($CreationOlderThan)})
|
||||
|
||||
return $DirectoryData;
|
||||
}
|
||||
|
||||
function Get-IcingaDirectoryCreationTimeEqual()
|
||||
{
|
||||
param (
|
||||
[string]$CreationTimeEqual,
|
||||
$DirectoryData
|
||||
)
|
||||
$CreationTimeEqual = Set-NumericNegative (ConvertTo-Seconds $CreationTimeEqual);
|
||||
$CreationTimeEqual = (Get-Date).AddSeconds($CreationTimeEqual);
|
||||
$DirectoryData = ($DirectoryData | Where-Object {$_.CreationTime.Day -eq $CreationTimeEqual.Day -And $_.CreationTime.Month -eq $CreationTimeEqual.Month -And $_.CreationTime.Year -eq $CreationTimeEqual.Year})
|
||||
|
||||
return $DirectoryData;
|
||||
}
|
||||
Loading…
Reference in a new issue