-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmart_windows.ps1
More file actions
38 lines (32 loc) · 1.04 KB
/
Copy pathsmart_windows.ps1
File metadata and controls
38 lines (32 loc) · 1.04 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
# Checkmk monitoring script in PowerShell
# Error handling function
function Write-ErrorAndExit {
param (
[string]$Message
)
Write-Error $Message
exit 1
}
# Check if smartctl is installed
if (-not (Get-Command smartctl -ErrorAction SilentlyContinue)) {
Write-ErrorAndExit "ERROR: smartctl not found"
}
# Check smartctl version
$smartctlVersion = smartctl -V
if (-not $smartctlVersion -match '^smartctl 7') {
Write-ErrorAndExit "ERROR: smartctl version 7 or newer is required"
}
# Output for smart_posix_all
Write-Host "<<<smart_posix_all:sep(0)>>>"
$device = smartctl --scan | ForEach-Object { $_.Split(" ")[0].Trim() }
foreach ($device in $devices) {
$smartOutput = smartctl --all --json=c $device
Write-Host $smartOutput
}
Write-Host "<<<smart_posix_scan_arg:sep(0)>>>"
$deviceArgs = smartctl --scan | ForEach-Object { $_.Split("#")[0].Trim() }
foreach ($deviceArg in $deviceArgs) {
# Run smartctl with the extracted device information
smartctl --all --json=c ($deviceArg).Split(" ")
Write-Host ""
}