icinga-powershell-framework/lib/icinga/plugin/ConvertTo-IcingaPluginOutputTranslation.psm1

35 lines
814 B
PowerShell
Raw Normal View History

2021-05-07 08:38:10 -04:00
function ConvertTo-IcingaPluginOutputTranslation()
{
param (
$Value = $null,
[hashtable]$Translation = @{ }
);
if ($null -eq $Value) {
return 'Nothing';
}
if ($null -eq $Translation -Or $Translation.Count -eq 0) {
return $Value;
}
[array]$TranslationKeys = $Translation.Keys;
[array]$TranslationValues = $Translation.Values;
[int]$Index = 0;
[bool]$FoundTranslation = $FALSE;
foreach ($entry in $TranslationKeys) {
if (([string]($Value)).ToLower() -eq ([string]($entry)).ToLower()) {
$FoundTranslation = $TRUE;
break;
}
$Index += 1;
}
if ($FoundTranslation -eq $FALSE) {
return $Value;
}
return $TranslationValues[$Index];
}