From 7be99ac704f266d4e81df8fcde1b6c964fb675e8 Mon Sep 17 00:00:00 2001 From: stevie-sy <38723488+stevie-sy@users.noreply.github.com> Date: Tue, 27 Jul 2021 09:22:21 +0200 Subject: [PATCH 1/4] Update icinga-powershell-plugins.psd1 Add Cmdlet IcingaCheckFreePartitionSpace --- icinga-powershell-plugins.psd1 | Bin 11056 -> 5594 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/icinga-powershell-plugins.psd1 b/icinga-powershell-plugins.psd1 index 53462165770835d54098378b9ceadaabaf584c35..1918b8da2653292dcd07496b95fe607f5e4caa6f 100644 GIT binary patch literal 5594 zcmbtYUvnBa5P$DXzr($eWCFy*PSR#NV}glI$0k=Fq%X{5j=Kd^-$_?VheOkRvOe@9 z^(%CBk`95*9hdN6gS0>GU+u2;zkmKc|MKGx9)50EoG0)RxFC$G1@9NHb<%m&dC}4Y zm($Tjv0nZ`0(c3p-<-XGc5l%;ZJ(aJe%XH0d-bLr^}^my5WPHmeP;2uj7iPJ9)Nff z5xNZ98M{ZuD@c-dmgGx9MJE&KiQ(MO<%)5OQvVTo&3NoxK}NDXHgp4)W+B~-!xRiL z(v1oZ-eo$!D#@}9C(D&APeigO(NnMYqIcps^xogzrGLHd8QcYkh?7iO`xIjIy@(|V zM8zswSh%mX@D?cd5-9L6@qQ;XX7|F2RuJ8ZV#_d7RA#qhnEA>gfwG8o2?}{yI^!1p z%n65B8&nh~Ie&8gMgJ}=fb$svSNCAzcni-}5JW zPnoXOnHguzMs&^Ypsm#zDE;0MCIa9jOtdGTABh_Pmt;YrP(nkX;u_>>LzF*l2Dm`0 zN0RYPQ<%8Bf-sS*X1L)Rs7%c^@VXP5+()_#v8K#d45^Q9}=0O(uRILz(Yf z-r7hR4Q~8q>fJ!v*a0{G=tDCuW02~ijHm>@Xl#t}b-x)qAGt&cJUoUKU=d^X3NJ<~b-lW!JP9)Hw|JD_02?oIYrfQwLu zm7r*w<@XuZ6#&aOVwCE#JDXskGTc=%8I(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- zDR|a9q&ctlT=HfXVAqjOk?aFbSGm4#Bp#lzGONG!&QQkZnta;OGIRZCT0%eH_l7vN zb7X|9PD5&;pTuW}QP`}7r^;e{@54_L6`|?(CPuG8dj9waZ#GZwbTNyW2D{XCIm5kO OG4Gz!+q8x1HU1BRGR(pN From 1f91fb43fac23c26cb2043b200b3de79478be717 Mon Sep 17 00:00:00 2001 From: stevie-sy <38723488+stevie-sy@users.noreply.github.com> Date: Tue, 27 Jul 2021 09:25:48 +0200 Subject: [PATCH 2/4] Create 27-Invoke-IcingaCheckFreePartitionSpace.md Add docs for Invoke-IcingaCheckFreePartitionSpace --- ...27-Invoke-IcingaCheckFreePartitionSpace.md | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 doc/plugins/27-Invoke-IcingaCheckFreePartitionSpace.md diff --git a/doc/plugins/27-Invoke-IcingaCheckFreePartitionSpace.md b/doc/plugins/27-Invoke-IcingaCheckFreePartitionSpace.md new file mode 100644 index 00000000..7ed539d9 --- /dev/null +++ b/doc/plugins/27-Invoke-IcingaCheckFreePartitionSpace.md @@ -0,0 +1,60 @@ + +# Invoke-IcingaCheckFreePartitionSpace + +## Description + +Checks how much space on a partition is free. + +Invoke-IcingaCheckFreePartition returns either 'OK', 'WARNING' or 'CRITICAL', based on the thresholds set. +e.g 'C:' is at 8% usage, WARNING is set to 60, CRITICAL is set to 80. In this case the check will return OK. + +The plugin will return `UNKNOWN` in case partition data (size and free space) can not be fetched. This is +normally happening in case the user the plugin is running with does not have permissions to fetch this +specific partition data. + +More Information on https://github.com/Icinga/icinga-powershell-plugins + +## Permissions + +To execute this plugin you will require to grant the following user permissions. + +### WMI Permissions + +* Root\Cimv2 + +### Performance Counter + +* LogicalDisk(*)\% free space + +### Required User Groups + +* Performance Monitor Users + +## Arguments + +| Argument | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | +| Warning | Object | false | | Used to specify a Warning threshold. This can either be a byte-value type like '10GB' or a %-value, like '10%' | +| Critical | Object | false | | Used to specify a Critical threshold. This can either be a byte-value type like '10GB' or a %-value, like '10%' | +| Include | Array | false | @() | Used to specify an array of partitions to be included. If not set, the check expects that all not excluded partitions should be checked. e.g. 'C:','D:' | +| Exclude | Array | false | @() | Used to specify an array of partitions to be excluded. e.g. 'C:','D:' | +| IgnoreEmptyChecks | SwitchParameter | false | False | Overrides the default behaviour of the plugin in case no check element is left for being checked (if all elements are filtered out for example). Instead of returning `Unknown` the plugin will return `Ok` instead if this argument is set. | +| NoPerfData | SwitchParameter | false | False | Disables the performance data output of this plugin | +| SkipUnknown | SwitchParameter | false | False | Allows to set Unknown partitions to Ok in case no metrics could be loaded. | +| Verbosity | Int32 | 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 3: Identical to Verbose 2, but prints in addition the check package configuration e.g (All must be [OK]) | +| ThresholdInterval | Object | | | 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. | + +## Examples + +### Example Command 1 + +```powershell +Invoke-IcingaCheckFreePartitionSpace -Warning 5GB -Critical 2GB +``` + +### Example Output 1 + +```powershell +[OK]: Check package "Free Partition Space" is [OK]| 'partition_c'=7493583000B;5368709120:;2147483648:;0;29485960000 +``` + From bfa64de6fecc29c88b54a9f3fd14858cbfc7bf2e Mon Sep 17 00:00:00 2001 From: stevie-sy <38723488+stevie-sy@users.noreply.github.com> Date: Tue, 27 Jul 2021 09:32:06 +0200 Subject: [PATCH 3/4] Update 10-Icinga-Plugins.md Add docs for IcingaCheckFreePartitionSpace --- doc/10-Icinga-Plugins.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/10-Icinga-Plugins.md b/doc/10-Icinga-Plugins.md index f65fe1b3..9576681d 100644 --- a/doc/10-Icinga-Plugins.md +++ b/doc/10-Icinga-Plugins.md @@ -31,6 +31,7 @@ icinga> icinga { Invoke-IcingaCheckCPU -Warning 20 -Critical 40 -Core _Total -Th * [Invoke-IcingaCheckDiskHealth](plugins/20-Invoke-IcingaCheckDiskHealth.md) * [Invoke-IcingaCheckEventlog](plugins/06-Invoke-IcingaCheckEventlog.md) * [Invoke-IcingaCheckFirewall](plugins/07-Invoke-IcingaCheckFirewall.md) +* [Invoke-IcingaCheckFreePartitionSpace](plugins/27-Invoke-IcingaCheckFreePartitionSpace.md) * [Invoke-IcingaCheckHTTPStatus](plugins/25-Invoke-IcingaCheckHTTPStatus.md) * [Invoke-IcingaCheckICMP](plugins/08-Invoke-IcingaCheckICMP.md) * [Invoke-IcingaCheckMemory](plugins/09-Invoke-IcingaCheckMemory.md) From 852937cd0bba5e741b8a41ba512c71c7901254a2 Mon Sep 17 00:00:00 2001 From: stevie-sy <38723488+stevie-sy@users.noreply.github.com> Date: Tue, 27 Jul 2021 09:35:18 +0200 Subject: [PATCH 4/4] Create Invoke-IcingaCheckFreePartitionSpace.psm1 Add Check Invoke-IcingaCheckFreePartition to check for free space als alternative to Invoke-IcingaCheckUsedPartition like the "old" check >disk-windows (check_disk.exe)< offers the param disk_win_show_used. --- .../Invoke-IcingaCheckFreePartitionSpace.psm1 | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 plugins/Invoke-IcingaCheckFreePartitionSpace.psm1 diff --git a/plugins/Invoke-IcingaCheckFreePartitionSpace.psm1 b/plugins/Invoke-IcingaCheckFreePartitionSpace.psm1 new file mode 100644 index 00000000..052a23f3 --- /dev/null +++ b/plugins/Invoke-IcingaCheckFreePartitionSpace.psm1 @@ -0,0 +1,142 @@ +<# +.SYNOPSIS + Checks how much space on a partition is free. +.DESCRIPTION + Invoke-IcingaCheckFreePartition returns either 'OK', 'WARNING' or 'CRITICAL', based on the thresholds set. + e.g 'C:' is has 8% free, WARNING is set to 60, CRITICAL is set to 80. In this case the check will return OK. + + The plugin will return `UNKNOWN` in case partition data (size and free space) can not be fetched. This is + normally happening in case the user the plugin is running with does not have permissions to fetch this + specific partition data. + + More Information on https://github.com/Icinga/icinga-powershell-plugins +.FUNCTIONALITY + This module is intended to be used to check how much free there is on an partition. + Based on the thresholds set the status will change between 'OK', 'WARNING' or 'CRITICAL'. The function will return one of these given codes. + + The plugin will return `UNKNOWN` in case partition data (size and free space) can not be fetched. This is + normally happening in case the user the plugin is running with does not have permissions to fetch this + specific partition data. +.ROLE + ### WMI Permissions + + * Root\Cimv2 + + ### Performance Counter + + * LogicalDisk(*)\% free space + + ### Required User Groups + + * Performance Monitor Users +.EXAMPLE + PS>Invoke-IcingaCheckFreePartitionSpace -Warning 5GB -Critical 2GB + [OK]: Check package "Free Partition Space" is [OK] + | 'partition_c'=7493583000B;5368709120:;2147483648:;0;29485960000 +.PARAMETER Warning + Used to specify a Warning threshold. This can either be a byte-value type like '10GB' + or a %-value, like '10%' +.PARAMETER Critical + Used to specify a Critical threshold. This can either be a byte-value type like '10GB' + or a %-value, like '10%' +.PARAMETER Exclude + Used to specify an array of partitions to be excluded. + e.g. 'C:','D:' +.PARAMETER Include + Used to specify an array of partitions to be included. If not set, the check expects that all not excluded partitions should be checked. + e.g. 'C:','D:' +.PARAMETER IgnoreEmptyChecks + Overrides the default behaviour of the plugin in case no check element is left for being checked (if all elements are filtered out for example). + Instead of returning `Unknown` the plugin will return `Ok` instead if this argument is set. +.PARAMETER SkipUnknown + Allows to set Unknown partitions to Ok in case no metrics could be loaded. +.PARAMETER NoPerfData + Disables the performance data output of this plugin +.PARAMETER Verbosity + 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]) +.INPUTS + System.String +.OUTPUTS + System.String +.LINK + https://github.com/Icinga/icinga-powershell-plugins +.NOTES +#> + +function Invoke-IcingaCheckFreePartitionSpace() +{ + param( + $Warning = $null, + $Critical = $null, + [array]$Include = @(), + [array]$Exclude = @(), + [switch]$IgnoreEmptyChecks = $FALSE, + [switch]$NoPerfData = $FALSE, + [switch]$SkipUnknown = $FALSE, + [ValidateSet(0, 1, 2, 3)] + [int]$Verbosity = 0 + ); + + $Disks = Get-IcingaPhysicalDiskInfo; + $DiskPackage = New-IcingaCheckPackage -Name 'Free Partition Space' -Verbose $Verbosity -IgnoreEmptyPackage:$IgnoreEmptyChecks -OperatorAnd -AddSummaryHeader; + + foreach ($disk in $Disks.Values) { + + foreach ($partitions in $disk.PartitionLayout.Keys) { + $partition = $disk.PartitionLayout[$partitions]; + $ProcessPartition = $TRUE; + + if ([string]::IsNullOrEmpty($partition.DriveLetter)) { + continue; + } + + if ($disk.DriveReference.ContainsKey($partition.DriveLetter) -eq $FALSE) { + continue; + } + + $PartitionId = $disk.DriveReference[$partition.DriveLetter]; + + if ($partitions -ne $PartitionId) { + continue; + } + + foreach ($entry in $Include) { + $ProcessPartition = $FALSE; + if ($entry.Replace(':', '').Replace('\', '').Replace('/', '').ToLower() -eq $partition.DriveLetter.Replace(':', '').ToLower()) { + $ProcessPartition = $TRUE; + break; + } + } + foreach ($entry in $Exclude) { + if ($entry.Replace(':', '').Replace('\', '').Replace('/', '').ToLower() -eq $partition.DriveLetter.Replace(':', '').ToLower()) { + $ProcessPartition = $FALSE; + break; + } + } + + if ($ProcessPartition -eq $FALSE) { + continue; + } + + $IcingaCheck = New-IcingaCheck -Name ([string]::Format('Partition {0}', $partition.DriveLetter)) -Value $partition.FreeSpace -Unit 'B' -Minimum 0 -Maximum $partition.Size -NoPerfData:$SetUnknown -BaseValue $partition.Size; + + if ([string]::IsNullOrEmpty($partition.FreeSpace) -Or [string]::IsNullOrEmpty($partition.Size)) { + if ($SkipUnknown -eq $FALSE) { + [void]$IcingaCheck.SetUnknown('No disk size and/or free space available', $TRUE) + } else { + [void]$IcingaCheck.SetOk('No disk size and/or free space available', $TRUE) + } + } else { + [void]$IcingaCheck.WarnIfLowerThan($Warning).CritIfLowerThan($Critical) + } + + $DiskPackage.AddCheck($IcingaCheck); + } + } + + return (New-IcingaCheckResult -Check $DiskPackage -NoPerfData $NoPerfData -Compile); +}