Splitt into ConvertTo-ServiceStatusCode, to fit project structure, changed Free Space to Used Space

This commit is contained in:
Crited 2019-07-24 11:44:33 +02:00
parent 8cae29a79a
commit 802f5b3205
4 changed files with 17 additions and 18 deletions

View file

@ -13,7 +13,7 @@ function Invoke-IcingaCheckService()
$FoundService = Get-IcingaServices -Service $Service; $FoundService = Get-IcingaServices -Service $Service;
$ServiceName = $FoundService.Values.metadata.ServiceName; $ServiceName = $FoundService.Values.metadata.ServiceName;
$DisplayName = $FoundService.Values.metadata.DisplayName; $DisplayName = $FoundService.Values.metadata.DisplayName;
$Status = Get-IcingaServicesStatusTranslation -Status $Status; $Status = ConvertTo-ServiceStatusCode -Status $Status;
$StatusRaw = $FoundService.Values.configuration.Status.raw; $StatusRaw = $FoundService.Values.configuration.Status.raw;
$IcingaCheck = New-IcingaCheck -Name ([string]::Format('Service "{0} ({1})"', $DisplayName, $ServiceName)) -Value $StatusRaw -ObjectExists $FoundService -ValueTranslation $ProviderEnums.ServicesStatus; $IcingaCheck = New-IcingaCheck -Name ([string]::Format('Service "{0} ({1})"', $DisplayName, $ServiceName)) -Value $StatusRaw -ObjectExists $FoundService -ValueTranslation $ProviderEnums.ServicesStatus;

View file

@ -1,7 +1,7 @@
Import-IcingaLib core\perfcounter; Import-IcingaLib core\perfcounter;
Import-IcingaLib icinga\plugin; Import-IcingaLib icinga\plugin;
function Invoke-IcingaCheckFreePartition() function Invoke-IcingaCheckUsedPartitionSpace()
{ {
param( param(
$Warning, $Warning,
@ -33,7 +33,7 @@ function Invoke-IcingaCheckFreePartition()
} }
} }
$IcingaCheck = New-IcingaCheck -Name ([string]::Format('Partition {0}', $Letter)) -Value $DiskFree.([string]::Format($Letter))."Free Space" -Unit '%'; $IcingaCheck = New-IcingaCheck -Name ([string]::Format('Partition {0}', $Letter)) -Value (100-($DiskFree.([string]::Format($Letter))."Free Space")) -Unit '%';
$IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null; $IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
$DiskPackage.AddCheck($IcingaCheck); $DiskPackage.AddCheck($IcingaCheck);
} }

View file

@ -0,0 +1,14 @@
function ConvertTo-ServiceStatusCode()
{
param (
$Status
)
if ($Status -match "^\d+$") {
return $Status
} else {
$Status = $ProviderEnums.ServiceStatus.($Status);
}
return $Status;
}

View file

@ -63,18 +63,3 @@ function Get-IcingaServices()
} }
return $ServiceData; return $ServiceData;
} }
function Get-IcingaServicesStatusTranslation()
{
param (
$Status
)
if ($Status -match "^\d+$") {
return $Status
} else {
$Status = $ProviderEnums.ServiceStatus.($Status);
}
return $Status;
}