-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsystems_check.ps1
74 lines (61 loc) · 7.34 KB
/
systems_check.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Systems Availability Check Script, written by Ugo Emekauwa ([email protected] or [email protected])
# Start script
Write-Output "$(Get-Date) - Starting Systems Check Script." | Out-File -Append "c:\Logs\systems_check.log"
# Setting up ping command variable
Write-Output "$(Get-Date) - Setting up ping command variable." | Out-File -Append "c:\Logs\systems_check.log"
$ping = New-Object System.Net.NetworkInformation.Ping
# Setting email alert sender
Write-Output "$(Get-Date) - Setting email alert sender." | Out-File -Append "c:\Logs\systems_check.log"
$email_sender = "[email protected]"
# Setting email alert recipients (multiple recipients should be separated by a comma)
Write-Output "$(Get-Date) - Setting email alert recipients." | Out-File -Append "c:\Logs\systems_check.log"
$email_recipients = "[email protected], [email protected]"
# Setting SMTP server for sending email alerts
Write-Output "$(Get-Date) - Setting SMTP server for sending email alerts." | Out-File -Append "c:\Logs\systems_check.log"
$smtp_server = "smtp.company.org"
# Capturing values from system XML file
Write-Output "$(Get-Date) - Capturing values from system XML file." | Out-File -Append "c:\Logs\systems_check.log"
[xml]$systemfile = Get-Content -Path "c:\Systems\system1.xml"
# Pinging server node 1 (attempt to ping will be made for up to 1 minute)
Write-Output "$(Get-Date) - Pinging server $($systemfile.cluster.nodes.node1.name)" | Out-File -Append "c:\Logs\systems_check.log"
$date = Get-Date
Do {
$result = $ping.Send($systemfile.cluster.nodes.node1.ip_address)
} While ($result.Status -ne "Success" -and $date.AddMinutes(1) -gt (Get-Date))
# Log results of the ping attempt for server node 1 and send an email alert if the ping attempt failed
If ($result.Status -ne "Success"){
Send-MailMessage -From $email_sender -To $email_recipients -Subject "[System Hardware Alert]: Server $($systemfile.cluster.nodes.node1.name) in $($systemfile.cluster.datacenter) is not Responding" -body "BRIEF SUMMARY ON AFFECTED DEVICE: `nName: $($systemfile.cluster.nodes.node1.name) `nSerial Number: $($systemfile.cluster.nodes.node1.serial) `nLocation: $($systemfile.cluster.datacenter) `nTOR: $($systemfile.cluster.tor) `nCluster Device Association: $($systemfile.cluster.name) `n `nISSUE: Please be advised that on $($(Get-Date)), the server node named $($systemfile.cluster.nodes.node1.name) with the serial number $($systemfile.cluster.nodes.node1.serial) under $($systemfile.cluster.name) located in $($systemfile.cluster.datacenter) did not respond to system pings. Please check the cluster server node and/or data center environment. `n `nRESOLUTION: Please verify that there is not a power or cooling issue with the device. If none of the above issues are present, please escalate to the infrastructure team." -SmtpServer $smtp_server
Write-Output "$(Get-Date) - Server $($systemfile.cluster.nodes.node1.name) is unreachable. Alert notification email sent." | Out-File -Append "c:\Logs\systems_check.log"
} Else {
Write-Output "$(Get-Date) - Server $($systemfile.cluster.nodes.node1.name) with the serial number $($systemfile.cluster.nodes.node1.serial) under $($systemfile.cluster.name) is online." | Out-File -Append "c:\Logs\systems_check.log"
}
# Pinging server node 2 (Attempt to ping will be made for up to 1 minute)
Write-Output "$(Get-Date) - Pinging server $($systemfile.cluster.nodes.node2.name)" | Out-File -Append "c:\Logs\systems_check.log"
$date = Get-Date
Do {
$result = $ping.Send($systemfile.cluster.nodes.node2.ip_address)
} While ($result.Status -ne "Success" -and $date.AddMinutes(1) -gt (Get-Date))
# Log results of the ping attempt for server node 2 and send an email alert if the ping attempt failed
If ($result.Status -ne "Success"){
Send-MailMessage -From $email_sender -To $email_recipients -Subject "[System Hardware Alert]: Server $($systemfile.cluster.nodes.node2.name) in $($systemfile.cluster.datacenter) is not Responding" -body "BRIEF SUMMARY ON AFFECTED DEVICE: `nName: $($systemfile.cluster.nodes.node2.name) `nSerial Number: $($systemfile.cluster.nodes.node2.serial) `nLocation: $($systemfile.cluster.datacenter) `nTOR: $($systemfile.cluster.tor) `nCluster Device Association: $($systemfile.cluster.name) `n `nISSUE: Please be advised that on $($(Get-Date)), the server node named $($systemfile.cluster.nodes.node2.name) with the serial number $($systemfile.cluster.nodes.node2.serial) under $($systemfile.cluster.name) located in $($systemfile.cluster.datacenter) did not respond to system pings. Please check the cluster server node and/or data center environment. `n `nRESOLUTION: Please verify that there is not a power or cooling issue with the device. If none of the above issues are present, please escalate to the infrastructure team." -SmtpServer $smtp_server
Write-Output "$(Get-Date) - Server $($systemfile.cluster.nodes.node2.name) is unreachable. Alert notification email sent." | Out-File -Append "c:\Logs\systems_check.log"
} Else {
Write-Output "$(Get-Date) - Server $($systemfile.cluster.nodes.node2.name) with the serial number $($systemfile.cluster.nodes.node2.serial) under $($systemfile.cluster.name) is online." | Out-File -Append "c:\Logs\systems_check.log"
}
# Pinging server node 3, sending alert if unavailable (Attempt to ping will be made for up to 1 minute)
Write-Output "$(Get-Date) - Pinging server $($systemfile.cluster.nodes.node3.name)" | Out-File -Append "c:\Logs\systems_check.log"
$date = Get-Date
Do {
$result = $ping.Send($systemfile.cluster.nodes.node3.ip_address)
} While ($result.Status -ne "Success" -and $date.AddMinutes(1) -gt (Get-Date))
# Log results of the ping attempt for server node 3 and send an email alert if the ping attempt failed
$date = get-date
If ($result.Status -ne "Success"){
Send-MailMessage -From $email_sender -To $email_recipients -Subject "[System Hardware Alert]: Server $($systemfile.cluster.nodes.node3.name) in $($systemfile.cluster.datacenter) is not Responding" -body "BRIEF SUMMARY ON AFFECTED DEVICE: `nName: $($systemfile.cluster.nodes.node3.name) `nSerial Number: $($systemfile.cluster.nodes.node3.serial) `nLocation: $($systemfile.cluster.datacenter) `nTOR: $($systemfile.cluster.tor) `nCluster Device Association: $($systemfile.cluster.name) `n `nISSUE: Please be advised that on $($(Get-Date)), the server node named $($systemfile.cluster.nodes.node3.name) with the serial number $($systemfile.cluster.nodes.node3.serial) under $($systemfile.cluster.name) located in $($systemfile.cluster.datacenter) did not respond to system pings. Please check the cluster server node and/or data center environment. `n `nRESOLUTION: Please verify that there is not a power or cooling issue with the device. If none of the above issues are present, please escalate to the infrastructure team." -SmtpServer $smtp_server
Write-Output "$(Get-Date) - Server $($systemfile.cluster.nodes.node3.name) is unreachable. Alert notification email sent." | Out-File -Append "c:\Logs\systems_check.log"
} Else {
Write-Output "$(Get-Date) - Server $($systemfile.cluster.nodes.node3.name) with the serial number $($systemfile.cluster.nodes.node3.serial) under $($systemfile.cluster.name) is online." | Out-File -Append "c:\Logs\systems_check.log"
}
# Exiting script
Write-Output "$(Get-Date) - Systems Check Script complete, exiting." | Out-File -Append "c:\Logs\systems_check.log"
Exit