From ee33bc075c8033997cfec242e5f51b1d6fafcae3 Mon Sep 17 00:00:00 2001 From: Crited Date: Tue, 29 Oct 2019 10:18:20 +0100 Subject: [PATCH] Set default for Warning, Critical; Change Verbose to Verbosity with default and ValidateSet, Add ValidateSet for ServiceStatus, Fixed CPU-Check --- lib/plugins/Invoke-IcingaCheckCPU.psm1 | 11 ++++++----- lib/plugins/Invoke-IcingaCheckDirectory.psm1 | 19 ++++++++++--------- lib/plugins/Invoke-IcingaCheckEventlog.psm1 | 13 +++++++------ .../Invoke-IcingaCheckPerfcounter.psm1 | 11 ++++++----- .../Invoke-IcingaCheckProcessCount.psm1 | 11 ++++++----- lib/plugins/Invoke-IcingaCheckService.psm1 | 6 ++++-- lib/plugins/Invoke-IcingaCheckUpdates.psm1 | 9 +++++---- lib/plugins/Invoke-IcingaCheckUptime.psm1 | 11 ++++++----- .../Invoke-IcingaCheckUsedPartitionSpace.psm1 | 9 +++++---- lib/plugins/Invoke-IcingaCheckUsers.psm1 | 11 ++++++----- 10 files changed, 61 insertions(+), 50 deletions(-) diff --git a/lib/plugins/Invoke-IcingaCheckCPU.psm1 b/lib/plugins/Invoke-IcingaCheckCPU.psm1 index 194dafc..7fdd5c7 100644 --- a/lib/plugins/Invoke-IcingaCheckCPU.psm1 +++ b/lib/plugins/Invoke-IcingaCheckCPU.psm1 @@ -38,15 +38,16 @@ Import-IcingaLib icinga\plugin; function Invoke-IcingaCheckCPU() { param( - [int]$Warning, - [int]$Critical, - $Core = '*', + [int]$Warning = $null, + [int]$Critical = $null, + [string]$Core = '*', [switch]$NoPerfData, - $Verbose + [ValidateSet(0, 1, 2, 3)] + [int]$Verbosity = 0 ); $CpuCounter = New-IcingaPerformanceCounter -Counter ([string]::Format('\Processor({0})\% processor time', $Core)); - $CpuPackage = New-IcingaCheckPackage -Name 'CPU Load' -OperatorAnd -Verbos $Verbose; + $CpuPackage = New-IcingaCheckPackage -Name 'CPU Load' -OperatorAnd -Verbose $Verbosity; $CpuCount = ([string](Get-IcingaCpuCount)).Length; if ($CpuCounter.Counters.Count -ne 0) { diff --git a/lib/plugins/Invoke-IcingaCheckDirectory.psm1 b/lib/plugins/Invoke-IcingaCheckDirectory.psm1 index 7b0957e..9f7f26d 100644 --- a/lib/plugins/Invoke-IcingaCheckDirectory.psm1 +++ b/lib/plugins/Invoke-IcingaCheckDirectory.psm1 @@ -11,19 +11,19 @@ Import-IcingaLib provider\directory; 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 - PS>Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -Warning 20 -Critical 30 -Verbose 3 + PS>Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -Warning 20 -Critical 30 -Verbosity 3 [OK]: Check package "C:\Users\Icinga\Downloads" is [OK] (Match All) \_ [OK]: C:\Users\Icinga\Downloads is 19 .EXAMPLE - PS>Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -Warning 20 -Critical 30 -Verbose 3 + PS>Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -Warning 20 -Critical 30 -Verbosity 3 [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 -Verbose 3 -YoungerThen 20d -OlderThen 10d + PS>Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -Warning 20 -Critical 30 -Verbosity 3 -YoungerThen 20d -OlderThen 10d [OK]: Check package "C:\Users\Icinga\Downloads" is [OK] (Match All) \_ [OK]: C:\Users\Icinga\Downloads is 1 .EXAMPLE - PS>Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -FileNames "*.txt","*.sql" -Warning 20 -Critical 30 -Verbose 3 + PS>Invoke-IcingaCheckDirectory -Path "C:\Users\Icinga\Downloads" -FileNames "*.txt","*.sql" -Warning 20 -Critical 30 -Verbosity 3 [OK]: Check package "C:\Users\Icinga\Downloads" is [OK] (Match All) \_ [OK]: C:\Users\Icinga\Downloads is 4 .PARAMETER Warning @@ -62,12 +62,13 @@ function Invoke-IcingaCheckDirectory() [string]$Path, [array]$FileNames, [switch]$Recurse, - [int]$Critical, - [int]$Warning, + [int]$Critical = $null, + [int]$Warning = $null, [string]$YoungerThen, [string]$OlderThen, - [int]$Verbose - ); + [ValidateSet(0, 1, 2, 3)] + [int]$Verbosity = 0 + ); $DirectoryData = Get-IcingaDirectoryAll -Path $Path -FileNames $FileNames ` -Recurse $Recurse -YoungerThen $YoungerThen -OlderThen $OlderThen; @@ -79,7 +80,7 @@ function Invoke-IcingaCheckDirectory() ($Critical) ) | Out-Null; - $DirectoryPackage = New-IcingaCheckPackage -Name $Path -OperatorAnd -Checks $DirectoryCheck -Verbose $Verbose; + $DirectoryPackage = New-IcingaCheckPackage -Name $Path -OperatorAnd -Checks $DirectoryCheck -Verbose $Verbosity; return (New-IcingaCheckresult -Check $DirectoryPackage -NoPerfData $TRUE -Compile); } \ No newline at end of file diff --git a/lib/plugins/Invoke-IcingaCheckEventlog.psm1 b/lib/plugins/Invoke-IcingaCheckEventlog.psm1 index 09c1fc6..1f25d89 100644 --- a/lib/plugins/Invoke-IcingaCheckEventlog.psm1 +++ b/lib/plugins/Invoke-IcingaCheckEventlog.psm1 @@ -3,8 +3,8 @@ Import-IcingaLib icinga\plugin; function Invoke-IcingaCheckEventlog() { param( - $Warning, - $Critical, + $Warning = $null, + $Critical = $null, [string]$LogName, [array]$IncludeEventId, [array]$ExcludeEventId, @@ -18,10 +18,11 @@ function Invoke-IcingaCheckEventlog() $Before = $null, [switch]$DisableTimeCache = $FALSE, [switch]$NoPerfData, - $Verbose + [ValidateSet(0, 1, 2, 3)] + [int]$Verbosity = 0 ); - $EventLogPackage = New-IcingaCheckPackage -Name 'EventLog' -OperatorAnd -Verbose $Verbose; + $EventLogPackage = New-IcingaCheckPackage -Name 'EventLog' -OperatorAnd -Verbose $Verbosity; $EventLogData = Get-IcingaEventLog -LogName $LogName -IncludeEventId $IncludeEventId -ExcludeEventId $ExcludeEventId -IncludeUsername $IncludeUsername -ExcludeUsername $ExcludeUsername ` -IncludeEntryType $IncludeEntryType -ExcludeEntryType $ExcludeEntryType -IncludeMessage $IncludeMessage -ExcludeMessage $ExcludeMessage ` -After $After -Before $Before -DisableTimeCache $DisableTimeCache; @@ -29,7 +30,7 @@ function Invoke-IcingaCheckEventlog() if ($EventLogData.eventlog.Count -ne 0) { foreach ($event in $EventLogData.eventlog.Keys) { $eventEntry = $EventLogData.eventlog[$event]; - $EventLogEntryPackage = New-IcingaCheckPackage -Name ([string]::Format('Between: [{0}] - [{1}] there occured {2} event(s).', $eventEntry.OldestEntry, $eventEntry.NewestEntry, $eventEntry.Count)) -OperatorAnd -Verbose $Verbose; + $EventLogEntryPackage = New-IcingaCheckPackage -Name ([string]::Format('Between: [{0}] - [{1}] there occured {2} event(s).', $eventEntry.OldestEntry, $eventEntry.NewestEntry, $eventEntry.Count)) -OperatorAnd -Verbose $Verbosity; $IcingaCheck = New-IcingaCheck -Name ([string]::Format('EventId {0}', $EventLogData.eventlog[$event].EventId)) -Value $eventEntry.Count -NoPerfData; $IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null; $EventLogEntryPackage.AddCheck($IcingaCheck); @@ -37,7 +38,7 @@ function Invoke-IcingaCheckEventlog() $EventLogPackage.AddCheck($EventLogEntryPackage); } - $EventLogCountPackage = New-IcingaCheckPackage -Name 'EventLog Count' -OperatorAnd -Verbose $Verbose -Hidden; + $EventLogCountPackage = New-IcingaCheckPackage -Name 'EventLog Count' -OperatorAnd -Verbose $Verbosity -Hidden; foreach ($event in $EventLogData.events.Keys) { $IcingaCheck = New-IcingaCheck -Name ([string]::Format('EventId {0}', $event)) -Value $EventLogData.events[$event] -Unit 'c'; diff --git a/lib/plugins/Invoke-IcingaCheckPerfcounter.psm1 b/lib/plugins/Invoke-IcingaCheckPerfcounter.psm1 index 4863cfb..58ea192 100644 --- a/lib/plugins/Invoke-IcingaCheckPerfcounter.psm1 +++ b/lib/plugins/Invoke-IcingaCheckPerfcounter.psm1 @@ -4,18 +4,19 @@ function Invoke-IcingaCheckPerfcounter() { param( [array]$PerfCounter, - $Warning, - $Critical, + [double]$Warning = $null, + [double]$Critical = $null, [switch]$NoPerfData, - [int]$Verbose + [ValidateSet(0, 1, 2, 3)] + [int]$Verbosity = 0 ); $Counters = New-IcingaPerformanceCounterArray -CounterArray $PerfCounter; - $CheckPackage = New-IcingaCheckPackage -Name 'Performance Counter' -OperatorAnd -Verbose $Verbose; + $CheckPackage = New-IcingaCheckPackage -Name 'Performance Counter' -OperatorAnd -Verbose $Verbosity; foreach ($counter in $Counters.Keys) { - $CounterPackage = New-IcingaCheckPackage -Name $counter -OperatorAnd -Verbose $Verbose; + $CounterPackage = New-IcingaCheckPackage -Name $counter -OperatorAnd -Verbose $Verbosity; foreach ($instanceName in $Counters[$counter].Keys) { $instance = $Counters[$counter][$instanceName]; diff --git a/lib/plugins/Invoke-IcingaCheckProcessCount.psm1 b/lib/plugins/Invoke-IcingaCheckProcessCount.psm1 index 37ff850..117602a 100644 --- a/lib/plugins/Invoke-IcingaCheckProcessCount.psm1 +++ b/lib/plugins/Invoke-IcingaCheckProcessCount.psm1 @@ -16,7 +16,7 @@ Import-IcingaLib icinga\plugin; [OK]: Check package "Process Check" is [OK] | 'Process Count "conhost"'=3;; .EXAMPLE - PS>Invoke-IcingaCheckProcessCount -Process conhost,wininit -Warning 5 -Critical 10 -Verbose 4 + PS>Invoke-IcingaCheckProcessCount -Process conhost,wininit -Warning 5 -Critical 10 -Verbosity 4 [OK]: Check package "Process Check" is [OK] (Match All) \_ [OK]: Process Count "conhost" is 3 \_ [OK]: Process Count "wininit" is 1 @@ -40,16 +40,17 @@ Import-IcingaLib icinga\plugin; function Invoke-IcingaCheckProcessCount() { param( - [int]$Warning, - [int]$Critical, + [int]$Warning = $null, + [int]$Critical = $null, [array]$Process, [switch]$NoPerfData, - $Verbose + [ValidateSet(0, 1, 2, 3)] + [int]$Verbosity = 0 ); $ProcessInformation = (Get-IcingaProcessData -Name $Process) - $ProcessPackage = New-icingaCheckPackage -Name "Process Check" -OperatorAnd -Verbose $Verbose -NoPerfData $NoPerfData; + $ProcessPackage = New-icingaCheckPackage -Name "Process Check" -OperatorAnd -Verbose $Verbosity -NoPerfData $NoPerfData; if ($Process.Count -eq 0) { $ProcessCount = $ProcessInformation['Process Count']; diff --git a/lib/plugins/Invoke-IcingaCheckService.psm1 b/lib/plugins/Invoke-IcingaCheckService.psm1 index 23f8b30..3a59d28 100644 --- a/lib/plugins/Invoke-IcingaCheckService.psm1 +++ b/lib/plugins/Invoke-IcingaCheckService.psm1 @@ -34,11 +34,13 @@ function Invoke-IcingaCheckService() { param( [array]$Service, + [ValidateSet('Stopped', 'StartPending', 'StopPending', 'Running', 'ContinuePending', 'PausePending', 'Paused')] [string]$Status, - [int]$Verbose + [ValidateSet(0, 1, 2, 3)] + [int]$Verbosity = 0 ); - $ServicesPackage = New-IcingaCheckPackage -Name 'Services' -OperatorAnd -Verbose $Verbose; + $ServicesPackage = New-IcingaCheckPackage -Name 'Services' -OperatorAnd -Verbose $Verbosity; if ($Service.Count -ne 1) { foreach ($services in $Service) { diff --git a/lib/plugins/Invoke-IcingaCheckUpdates.psm1 b/lib/plugins/Invoke-IcingaCheckUpdates.psm1 index 25e61f8..a878db4 100644 --- a/lib/plugins/Invoke-IcingaCheckUpdates.psm1 +++ b/lib/plugins/Invoke-IcingaCheckUpdates.psm1 @@ -33,10 +33,11 @@ function Invoke-IcingaCheckUpdates() { param ( [array]$UpdateFilter, - [int]$Warning, - [int]$Critical, + [int]$Warning = $null, + [int]$Critical = $null, [switch]$NoPerfData, - [int]$Verbose + [ValidateSet(0, 1, 2, 3)] + [int]$Verbosity = 0 ); $PendingUpdates = Get-IcingaUpdatesPending; @@ -74,7 +75,7 @@ function Invoke-IcingaCheckUpdates() $IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null; $UpdateCount.AddCheck($IcingaCheck); - $UpdatePackage = New-IcingaCheckPackage -Name 'Updates' -OperatorAnd -Verbose $Verbose -Checks @( + $UpdatePackage = New-IcingaCheckPackage -Name 'Updates' -OperatorAnd -Verbose $Verbosity -Checks @( $UpdateCount ); diff --git a/lib/plugins/Invoke-IcingaCheckUptime.psm1 b/lib/plugins/Invoke-IcingaCheckUptime.psm1 index 147c04a..e9ba339 100644 --- a/lib/plugins/Invoke-IcingaCheckUptime.psm1 +++ b/lib/plugins/Invoke-IcingaCheckUptime.psm1 @@ -35,11 +35,12 @@ Import-IcingaLib core\tools; function Invoke-IcingaCheckUptime() { param( - [string]$Warning, - [string]$Critical, + [string]$Warning = $null, + [string]$Critical = $null, [switch]$NoPerfData, - [int]$Verbose - ); + [ValidateSet(0, 1, 2, 3)] + [int]$Verbosity = 0 + ); $WindowsData = Get-IcingaWindows; $Name = ([string]::Format('Windows Uptime: {0}', (ConvertFrom-TimeSpan -Seconds $WindowsData.windows.metadata.uptime.value))); @@ -51,7 +52,7 @@ function Invoke-IcingaCheckUptime() (ConvertTo-SecondsFromIcingaThresholds -Threshold $Critical) ) | Out-Null; - $CheckPackage = New-IcingaCheckPackage -Name $Name -OperatorAnd -Checks $IcingaCheck -Verbose $Verbose; + $CheckPackage = New-IcingaCheckPackage -Name $Name -OperatorAnd -Checks $IcingaCheck -Verbose $Verbosity; return (New-IcingaCheckresult -Check $CheckPackage -NoPerfData $NoPerfData -Compile); } diff --git a/lib/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 b/lib/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 index 6d58b45..6cbcbd5 100644 --- a/lib/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 +++ b/lib/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 @@ -45,16 +45,17 @@ Import-IcingaLib icinga\plugin; function Invoke-IcingaCheckUsedPartitionSpace() { param( - [int]$Warning, - [int]$Critical, + [int]$Warning = $null, + [int]$Critical = $null, [array]$Include = @(), [array]$Exclude = @(), [switch]$NoPerfData, - $Verbose + [ValidateSet(0, 1, 2, 3)] + [int]$Verbosity = 0 ); $DiskFree = Get-IcingaDiskPartitions; - $DiskPackage = New-IcingaCheckPackage -Name 'Used Partition Space' -OperatorAnd -Verbos $Verbose; + $DiskPackage = New-IcingaCheckPackage -Name 'Used Partition Space' -OperatorAnd -Verbos $Verbosity; foreach ($Letter in $DiskFree.Keys) { if ($Include.Count -ne 0) { diff --git a/lib/plugins/Invoke-IcingaCheckUsers.psm1 b/lib/plugins/Invoke-IcingaCheckUsers.psm1 index d3e6de9..3139e9f 100644 --- a/lib/plugins/Invoke-IcingaCheckUsers.psm1 +++ b/lib/plugins/Invoke-IcingaCheckUsers.psm1 @@ -37,13 +37,14 @@ function Invoke-IcingaCheckUsers() { param ( [array]$Username, - [int]$Warning, - [int]$Critical, + [int]$Warning = $null, + [int]$Critical = $null, [switch]$NoPerfData, - [int]$Verbose - ); + [ValidateSet(0, 1, 2, 3)] + [int]$Verbosity = 0 + ); - $UsersPackage = New-IcingaCheckPackage -Name 'Users' -OperatorAnd -Verbose $Verbose; + $UsersPackage = New-IcingaCheckPackage -Name 'Users' -OperatorAnd -Verbose $Verbosity; $LoggedOnUsers = Get-IcingaLoggedOnUsers -UserFilter $Username; if ($Username.Count -ne 0) {