sensu-plugins-windows 2.2.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +11 -0
- data/bin/powershell/check-multi-template/README.md +177 -0
- data/bin/powershell/check-multi-template/check-adapters.ps1 +115 -0
- data/bin/powershell/check-multi-template/check-focusedprocess.ps1 +102 -0
- data/bin/powershell/check-multi-template/check-iscsi.ps1 +114 -0
- data/bin/powershell/check-multi-template/check-multi-template.ps1 +603 -0
- data/bin/powershell/check-multi-template/check-processes.ps1 +109 -0
- data/bin/powershell/check-multi-template/check-services.ps1 +116 -0
- data/lib/sensu-plugins-windows/version.rb +2 -2
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e2c09a015df087022d158773dc055bc71862dac29c00f1d99d4982b980289b6c
|
4
|
+
data.tar.gz: 7c39068ecf25e4123c27741af9addff0ceac3c121a26474b250f1e2fdbbc3df0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44c6c198d8c0fe28f308983ca9328a0b9de44e773aca7190884c1c5a18fd171f0db214a8f878cffbeaf1e5f346f5ef60dadb439cd41b40dc5711cc9f65a88684
|
7
|
+
data.tar.gz: 23ad80d6943f331720853e9a1ede22f70ad7bc947abd62925b502f7624d1341a2da56ef95e73d1db291b4af4596c34781a35e1ea3543c84f005d069767fe22f7
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,16 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [2.3.0] - 2017-11-12
|
10
|
+
### Added
|
11
|
+
- new check: `powershell/check-multi-template/check-processes.ps1` (@absolutejam)
|
12
|
+
- new check `powershell/check-multi-template/check-services.ps1` (@absolutejam)
|
13
|
+
- new check `powershell/check-multi-template/check-multi-template.ps1` (@absolutejam)
|
14
|
+
- new check `powershell/check-multi-template/check-iscsi.ps1` (@absolutejam)
|
15
|
+
- new check `powershell/check-multi-template/check-focusedprocess.ps1` (@absolutejam)
|
16
|
+
- new check: `powershell/check-multi-template/check-adapters.ps1` (@absolutejam)
|
17
|
+
- documentation `powershell/check-multi-template/README.md` (@absolutejam)
|
18
|
+
|
9
19
|
## [2.2.1] - 2017-09-25
|
10
20
|
### Changed
|
11
21
|
- update changelog guidelines location (@majormoses)
|
@@ -125,6 +135,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
|
125
135
|
- Initial release
|
126
136
|
|
127
137
|
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-Windows/compare/2.2.1...HEAD
|
138
|
+
[2.3.0]: https://github.com/sensu-plugins/sensu-plugins-Windows/compare/2.2.1...2.3.0
|
128
139
|
[2.2.1]: https://github.com/sensu-plugins/sensu-plugins-Windows/compare/2.2.0...2.2.1
|
129
140
|
[2.2.0]: https://github.com/sensu-plugins/sensu-plugins-Windows/compare/2.1.0...2.2.0
|
130
141
|
[2.1.0]: https://github.com/sensu-plugins/sensu-plugins-Windows/compare/2.0.0...2.1.0
|
@@ -0,0 +1,177 @@
|
|
1
|
+
# check-multi-template
|
2
|
+
|
3
|
+
A Sensu Powershell template.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
The `check-multi-template` is designed to provide a single base template for
|
8
|
+
PowerShell plugins, reducing uneccessary boilerplate and providing a base set of
|
9
|
+
features and expecations that make it easier to write checks. In particular, the
|
10
|
+
plugins based upon the template can consume multiple items to be checked -
|
11
|
+
Please see *Paramaters* heading for more info.
|
12
|
+
|
13
|
+
The template itself can be copied, altered and used directly, but it is more
|
14
|
+
effective to import it and use it as a template.
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Take a look at any of the other checks in this directory (eg.
|
19
|
+
`check-adapters.ps1`), and you will see they all include the following elements:
|
20
|
+
|
21
|
+
- **Parameter block** - Arguments provided from the CLI. Please see
|
22
|
+
*Parameters* heading for more info.
|
23
|
+
- **Template import** - Dot source import of the template from the same folder
|
24
|
+
as the plugin. This imports all of of the default options and all functions.
|
25
|
+
- **CheckOptions hashtable** - Configuration for the check. Overrides defaults
|
26
|
+
from the template.
|
27
|
+
- **Call to `Invoke-Main` function** - Along with the parameters to be
|
28
|
+
consumed, eg.
|
29
|
+
`Invoke-Main -CriticalItems $CriticalAdapters -ImportantItems $ImportantAdapters`
|
30
|
+
|
31
|
+
## Features
|
32
|
+
|
33
|
+
The crux of the template logic comes from simply comparing the values in arrays -
|
34
|
+
one consisting of values that have been passed in via. command-line arguments,
|
35
|
+
the other consisting of items in a specific state.
|
36
|
+
|
37
|
+
If you look in the function `Invoke-Main`, you will see 3 main steps in
|
38
|
+
determining service health:
|
39
|
+
|
40
|
+
- Compare all items passed in via. CLI parameters (`ImportantItems` &
|
41
|
+
`CriticalItems`) against `BaseItems` array. This first checks to see if any of
|
42
|
+
the items are missing. This can be disabled by changing
|
43
|
+
`$CheckOptions.CheckMissing` to `$False`.
|
44
|
+
|
45
|
+
- Compare `ImportantItems` against `FailedItems` array.
|
46
|
+
|
47
|
+
- Compare `CriticalItems` against `FailedItems` array.
|
48
|
+
|
49
|
+
And these arrays are populated via. the scriptblocks (Anonymous functions) in
|
50
|
+
`$CheckOptions`. For example, the scriptblocks used in `check-adapters` are:
|
51
|
+
|
52
|
+
```powershell
|
53
|
+
'ScriptBlockBaseItems' = {
|
54
|
+
Get-NetAdapter |
|
55
|
+
Select-Object -ExpandProperty Name
|
56
|
+
}
|
57
|
+
|
58
|
+
'ScriptBlockFailedItems' = {
|
59
|
+
Get-NetAdapter |
|
60
|
+
Where-Object { $_.Status -ne 'Up' } |
|
61
|
+
Select-Object -ExpandProperty Name
|
62
|
+
}
|
63
|
+
```
|
64
|
+
|
65
|
+
As you can see, the `ScriptBlockBaseItems` simply gets all network adapters on
|
66
|
+
the machine and then expands the `Name` property.
|
67
|
+
|
68
|
+
The `ScriptBlockFailedItems` simply does the same, but only for adapters with
|
69
|
+
a state not equal to 'Up'.
|
70
|
+
|
71
|
+
Now, we compare our CLI parameters against these, and if any of the items we
|
72
|
+
passed in are present in `FailedItems`, the script will flag it according to
|
73
|
+
whether it was part of the `CriticalItems` or `ImportantItems` parameter.
|
74
|
+
|
75
|
+
### Inverting the logic
|
76
|
+
|
77
|
+
The logic can be reversed but changing `$CheckOptions.Inverse` to `$True`,
|
78
|
+
meaning that the script will check to see if `ImportantItems` and
|
79
|
+
`CriticalItems` are *absent* from `FailedItems`.
|
80
|
+
|
81
|
+
An example of this being used is in `check-iscsi.ps1` as it checks to see if
|
82
|
+
any of the IQNs passed in at the CLI are *absent* from the list of all sessions.
|
83
|
+
|
84
|
+
**NOTE:** Inverting the logic will automatically disable the 'missing' check.
|
85
|
+
|
86
|
+
### Parameters
|
87
|
+
|
88
|
+
Most of the examples will have parameters equivalent to the template's
|
89
|
+
`CriticalItems` and `ImportantItems` parameters (eg. `check-adapters.ps1` has
|
90
|
+
`CriticalAdapters` and `ImportantAdapters`) which allows the plugin to provide
|
91
|
+
a different return value based on whether items were flagged as 'critical' or
|
92
|
+
'important'.
|
93
|
+
|
94
|
+
> **NOTE:** The highest severity result is taken for the final check result.
|
95
|
+
> This means that if both items in `ImportantItems` and items in
|
96
|
+
> `CriticalItems` are flagged as in a failed state, the overall status will be
|
97
|
+
> `CRITICAL:` (Exit code `2`). All failed items will still be shown in the
|
98
|
+
> check output with their respective importance levels.
|
99
|
+
|
100
|
+
Additionally, there is some extra processing done in the parameters to
|
101
|
+
accommodate for multiple instances of Sensu's token substitution. Here is an
|
102
|
+
excerpt from the help provided in the template detailing this:
|
103
|
+
|
104
|
+
> Sensu check token substitution:
|
105
|
+
> Because this check is designed to make full use of Sensu's check token
|
106
|
+
> substitution (https://sensuapp.org/docs/latest/reference/checks.html#check-token-substitution)
|
107
|
+
> feature, some special considerations have been taken for how the arguments are parsed.
|
108
|
+
>
|
109
|
+
> The main parameters support a list of of comma-separated strings.
|
110
|
+
> eg. -CriticalItems 'value1','value2'
|
111
|
+
> They also accepts accept a single string with comma-separated values.
|
112
|
+
> eg. -param1 'value1,value2'
|
113
|
+
> ...or you can mix & match the two and all of the values will be merged.
|
114
|
+
> eg. -param1 'value1','value2,value3'
|
115
|
+
> Additionally, any use of the word 'None' will be ignored.
|
116
|
+
> eg. -param1 'value1','None,value2','None'
|
117
|
+
>
|
118
|
+
> This is because Sensu's client attribute substitution tokens only work with
|
119
|
+
> flat strings, but by supporting both of the above methods, it allows the use
|
120
|
+
> of multiple values within a single check/client attribute AND multiple
|
121
|
+
> different client/check attributes to be used. Additionally, because 'None'
|
122
|
+
> is ignored, it allows the user to provide a default value in the check
|
123
|
+
> token substitution, as not to throw an error if the value is missing.
|
124
|
+
>
|
125
|
+
> Token substitution example:
|
126
|
+
> Check attribute 'check_attr' = "alpha,bravo"
|
127
|
+
> Client attribute 'client_attr' = "charlie,delta"
|
128
|
+
>
|
129
|
+
> powershell.exe -File check.ps1 -param1 ":::check_attr|None:::",":::missing_attr|None:::",":::client_attr|None:::"
|
130
|
+
>
|
131
|
+
> Which evaluates to:
|
132
|
+
>
|
133
|
+
> powershell.exe -File check.ps1 -param "alpha,bravo","None","charlie,delta"
|
134
|
+
>
|
135
|
+
> The script then strips any instances of 'None' and processes the
|
136
|
+
> comma-separated string as single flat array.
|
137
|
+
|
138
|
+
Here is an example of real-world usage:
|
139
|
+
|
140
|
+
```json
|
141
|
+
{
|
142
|
+
"checks": {
|
143
|
+
"services-running": {
|
144
|
+
"command": "powershell.exe -noprofile -noninteractive -executionpolicy bypass -nologo -file C:\\\\opt\\\\sensu\\\\check-scripts\\\\check-services.ps1 -criticalservices \":::vars.services.critical|None:::,:::vars.services.critical_group|None:::,:::vars.services.critical_all|None:::\" -importantservices \":::vars.services.important|None:::,:::vars.services.important_group|None:::,:::vars.services.important_all|None:::\"",
|
145
|
+
"description": "Checks the status of services",
|
146
|
+
"handlers": [
|
147
|
+
"default"
|
148
|
+
],
|
149
|
+
"interval": 60,
|
150
|
+
"occurrences": 3,
|
151
|
+
"subscribers": [
|
152
|
+
"winservers"
|
153
|
+
]
|
154
|
+
}
|
155
|
+
}
|
156
|
+
}
|
157
|
+
```
|
158
|
+
|
159
|
+
And within the host's `client.json`:
|
160
|
+
|
161
|
+
```json
|
162
|
+
...
|
163
|
+
"vars": {
|
164
|
+
"services": {
|
165
|
+
"critical": "criticalA,criticalB",
|
166
|
+
"critical_group": "criticalC",
|
167
|
+
"critical_all": "criticalD,criticalE",
|
168
|
+
"important": "importantA,importantB",
|
169
|
+
"important_all": "importantD,serviceE"
|
170
|
+
}
|
171
|
+
}
|
172
|
+
```
|
173
|
+
|
174
|
+
These values are populated by my config-management tool, and it allows me to
|
175
|
+
specify values for the host, the host's group (eg. webservers) and all hosts
|
176
|
+
without Sensu having any issues. As you can see, `important_group` is missing,
|
177
|
+
but that will simply be substituted with `None` as per the check definition.
|
@@ -0,0 +1,115 @@
|
|
1
|
+
#
|
2
|
+
# check-adapters.ps1
|
3
|
+
#
|
4
|
+
# DESCRIPTION:
|
5
|
+
# This plugin checks that the specified network adapters are up.
|
6
|
+
#
|
7
|
+
# It accepts the '-CriticalAdapters' and '-ImportantAdapters' parameters to
|
8
|
+
# provide different status level outputs and also checks if the items passed
|
9
|
+
# are missing completely. Please see the '-Help' parameter, under the 'Sensu
|
10
|
+
# check token substitution' header for more info on some extra parsing
|
11
|
+
# features.
|
12
|
+
#
|
13
|
+
# It is built atop check-multi-template.ps1 as an example, and can be easily
|
14
|
+
# adapted to check other things.
|
15
|
+
#
|
16
|
+
# OUTPUT:
|
17
|
+
# Missing example:
|
18
|
+
# CheckNetworkAdapter CRITICAL:
|
19
|
+
# The following adapters are missing:
|
20
|
+
# - Ethernet
|
21
|
+
#
|
22
|
+
# OK example:
|
23
|
+
# CheckNetworkAdapter OK:
|
24
|
+
# All interfaces are up.
|
25
|
+
#
|
26
|
+
# WARN example:
|
27
|
+
# CheckNetworkAdapter WARN:
|
28
|
+
# The following important adapters are down:
|
29
|
+
# - OOB MANAGEMENT
|
30
|
+
#
|
31
|
+
# CRITICAL example:
|
32
|
+
# CheckNetworkAdapter CRITICAL:
|
33
|
+
# The following critical adapters are down:
|
34
|
+
# - CLUSTER HEARTBEAT
|
35
|
+
# The following important adapters are down:
|
36
|
+
# - OOB MANAGEMENT
|
37
|
+
#
|
38
|
+
# PLATFORMS:
|
39
|
+
# Windows
|
40
|
+
#
|
41
|
+
# DEPENDENCIES:
|
42
|
+
#
|
43
|
+
# USAGE:
|
44
|
+
# Please run this check with the '-help' parameter for more info.
|
45
|
+
#
|
46
|
+
# NOTES:
|
47
|
+
#
|
48
|
+
# LICENSE:
|
49
|
+
# Copyright 2016 James Booth <james@absolutejam.co.uk>
|
50
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE for
|
51
|
+
# details.
|
52
|
+
#
|
53
|
+
|
54
|
+
|
55
|
+
[CmdletBinding()]
|
56
|
+
Param(
|
57
|
+
# Network adapters to check. If any are not 'up', they will return a
|
58
|
+
# CRITICAL (2) status.
|
59
|
+
[Parameter(
|
60
|
+
Mandatory = $False
|
61
|
+
)]
|
62
|
+
[string]$CriticalAdapters,
|
63
|
+
|
64
|
+
# Network adapters to check. If any are not 'up', they will return a
|
65
|
+
# WARNING (1) status.
|
66
|
+
[Parameter(
|
67
|
+
Mandatory = $False
|
68
|
+
)]
|
69
|
+
[string]$ImportantAdapters,
|
70
|
+
|
71
|
+
# Display help about this check.
|
72
|
+
[switch]$Help
|
73
|
+
)
|
74
|
+
|
75
|
+
# Import template
|
76
|
+
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
77
|
+
. "$here\check-multi-template.ps1"
|
78
|
+
|
79
|
+
# Override check options
|
80
|
+
$CheckOptions = @{
|
81
|
+
'CheckName' = 'CheckNetworkAdapter'
|
82
|
+
'MessageOK' = 'All interfaces are up.'
|
83
|
+
'MessageImportant' = 'The following important adapters are down:'
|
84
|
+
'MessageCritical' = 'The following critical adapters are down:'
|
85
|
+
'MessageMissing' = 'The following adapters are missing:'
|
86
|
+
'MessageNoneSpecified' = 'No adapters specified.'
|
87
|
+
'MissingState' = 2
|
88
|
+
|
89
|
+
'ScriptBlockBaseItems' = {
|
90
|
+
Get-NetAdapter |
|
91
|
+
Select-Object -ExpandProperty Name
|
92
|
+
}
|
93
|
+
|
94
|
+
'ScriptBlockMatchItems' = {
|
95
|
+
Get-NetAdapter |
|
96
|
+
Where-Object { $_.Status -ne 'Up' } |
|
97
|
+
Select-Object -ExpandProperty Name
|
98
|
+
}
|
99
|
+
|
100
|
+
'CheckHelp' = @'
|
101
|
+
Checks whether any specified network adapters are not 'up'.
|
102
|
+
|
103
|
+
Arguments:
|
104
|
+
-CriticalAdapters A string of comma-separated network adapters
|
105
|
+
-ImportantAdapters A string of comma-separated network adapters
|
106
|
+
-Help Show help
|
107
|
+
|
108
|
+
Example usage:
|
109
|
+
powershell.exe -file check-adapters.ps1 -criticaladapters "CLUSTER NETWORK" -warningadapters"MONITORING NETWORK"
|
110
|
+
|
111
|
+
'@
|
112
|
+
}
|
113
|
+
|
114
|
+
# Run!
|
115
|
+
Invoke-Main -CriticalItems $CriticalAdapters -ImportantItems $ImportantAdapters
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#
|
2
|
+
# check-focusedprocess.ps1
|
3
|
+
#
|
4
|
+
# DESCRIPTION:
|
5
|
+
# This plugin checks the focused process.
|
6
|
+
#
|
7
|
+
# It accepts the '-Process' parameter.
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# OK example:
|
11
|
+
# FocusedProcess OK:
|
12
|
+
# <name> is focused.
|
13
|
+
#
|
14
|
+
# CRITICAL example:
|
15
|
+
# FocusedProcess CRITICAL:
|
16
|
+
# The following process is not focused:
|
17
|
+
# - <name>
|
18
|
+
#
|
19
|
+
# PLATFORMS:
|
20
|
+
# Windows
|
21
|
+
#
|
22
|
+
# DEPENDENCIES:
|
23
|
+
#
|
24
|
+
# USAGE:
|
25
|
+
# Please run this check with the '-help' parameter for more info.
|
26
|
+
#
|
27
|
+
# NOTES:
|
28
|
+
#
|
29
|
+
# LICENSE:
|
30
|
+
# Copyright 2016 James Booth <james@absolutejam.co.uk>
|
31
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE for
|
32
|
+
# details.
|
33
|
+
#
|
34
|
+
|
35
|
+
|
36
|
+
[CmdletBinding()]
|
37
|
+
Param(
|
38
|
+
# Process to check. If not the focused process, return CRITICAL (2) status.
|
39
|
+
[Parameter(
|
40
|
+
Mandatory = $False
|
41
|
+
)]
|
42
|
+
[string]$Process,
|
43
|
+
|
44
|
+
# Display help about this check.
|
45
|
+
[switch]$Help
|
46
|
+
)
|
47
|
+
|
48
|
+
# Import template
|
49
|
+
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
50
|
+
. "$here\check-multi-template.ps1"
|
51
|
+
|
52
|
+
# Override check options
|
53
|
+
$CheckOptions = @{
|
54
|
+
'CheckName' = 'FocusedProcess'
|
55
|
+
'MessageOK' = "$Process is focused."
|
56
|
+
'MessageCritical' = 'The following process is not focused:'
|
57
|
+
'MessageNoneSpecified' = 'No process specified.'
|
58
|
+
'CheckMissing' = $False
|
59
|
+
'Inverse' = $True
|
60
|
+
'ScriptBlockMatchItems' = {
|
61
|
+
Add-Type @"
|
62
|
+
using System;
|
63
|
+
using System.Runtime.InteropServices;
|
64
|
+
public class UserWindows {
|
65
|
+
[DllImport("user32.dll")]
|
66
|
+
public static extern IntPtr GetForegroundWindow();
|
67
|
+
}
|
68
|
+
"@
|
69
|
+
|
70
|
+
try {
|
71
|
+
$ActiveHandle = [UserWindows]::GetForegroundWindow()
|
72
|
+
$Process = Get-Process |
|
73
|
+
Where-Object { $_.MainWindowHandle -eq $activeHandle }
|
74
|
+
$Process |
|
75
|
+
Select-Object -ExpandProperty ProcessName
|
76
|
+
#Select-Object ProcessName,
|
77
|
+
# @{ N="AppTitle"; E= {($_.MainWindowTitle)} }
|
78
|
+
} catch {
|
79
|
+
Throw "Failed to get active Window details. More Info: $_"
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
'CheckHelp' = @'
|
84
|
+
Checks the currently focussed process on a machine. This is useful for machines
|
85
|
+
such as digital signage that should always have a dedicated process displayed.
|
86
|
+
|
87
|
+
Arguments:
|
88
|
+
-Process The process name that should be focused.
|
89
|
+
-Help Show help
|
90
|
+
|
91
|
+
Example usage:
|
92
|
+
powershell.exe -file check-focusedprocess.ps1 -process "chrome"
|
93
|
+
|
94
|
+
'@
|
95
|
+
}
|
96
|
+
|
97
|
+
if ((Format-ParamArray -Param $Process).Count -gt 1) {
|
98
|
+
Throw 'Only accepts a single process'
|
99
|
+
}
|
100
|
+
|
101
|
+
# Run!
|
102
|
+
Invoke-Main -CriticalItems $Process
|
@@ -0,0 +1,114 @@
|
|
1
|
+
#
|
2
|
+
# check-iscsi.ps1
|
3
|
+
#
|
4
|
+
# DESCRIPTION:
|
5
|
+
# This plugin checks that the specified iSCSI sessions are connected.
|
6
|
+
#
|
7
|
+
# It accepts the '-CriticalIQNs and '-ImportantIQNs' parameters to provide
|
8
|
+
# different status level outputs and also checks if the items passed are
|
9
|
+
# missing completely. Please see the '-Help' parameter, under the 'Sensu
|
10
|
+
# check token substitution' header for more info on some extra parsing
|
11
|
+
# features.
|
12
|
+
#
|
13
|
+
# It is built atop check-multi-template.ps1 as an example, and can be easily
|
14
|
+
# adapted to check other things.
|
15
|
+
#
|
16
|
+
# OUTPUT:
|
17
|
+
# OK example:
|
18
|
+
# CheckIscsi OK:
|
19
|
+
# All iSCSI sessions are connected.
|
20
|
+
#
|
21
|
+
# WARN example:
|
22
|
+
# CheckIscsi WARN:
|
23
|
+
# The following important sessions are not connected:
|
24
|
+
# - iqn.2001-05.com.equallogic:4-42a846-3d3bb3c30-9140000001255ddf-vol01
|
25
|
+
#
|
26
|
+
# CRITICAL example:
|
27
|
+
# CheckIscsi CRITICAL:
|
28
|
+
# The following critical sessions are not connected:
|
29
|
+
# - iqn.2001-05.com.equallogic:4-42a846-3d3bb3c30-9140000001255ddf-vol01
|
30
|
+
#
|
31
|
+
# CheckIscsi CRITICAL:
|
32
|
+
# The following critical sessions are not connected:
|
33
|
+
# - iqn.2001-05.com.equallogic:4-42a846-3d3bb3c30-9140000001255ddf-vol01
|
34
|
+
# The following important sessions are not connected:
|
35
|
+
# - iqn.2001-05.com.equallogic:4-42a846-3d3bb3c30-9140000001255ddf-vol02
|
36
|
+
#
|
37
|
+
# PLATFORMS:
|
38
|
+
# Windows
|
39
|
+
#
|
40
|
+
# DEPENDENCIES:
|
41
|
+
#
|
42
|
+
# USAGE:
|
43
|
+
# Please run this check with the '-help' parameter for more info.
|
44
|
+
#
|
45
|
+
# NOTES:
|
46
|
+
#
|
47
|
+
# LICENSE:
|
48
|
+
# Copyright 2016 James Booth <james@absolutejam.co.uk>
|
49
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE for
|
50
|
+
# details.
|
51
|
+
#
|
52
|
+
|
53
|
+
|
54
|
+
[CmdletBinding()]
|
55
|
+
Param(
|
56
|
+
# Target IQNs to check. If any are not connected, they will return a
|
57
|
+
# CRITICAL (2) status.
|
58
|
+
[Parameter(
|
59
|
+
Mandatory = $False
|
60
|
+
)]
|
61
|
+
[string]$CriticalIQNs,
|
62
|
+
|
63
|
+
# Target IQNs to check. If any are not connected, they will return a
|
64
|
+
# WARNING (1) status.
|
65
|
+
[Parameter(
|
66
|
+
Mandatory = $False
|
67
|
+
)]
|
68
|
+
[string]$ImportantIQNs,
|
69
|
+
|
70
|
+
# Display help about this check.
|
71
|
+
[switch]$Help
|
72
|
+
)
|
73
|
+
|
74
|
+
# Import template
|
75
|
+
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
76
|
+
. "$here\check-multi-template.ps1"
|
77
|
+
|
78
|
+
# Override check options
|
79
|
+
$CheckOptions = @{
|
80
|
+
'CheckName' = 'CheckIscsi'
|
81
|
+
'MessageOK' = 'All iSCSI sessions are connected.'
|
82
|
+
'MessageImportant' = 'The following important sessions are not connected:'
|
83
|
+
'MessageCritical' = 'The following critical sessions are not connected:'
|
84
|
+
'MessageMissing' = 'The following sessions are missing:'
|
85
|
+
'MessageNoneSpecified' = 'No IQNs specified.'
|
86
|
+
'MissingState' = 2
|
87
|
+
'Inverse' = $True
|
88
|
+
|
89
|
+
'ScriptBlockBaseItems' = {
|
90
|
+
Get-IscsiSession |
|
91
|
+
Select-Object -ExpandProperty TargetNodeAddress
|
92
|
+
}
|
93
|
+
|
94
|
+
'ScriptBlockMatchItems' = {
|
95
|
+
Get-IscsiSession |
|
96
|
+
Select-Object -ExpandProperty TargetNodeAddress
|
97
|
+
}
|
98
|
+
|
99
|
+
'CheckHelp' = @'
|
100
|
+
Checks whether any specified iSCSI sessions are not connected.
|
101
|
+
|
102
|
+
Arguments:
|
103
|
+
-CriticalIQNs A string of comma-separated iSCSI IQNs
|
104
|
+
-ImportantIQNs A string of comma-separated iSCSI IQNs
|
105
|
+
-Help Show help
|
106
|
+
|
107
|
+
Example usage:
|
108
|
+
powershell.exe -file check-iscsi.ps1 -criticaliqns "iqn..." -warningiqns "iqn..."
|
109
|
+
|
110
|
+
'@
|
111
|
+
}
|
112
|
+
|
113
|
+
# Run!
|
114
|
+
Invoke-Main -CriticalItems $CriticalIQNs -ImportantItems $ImportantIQNs
|