HP Disk Monitoring

Das komplette HP Disk Monitoring Skript basiert auf PowerShell, jedoch wird dieses Skript jeweils über die start_disk_monitoring.bat Datei, welche sich im gleichen Verzeichnis befindet ausgelöst. Zur korrekten Einrichtung, wird das untere Skript als Zip heruntergeladen und unter C:\_\_disk_monitoring entpackt. Nun wird ein neuer Scheduled Task eingerichtet, welcher z.B. alle 15 Minuten das start_disk_monitoring.bat Skript ausführt.

WICHTIG: Im Skript selber, müssen natürlich noch die Angaben der Email Adresse und das Passwort aktuallisiert werden, da man sonst im Falle eines Ausfalls nicht benachrichtigt würde.

Skript Sourcecode

Filename: disk_monitoring.ps1

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
49
$localhost="HOST-BLACKRACK"
Get-item ".\log.txt" -ea 0 | Remove-Item -ea 0
$logfile=".\log.txt"
 
 
function CheckSmartArray {
Write-Host " "
Write-Host "Checking SmartArray on system"$localhost"" -foregroundcolor green
C:\Windows\System32\cmd.exe /c "C:\Program Files\HP\hpssacli\bin\hpssacli.exe" controller slot=0 physicaldrive all show
}
 
CheckSmartArray | out-file -filepath $logfile -append
 
function SentDiskDrivefailedviaMail {
$Logs=Get-Content $logfile
$smtpServer = "smtp.gmail.com"
$smtpFrom = "mail.blackgate@gmail.com"
$SMTPPort = "587"
$Username = "mail.blackgate@gmail.com"
$Password = "PASSWORD"
$smtpTo = "michael.r467@gmail.com"
$messageSubject = "Disk Drive failed at $localhost"
 
[string]$messagebody = ""
 
foreach ($log in $logs )
{
    $messagebody = $messagebody + $log + "`r`n"
}
Write-Host "failed disk detected – starting to sent mail to $smtpTo via $smtpServer …." -ForegroundColor red
$SMTPClient = New-Object Net.Mail.SmtpClient( $smtpServer, $SMTPPort )
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$SMTPClient.Send($smtpFrom,$smtpTo,$messagesubject,$messagebody)
Write-Host "mail sent completed " -ForegroundColor green
Write-Host " "
}
 
#Check logfile if a "Failed" status can be found, if true send a mail with "SentDiskDrivefailedviaMail" function
[array]$logcontent=gc $logfile
foreach ($line in $logcontent) {
    if ($line -match "Failed") {
    Write-Host " "
    write-host "failed disk found at $localhost " -foregroundcolor red
    write-host "detailed logs can be found $logfile " -foregroundcolor red
    Write-Host " "
    SentDiskDrivefailedviaMail
    }
}