Adding windows disk monitoring
This commit is contained in:
parent
52b0655b97
commit
83cb536866
21
_windows_disk_monitoring/README.md
Normal file
21
_windows_disk_monitoring/README.md
Normal file
@ -0,0 +1,21 @@
|
||||
# windows-disk-monitoring
|
||||
|
||||
Monitors the disk of an HP server and copies the report to the web-frontend.
|
||||
|
||||
### Preparations:
|
||||
|
||||
- Please install "```Smart Storage Administrator```": (ssacli.exe)
|
||||
- Customize the following variables in the file "```disk_monitoring.ps1```"
|
||||
```
|
||||
$smtpServer = "smtp.gmail.com"
|
||||
$smtpFrom = "MY_SERVER_MAIL@gmail.com"
|
||||
$SMTPPort = "587"
|
||||
$Username = "MY_SERVER_MAIL@gmail.com"
|
||||
$Password = "MY_SERVER_MAIL_PASSWORD"
|
||||
$smtpTo = "MY_DESTINATION_MAIL"
|
||||
```
|
||||
- Customize the SMB variables in the file "```start_disk_monitoring.bat```" or comment it out!
|
||||
```net use x: \\MY_SMB_SERVER_IP\web /USER:MY_SMB_USER MY_SMB_PASSWORD```
|
||||
|
||||
### Automated checks:
|
||||
- Installation of the windows scheduler task to automate the checks. The template is located in the file "```windows_task_scheduler_template.xml```"
|
50
_windows_disk_monitoring/disk_monitoring.ps1
Normal file
50
_windows_disk_monitoring/disk_monitoring.ps1
Normal file
@ -0,0 +1,50 @@
|
||||
$localhost="HOST-BLACKNET"
|
||||
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\Smart Storage Administrator\ssacli\bin\ssacli.exe" controller slot=2 physicaldrive all show
|
||||
C:\Windows\System32\cmd.exe /c "C:\Program Files\Smart Storage Administrator\ssacli\bin\ssacli.exe" controller slot=0 physicaldrive all show
|
||||
}
|
||||
|
||||
CheckSmartArray | out-file -filepath $logfile -append
|
||||
|
||||
function SentDiskDrivefailedviaMail {
|
||||
$Logs=Get-Content $logfile
|
||||
$smtpServer = "smtp.gmail.com"
|
||||
$smtpFrom = "MY_SERVER_MAIL@gmail.com"
|
||||
$SMTPPort = "587"
|
||||
$Username = "MY_SERVER_MAIL@gmail.com"
|
||||
$Password = "MY_SERVER_MAIL_PASSWORD"
|
||||
$smtpTo = "MY_DESTINATION_MAIL"
|
||||
$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
|
||||
}
|
||||
}
|
BIN
_windows_disk_monitoring/log.txt
Normal file
BIN
_windows_disk_monitoring/log.txt
Normal file
Binary file not shown.
9
_windows_disk_monitoring/start_disk_monitoring.bat
Normal file
9
_windows_disk_monitoring/start_disk_monitoring.bat
Normal file
@ -0,0 +1,9 @@
|
||||
@echo off
|
||||
cd C:\_\hp_disk_monitoring\
|
||||
REM Generates the array output health data and send mail if failed disks are found:
|
||||
Powershell.exe -executionpolicy remotesigned -File C:\_\hp_disk_monitoring\disk_monitoring.ps1
|
||||
|
||||
REM Mounts the SMB volume where the frontend is hosted and copies the report:
|
||||
net use x: \\MY_SMB_SERVER_IP\web /USER:MY_SMB_USER MY_SMB_PASSWORD
|
||||
xcopy C:\_\hp_disk_monitoring\log.txt x:\hprack-mon\ /Y
|
||||
net use x: /delete
|
BIN
_windows_disk_monitoring/windows_task_scheduler_template.xml
Normal file
BIN
_windows_disk_monitoring/windows_task_scheduler_template.xml
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user