From 83cb53686633fa78ebbb3b515364110ffd3706c4 Mon Sep 17 00:00:00 2001 From: Michael Reber Date: Tue, 12 Nov 2019 08:58:12 +0100 Subject: [PATCH] Adding windows disk monitoring --- _windows_disk_monitoring/README.md | 21 ++++++++ _windows_disk_monitoring/disk_monitoring.ps1 | 50 ++++++++++++++++++ _windows_disk_monitoring/log.txt | Bin 0 -> 1922 bytes .../start_disk_monitoring.bat | 9 ++++ .../windows_task_scheduler_template.xml | Bin 0 -> 3924 bytes 5 files changed, 80 insertions(+) create mode 100644 _windows_disk_monitoring/README.md create mode 100644 _windows_disk_monitoring/disk_monitoring.ps1 create mode 100644 _windows_disk_monitoring/log.txt create mode 100644 _windows_disk_monitoring/start_disk_monitoring.bat create mode 100644 _windows_disk_monitoring/windows_task_scheduler_template.xml diff --git a/_windows_disk_monitoring/README.md b/_windows_disk_monitoring/README.md new file mode 100644 index 0000000..8203e66 --- /dev/null +++ b/_windows_disk_monitoring/README.md @@ -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```" diff --git a/_windows_disk_monitoring/disk_monitoring.ps1 b/_windows_disk_monitoring/disk_monitoring.ps1 new file mode 100644 index 0000000..1589189 --- /dev/null +++ b/_windows_disk_monitoring/disk_monitoring.ps1 @@ -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 + } +} diff --git a/_windows_disk_monitoring/log.txt b/_windows_disk_monitoring/log.txt new file mode 100644 index 0000000000000000000000000000000000000000..576c941a1a5216bbc2b03d4bc2534c48f20af098 GIT binary patch literal 1922 zcmchX-D(0c5QWcm!FSk83trUhs;hU3(w1IW*e7sRaKW~sBKq=e&upxX!TrN1A%C06 zRW5tVub~L zZs=)B?@P>hN`f8c+~342dTgb7sAI)bG>u+~Ip3#tJ;X=0CK~(_kvC%hf+351@yRR1 z&lsfhG2ZZKkXE5l^iz&T-Hb+^V$-r{^vb2!wC+IDE=|*}O!KF$B3&kAu$3uyU&n}w zj;XB~i?mt+ZuP1P^(q!cdhI&WtDKduSCb}7uP$kPOCjgEY|{7{3UNsjl%@%8Mx!%U u{yaaI&Ddn+^7XO#r^(M{lO`*dUD9-{n>v5zOq$LeZYnHI6IP~?_vjZy4gN9! literal 0 HcmV?d00001 diff --git a/_windows_disk_monitoring/start_disk_monitoring.bat b/_windows_disk_monitoring/start_disk_monitoring.bat new file mode 100644 index 0000000..7d736c1 --- /dev/null +++ b/_windows_disk_monitoring/start_disk_monitoring.bat @@ -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 diff --git a/_windows_disk_monitoring/windows_task_scheduler_template.xml b/_windows_disk_monitoring/windows_task_scheduler_template.xml new file mode 100644 index 0000000000000000000000000000000000000000..a01ace9aae18e580a70e29563cb232c9def72a9c GIT binary patch literal 3924 zcmbtXTTdEM5T55I{SU-#a`GqxnMx!>xtCDB$(EEPFGZ|5P(tZrKL9n98>L=IN50E8 zxW0hrK&tXlK1c<-J)qnzMJy|#X$`?iO}7%`Gm)=Sz$b#PTj(4sQXcCNJ5%V7@Vy3S zUac8}_em`Zu>S;VK|aCaqLlGe#B)JqW32Jas;!xwIoMZ`b7;8%LInC095J5heGA`f zJeg1AHU5V346sigrBhW&4*8{K5?{ix=sC|Mjv*t3F z*#4uerwJH z=wSyw%=}H$veNC@j0hmZsyRgMva@J$n%iZL)JS{VuY}Spd&}r)JoD9N)H?m--L$gF z>sNi0@TP)FvwrNO-Y2vA@V#BclLL34Q#Lsnl5@~icm+LfQ=tWkDyo8WZ5utpbx)(@ zb7UiPuGMpljBv7yfYQ{i=RD_>tzo~1ozZLV>2+2riA;{H?{m)=)BV`Bp`T}r&9fxU zs^diKi1dlp6XyZ#?P2Y!?PutW5$Jubu@>f7s1tI4xjew>Lo42j;(OTudZc+B0r@G> zl`YJJQ|LPcm0oay4%I5ZZ{COCTj6F6b^d@I7O_pVzfIEDT0?Bj>n41hqW(JSCC`4& z3Ht2&x|xKpg%;X`y3`v+xS$>v&EEAgz8=Z?^=<>L??LcwU=MRL zuC9EmewR5~?Bv`@l$^_}_>$TUmFIKx8u27{I>xIwlep|LXWweSDu}VGsCm|DLjzXv zX2~;dSw*dq@a;*TRLN+iX}%=qVt~&8mZan1(|oyXWw?l>QC4yKn9Jt|BgX8EQMv5F z8s_6fYbru+?Y5lO`@d+uZFb^Zz>XpMh*K|s{^aRv6N=I1T|NYdpV#*x_*Pt^V(x(4 zK^!cuX|ES?_!vic*BZcb-t#ST9js&Q9qYOesGO<_-7VJ8xC~0sGu@ A`~Uy| literal 0 HcmV?d00001