Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ugo-emekauwa authored Dec 1, 2019
0 parents commit 54c1d7d
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
23 changes: 23 additions & 0 deletions system1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<cluster>
<name>Service Cluster 1</name>
<datacenter>RTP</datacenter>
<tor>tor-switch1-rack34</tor>
<nodes>
<node1>
<name>server-node1</name>
<serial>SVC12040VCB</serial>
<ip_address>192.168.2.111</ip_address>
</node1>
<node2>
<name>server-node2</name>
<serial>MGQ22040VPS</serial>
<ip_address>192.168.2.112</ip_address>
</node2>
<node3>
<name>server-node3</name>
<serial>ZBL320400V8</serial>
<ip_address>192.168.2.113</ip_address>
</node3>
</nodes>
</cluster>
71 changes: 71 additions & 0 deletions systems_check.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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"
Do {
$result = $ping.Send($systemfile.cluster.nodes.node1.ip_address)
} While ($result.Status -ne "Success" -and $(Get-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"
Do {
$result = $ping.Send($systemfile.cluster.nodes.node2.ip_address)
} While ($result.Status -ne "Success" -and $(Get-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"
Do {
$result = $ping.Send($systemfile.cluster.nodes.node3.ip_address)
} While ($result.Status -ne "Success" -and $(Get-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

0 comments on commit 54c1d7d

Please sign in to comment.