-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmart_posix.ps1
More file actions
48 lines (41 loc) · 1.43 KB
/
smart_posix.ps1
File metadata and controls
48 lines (41 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright (C) 2024 Checkmk GmbH - License: GNU General Public License v2
# PowerShell port of checkmk's smart_posix_all plugin
# slightly adapted by Colin Pohle, Version 1.1
${smartctl_bin} = "C:\ProgramData\checkmk\agent\bin\smartctl.exe"
function Main {
if (-not (Test-Path $smartctl_bin)) {
Write-Error "ERROR: smartctl.exe not found at $smartctl_bin"
exit 1
}
$versionOutput = & $smartctl_bin -V 2>&1
if (-not ($versionOutput -match "^smartctl 7")) {
Write-Error "ERROR: smartctl version 7 or newer is required"
exit 1
}
Write-Output "<<<smart_posix_all:sep(0)>>>"
$devices = & $smartctl_bin --scan | ForEach-Object {
($_ -split '\s+')[0]
}
foreach ($device in $devices) {
& $smartctl_bin --all --json=c $device
Write-Output ""
}
# the following seems to just run the same again with a different way of specifying the disk to smartctl,
# this causes a long agent execution time - especially in systems with many disks
<#
Write-Output "<<<smart_posix_scan_arg:sep(0)>>>"
$scanArgs = & $smartctl_bin --scan | ForEach-Object {
($_ -split '#')[0].Trim()
}
foreach ($deviceArgs in $scanArgs) {
$deviceArgs = $deviceArgs -split ' '
if ($deviceArgs) {
& $smartctl_bin --all --json=c $deviceArgs
Write-Output ""
}
}
#>
}
if (-not $env:MK_SOURCE_ONLY) {
Main
}