Set default for Warning, Critical; Change Verbose to Verbosity with default and ValidateSet, Add ValidateSet for ServiceStatus, Fixed CPU-Check

This commit is contained in:
Crited 2019-10-29 10:18:20 +01:00
parent 4e4c79d0df
commit 6d80c0434a
10 changed files with 61 additions and 50 deletions

View file

@ -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) {

View file

@ -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,11 +62,12 @@ 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 `
@ -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);
}

View file

@ -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';

View file

@ -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];

View file

@ -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'];

View file

@ -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) {

View file

@ -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
);

View file

@ -35,10 +35,11 @@ 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;
@ -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);
}

View file

@ -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) {

View file

@ -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) {