|
1 | 1 | <# |
2 | 2 | .SYNOPSIS |
3 | | - Checks hash against filehash of a file |
| 3 | + Checks hash against file hash of a file |
4 | 4 | .DESCRIPTION |
5 | | - Invoke-IcingaCheckCheckSum returns either 'OK' or 'CRITICAL', whether the check matches or not. |
| 5 | + Invoke-IcingaCheckCheckSum returns either 'OK' or 'CRITICAL', whether the check matches or not. |
6 | 6 |
|
7 | | - More Information on https://github.com/Icinga/icinga-powershell-plugins |
| 7 | + More Information on https://github.com/Icinga/icinga-powershell-plugins |
8 | 8 | .FUNCTIONALITY |
9 | | - This module is intended to be used to check a hash against a filehash of a file, to determine whether changes have occured. |
10 | | - Based on the match result the status will change between 'OK' or 'CRITICAL'. The function will return one of these given codes. |
| 9 | + This module is intended to be used to check a hash against a file hash of a file, to determine whether changes have occurred. |
| 10 | + Based on the match result the status will change between 'OK' or 'CRITICAL'. The function will return one of these given codes. |
11 | 11 | .EXAMPLE |
12 | | - PS> Invoke-IcingaCheckCheckSum -Path "C:\Users\Icinga\Downloads\test.txt" |
13 | | - [OK] CheckSum C:\Users\Icinga\Downloads\test.txt is 008FB84A017F5DFDAF038DB2FDD6934E6E5D9CD3C7AACE2F2168D7D93AF51E4B |
| 12 | + PS> Invoke-IcingaCheckCheckSum -Path "C:\Users\Icinga\Downloads\test.txt" |
| 13 | + [OK] CheckSum C:\Users\Icinga\Downloads\test.txt is 008FB84A017F5DFDAF038DB2FDD6934E6E5D9CD3C7AACE2F2168D7D93AF51E4B |
14 | 14 | .EXAMPLE |
15 | | - PS> Invoke-IcingaCheckCheckSum -Path "C:\Users\Icinga\Downloads\test.txt" -Hash 008FB84A017F5DFDAF038DB2FDD6934E6E5D9CD3C7AACE2F2168D7D93AF51E4B |
16 | | - [OK] CheckSum C:\Users\Icinga\Downloads\test.txt is 008FB84A017F5DFDAF038DB2FDD6934E6E5D9CD3C7AACE2F2168D7D93AF51E4B| |
| 15 | + PS> Invoke-IcingaCheckCheckSum -Path "C:\Users\Icinga\Downloads\test.txt" -Hash 008FB84A017F5DFDAF038DB2FDD6934E6E5D9CD3C7AACE2F2168D7D93AF51E4B |
| 16 | + [OK] CheckSum C:\Users\Icinga\Downloads\test.txt is 008FB84A017F5DFDAF038DB2FDD6934E6E5D9CD3C7AACE2F2168D7D93AF51E4B| |
17 | 17 | .EXAMPLE |
18 | | - PS> Invoke-IcingaCheckCheckSum -Path "C:\Users\Icinga\Downloads\test.txt" -Hash 008FB84A017F5DFDAF038DB2FDD6934E6E5D |
19 | | - [CRITICAL] CheckSum C:\Users\Icinga\Downloads\test.txt 008FB84A017F5DFDAF038DB2FDD6934E6E5D9CD3C7AACE2F2168D7D93AF51E4B is not matching 008FB84A017F5DFDAF038DB2FDD6934E6E5D |
| 18 | + PS> Invoke-IcingaCheckCheckSum -Path "C:\Users\Icinga\Downloads\test.txt" -Hash 008FB84A017F5DFDAF038DB2FDD6934E6E5D |
| 19 | + [CRITICAL] CheckSum C:\Users\Icinga\Downloads\test.txt 008FB84A017F5DFDAF038DB2FDD6934E6E5D9CD3C7AACE2F2168D7D93AF51E4B is not matching 008FB84A017F5DFDAF038DB2FDD6934E6E5D |
20 | 20 | .PARAMETER WarningBytes |
21 | | - Used to specify a string to the path of a file, which will be checked. |
| 21 | + Used to specify a string to the path of a file, which will be checked. |
22 | 22 |
|
23 | | - The string has to be like "C:\Users\Icinga\test.txt" |
| 23 | + The string has to be like "C:\Users\Icinga\test.txt" |
24 | 24 |
|
25 | 25 | .PARAMETER Algorithm |
26 | | - Used to specify a string, which contains the algorithm to be used. |
| 26 | + Used to specify a string, which contains the algorithm to be used. |
27 | 27 |
|
28 | | - Allowed algorithms: 'SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5' |
| 28 | + Allowed algorithms: 'SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5' |
29 | 29 |
|
30 | 30 | .INPUTS |
31 | | - System.String |
| 31 | + System.String |
32 | 32 |
|
33 | 33 | .OUTPUTS |
34 | | - System.String |
| 34 | + System.String |
35 | 35 |
|
36 | 36 | .LINK |
37 | | - https://github.com/Icinga/icinga-powershell-plugins |
| 37 | + https://github.com/Icinga/icinga-powershell-plugins |
38 | 38 | .NOTES |
39 | 39 | #> |
40 | 40 |
|
41 | 41 | function Invoke-IcingaCheckCheckSum() |
42 | 42 | { |
43 | | - param( |
44 | | - [string]$Path = $null, |
45 | | - [ValidateSet('SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5')] |
46 | | - [string]$Algorithm = 'SHA256', |
47 | | - [string]$Hash = $null, |
48 | | - [switch]$NoPerfData, |
49 | | - [ValidateSet(0, 1, 2, 3)] |
50 | | - [int]$Verbosity = 0 |
51 | | - ); |
52 | | - |
53 | | - [string]$FileHash = (Get-FileHash $Path -Algorithm $Algorithm).Hash |
54 | | - $CheckSumCheck = New-IcingaCheck -Name "CheckSum $Path" -Value $FileHash; |
55 | | - |
56 | | - If(([string]::IsNullOrEmpty($Hash)) -eq $FALSE){ |
57 | | - $CheckSumCheck.CritIfNotMatch($Hash) | Out-Null; |
58 | | - } |
59 | | - |
60 | | - return (New-IcingaCheckresult -Check $CheckSumCheck -NoPerfData $NoPerfData -Compile); |
| 43 | + param ( |
| 44 | + [string]$Path = $null, |
| 45 | + [ValidateSet('SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5')] |
| 46 | + [string]$Algorithm = 'SHA256', |
| 47 | + [string]$Hash = $null, |
| 48 | + [switch]$NoPerfData, |
| 49 | + [ValidateSet(0, 1, 2, 3)] |
| 50 | + [int]$Verbosity = 0 |
| 51 | + ); |
| 52 | + |
| 53 | + if ([string]::IsNullOrEmpty($Path)) { |
| 54 | + Exit-IcingaThrowException -Force -CustomMessage 'Unset argument "-Path"' -ExceptionType 'Configuration' -ExceptionThrown $IcingaExceptions.Configuration.PluginArgumentMissing; |
| 55 | + } |
| 56 | + |
| 57 | + if ((Test-Path $Path) -eq $FALSE -Or (Get-Item $Path) -Is [System.IO.DirectoryInfo]) { |
| 58 | + Exit-IcingaThrowException -Force -CustomMessage '"-Path" is not directing to a file' -ExceptionType 'Configuration' -ExceptionThrown $IcingaExceptions.Configuration.PluginArgumentConflict; |
| 59 | + } |
| 60 | + |
| 61 | + [string]$FileHash = (Get-FileHash $Path -Algorithm $Algorithm).Hash |
| 62 | + $CheckSumCheck = New-IcingaCheck -Name "CheckSum $Path" -Value $FileHash; |
| 63 | + |
| 64 | + If (([string]::IsNullOrEmpty($Hash)) -eq $FALSE) { |
| 65 | + $CheckSumCheck.CritIfNotMatch($Hash) | Out-Null; |
| 66 | + } |
| 67 | + |
| 68 | + return (New-IcingaCheckResult -Check $CheckSumCheck -NoPerfData $NoPerfData -Compile); |
61 | 69 | } |
0 commit comments