Added proper exception handling for Cache write failures

This commit is contained in:
Lord Hepipud 2019-09-17 17:56:56 +02:00
parent f92fc80707
commit 0d7954617c
2 changed files with 7 additions and 1 deletions

View file

@ -28,5 +28,10 @@ function Set-IcingaCacheData()
}
}
try {
Set-Content -Path $CacheFile -Value (ConvertTo-Json -InputObject $cacheData -Depth 100) | Out-Null;
} catch {
Exit-IcingaThrowException -InputString $_.Exception -CustomMessage (Get-IcingaCacheDir) -StringPattern 'System.UnauthorizedAccessException' -ExceptionType 'Permission' -ExceptionThrown $IcingaExceptions.Permission.CacheFolder;
Exit-IcingaThrowException -CustomMessage $_.Exception -ExceptionType 'Unhandled' -Force;
}
}

View file

@ -6,6 +6,7 @@
[hashtable]$Permission = @{
PerformanceCounter = 'A Plugin failed to fetch Performance Counter information. This may be caused when the used Service User is not permitted to access these information. To fix this, please add the User the Icinga Agent is running on into the "Performance Log Users" group and restart the service.';
CacheFolder = "A plugin failed to write new data into the configured cache directory. Please update the permissions of this folder to allow write access for the user the Icinga Service is running with or use another folder as cache directory.";
};
[hashtable]$Inputs = @{