mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Adds new exception messages and custom exception handling
This commit is contained in:
parent
2b740785fe
commit
7860818be1
2 changed files with 25 additions and 11 deletions
|
|
@ -5,7 +5,7 @@ function Exit-IcingaThrowException()
|
|||
[string]$StringPattern,
|
||||
[string]$CustomMessage,
|
||||
[string]$ExceptionThrown,
|
||||
[ValidateSet('Permission','Input','Unhandled')]
|
||||
[ValidateSet('Permission','Input','Configuration','Unhandled','Custom')]
|
||||
[string]$ExceptionType = 'Unhandled',
|
||||
[switch]$Force
|
||||
);
|
||||
|
|
@ -32,9 +32,16 @@ function Exit-IcingaThrowException()
|
|||
$ExceptionTypeString = 'Invalid Input';
|
||||
$ExceptionMessageLib = $IcingaExceptions.Inputs;
|
||||
};
|
||||
'Configuration' {
|
||||
$ExceptionTypeString = 'Invalid Configuration';
|
||||
$ExceptionMessageLib = $IcingaExceptions.Configuration;
|
||||
};
|
||||
'Unhandled' {
|
||||
$ExceptionTypeString = 'Unhandled';
|
||||
};
|
||||
'Custom' {
|
||||
$ExceptionTypeString = 'Custom';
|
||||
};
|
||||
}
|
||||
|
||||
[string]$ExceptionName = '';
|
||||
|
|
@ -47,9 +54,10 @@ function Exit-IcingaThrowException()
|
|||
}
|
||||
}
|
||||
} else {
|
||||
$ExceptionName = 'Unhandled Exception';
|
||||
$ExceptionName = [string]::Format('{0} Exception', $ExceptionTypeString);
|
||||
$ExceptionThrown = [string]::Format(
|
||||
'Unhandled exception occured:{0}{1}',
|
||||
'{0} exception occured:{1}{2}',
|
||||
$ExceptionTypeString,
|
||||
"`r`n",
|
||||
$InputString
|
||||
);
|
||||
|
|
|
|||
|
|
@ -5,17 +5,22 @@
|
|||
#>
|
||||
|
||||
[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.";
|
||||
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 = @{
|
||||
PerformanceCounter = 'A plugin failed to fetch Performance Counter information. Please ensure the counter is written properly and available on your system.';
|
||||
EventLogLogName = 'Failed to fetch EventLog information. Please specify a valid LogName.';
|
||||
EventLog = 'Failed to fetch EventLog information. Please check your inputs for EntryTypes and other categories and try again.';
|
||||
ConversionUnitMissing = 'Unable to parse input value. You have to add an unit to your input value. Example: "10GB". Allowed units are: "B, KB, MB, GB, TB, PB, KiB, MiB, GiB, TiB, PiB".';
|
||||
PerformanceCounter = 'A plugin failed to fetch Performance Counter information. Please ensure the counter is written properly and available on your system.';
|
||||
EventLogLogName = 'Failed to fetch EventLog information. Please specify a valid LogName.';
|
||||
EventLog = 'Failed to fetch EventLog information. Please check your inputs for EntryTypes and other categories and try again.';
|
||||
ConversionUnitMissing = 'Unable to parse input value. You have to add an unit to your input value. Example: "10GB". Allowed units are: "B, KB, MB, GB, TB, PB, KiB, MiB, GiB, TiB, PiB".';
|
||||
};
|
||||
|
||||
[hashtable]$Configuration = @{
|
||||
PluginArgumentConflict = 'Your plugin argument configuration is causing a conflict. Mostly this error is caused by missmatching configurations by enabling multiple switch arguments which are resulting in a conflicting configuration for the plugin.';
|
||||
PluginArgumentmissing = 'Your plugin argument configuration is missing mandatory arguments. This is error is caused when mandatory or required arguments are missing from a plugin call and the operation is unable to process without them.';
|
||||
}
|
||||
|
||||
<#
|
||||
# Once we defined a new enum hashtable above, simply add it to this list
|
||||
# to make it available within the entire module.
|
||||
|
|
@ -24,8 +29,9 @@
|
|||
# $IcingaExceptionEnums.IcingaExecptionHandlers.PerformanceCounter
|
||||
#>
|
||||
[hashtable]$IcingaExceptions = @{
|
||||
Permission = $Permission;
|
||||
Inputs = $Inputs;
|
||||
Permission = $Permission;
|
||||
Inputs = $Inputs;
|
||||
Configuration = $Configuration;
|
||||
}
|
||||
|
||||
Export-ModuleMember -Variable @( 'IcingaExceptions' );
|
||||
|
|
|
|||
Loading…
Reference in a new issue