You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge pull request #645 from Icinga:fix/error_and_exception_handling_while_using_api
Fix: Error and exception handling over API checks
Fixes error and exception handling while using API-Checks, which now will in most cases always return a proper check-result object and also abort while running into plugin execution errors, in case a server is not reachable by the time sync plugin as example.
Copy file name to clipboardExpand all lines: doc/100-General/10-Changelog.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
18
18
*[#615](https://github.com/Icinga/icinga-powershell-framework/issues/615) Fixes the framework migration tasks which fails in case multiple versions of the framework are installed, printing warnings in case there is
19
19
*[#617](https://github.com/Icinga/icinga-powershell-framework/issues/617) Fixes failing calls for plugins which use a switch argument like `-NoPerfData`, which is followed directly by the `-ThresholdInterval` argument
20
20
*[#621](https://github.com/Icinga/icinga-powershell-framework/pull/621) Fixes `-ThresholdInterval` key detection on newer systems
21
+
*[#645](https://github.com/Icinga/icinga-powershell-framework/pull/645) Fixes error and exception handling while using API-Checks, which now will in most cases always return a proper check-result object and also abort while running into plugin execution errors, in case a server is not reachable by the time sync plugin for example
# Check if there are an inventory aliases configured
17
19
# This should be maintained by the developer and not occur
@@ -56,10 +58,20 @@ function Invoke-IcingaApiChecksRESTCall()
56
58
}
57
59
58
60
if ((Test-IcingaRESTApiCommand-Command $ExecuteCommand-Endpoint 'apichecks') -eq$FALSE) {
61
+
62
+
Add-IcingaHashtableItem`
63
+
-Hashtable $ContentResponse`
64
+
-Key $ExecuteCommand`
65
+
-Value @{
66
+
'exitcode'=3;
67
+
'checkresult'= [string]::Format('[UNKNOWN] Icinga Permission error was thrown: Permission denied for command "{0}"{1}{1}The command "{0}" you are trying to execute over the REST-Api endpoint "apichecks" is not whitelisted for remote execution.',$ExecuteCommand, (New-IcingaNewLine));
-ContentBody ([string]::Format('The command "{0}" you are trying to execute over this REST-Api endpoint "apichecks" is not whitelisted for remote execution.',$ExecuteCommand))
74
+
-ContentBody $ContentResponse
63
75
) -Stream $Connection.Stream;
64
76
65
77
return;
@@ -100,9 +112,19 @@ function Invoke-IcingaApiChecksRESTCall()
100
112
-Value $CmdArgValue|Out-Null;
101
113
};
102
114
103
-
[int]$ExitCode=&$ExecuteCommand@Arguments;
115
+
try {
116
+
[int]$ExitCode=&$ExecuteCommand@Arguments;
117
+
} catch {
118
+
[int]$ExitCode=3;
119
+
$InternalError=$_.Exception.Message;
120
+
}
104
121
} elseif ($Request.Method-eq'GET') {
105
-
[int]$ExitCode=&$ExecuteCommand;
122
+
try {
123
+
[int]$ExitCode=&$ExecuteCommand;
124
+
} catch {
125
+
[int]$ExitCode=3;
126
+
$InternalError=$_.Exception.Message;
127
+
}
106
128
} else {
107
129
Send-IcingaTCPClientMessage-Message (
108
130
New-IcingaTCPClientRESTMessage`
@@ -115,7 +137,16 @@ function Invoke-IcingaApiChecksRESTCall()
115
137
116
138
# Once the check is executed, the plugin output and the performance data are stored
117
139
# within a special cache map we can use for accessing
0 commit comments