2019-07-18 11:54:39 -04:00
function New-IcingaCheck ( )
{
param (
2024-03-13 12:38:08 -04:00
[ string ] $Name = '' ,
$Value = $null ,
$BaseValue = $null ,
$Unit = '' ,
$MetricIndex = 'default' ,
$MetricName = '' ,
$MetricTemplate = '' ,
[ string ] $Minimum = '' ,
[ string ] $Maximum = '' ,
$ObjectExists = -1 ,
$Translation = $null ,
[ string ] $LabelName = $null ,
[ switch ] $NoPerfData = $FALSE ,
[ switch ] $NoHeaderReport = $FALSE
2019-07-18 11:54:39 -04:00
) ;
2021-05-07 08:38:10 -04:00
$IcingaCheck = New-IcingaCheckBaseObject ;
$IcingaCheck . Name = $Name ;
$IcingaCheck . __ObjectType = 'IcingaCheck' ;
2024-02-12 05:24:51 -05:00
# Ensure we always set our current value to 0 in case it is null and we set a unit, to prevent conversion exceptions
if ( [ string ] :: IsNullOrEmpty ( $Unit ) -eq $FALSE -And $null -eq $Value ) {
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Value' -Value 0 ;
} else {
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Value' -Value $Value ;
}
2025-04-22 07:47:53 -04:00
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'BaseValue' -Value $BaseValue ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Unit' -Value $Unit ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'MetricIndex' -Value $MetricIndex ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'MetricName' -Value $MetricName ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'MetricTemplate' -Value $MetricTemplate ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Minimum' -Value $Minimum ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Maximum' -Value $Maximum ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'ObjectExists' -Value $ObjectExists ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Translation' -Value $Translation ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'LabelName' -Value $LabelName ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'NoPerfData' -Value ( [ bool ] $NoPerfData ) ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name '__WarningValue' -Value $null ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name '__CriticalValue' -Value $null ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name '__LockedState' -Value $FALSE ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name '__ThresholdObject' -Value $null ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name '__RequireThresholdValidation' -Value $TRUE ;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name '__TimeInterval' -Value $null ;
2021-05-07 08:38:10 -04:00
2024-03-13 12:38:08 -04:00
$IcingaCheck . __SetNoHeaderReport ( $NoHeaderReport ) ;
2021-05-31 12:55:40 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name 'Compile' -Value {
$this . __ValidateThresholdInput ( ) ;
if ( $null -eq $this . __ThresholdObject ) {
$this . __CreateDefaultThresholdObject ( ) ;
}
$this . __SetCheckOutput ( ) ;
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name '__SetInternalTimeInterval' -Value {
$CallStack = Get-PSCallStack ;
[ bool ] $FoundInterval = $FALSE ;
foreach ( $entry in $CallStack ) {
if ( $FoundInterval ) {
break ;
}
[ string ] $CheckCommand = $entry . Command ;
if ( $CheckCommand -eq $this . __CheckCommand ) {
[ string ] $CheckArguments = $entry . Arguments . Replace ( '{' , '' ) . Replace ( '}' , '' ) ;
[ array ] $SplitArgs = $CheckArguments . Split ( ',' ) ;
foreach ( $SetArg in $SplitArgs ) {
$SetArg = $SetArg . Replace ( ' ' , '' ) ;
if ( $FoundInterval ) {
$this . __TimeInterval = $SetArg ;
break ;
}
2023-05-12 05:07:37 -04:00
if ( $SetArg -eq '-ThresholdInterval' -Or $SetArg -eq '-ThresholdInterval:' ) {
2021-05-07 08:38:10 -04:00
$FoundInterval = $TRUE ;
continue ;
}
}
break ;
}
2019-10-05 16:08:19 -04:00
}
2021-05-07 08:38:10 -04:00
}
2019-10-05 16:08:19 -04:00
2021-05-07 08:38:10 -04:00
# Override shared function
$IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name '__GetHeaderOutputValue' -Value {
if ( $null -eq $this . __ThresholdObject ) {
return ''
}
if ( [ string ] :: IsNullOrEmpty ( $this . __ThresholdObject . HeaderValue ) ) {
return '' ;
}
return (
[ string ] :: Format (
' ({0})' ,
$this . __ThresholdObject . HeaderValue
)
)
}
2021-05-29 05:20:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name '__CreateDefaultThresholdObject' -Value {
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
2021-05-31 12:55:40 -04:00
$this . __ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
$this . __SetCheckState ( $this . __ThresholdObject , $IcingaEnums . IcingaExitCode . Ok ) ;
2021-05-29 05:20:10 -04:00
}
2021-05-07 08:38:10 -04:00
# Override shared function
$IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name '__SetCheckOutput' -Value {
param ( $PluginOutput ) ;
if ( $this . __InLockState ( ) ) {
2019-10-06 04:46:11 -04:00
return ;
}
2021-05-07 08:38:10 -04:00
$PluginThresholds = '' ;
$TimeSpan = '' ;
2024-08-19 10:13:24 -04:00
$PluginThresholds = $this . __ThresholdObject . Message ;
2021-03-08 08:15:50 -05:00
2021-05-07 08:38:10 -04:00
if ( [ string ] :: IsNullOrEmpty ( $PluginOutput ) -eq $FALSE ) {
$PluginThresholds = $PluginOutput ;
}
2021-03-08 08:15:50 -05:00
2024-08-19 10:13:24 -04:00
<# if ($null -ne $this . __ThresholdObject -And [string]::IsNullOrEmpty($this . __ThresholdObject . TimeSpan) -eq $FALSE) {
2021-05-07 08:38:10 -04:00
$TimeSpan = [ string ] :: Format (
'{0}({1}m avg.)' ,
( & { if ( [ string ] :: IsNullOrEmpty ( $PluginThresholds ) ) { return '' ; } else { return ' ' } } ) ,
2022-05-24 10:44:52 -04:00
$this . __ThresholdObject . TimeSpanOutput
2019-10-05 16:08:19 -04:00
) ;
2024-08-19 10:13:24 -04:00
} #>
2019-10-05 16:08:19 -04:00
2021-05-31 09:39:52 -04:00
[ bool ] $AddColon = $TRUE ;
if ( [ string ] :: IsNullOrEmpty ( $this . Name ) -eq $FALSE -And $this . Name [ $this . Name . Length - 1 ] -eq ':' ) {
$AddColon = $FALSE ;
}
2021-05-07 08:38:10 -04:00
$this . __CheckOutput = [ string ] :: Format (
2021-05-31 09:39:52 -04:00
'{0} {1}{2} {3}{4}' ,
2021-05-07 08:38:10 -04:00
$IcingaEnums . IcingaExitCodeText [ $this . __CheckState ] ,
$this . Name ,
2021-05-31 09:39:52 -04:00
( & { if ( $AddColon ) { return ':' ; } else { return '' ; } } ) ,
2021-05-07 08:38:10 -04:00
$PluginThresholds ,
$TimeSpan
) ;
$this . __SetPerformanceData ( ) ;
2019-07-19 13:38:09 -04:00
}
2021-05-07 08:38:10 -04:00
# __GetTimeSpanThreshold(0, 'Core_30_20', 'Core_30')
$IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name '__GetTimeSpanThreshold' -Value {
2022-05-24 10:44:52 -04:00
param ( $TimeSpanLabel , $Label , $MultiOutput ) ;
2019-09-28 15:45:59 -04:00
2021-05-07 08:38:10 -04:00
[ hashtable ] $TimeSpans = @ {
'Warning' = '' ;
'Critical' = '' ;
2022-05-24 10:44:52 -04:00
'Interval' = '' ;
2021-05-07 08:38:10 -04:00
}
2019-09-28 15:45:59 -04:00
2022-05-24 10:44:52 -04:00
[ string ] $LabelName = ( Format-IcingaPerfDataLabel -PerfData $this . Name -MultiOutput: $MultiOutput ) ;
2021-05-07 08:38:10 -04:00
if ( [ string ] :: IsNullOrEmpty ( $this . LabelName ) -eq $FALSE ) {
$LabelName = $this . LabelName ;
}
2019-10-30 13:17:39 -04:00
2021-05-07 08:38:10 -04:00
if ( $Label -ne $LabelName ) {
return $TimeSpans ;
}
2019-10-30 13:17:39 -04:00
2022-05-24 10:44:52 -04:00
$TimeSpan = $TimeSpanLabel . Replace ( $Label , '' ) . Replace ( '_' , '' ) . Replace ( '::Interval' , '' ) . Replace ( '::' , '' ) ;
2019-10-30 13:17:39 -04:00
2021-05-07 08:38:10 -04:00
if ( $null -ne $this . __WarningValue -And [ string ] :: IsNullOrEmpty ( $this . __WarningValue . TimeSpan ) -eq $FALSE -And $this . __WarningValue . TimeSpan -eq $TimeSpan ) {
2024-08-19 10:13:24 -04:00
$TimeSpans . Warning = $this . __WarningValue . Threshold . Threshold ;
2021-05-07 08:38:10 -04:00
}
if ( $null -ne $this . __CriticalValue -And [ string ] :: IsNullOrEmpty ( $this . __CriticalValue . TimeSpan ) -eq $FALSE -And $this . __CriticalValue . TimeSpan -eq $TimeSpan ) {
2024-08-19 10:13:24 -04:00
$TimeSpans . Critical = $this . __CriticalValue . Threshold . Threshold ;
2021-05-07 08:38:10 -04:00
}
2022-05-24 10:44:52 -04:00
$TimeSpans . Interval = $TimeSpan ;
2020-05-29 12:35:41 -04:00
2021-05-07 08:38:10 -04:00
return $TimeSpans ;
2020-05-19 11:30:50 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__GetWarningThresholdObject' -Value {
return $this . __WarningValue ;
}
2020-05-29 12:35:41 -04:00
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__GetCriticalThresholdObject' -Value {
return $this . __CriticalValue ;
2020-05-19 11:30:50 -04:00
}
2025-01-29 08:45:53 -05:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__CreatePerfDataLabel' -Value {
$PerfDataTemplate = ( $this . __CheckCommand . Replace ( 'Invoke-IcingaCheck' , '' ) ) ;
if ( [ string ] :: IsNullOrEmpty ( $this . MetricTemplate ) -eq $FALSE ) {
$PerfDataTemplate = $this . MetricTemplate ;
}
[ string ] $PerfDataName = [ string ] :: Format (
'{0}::ifw_{1}::{2}' ,
$this . MetricIndex ,
$PerfDataTemplate . ToLower ( ) ,
$this . MetricName
) ;
return $PerfDataName ;
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__SetPerformanceData' -Value {
if ( $null -eq $this . __ThresholdObject -Or $this . NoPerfData ) {
return ;
2019-07-19 13:38:09 -04:00
}
2022-05-24 10:44:52 -04:00
[ string ] $LabelName = ( Format-IcingaPerfDataLabel -PerfData $this . Name ) ;
[ string ] $MultiLabelName = ( Format-IcingaPerfDataLabel -PerfData $this . Name -MultiOutput ) ;
2024-08-15 10:18:24 -04:00
$value = ConvertTo-Integer -Value $this . __ThresholdObject . Value ;
2022-05-24 10:44:52 -04:00
$warning = '' ;
$critical = '' ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
# Set our threshold to nothing if we use time spans, as it would cause performance metrics to
# contain warning/critical values for everything, which is not correct
if ( [ string ] :: IsNullOrEmpty ( $this . __WarningValue . TimeSpan ) ) {
2024-08-19 10:13:24 -04:00
$warning = ConvertTo-Integer -Value $this . __WarningValue . Threshold . Threshold -NullAsEmpty ;
2021-05-07 08:38:10 -04:00
}
if ( [ string ] :: IsNullOrEmpty ( $this . __CriticalValue . TimeSpan ) ) {
2024-08-19 10:13:24 -04:00
$critical = ConvertTo-Integer -Value $this . __CriticalValue . Threshold . Threshold -NullAsEmpty ;
2021-05-07 08:38:10 -04:00
}
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
if ( [ string ] :: IsNullOrEmpty ( $this . LabelName ) -eq $FALSE ) {
2022-05-24 10:44:52 -04:00
$LabelName = $this . LabelName ;
$MultiLabelName = $this . LabelName ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
if ( [ string ] :: IsNullOrEmpty ( $this . Minimum ) -And [ string ] :: IsNullOrEmpty ( $this . Maximum ) ) {
if ( $this . Unit -eq '%' ) {
$this . Minimum = '0' ;
$this . Maximum = '100' ;
} elseif ( $null -ne $this . BaseValue ) {
$this . Minimum = '0' ;
$this . Maximum = $this . __ThresholdObject . BaseValue ;
}
2020-05-12 10:37:08 -04:00
2021-09-03 15:47:37 -04:00
if ( [ string ] :: IsNullOrEmpty ( $this . Maximum ) -eq $FALSE -And ( Test-Numeric $this . Maximum ) -And ( Test-Numeric $this . Value ) -And $this . Value -gt $this . Maximum ) {
2024-08-19 10:13:24 -04:00
$this . Maximum = $this . __ThresholdObject . Value ;
2021-05-07 08:38:10 -04:00
}
}
2019-07-18 11:54:39 -04:00
2025-01-29 08:45:53 -05:00
[ string ] $PerfDataName = $this . __CreatePerfDataLabel ( ) ;
2024-08-19 10:13:24 -04:00
# Ensure we only add a label with identical name once
if ( $Global:Icinga . Private . Scheduler . PerfDataWriter . Cache . ContainsKey ( $PerfDataName ) -eq $FALSE ) {
$Global:Icinga . Private . Scheduler . PerfDataWriter . Cache . Add ( $PerfDataName , $TRUE ) ;
} else {
return ;
}
[ string ] $PerfDataLabel = [ string ] :: Format (
'{0}={1}{2};{3};{4};{5};{6}' ,
2025-03-27 10:11:00 -04:00
$PerfDataName . ToLower ( ) ,
2024-08-19 10:13:24 -04:00
( Format-IcingaPerfDataValue $value ) ,
2025-03-27 10:11:00 -04:00
$this . __ThresholdObject . Unit ,
2024-08-19 10:13:24 -04:00
( Format-IcingaPerfDataValue $warning ) ,
( Format-IcingaPerfDataValue $critical ) ,
( Format-IcingaPerfDataValue $this . Minimum ) ,
( Format-IcingaPerfDataValue $this . Maximum )
) ;
# Add a space before adding another metric
if ( $Global:Icinga . Private . Scheduler . PerfDataWriter . Storage . Length -ne 0 ) {
$Global:Icinga . Private . Scheduler . PerfDataWriter . Storage . Append ( ' ' ) | Out-Null ;
}
2025-01-29 08:45:53 -05:00
# This is just to make sure the background daemon has data to work with and also ensure we don't increase
# memory in case we don't have the daemon running
if ( $Global:Icinga . Private . Scheduler . PerfDataWriter . Daemon . ContainsKey ( $PerfDataName ) -eq $FALSE ) {
$Global:Icinga . Private . Scheduler . PerfDataWriter . Daemon . Add (
$PerfDataName ,
@ {
'Value' = $value ;
'Unit' = $this . __ThresholdObject . PerfUnit
}
) ;
} else {
$Global:Icinga . Private . Scheduler . PerfDataWriter . Daemon [ $PerfDataName ] = @ {
'Value' = $value ;
'Unit' = $this . __ThresholdObject . PerfUnit
}
}
2025-03-27 10:11:00 -04:00
$Global:Icinga . Private . Scheduler . PerfDataWriter . Storage . Append ( $PerfDataLabel ) | Out-Null ;
2021-05-07 08:38:10 -04:00
}
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__ValidateObject' -Value {
if ( $null -eq $this . ObjectExists ) {
$this . SetUnknown ( ) | Out-Null ;
$this . __SetCheckOutput ( 'The object does not exist' ) ;
$this . __LockState ( ) ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
}
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__LockState' -Value {
$this . __LockedState = $TRUE ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__InLockState' -Value {
return $this . __LockedState ;
}
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__ValidateUnit' -Value {
if ( [ string ] :: IsNullOrEmpty ( $this . Unit ) -eq $FALSE -And ( -Not $IcingaEnums . IcingaMeasurementUnits . ContainsKey ( $this . Unit ) ) ) {
$this . SetUnknown ( ) ;
$this . __SetCheckOutput (
[ string ] :: Format (
'Usage of invalid plugin unit "{0}". Allowed units are: {1}' ,
$this . Unit ,
( ( $IcingaEnums . IcingaMeasurementUnits . Keys | Sort-Object name ) -Join ', ' )
)
2019-07-18 11:54:39 -04:00
) ;
2021-05-07 08:38:10 -04:00
$this . __LockState ( ) ;
$this . unit = $null ;
}
2019-07-18 11:54:39 -04:00
}
2022-05-24 10:44:52 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__ValidateMetricsName' -Value {
if ( [ string ] :: IsNullOrEmpty ( $this . MetricIndex ) ) {
Write-IcingaConsoleError -Message 'The metric index has no default value for the check object "{0}"' -Objects $this . Name ;
} else {
$this . MetricIndex = Format-IcingaPerfDataLabel -PerfData $this . MetricIndex -MultiOutput ;
}
if ( [ string ] :: IsNullOrEmpty ( $this . MetricName ) ) {
$this . MetricName = Format-IcingaPerfDataLabel -PerfData $this . Name -MultiOutput ;
} else {
$this . MetricName = Format-IcingaPerfDataLabel -PerfData $this . MetricName -MultiOutput ;
}
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__ConvertMinMax' -Value {
if ( [ string ] :: IsNullOrEmpty ( $this . Unit ) -eq $FALSE ) {
if ( [ string ] :: IsNullOrEmpty ( $this . Minimum ) -eq $FALSE ) {
$this . Minimum = ( Convert-IcingaPluginThresholds -Threshold ( [ string ] :: Format ( '{0}{1}' , $this . Minimum , $this . Unit ) ) ) . Value ;
}
if ( [ string ] :: IsNullOrEmpty ( $this . Maximum ) -eq $FALSE ) {
$this . Maximum = ( Convert-IcingaPluginThresholds -Threshold ( [ string ] :: Format ( '{0}{1}' , $this . Maximum , $this . Unit ) ) ) . Value ;
}
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
}
2019-07-18 11:54:39 -04:00
2021-07-15 09:37:53 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__SetCurrentExecutionTime' -Value {
if ( $null -eq $global:Icinga ) {
$global:Icinga = @ { } ;
}
if ( $global:Icinga . ContainsKey ( 'CurrentDate' ) -eq $FALSE ) {
$global:Icinga . Add ( 'CurrentDate' , ( Get-Date ) ) ;
return ;
}
if ( $null -ne $global:Icinga . CurrentDate ) {
return ;
}
$global:Icinga . CurrentDate = ( Get-Date ) . ToUniversalTime ( ) ;
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__AddCheckDataToCache' -Value {
2020-05-12 10:37:08 -04:00
2021-05-07 08:38:10 -04:00
# We only require this in case we are running as daemon
2021-12-09 11:42:06 -05:00
if ( [ string ] :: IsNullOrEmpty ( $this . __CheckCommand ) -Or $Global:Icinga . Protected . RunAsDaemon -eq $FALSE ) {
2021-05-07 08:38:10 -04:00
return ;
}
2019-07-18 11:54:39 -04:00
2021-12-09 11:42:06 -05:00
if ( $global:Icinga . Private . Scheduler . CheckData . ContainsKey ( $this . __CheckCommand ) -eq $FALSE ) {
2021-05-07 08:38:10 -04:00
return ;
2019-07-19 13:38:09 -04:00
}
2021-05-07 08:38:10 -04:00
# Fix possible error for identical time stamps due to internal exceptions
# and check execution within the same time slot because of this
[ string ] $TimeIndex = Get-IcingaUnixTime ;
2022-05-24 10:44:52 -04:00
[ string ] $LabelName = $this . Name ;
if ( [ string ] :: IsNullOrEmpty ( $this . LabelName ) -eq $FALSE ) {
$LabelName = $this . LabelName ;
}
2020-05-12 10:37:08 -04:00
2022-05-24 10:44:52 -04:00
Add-IcingaHashtableItem -Hashtable $global:Icinga . Private . Scheduler . CheckData [ $this . __CheckCommand ] [ 'results' ] -Key $LabelName -Value @ { } | Out-Null ;
Add-IcingaHashtableItem -Hashtable $global:Icinga . Private . Scheduler . CheckData [ $this . __CheckCommand ] [ 'results' ] [ $LabelName ] -Key $TimeIndex -Value $this . Value -Override | Out-Null ;
2019-07-19 13:38:09 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'SetOk' -Value {
param ( [ string ] $Message , [ bool ] $Lock ) ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
if ( $this . __InLockState ( ) -eq $FALSE ) {
$this . __CheckState = $IcingaEnums . IcingaExitCode . Ok ;
$this . __SetCheckOutput ( $Message ) ;
2019-07-19 13:38:09 -04:00
}
2021-05-07 08:38:10 -04:00
if ( $Lock ) {
$this . __LockState ( ) ;
}
2020-05-12 10:37:08 -04:00
2019-07-19 13:38:09 -04:00
return $this ;
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'SetWarning' -Value {
param ( [ string ] $Message , [ bool ] $Lock ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
if ( $this . __InLockState ( ) -eq $FALSE ) {
$this . __CheckState = $IcingaEnums . IcingaExitCode . Warning ;
$this . __SetCheckOutput ( $Message ) ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
if ( $Lock ) {
$this . __LockState ( ) ;
}
2020-05-12 10:37:08 -04:00
2019-07-18 11:54:39 -04:00
return $this ;
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'SetCritical' -Value {
param ( [ string ] $Message , [ bool ] $Lock ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
if ( $this . __InLockState ( ) -eq $FALSE ) {
$this . __CheckState = $IcingaEnums . IcingaExitCode . Critical ;
$this . __SetCheckOutput ( $Message ) ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
if ( $Lock ) {
$this . __LockState ( ) ;
}
2020-05-12 10:37:08 -04:00
2019-07-18 11:54:39 -04:00
return $this ;
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'SetUnknown' -Value {
param ( [ string ] $Message , [ bool ] $Lock ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
if ( $this . __InLockState ( ) -eq $FALSE ) {
$this . __CheckState = $IcingaEnums . IcingaExitCode . Unknown ;
$this . __SetCheckOutput ( $Message ) ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
if ( $Lock ) {
$this . __LockState ( ) ;
}
2020-05-12 10:37:08 -04:00
2019-07-18 11:54:39 -04:00
return $this ;
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__SetCheckState' -Value {
param ( $ThresholdObject , $State ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
if ( $ThresholdObject . HasError ) {
$this . SetUnknown ( ) | Out-Null ;
$this . __ThresholdObject = $ThresholdObject ;
2024-08-19 10:13:24 -04:00
$this . __SetCheckOutput ( $this . __ThresholdObject . Message ) ;
2021-05-07 08:38:10 -04:00
$this . __LockState ( ) ;
return ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
if ( $this . __InLockState ( ) ) {
return ;
}
2020-05-29 12:35:41 -04:00
2021-05-07 08:38:10 -04:00
# In case no thresholds are set, always set the first value
if ( $null -eq $this . __ThresholdObject ) {
$this . __ThresholdObject = $ThresholdObject ;
}
2020-05-19 11:30:50 -04:00
2024-08-19 10:13:24 -04:00
if ( $ThresholdObject . IsOk -eq $FALSE ) {
2021-05-07 08:38:10 -04:00
if ( $this . __CheckState -lt $State ) {
$this . __CheckState = $State ;
$this . __ThresholdObject = $ThresholdObject ;
2019-07-19 13:38:09 -04:00
}
}
2021-05-07 08:38:10 -04:00
$this . __SetCheckOutput ( ) ;
}
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__GetBaseThresholdArguments' -Value {
return @ {
'-InputValue' = $this . Value ;
'-BaseValue' = $this . BaseValue ;
'-Unit' = $this . Unit ;
'-CheckName' = $this . __GetName ( ) ;
2025-01-29 08:45:53 -05:00
'-PerfDataLabel' = $this . __CreatePerfDataLabel ( ) ;
2021-07-05 11:48:40 -04:00
'-ThresholdCache' = ( Get-IcingaThresholdCache -CheckCommand $this . __CheckCommand ) ;
2021-05-07 08:38:10 -04:00
'-Translation' = $this . Translation ;
'-TimeInterval' = $this . __TimeInterval ;
2025-04-10 10:35:26 -04:00
'-NoPerfData' = $this . NoPerfData ;
2021-05-07 08:38:10 -04:00
} ;
2019-07-19 13:38:09 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'WarnOutOfRange' -Value {
param ( $Threshold ) ;
2019-07-18 11:54:39 -04:00
2021-07-15 09:37:53 -04:00
if ( $null -ne $Threshold -And $Threshold . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Threshold ) {
$this . WarnOutOfRange ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Threshold' , $Threshold ) ;
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
$this . __WarningValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Warning ) ;
return $this ;
}
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'WarnDateTime' -Value {
param ( $Threshold ) ;
if ( $null -ne $Threshold -And $Threshold . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Threshold ) {
$this . WarnDateTime ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Threshold' , $Threshold ) ;
2021-07-15 09:37:53 -04:00
$ThresholdArguments . Add ( '-DateTime' , $TRUE ) ;
2021-05-07 08:38:10 -04:00
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$this . __WarningValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Warning ) ;
2020-05-12 10:37:08 -04:00
2019-07-18 11:54:39 -04:00
return $this ;
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'WarnIfLike' -Value {
param ( $Threshold ) ;
2019-07-18 11:54:39 -04:00
2025-04-22 07:47:53 -04:00
$this . __RequireThresholdValidation = $FALSE ;
2021-07-15 09:37:53 -04:00
if ( $null -ne $Threshold -And $Threshold . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Threshold ) {
$this . WarnIfLike ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Threshold' , $Threshold ) ;
$ThresholdArguments . Add ( '-Matches' , $TRUE ) ;
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$this . __WarningValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Warning ) ;
2020-05-12 10:37:08 -04:00
2019-07-18 11:54:39 -04:00
return $this ;
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'WarnIfNotLike' -Value {
param ( $Threshold ) ;
2019-07-18 11:54:39 -04:00
2025-04-22 07:47:53 -04:00
$this . __RequireThresholdValidation = $FALSE ;
2021-07-15 09:37:53 -04:00
if ( $null -ne $Threshold -And $Threshold . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Threshold ) {
$this . WarnIfNotLike ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Threshold' , $Threshold ) ;
$ThresholdArguments . Add ( '-NotMatches' , $TRUE ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
$this . __WarningValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Warning ) ;
2020-05-12 10:37:08 -04:00
2019-07-18 11:54:39 -04:00
return $this ;
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'WarnIfMatch' -Value {
param ( $Threshold ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
return $this . WarnIfLike ( $Threshold ) ;
}
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'WarnIfNotMatch' -Value {
param ( $Threshold ) ;
2020-05-12 10:37:08 -04:00
2021-05-07 08:38:10 -04:00
return $this . WarnIfNotLike ( $Threshold ) ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'CritOutOfRange' -Value {
param ( $Threshold ) ;
2019-07-19 13:38:09 -04:00
2021-07-15 09:37:53 -04:00
if ( $null -ne $Threshold -And $Threshold . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Threshold ) {
$this . CritOutOfRange ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Threshold' , $Threshold ) ;
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
$this . __CriticalValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Critical ) ;
return $this ;
}
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'CritDateTime' -Value {
param ( $Threshold ) ;
if ( $null -ne $Threshold -And $Threshold . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Threshold ) {
$this . CritDateTime ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Threshold' , $Threshold ) ;
2021-07-15 09:37:53 -04:00
$ThresholdArguments . Add ( '-DateTime' , $TRUE ) ;
2021-05-07 08:38:10 -04:00
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
$this . __CriticalValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Critical ) ;
2020-05-12 10:37:08 -04:00
2019-07-19 13:38:09 -04:00
return $this ;
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'CritIfLike' -Value {
param ( $Threshold ) ;
2019-07-19 13:38:09 -04:00
2025-04-22 07:47:53 -04:00
$this . __RequireThresholdValidation = $FALSE ;
2021-07-15 09:37:53 -04:00
if ( $null -ne $Threshold -And $Threshold . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Threshold ) {
$this . CritIfLike ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Threshold' , $Threshold ) ;
$ThresholdArguments . Add ( '-Matches' , $TRUE ) ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
$this . __CriticalValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Critical ) ;
2020-05-12 10:37:08 -04:00
2019-07-19 13:38:09 -04:00
return $this ;
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'CritIfNotLike' -Value {
param ( $Threshold ) ;
2019-07-18 11:54:39 -04:00
2025-04-22 07:47:53 -04:00
$this . __RequireThresholdValidation = $FALSE ;
2021-07-15 09:37:53 -04:00
if ( $null -ne $Threshold -And $Threshold . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Threshold ) {
$this . CritIfNotLike ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Threshold' , $Threshold ) ;
$ThresholdArguments . Add ( '-NotMatches' , $TRUE ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
$this . __CriticalValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Critical ) ;
2020-05-12 10:37:08 -04:00
2019-07-18 11:54:39 -04:00
return $this ;
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'CritIfMatch' -Value {
param ( $Threshold ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
return $this . CritIfLike ( $Threshold ) ;
}
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'CritIfNotMatch' -Value {
param ( $Threshold ) ;
2020-05-12 10:37:08 -04:00
2021-05-07 08:38:10 -04:00
return $this . CritIfNotLike ( $Threshold ) ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'WarnIfBetweenAndEqual' -Value {
param ( $Min , $Max ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
[ string ] $Threshold = [ string ] :: Format ( '@{0}:{1}' , $Min , $Max ) ;
2020-05-12 10:37:08 -04:00
2021-05-07 08:38:10 -04:00
return $this . WarnOutOfRange ( $Threshold ) ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'CritIfBetweenAndEqual' -Value {
param ( $Min , $Max ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
[ string ] $Threshold = [ string ] :: Format ( '@{0}:{1}' , $Min , $Max ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
return $this . CritOutOfRange ( $Threshold ) ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'WarnIfLowerThan' -Value {
param ( $Value ) ;
2019-09-13 14:44:15 -04:00
2021-07-15 09:37:53 -04:00
if ( $null -ne $Value -And $Value . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Value ) {
$this . WarnIfLowerThan ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ string ] $Threshold = [ string ] :: Format ( '{0}:' , $Value ) ;
2019-07-24 11:19:56 -04:00
2021-05-07 08:38:10 -04:00
return $this . WarnOutOfRange ( $Threshold ) ;
}
2019-07-24 11:19:56 -04:00
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'CritIfLowerThan' -Value {
param ( $Value ) ;
2019-07-24 11:19:56 -04:00
2021-07-15 09:37:53 -04:00
if ( $null -ne $Value -And $Value . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Value ) {
$this . CritIfLowerThan ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ string ] $Threshold = [ string ] :: Format ( '{0}:' , $Value ) ;
2019-07-24 11:19:56 -04:00
2021-05-07 08:38:10 -04:00
return $this . CritOutOfRange ( $Threshold ) ;
2019-07-24 11:19:56 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'WarnIfGreaterThan' -Value {
param ( $Value ) ;
2019-07-18 11:54:39 -04:00
2021-07-15 09:37:53 -04:00
if ( $null -ne $Value -And $Value . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Value ) {
$this . WarnIfGreaterThan ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ string ] $Threshold = [ string ] :: Format ( '~:{0}' , $Value ) ;
2019-07-24 11:10:16 -04:00
2021-05-07 08:38:10 -04:00
return $this . WarnOutOfRange ( $Threshold ) ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'CritIfGreaterThan' -Value {
param ( $Value ) ;
2019-07-19 13:38:09 -04:00
2021-07-15 09:37:53 -04:00
if ( $null -ne $Value -And $Value . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Value ) {
$this . CritIfGreaterThan ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ string ] $Threshold = [ string ] :: Format ( '~:{0}' , $Value ) ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
return $this . CritOutOfRange ( $Threshold ) ;
2019-07-19 13:38:09 -04:00
}
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'WarnIfBetween' -Value {
param ( $Min , $Max ) ;
2019-10-30 13:17:39 -04:00
2021-05-07 08:38:10 -04:00
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Minimum' , $Min ) ;
$ThresholdArguments . Add ( '-Maximum' , $Max ) ;
$ThresholdArguments . Add ( '-IsBetween' , $TRUE ) ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
$this . __WarningValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Warning ) ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
return $this ;
2019-07-19 13:38:09 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'CritIfBetween' -Value {
param ( $Min , $Max ) ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Minimum' , $Min ) ;
$ThresholdArguments . Add ( '-Maximum' , $Max ) ;
$ThresholdArguments . Add ( '-IsBetween' , $TRUE ) ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
$this . __CriticalValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Critical ) ;
return $this ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'WarnIfLowerEqualThan' -Value {
param ( $Threshold ) ;
2019-07-18 11:54:39 -04:00
2021-07-15 09:37:53 -04:00
if ( $null -ne $Threshold -And $Threshold . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Threshold ) {
$this . WarnIfLowerEqualThan ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Threshold' , $Threshold ) ;
$ThresholdArguments . Add ( '-IsLowerEqual' , $TRUE ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
$this . __WarningValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Warning ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
return $this ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'CritIfLowerEqualThan' -Value {
param ( $Threshold ) ;
2019-07-18 11:54:39 -04:00
2021-07-15 09:37:53 -04:00
if ( $null -ne $Threshold -And $Threshold . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Threshold ) {
$this . CritIfLowerEqualThan ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Threshold' , $Threshold ) ;
$ThresholdArguments . Add ( '-IsLowerEqual' , $TRUE ) ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$this . __CriticalValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Critical ) ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
return $this ;
}
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'WarnIfGreaterEqualThan' -Value {
param ( $Threshold ) ;
2019-07-19 13:38:09 -04:00
2021-07-15 09:37:53 -04:00
if ( $null -ne $Threshold -And $Threshold . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Threshold ) {
$this . WarnIfGreaterEqualThan ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Threshold' , $Threshold ) ;
$ThresholdArguments . Add ( '-IsGreaterEqual' , $TRUE ) ;
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
2019-07-18 11:54:39 -04:00
2021-05-07 08:38:10 -04:00
$this . __WarningValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Warning ) ;
2019-10-30 13:17:39 -04:00
2021-05-07 08:38:10 -04:00
return $this ;
2019-07-18 11:54:39 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name 'CritIfGreaterEqualThan' -Value {
param ( $Threshold ) ;
2019-07-19 13:38:09 -04:00
2021-07-15 09:37:53 -04:00
if ( $null -ne $Threshold -And $Threshold . GetType ( ) . BaseType . Name . ToLower ( ) -eq 'array' ) {
foreach ( $entry in $Threshold ) {
$this . CritIfGreaterEqualThan ( $entry ) | Out-Null ;
# Break on first value causing a warning
if ( $ThresholdObject . InRange -eq $FALSE ) {
break ;
}
}
return $this ;
}
2021-05-07 08:38:10 -04:00
[ hashtable ] $ThresholdArguments = $this . __GetBaseThresholdArguments ( ) ;
$ThresholdArguments . Add ( '-Threshold' , $Threshold ) ;
$ThresholdArguments . Add ( '-IsGreaterEqual' , $TRUE ) ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
$this . __CriticalValue = $ThresholdObject ;
$this . __SetCheckState ( $ThresholdObject , $IcingaEnums . IcingaExitCode . Critical ) ;
2019-09-13 14:44:15 -04:00
2021-05-07 08:38:10 -04:00
return $this ;
}
$IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name '__ValidateThresholdInput' -Value {
if ( $null -eq $this . __WarningValue -Or $null -eq $this . __CriticalValue ) {
return ;
2021-02-23 07:40:12 -05:00
}
2025-04-22 07:47:53 -04:00
if ( $this . __RequireThresholdValidation -eq $FALSE ) {
return ;
}
2021-05-07 08:38:10 -04:00
[ bool ] $OutOfRange = $FALSE ;
2019-10-05 15:50:13 -04:00
2024-08-19 10:13:24 -04:00
# Both thresholds use the mode
if ( $this . __WarningValue . Threshold . Mode -eq $this . __CriticalValue . Threshold . Mode ) {
#Handles 20
if ( $this . __WarningValue . Threshold . Mode -eq $IcingaEnums . IcingaThresholdMethod . Default -And $null -ne $this . __WarningValue . Threshold . Value -And $null -ne $this . __CriticalValue . Threshold . Value ) {
if ( $this . __WarningValue . Threshold . Value -gt $this . __CriticalValue . Threshold . Value ) {
$OutOfRange = $TRUE ;
}
2021-05-07 08:38:10 -04:00
}
2019-07-19 13:38:09 -04:00
2024-08-19 10:13:24 -04:00
# Handles: 30:40
if ( $this . __WarningValue . Threshold . Mode -eq $IcingaEnums . IcingaThresholdMethod . Between ) {
if ( $this . __WarningValue . Threshold . StartRange -lt $this . __CriticalValue . Threshold . StartRange ) {
$OutOfRange = $TRUE ;
}
if ( $this . __WarningValue . Threshold . EndRange -gt $this . __CriticalValue . Threshold . EndRange ) {
$OutOfRange = $TRUE ;
}
# Handles: @30:40
} elseif ( $this . __WarningValue . Threshold . Mode -eq $IcingaEnums . IcingaThresholdMethod . Outside ) {
if ( $this . __WarningValue . Threshold . StartRange -ge $this . __CriticalValue . Threshold . StartRange ) {
$OutOfRange = $TRUE ;
}
if ( $this . __WarningValue . Threshold . EndRange -le $this . __CriticalValue . Threshold . EndRange ) {
$OutOfRange = $TRUE ;
}
}
2019-07-19 13:38:09 -04:00
2024-08-19 10:13:24 -04:00
# Handles: 20:
if ( $this . __WarningValue . Threshold . Mode -eq $IcingaEnums . IcingaThresholdMethod . Lower -And $null -ne $this . __WarningValue . Threshold . Value -And $null -ne $this . __CriticalValue . Threshold . Value ) {
if ( $this . __WarningValue . Threshold . Value -lt $this . __CriticalValue . Threshold . Value ) {
$OutOfRange = $TRUE ;
}
2019-07-19 13:38:09 -04:00
}
2021-05-07 08:38:10 -04:00
2024-08-19 10:13:24 -04:00
# Handles: ~:20
if ( $this . __WarningValue . Threshold . Mode -eq $IcingaEnums . IcingaThresholdMethod . Greater -And $null -ne $this . __WarningValue . Threshold . Value -And $null -ne $this . __CriticalValue . Threshold . Value ) {
if ( $this . __WarningValue . Threshold . Value -gt $this . __CriticalValue . Threshold . Value ) {
$OutOfRange = $TRUE ;
}
2021-05-07 08:38:10 -04:00
}
2024-08-19 10:13:24 -04:00
} else {
# Todo: Implement handling for mixed modes
2021-05-07 08:38:10 -04:00
}
if ( $OutOfRange ) {
2024-08-19 10:13:24 -04:00
$this . SetUnknown ( [ string ] :: Format ( 'Warning threshold range "{0}" is greater than Critical threshold range "{1}"' , $this . __WarningValue . Threshold . Threshold , $this . __CriticalValue . Threshold . Threshold ) , $TRUE ) | Out-Null ;
2021-05-07 08:38:10 -04:00
}
2019-07-19 13:38:09 -04:00
}
2021-05-07 08:38:10 -04:00
$IcingaCheck . __ValidateObject ( ) ;
$IcingaCheck . __ValidateUnit ( ) ;
2022-05-24 10:44:52 -04:00
$IcingaCheck . __ValidateMetricsName ( ) ;
2021-07-15 09:37:53 -04:00
$IcingaCheck . __SetCurrentExecutionTime ( ) ;
2021-05-07 08:38:10 -04:00
$IcingaCheck . __AddCheckDataToCache ( ) ;
$IcingaCheck . __SetInternalTimeInterval ( ) ;
$IcingaCheck . __ConvertMinMax ( ) ;
2019-07-19 13:38:09 -04:00
2021-05-07 08:38:10 -04:00
return $IcingaCheck ;
2019-07-18 11:54:39 -04:00
}