Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Param($action, $alertcode)
- # Set the variables below to suit your environment. The script will default to using localhost and port 25 if neither value is specified
- # Change the $MailSubject as preferred "COMPUTERNAME" and "ALERTDETAIL" will be replaced with the appropriate values if left in place.
- # For Gmail accounts:
- # Set SMTPServer = "smtp.gmail.com"
- # set SMTPUser and SMTPPassword to your gmail credentials, do not include the @gmail.com part in the username.
- # set SMTPPort = 587. Set EnableSSL = $true
- ## Change variables here
- $EmailFrom = ""
- $EmailTo = ""
- $SMTPServer = ""
- $SMTPPort = ""
- $SMTPUser = ""
- $SMTPPassword = ""
- $EnableSSL = $false
- $MailSubject = "Dell Server Alert on COMPUTERNAME - ALERTDETAIL"
- ## End of variables
- function SetDellAlert
- {
- Param($DellEvent, $DellEventDescription, $EventID)
- $omsacommand = "omconfig system alertaction event=$DellEvent execappath=`"$powershellpath -executionpolicy unrestricted $scriptpath email $EventID`" "
- "Configuring Alert: $DellEvent ($DellEventDescription)"
- Invoke-Expression $omsacommand
- }
- function SendAlert($Subject)
- {
- $MailClient = new-object system.net.mail.smtpClient
- $MailClient.EnableSSL = $EnableSSL
- if ($SMTPServer -eq "") {$SMTPServer = "localhost"}
- if ($SMTPPort -eq "") {$SMTPPort = "25"}
- if ($SMTPUser -ne "")
- {
- $MailClient.UseDefaultCredentials = "false"
- $MailClient.Credentials = New-Object System.Net.NetworkCredential($SMTPUser, $SMTPPassword)
- }
- $MailMessage = New-Object system.net.mail.mailmessage
- $MailMessage.from = ($EmailFrom)
- $MailMessage.to.add($EmailTo)
- $MailMessage.subject = $Subject
- $MailMessage.body = ""
- $MailClient.Host = $SMTPServer
- $MailClient.Port = $SMTPPort
- $MailClient.Send($MailMessage)
- }
- Function CreateMessageBody
- {
- $result = invoke-expression "omreport chassis info"
- $result = $result + (invoke-expression "omreport system alertlog")
- $result
- }
- $AlertConfig = "powersupply|Power supply failure", "powersupplywarn|Power supply warning", "tempwarn|Temperature warning", "tempfail|Temperature failure", "fanwarn|Fan speed warning", "fanfail|Fan speed failure", "voltwarn|Voltage warning", "voltfail|Voltage failure", "intrusion|Chassis intrusion", "redundegrad|Redundancy degraded", "redunlost|Redundancy lost", "memprefail|Memory pre-failure", "memfail|Memory failure", "hardwarelogwarn|Hardware log warning", "hardwarelogfull|Hardware log full", "processorwarn|Processor warning", "processorfail|Processor failure", "watchdogasr|Watchdog asr", "batterywarn|Battery warning", "batteryfail|Battery failure", "systempowerwarn|Power warning", "systempowerfail|Power failure", "systempeakpower|Peak power", "removableflashmediapresent|Removable flash media present", "removableflashmediaremoved|Removable flash media removed", "removableflashmediafail|Removable flash media failure", "storagesyswarn|Storage System warning", "storagesysfail|Storage System failure", "storagectrlwarn|Storage Controller warning", "storagectrlfail|Storage Controller failure", "pdiskwarn|Physical Disk warning", "pdiskfail|Physical Disk failure", "vdiskwarn|Virtual Disk warning", "vdiskfail|Virtual Disk failure", "enclosurewarn|Enclosure warning", "enclosurefail|Enclosure failure", "storagectrlbatterywarn|Storage Controller Battery warning", "storagectrlbatteryfail|Storage Controller Battery failure"
- $ComputerName = gc env:computername
- $a = New-Object -ComObject Scripting.FileSystemObject
- $f = $a.GetFile("$pshome\powershell.exe")
- $powershellpath = $f.Path
- $fullscriptpath=$MyInvocation.Mycommand.path
- $f = $a.GetFile($fullscriptpath)
- $scriptpath=$f.shortpath
- if ($action)
- {
- $action = $action.trim().tolower()
- switch ($action)
- {
- "setup"
- {
- for ($i = 0; $i -lt $AlertConfig.count; $i++)
- {
- $AlertDetails = $AlertConfig[$i].split("|")
- SetDellAlert $AlertDetails[0] $AlertDetails[1] $i
- }
- }
- "email"
- {
- $AlertDetails = $AlertConfig[$alertcode].split("|")
- $MailSubject = $MailSubject -replace('COMPUTERNAME', $ComputerName)
- $MailSubject = $MailSubject -replace('ALERTDETAIL', $AlertDetails[1])
- Sendalert $MailSubject
- }
- "testemail"
- {
- $MailSubject = $MailSubject -replace('COMPUTERNAME', $ComputerName)
- $MailSubject = $MailSubject -replace('ALERTDETAIL', "Test Alert")
- Sendalert $MailSubject
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement