2019-07-22 07:17:07 -04:00
|
|
|
<#
|
2020-08-20 08:16:16 -04:00
|
|
|
.SYNOPSIS
|
|
|
|
|
This will create a Performance Counter object in case a counter instance
|
2022-01-14 16:18:59 -05:00
|
|
|
does not exist, but still returning default members to allow us to smoothly
|
2020-08-20 08:16:16 -04:00
|
|
|
execute our code
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
This will create a Performance Counter object in case a counter instance
|
2022-01-14 16:18:59 -05:00
|
|
|
does not exist, but still returning default members to allow us to smoothly
|
2020-08-20 08:16:16 -04:00
|
|
|
execute our code
|
|
|
|
|
.FUNCTIONALITY
|
|
|
|
|
This will create a Performance Counter object in case a counter instance
|
2022-01-14 16:18:59 -05:00
|
|
|
does not exist, but still returning default members to allow us to smoothly
|
2020-08-20 08:16:16 -04:00
|
|
|
execute our code
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS>New-IcingaPerformanceCounterNullObject '\Processor(20)\%processor time' -ErrorMessage 'This counter with instance 20 does not exist';
|
|
|
|
|
|
|
|
|
|
FullName ErrorMessage
|
|
|
|
|
-------- ------------
|
|
|
|
|
\Processor(20)\%processor time This counter with instance 20 does not exist
|
|
|
|
|
.PARAMETER FullName
|
|
|
|
|
The full path/name of the Performance Counter which does not exist
|
|
|
|
|
.PARAMETER ErrorMessage
|
|
|
|
|
The error message which is included within the 'error' member of the Performance Counter
|
|
|
|
|
.INPUTS
|
|
|
|
|
System.String
|
|
|
|
|
.OUTPUTS
|
|
|
|
|
System.PSObject
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/Icinga/icinga-powershell-framework
|
|
|
|
|
#>
|
|
|
|
|
|
2020-08-04 08:48:32 -04:00
|
|
|
function New-IcingaPerformanceCounterNullObject()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[string]$FullName = '',
|
|
|
|
|
[string]$ErrorMessage = ''
|
|
|
|
|
);
|
2019-07-22 07:17:07 -04:00
|
|
|
|
2020-08-04 08:48:32 -04:00
|
|
|
$pc_instance = New-Object -TypeName PSObject;
|
|
|
|
|
$pc_instance | Add-Member -MemberType NoteProperty -Name 'FullName' -Value $FullName;
|
|
|
|
|
$pc_instance | Add-Member -MemberType NoteProperty -Name 'ErrorMessage' -Value $ErrorMessage;
|
2019-07-22 07:17:07 -04:00
|
|
|
|
2020-08-04 08:48:32 -04:00
|
|
|
$pc_instance | Add-Member -MemberType ScriptMethod -Name 'Name' -Value {
|
|
|
|
|
return $this.FullName;
|
|
|
|
|
}
|
2019-07-22 07:17:07 -04:00
|
|
|
|
2020-08-04 08:48:32 -04:00
|
|
|
$pc_instance | Add-Member -MemberType ScriptMethod -Name 'Value' -Value {
|
2022-01-14 16:18:59 -05:00
|
|
|
[hashtable]$ErrorMessage = @{ };
|
2019-07-22 07:17:07 -04:00
|
|
|
|
2020-08-04 08:48:32 -04:00
|
|
|
$ErrorMessage.Add('value', $null);
|
|
|
|
|
$ErrorMessage.Add('sample', $null);
|
|
|
|
|
$ErrorMessage.Add('help', $null);
|
|
|
|
|
$ErrorMessage.Add('type', $null);
|
|
|
|
|
$ErrorMessage.Add('error', $this.ErrorMessage);
|
2019-07-22 07:17:07 -04:00
|
|
|
|
2020-08-04 08:48:32 -04:00
|
|
|
return $ErrorMessage;
|
|
|
|
|
}
|
2019-07-22 07:17:07 -04:00
|
|
|
|
2020-08-04 08:48:32 -04:00
|
|
|
return $pc_instance;
|
|
|
|
|
}
|