Skip to content

Commit 3a4f3f0

Browse files
authored
Merge pull request #290 from DOliana:master
Add plugin to check JSON-Response This plugin is meant to 1. make an http call (supports basic auth) 2. parse the response if it is JSON 3. check the values in the JSON-response against provided thresholds
2 parents f79ee03 + 923ba90 commit 3a4f3f0

13 files changed

+1036
-52
lines changed

config/director/Invoke-IcingaCheckHttpJsonResponse.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

config/director/Plugins_Bundle.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
object CheckCommand "Invoke-IcingaCheckHttpJsonResponse" {
2+
import "PowerShell Base"
3+
4+
arguments += {
5+
"-ServerPath" = {
6+
set_if = {{
7+
var str = macro("$IcingaCheckHttpJsonResponse_String_ServerPath$"); if (len(str) == 0) { return false; }; return true;
8+
}}
9+
description = "Path for the request, example '/v1/my_endpoint'"
10+
value = {{
11+
var str = macro("$IcingaCheckHttpJsonResponse_String_ServerPath$");
12+
var argLen = len(str);
13+
if (argLen == 0) {
14+
return;
15+
}
16+
if (argLen != 0 && str.substr(0,1) == "'" && str.substr(argLen - 1, argLen) == "'") {
17+
return str;
18+
}
19+
return ("'" + str + "'");
20+
}}
21+
order = 3
22+
}
23+
"-Verbosity" = {
24+
description = "Changes the behavior of the plugin output which check states are printed: 0 (default): Only service checks/packages with state not OK will be printed 1: Only services with not OK will be printed including OK checks of affected check packages including Package config 2: Everything will be printed regardless of the check state 3: Identical to Verbose 2, but prints in addition the check package configuration e.g (All must be [OK])"
25+
value = "$IcingaCheckHttpJsonResponse_Int32_Verbosity$"
26+
order = 13
27+
}
28+
"-StatusOnRequestError" = {
29+
set_if = {{
30+
var str = macro("$IcingaCheckHttpJsonResponse_String_StatusOnRequestError$"); if (len(str) == 0) { return false; }; return true;
31+
}}
32+
description = "Status to set when the webservice cannot be reached or an error (e.g. 500) is returned - default is Unknown See https://icinga.com/docs/icinga-for-windows/latest/plugins/doc/10-Icinga-Plugins/ for description of threshold values"
33+
value = {{
34+
var str = macro("$IcingaCheckHttpJsonResponse_String_StatusOnRequestError$");
35+
var argLen = len(str);
36+
if (argLen == 0) {
37+
return;
38+
}
39+
if (argLen != 0 && str.substr(0,1) == "'" && str.substr(argLen - 1, argLen) == "'") {
40+
return str;
41+
}
42+
return ("'" + str + "'");
43+
}}
44+
order = 12
45+
}
46+
"-NoPerfData" = {
47+
set_if = "$IcingaCheckHttpJsonResponse_Switchparameter_NoPerfData$"
48+
order = 99
49+
}
50+
"-Password" = {
51+
description = "Credentials to use for basic auth"
52+
value = "(ConvertTo-IcingaSecureString '$IcingaCheckHttpJsonResponse_Securestring_Password$')"
53+
order = 6
54+
}
55+
"-Username" = {
56+
set_if = {{
57+
var str = macro("$IcingaCheckHttpJsonResponse_String_Username$"); if (len(str) == 0) { return false; }; return true;
58+
}}
59+
description = "Credentials to use for basic auth"
60+
value = {{
61+
var str = macro("$IcingaCheckHttpJsonResponse_String_Username$");
62+
var argLen = len(str);
63+
if (argLen == 0) {
64+
return;
65+
}
66+
if (argLen != 0 && str.substr(0,1) == "'" && str.substr(argLen - 1, argLen) == "'") {
67+
return str;
68+
}
69+
return ("'" + str + "'");
70+
}}
71+
order = 5
72+
}
73+
"-ValuePaths" = {
74+
description = "paths to look for values in the JSON object that is checked, including an alias for each parameter. Example: 'myAlias01:value01','myAlias02:nested.object.value02', 'myAlias03:'object'.'my.Par.With.Dots''"
75+
value = {{
76+
var arr = macro("$IcingaCheckHttpJsonResponse_Array_ValuePaths$");
77+
if (len(arr) == 0) {
78+
return "@()";
79+
}
80+
var psarr = arr.map(
81+
x => if (typeof(x) == String) {
82+
var argLen = len(x);
83+
if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
84+
x;
85+
} else {
86+
"'" + x + "'";
87+
}
88+
} else {
89+
x;
90+
}
91+
).join(",");
92+
return "@(" + psarr + ")";
93+
}}
94+
order = 8
95+
}
96+
"-ValueTypes" = {
97+
description = "Value types of each parameter. Supported Types: Numeric, Boolean, DateTime, String Example: 'myAlias01:Numeric','myAlias02:DateTime'"
98+
value = {{
99+
var arr = macro("$IcingaCheckHttpJsonResponse_Array_ValueTypes$");
100+
if (len(arr) == 0) {
101+
return "@()";
102+
}
103+
var psarr = arr.map(
104+
x => if (typeof(x) == String) {
105+
var argLen = len(x);
106+
if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
107+
x;
108+
} else {
109+
"'" + x + "'";
110+
}
111+
} else {
112+
x;
113+
}
114+
).join(",");
115+
return "@(" + psarr + ")";
116+
}}
117+
order = 9
118+
}
119+
"-C" = {
120+
value = "try { Use-Icinga -Minimal; } catch { Write-Output 'The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details'; Write-Output 'Error:' $$($$_.Exception.Message)Components:`r`n$$( Get-Module -ListAvailable 'icinga-powershell-*' )`r`n'Module-Path:'`r`n$$($$Env:PSModulePath); exit 3; }; Exit-IcingaExecutePlugin -Command 'Invoke-IcingaCheckHttpJsonResponse' "
121+
order = 0
122+
}
123+
"-ThresholdInterval" = {
124+
set_if = {{
125+
var str = macro("$IcingaCheckHttpJsonResponse_String_ThresholdInterval$"); if (len(str) == 0) { return false; }; return true;
126+
}}
127+
description = "Change the value your defined threshold checks against from the current value to a collected time threshold of the Icinga for Windows daemon, as described here: https://icinga.com/docs/icinga-for-windows/latest/doc/service/10-Register-Service-Checks/ An example for this argument would be 1m or 15m which will use the average of 1m or 15m for monitoring."
128+
value = {{
129+
var str = macro("$IcingaCheckHttpJsonResponse_String_ThresholdInterval$");
130+
var argLen = len(str);
131+
if (argLen == 0) {
132+
return;
133+
}
134+
if (argLen != 0 && str.substr(0,1) == "'" && str.substr(argLen - 1, argLen) == "'") {
135+
return str;
136+
}
137+
return ("'" + str + "'");
138+
}}
139+
order = 100
140+
}
141+
"-ServerUri" = {
142+
set_if = {{
143+
var str = macro("$IcingaCheckHttpJsonResponse_String_ServerUri$"); if (len(str) == 0) { return false; }; return true;
144+
}}
145+
description = "Base URI of the server, example 'https://example.comm'"
146+
value = {{
147+
var str = macro("$IcingaCheckHttpJsonResponse_String_ServerUri$");
148+
var argLen = len(str);
149+
if (argLen == 0) {
150+
return;
151+
}
152+
if (argLen != 0 && str.substr(0,1) == "'" && str.substr(argLen - 1, argLen) == "'") {
153+
return str;
154+
}
155+
return ("'" + str + "'");
156+
}}
157+
order = 2
158+
}
159+
"-Critical" = {
160+
description = "Critical thresholds using icinga-powershell syntax. Example: 'myNumericAlias01:~:2','myDateTimeAlias:-10d', 'myBooleanAlias:True'"
161+
value = {{
162+
var arr = macro("$IcingaCheckHttpJsonResponse_Array_Critical$");
163+
if (len(arr) == 0) {
164+
return "@()";
165+
}
166+
var psarr = arr.map(
167+
x => if (typeof(x) == String) {
168+
var argLen = len(x);
169+
if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
170+
x;
171+
} else {
172+
"'" + x + "'";
173+
}
174+
} else {
175+
x;
176+
}
177+
).join(",");
178+
return "@(" + psarr + ")";
179+
}}
180+
order = 11
181+
}
182+
"-IgnoreSSL" = {
183+
set_if = "$IcingaCheckHttpJsonResponse_Switchparameter_IgnoreSSL$"
184+
order = 99
185+
}
186+
"-Timeout" = {
187+
description = "Timeout in seconds before the http request is aborted. Defaults to 30"
188+
value = "$IcingaCheckHttpJsonResponse_Int32_Timeout$"
189+
order = 7
190+
}
191+
"-Warning" = {
192+
description = "Warning thresholds using icinga-powershell syntax. Example: 'myNumericAlias01:~:2','myDateTimeAlias:-10d', 'myBooleanAlias:True'"
193+
value = {{
194+
var arr = macro("$IcingaCheckHttpJsonResponse_Array_Warning$");
195+
if (len(arr) == 0) {
196+
return "@()";
197+
}
198+
var psarr = arr.map(
199+
x => if (typeof(x) == String) {
200+
var argLen = len(x);
201+
if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
202+
x;
203+
} else {
204+
"'" + x + "'";
205+
}
206+
} else {
207+
x;
208+
}
209+
).join(",");
210+
return "@(" + psarr + ")";
211+
}}
212+
order = 10
213+
}
214+
"-QueryParameter" = {
215+
set_if = {{
216+
var str = macro("$IcingaCheckHttpJsonResponse_String_QueryParameter$"); if (len(str) == 0) { return false; }; return true;
217+
}}
218+
description = "Query parameter for the request without ?, example 'command=example'"
219+
value = {{
220+
var str = macro("$IcingaCheckHttpJsonResponse_String_QueryParameter$");
221+
var argLen = len(str);
222+
if (argLen == 0) {
223+
return;
224+
}
225+
if (argLen != 0 && str.substr(0,1) == "'" && str.substr(argLen - 1, argLen) == "'") {
226+
return str;
227+
}
228+
return ("'" + str + "'");
229+
}}
230+
order = 4
231+
}
232+
"-NegateStringResults" = {
233+
set_if = "$IcingaCheckHttpJsonResponse_Switchparameter_NegateStringResults$"
234+
order = 99
235+
}
236+
}
237+
vars.IcingaCheckHttpJsonResponse_Switchparameter_NegateStringResults = false
238+
vars.IcingaCheckHttpJsonResponse_Switchparameter_IgnoreSSL = false
239+
vars.IcingaCheckHttpJsonResponse_Switchparameter_NoPerfData = false
240+
}

0 commit comments

Comments
 (0)