Skip to content

Commit 4109514

Browse files
authored
Merge pull request #135 from Icinga:feature/check_plugin_tcp
Feature: Adds new check plugin Invoke-IcingaCheckTCP Adds new check plugin Invoke-IcingaCheckCPU to check tcp connections for ports
2 parents fb78a9e + 9b80e18 commit 4109514

File tree

10 files changed

+348
-9
lines changed

10 files changed

+348
-9
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"DataList":{"IcingaCheckTCP Verbosity":{"list_name":"IcingaCheckTCP Verbosity","originalId":"2","entries":[{"allowed_roles":null,"entry_value":"0","entry_name":"0","format":"string"},{"allowed_roles":null,"entry_value":"1","entry_name":"1","format":"string"},{"allowed_roles":null,"entry_value":"2","entry_name":"2","format":"string"}],"owner":"stein"}},"Command":{"Invoke-IcingaCheckTCP":{"fields":[{"datafield_id":2,"is_required":"n","var_filter":null},{"datafield_id":3,"is_required":"n","var_filter":null},{"datafield_id":4,"is_required":"n","var_filter":null},{"datafield_id":5,"is_required":"n","var_filter":null},{"datafield_id":6,"is_required":"n","var_filter":null},{"datafield_id":7,"is_required":"n","var_filter":null},{"datafield_id":8,"is_required":"n","var_filter":null}],"object_name":"Invoke-IcingaCheckTCP","arguments":{"-C":{"value":"try { Use-Icinga; } catch { Write-Output \u0027The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details\u0027; exit 3; }; Exit-IcingaPluginNotInstalled \u0027Invoke-IcingaCheckTCP\u0027; exit Invoke-IcingaCheckTCP","order":"0"},"-Verbosity":{"value":"$IcingaCheckTCP_Object_Verbosity$","order":"6"},"-Warning":{"value":"$IcingaCheckTCP_Object_Warning$","order":"4"},"-Address":{"value":"$IcingaCheckTCP_String_Address$","order":"2"},"-Negate":{"set_if":"$IcingaCheckTCP_Switchparameter_Negate$","set_if_format":"string","order":"99"},"-Critical":{"value":"$IcingaCheckTCP_Object_Critical$","order":"5"},"-NoPerfData":{"set_if":"$IcingaCheckTCP_Switchparameter_NoPerfData$","set_if_format":"string","order":"99"},"-Ports":{"value":{"body":"var arr = macro(\"$IcingaCheckTCP_Array_Ports$\");\r\nif (len(arr) == 0) {\r\nreturn \"@()\";\r\n}\r\nreturn arr.join(\",\");","type":"Function"},"order":"3"}},"imports":["PowerShell Base"],"object_type":"object","vars":{"IcingaCheckTCP_Switchparameter_Negate":false,"IcingaCheckTCP_Switchparameter_NoPerfData":false}},"PowerShell Base":{"methods_execute":"PluginCheck","object_name":"PowerShell Base","vars":{},"is_string":null,"command":"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe","zone":null,"disabled":false,"fields":[],"arguments":{},"imports":[],"object_type":"object","timeout":"180"}},"Datafield":{"7":{"settings":{"visbility":"visible"},"description":"Disables the performance data output of this plugin. Default to FALSE.","caption":"NoPerfData","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeBoolean","originalId":"7","varname":"IcingaCheckTCP_Switchparameter_NoPerfData","format":null},"3":{"settings":{"visbility":"visible"},"description":"A single or a list of ports to check on the target address","caption":"Ports","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeArray","originalId":"3","varname":"IcingaCheckTCP_Array_Ports","format":null},"2":{"settings":{"visbility":"visible"},"description":"The IP address or FQDN of the target host","caption":"Address","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeString","originalId":"2","varname":"IcingaCheckTCP_String_Address","format":null},"4":{"settings":{"visbility":"visible"},"description":"By default the plugin will return [CRITICAL] in case connections to a port are not possible. By setting this argument,\nthe plugin will return [CRITICAL] for successful connections instead","caption":"Negate","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeBoolean","originalId":"4","varname":"IcingaCheckTCP_Switchparameter_Negate","format":null},"6":{"settings":{"visbility":"visible"},"description":"A critical threshold for the connection time in seconds. Allows the usage of unit additions, like 100ms.\n\nAllowed units: ms, s, m, h, d, w, M, y","caption":"Critical","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeString","originalId":"6","varname":"IcingaCheckTCP_Object_Critical","format":null},"5":{"settings":{"visbility":"visible"},"description":"A warning threshold for the connection time in seconds. Allows the usage of unit additions, like 100ms.\n\nAllowed units: ms, s, m, h, d, w, M, y","caption":"Warning","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeString","originalId":"5","varname":"IcingaCheckTCP_Object_Warning","format":null},"8":{"settings":{"datalist":"IcingaCheckTCP Verbosity","behavior":"strict","data_type":"string"},"description":"Changes the behavior of the plugin output which check states are printed:\n0 (default): Only service checks/packages with state not OK will be printed\n1: Only services with not OK will be printed including OK checks of affected check packages including Package config\n2: Everything will be printed regardless of the check state","caption":"Verbosity","datatype":"Icinga\\Module\\Director\\DataType\\DataTypeDatalist","originalId":"8","varname":"IcingaCheckTCP_Object_Verbosity","format":null}}}

config/director/Plugins_Bundle.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
object CheckCommand "Invoke-IcingaCheckTCP" {
2+
import "PowerShell Base"
3+
4+
arguments += {
5+
"-C" = {
6+
value = "try { Use-Icinga; } 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'; exit 3; }; Exit-IcingaPluginNotInstalled 'Invoke-IcingaCheckTCP'; exit Invoke-IcingaCheckTCP"
7+
order = 0
8+
}
9+
"-Verbosity" = {
10+
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"
11+
value = "$IcingaCheckTCP_Object_Verbosity$"
12+
order = 6
13+
}
14+
"-Warning" = {
15+
description = "A warning threshold for the connection time in seconds. Allows the usage of unit additions, like 100ms. Allowed units: ms, s, m, h, d, w, M, y"
16+
value = "$IcingaCheckTCP_Object_Warning$"
17+
order = 4
18+
}
19+
"-Address" = {
20+
description = "The IP address or FQDN of the target host"
21+
value = "$IcingaCheckTCP_String_Address$"
22+
order = 2
23+
}
24+
"-Negate" = {
25+
set_if = "$IcingaCheckTCP_Switchparameter_Negate$"
26+
order = 99
27+
}
28+
"-Critical" = {
29+
description = "A critical threshold for the connection time in seconds. Allows the usage of unit additions, like 100ms. Allowed units: ms, s, m, h, d, w, M, y"
30+
value = "$IcingaCheckTCP_Object_Critical$"
31+
order = 5
32+
}
33+
"-NoPerfData" = {
34+
set_if = "$IcingaCheckTCP_Switchparameter_NoPerfData$"
35+
order = 99
36+
}
37+
"-Ports" = {
38+
description = "A single or a list of ports to check on the target address"
39+
value = {{
40+
var arr = macro("$IcingaCheckTCP_Array_Ports$");
41+
if (len(arr) == 0) {
42+
return "@()";
43+
}
44+
return arr.join(",");
45+
}}
46+
order = 3
47+
}
48+
}
49+
vars.IcingaCheckTCP_Switchparameter_Negate = false
50+
vars.IcingaCheckTCP_Switchparameter_NoPerfData = false
51+
}

config/icinga/Plugins_Bundle.conf

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ object CheckCommand "Invoke-IcingaCheckICMP" {
216216

217217
arguments += {
218218
"-WarningPl" = {
219-
description = "Treshold on which the plugin will return 'WARNING' for possible packet loss in %"
219+
description = "Threshold on which the plugin will return 'WARNING' for possible packet loss in %"
220220
value = "$IcingaCheckICMP_Object_WarningPl$"
221221
order = 4
222222
}
@@ -226,7 +226,7 @@ object CheckCommand "Invoke-IcingaCheckICMP" {
226226
order = 6
227227
}
228228
"-Warning" = {
229-
description = "Treshold on which the plugin will return 'WARNING' for the response time in ms"
229+
description = "Threshold on which the plugin will return 'WARNING' for the response time in ms"
230230
value = "$IcingaCheckICMP_Object_Warning$"
231231
order = 2
232232
}
@@ -254,7 +254,7 @@ object CheckCommand "Invoke-IcingaCheckICMP" {
254254
order = 99
255255
}
256256
"-Critical" = {
257-
description = "Treshold on which the plugin will return 'CRITICAL' for the response time in ms"
257+
description = "Threshold on which the plugin will return 'CRITICAL' for the response time in ms"
258258
value = "$IcingaCheckICMP_Object_Critical$"
259259
order = 3
260260
}
@@ -263,7 +263,7 @@ object CheckCommand "Invoke-IcingaCheckICMP" {
263263
order = 99
264264
}
265265
"-CriticalPl" = {
266-
description = "Treshold on which the plugin will return 'CRITICAL' for the response time in ms"
266+
description = "Threshold on which the plugin will return 'CRITICAL' for the response time in ms"
267267
value = "$IcingaCheckICMP_Object_CriticalPl$"
268268
order = 5
269269
}
@@ -438,6 +438,58 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
438438
vars.IcingaCheckUpdates_Switchparameter_NoPerfData = false
439439
}
440440

441+
object CheckCommand "Invoke-IcingaCheckTCP" {
442+
import "PowerShell Base"
443+
444+
arguments += {
445+
"-C" = {
446+
value = "try { Use-Icinga; } 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'; exit 3; }; Exit-IcingaPluginNotInstalled 'Invoke-IcingaCheckTCP'; exit Invoke-IcingaCheckTCP"
447+
order = 0
448+
}
449+
"-Verbosity" = {
450+
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"
451+
value = "$IcingaCheckTCP_Object_Verbosity$"
452+
order = 6
453+
}
454+
"-Warning" = {
455+
description = "A warning threshold for the connection time in seconds. Allows the usage of unit additions, like 100ms. Allowed units: ms, s, m, h, d, w, M, y"
456+
value = "$IcingaCheckTCP_Object_Warning$"
457+
order = 4
458+
}
459+
"-Address" = {
460+
description = "The IP address or FQDN of the target host"
461+
value = "$IcingaCheckTCP_String_Address$"
462+
order = 2
463+
}
464+
"-Negate" = {
465+
set_if = "$IcingaCheckTCP_Switchparameter_Negate$"
466+
order = 99
467+
}
468+
"-Critical" = {
469+
description = "A critical threshold for the connection time in seconds. Allows the usage of unit additions, like 100ms. Allowed units: ms, s, m, h, d, w, M, y"
470+
value = "$IcingaCheckTCP_Object_Critical$"
471+
order = 5
472+
}
473+
"-NoPerfData" = {
474+
set_if = "$IcingaCheckTCP_Switchparameter_NoPerfData$"
475+
order = 99
476+
}
477+
"-Ports" = {
478+
description = "A single or a list of ports to check on the target address"
479+
value = {{
480+
var arr = macro("$IcingaCheckTCP_Array_Ports$");
481+
if (len(arr) == 0) {
482+
return "@()";
483+
}
484+
return arr.join(",");
485+
}}
486+
order = 3
487+
}
488+
}
489+
vars.IcingaCheckTCP_Switchparameter_Negate = false
490+
vars.IcingaCheckTCP_Switchparameter_NoPerfData = false
491+
}
492+
441493
object CheckCommand "Invoke-IcingaCheckPerfcounter" {
442494
import "PowerShell Base"
443495

@@ -757,7 +809,7 @@ object CheckCommand "Invoke-IcingaCheckDiskHealth" {
757809
order = 5
758810
}
759811
"-DiskReadSecCritical" = {
760-
description = "Critical treshold for disk Reads/sec is the rate of read operations on the disk."
812+
description = "Critical threshold for disk Reads/sec is the rate of read operations on the disk."
761813
value = "$IcingaCheckDiskHealth_Object_DiskReadSecCritical$"
762814
order = 7
763815
}
@@ -780,7 +832,7 @@ object CheckCommand "Invoke-IcingaCheckDiskHealth" {
780832
order = 99
781833
}
782834
"-DiskWriteSecWarning" = {
783-
description = "Warning theeshold for disk Writes/sec is the rate of write operations on the disk."
835+
description = "Warning threshold for disk Writes/sec is the rate of write operations on the disk."
784836
value = "$IcingaCheckDiskHealth_Object_DiskWriteSecWarning$"
785837
order = 8
786838
}

doc/10-Icinga-Plugins.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ To test thresholds with different input values, you can use the Framework Cmdlet
3131
* [Invoke-IcingaCheckScheduledTask](plugins/19-Invoke-IcingaCheckScheduledTask.md)
3232
* [Invoke-IcingaCheckService](plugins/13-Invoke-IcingaCheckService.md)
3333
* [Invoke-IcingaCheckStoragePool](plugins/21-Invoke-IcingaCheckStoragePool.md)
34+
* [Invoke-IcingaCheckTCP](plugins/23-Invoke-IcingaCheckTCP.md)
3435
* [Invoke-IcingaCheckTimeSync](plugins/18-Invoke-IcingaCheckTimeSync.md)
3536
* [Invoke-IcingaCheckUpdates](plugins/14-Invoke-IcingaCheckUpdates.md)
3637
* [Invoke-IcingaCheckUptime](plugins/15-Invoke-IcingaCheckUptime.md)

doc/31-Changelog.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ documentation before upgrading to a new release.
77

88
Released closed milestones can be found on [GitHub](https://github.com/Icinga/icinga-powershell-plugins/milestones?state=closed).
99

10-
## 1.4.0 (pending)
10+
## 1.4.0 (2021-03-02)
1111

1212
[Issue and PRs](https://github.com/Icinga/icinga-powershell-plugins/milestone/5?closed=1)
1313

1414
### Enhancements
1515

16-
* [#134](https://github.com/Icinga/icinga-powershell-plugins/pull/134) Adds autoloading for plugin information to standardize the development and projects and fixes plenty of spelling/code styling errosr
16+
* [#134](https://github.com/Icinga/icinga-powershell-plugins/pull/134) Adds autoloading for plugin information to standardize the development and projects and fixes plenty of spelling/code styling errors
17+
* [#135](https://github.com/Icinga/icinga-powershell-plugins/pull/135) Adds new check plugin `Invoke-IcingaCheckTCP`
1718

1819
### Bugfixes
1920

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
# Invoke-IcingaCheckTCP
3+
4+
## Description
5+
6+
Checks the connection for an address and a range of ports and fetches the connection status
7+
including the time require to connect.
8+
9+
Invoke-IcingaCheckTCP connects to a provided address and a single or a range of ports and determines if the
10+
connection was successful or not. In addition the time for a successful connection is measured.
11+
12+
By default the plugin will return [CRITICAL] if the connection is not possible, can how ever be changed by the
13+
`-Negate` argument which will return [CRITICAL] if the connection is possible.
14+
15+
In addition you can measure the connection time and alert by using `-Warning` or `-Critical`.
16+
17+
## Permissions
18+
19+
No special permissions required.
20+
21+
## Arguments
22+
23+
| Argument | Type | Required | Default | Description |
24+
| --- | --- | --- | --- | --- |
25+
| Address | String | false | | The IP address or FQDN of the target host |
26+
| Ports | Array | false | @() | A single or a list of ports to check on the target address |
27+
| Negate | SwitchParameter | false | False | By default the plugin will return [CRITICAL] in case connections to a port are not possible. By setting this argument, the plugin will return [CRITICAL] for successful connections instead |
28+
| Warning | Object | false | | A warning threshold for the connection time in seconds. Allows the usage of unit additions, like 100ms. Allowed units: ms, s, m, h, d, w, M, y |
29+
| Critical | Object | false | | A critical threshold for the connection time in seconds. Allows the usage of unit additions, like 100ms. Allowed units: ms, s, m, h, d, w, M, y |
30+
| NoPerfData | SwitchParameter | false | False | Disables the performance data output of this plugin. Default to FALSE. |
31+
| Verbosity | Object | false | 0 | 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 |
32+
33+
## Examples
34+
35+
### Example Command 1
36+
37+
```powershell
38+
Invoke-IcingaCheckTCP -Address 'example.com' -Ports 443, 80, 5665, 3001;
39+
```
40+
41+
### Example Output 1
42+
43+
```powershell
44+
[CRITICAL] Check package "TCP Connections" - [CRITICAL] example.com:3001 Status \_ [CRITICAL] Check package "example.com:3001" \_ [CRITICAL] example.com:3001 Status: Value "Not Connected" is not matching threshold "Connected" | 'port_80_time'=0.029526s;; 'port_80_status'=1;;1 'port_5665_status'=1;;1 'port_5665_time'=0.012666s;; 'port_3001_status'=0;;1 'port_3001_time'=21.041116s;; 'port_443_time'=0.353218s;; 'port_443_status'=1;;1
45+
```
46+
47+
### Example Command 2
48+
49+
```powershell
50+
Invoke-IcingaCheckTCP -Address 'example.com' -Ports 443, 80, 5665, 3001 -Negate;
51+
```
52+
53+
### Example Output 2
54+
55+
```powershell
56+
[CRITICAL] Check package "TCP Connections" - [CRITICAL] example.com:443 Status, example.com:5665 Status, example.com:80 Status\_ [CRITICAL] Check package "example.com:443"\_ [CRITICAL] example.com:443 Status: Value "Connected" is not matching threshold "Not Connected"\_ [CRITICAL] Check package "example.com:5665"\_ [CRITICAL] example.com:5665 Status: Value "Connected" is not matching threshold "Not Connected"\_ [CRITICAL] Check package "example.com:80"\_ [CRITICAL] example.com:80 Status: Value "Connected" is not matching threshold "Not Connected"| 'port_80_time'=0.017343s;; 'port_80_status'=1;;0 'port_5665_status'=1;;0 'port_5665_time'=0.013514s;; 'port_3001_status'=0;;0 'port_3001_time'=21.039489s;; 'port_443_time'=0.332817s;; 'port_443_status'=1;;0
57+
```
58+
59+
### Example Command 3
60+
61+
```powershell
62+
Invoke-IcingaCheckTCP -Address 'example.com' -Ports 443, 80, 5665, 3001 -Warning 100ms -Critical 200ms;
63+
```
64+
65+
### Example Output 3
66+
67+
```powershell
68+
[CRITICAL] Check package "TCP Connections" - [CRITICAL] example.com:3001 Status, example.com:3001 Time, example.com:443 Time\_ [CRITICAL] Check package "example.com:3001"\_ [CRITICAL] example.com:3001 Status: Value "Not Connected" is not matching threshold "Connected"\_ [CRITICAL] example.com:3001 Time: Value "21.038106s" is greater than threshold "0.2s"\_ [CRITICAL] Check package "example.com:443"\_ [CRITICAL] example.com:443 Time: Value "0.249976s" is greater than threshold "0.2s"| 'port_80_time'=0.017512s;0.1;0.2 'port_80_status'=1;;1 'port_5665_status'=1;;1 'port_5665_time'=0.013497s;0.1;0.2 'port_3001_status'=0;;1 'port_3001_time'=21.038106s;0.1;0.2 'port_443_time'=0.249976s;0.1;0.2 'port_443_status'=1;;1
69+
```

icinga-powershell-plugins.psd1

218 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)