PDA

Показать полную графическую версию : HDD/SSD S.M.A.R.T. - парсинг RAW-значений атрибутов.


rango13
02-07-2018, 07:52
Всем привет!

Есть доменная сеть с клиентами не ниже Windows 7. Встала интересная задача:
1. Сформировать список ПК из определённого файла.
2. Собирать по всем ПК/ноутбукам из п.1 S.M.A.R.T. атрибуты подключённых по SATA или M.2 имеющихся HDD/SSD(Бывает часто, что подключены оба).
3. После сборки этих данных - парсить RAW-значения атрибутов на предмет отличия от нуля:
- 05 Reallocated Sector Count
- 187 (BB) Reported Uncorrected Sector Count (UNC Error)
- 197 (С5) Current Pending Sector Count
- 198 (С6) Offline Uncorrectable Sector Count (Uncorrectable Sector Count)
- 200 (С8) Write Error Rate (MultiZone Error Rate)
4. Если находятся ПК, у которых RAW-значения накопителей выше нуля - отправить по почте список этих ПК.




##### п.1
$COMPUTERS = get-content D:\pc.txt

##### п.2
foreach ($computer in $COMPUTERS) {
$smart = gwmi -Namespace root\WMI -ComputerName $computer -Class MSStorageDriver_FailurePredictData
if ($smart.VendorSpecific.Length -gt 0) {
$smart = @($smart)
}
for ($n = 0; $n -lt $smart.Length; $n++) {
$result = @()
for ($i = 2; $i -lt $smart[$n].VendorSpecific.Length; $i += 12)
{
$result += [pscustomobject] @{
AttrID = $smart[$n].VendorSpecific[$i];
Raws = $smart[$n].VendorSpecific[($i+5)..($i+10)];

##### п.3
if(RAW-значение аттрибутов 05 или 187 или 197 или 198 или 200 больше нуля)
{

##### п.4
$Server = 'mail_server_address.ru'
$From = 'my_mail@mail_server_address.ru'
$To = 'my_mail@mail_server_address.ru'
$encoding = [System.Text.Encoding]::UTF8
$BodyM = ""
Send-MailMessage -From $From -To $To -SmtpServer $server -Body "$Theme `n$BodyM" -Subject "SMART Alert - $computer" -Encoding $encoding
}
}
}





AttrID Raws
------ ----
1 {55, 53, 153, 7...}
3 {0, 0, 0, 0...}
4 {65, 25, 0, 0...}
5 {9, 0, 0, 0...}
7 {232, 254, 47, 19...}
9 {36, 132, 0, 0...}
10 {0, 0, 0, 0...}
12 {185, 1, 0, 0...}
183 {0, 0, 0, 0...}
184 {0, 0, 0, 0...}
187 {0, 0, 0, 0...}
188 {12, 0, 0, 0...}
189 {6, 0, 0, 0...}
190 {38, 0, 32, 39...}
194 {38, 0, 0, 0...}
195 {55, 53, 153, 7...}
197 {0, 0, 0, 0...}
198 {0, 0, 0, 0...}
199 {0, 0, 0, 0...}
240 {242, 86, 0, 0...}


В нём, к примеру, значение атрибута №5 равно 9, т.е. уже с HDD имеется проблема(приложил картинку).

Вопрос только в том, как правильно парсить в п.3 эти значения?

Iska
02-07-2018, 08:53
1. Сформировать список ПК из определённого файла. »
Почему не из AD, если сеть доменная?

rango13
02-07-2018, 10:05
Почему не из AD, если сеть доменная? »
$COMPUTERS = Get-ADComputer -Filter {OperatingSystem -NotLike "*server*"} -Property * -SearchBase "OU=Test-Group, OU=WS, DC=domain, DC=loc" | Select Name -ExpandProperty DNSHostName | Sort
Можно и так - пока не принципиально.

Kazun
02-07-2018, 12:52
$RawIndex = 5,187,197,198,200
$IsSmartBad = $false

for ($n = 0; $n -lt $smart.Length; $n++) {
for ($i = 2; $i -lt $smart[$n].VendorSpecific.Length; $i += 12)
{
if($RawIndex -contains $smart[$n].VendorSpecific[$i]) {
$smart.VendorSpecific[($i+5)..($i+10)] | Where {$_ -gt 0} | Foreach {
$IsSmartBad = $true
}
}
}
}


if($IsSmartBad)
{
$Server = 'mail_server_address.ru'
$From = 'my_mail@mail_server_address.ru'
$To = 'my_mail@mail_server_address.ru'
$encoding = [System.Text.Encoding]::UTF8
$BodyM = ""
Send-MailMessage -From $From -To $To -SmtpServer $server -Body "$Theme `n$BodyM" -Subject "SMART Alert - $computer" -Encoding $encoding
}




© OSzone.net 2001-2012