Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Sends our Alert Mail
- function sendMail($AlertType, $body) {
- #SMTP server name
- $smtpServer = "smtp.gmail.com"
- $SMTPPort = "587"
- $Username = "@gmail.com"
- $Password = ""
- #Creating a Mail object
- $msg = New-Object System.Net.Mail.MailMessage
- #Creating SMTP server object
- $smtp = New-Object System.Net.Mail.SmtpClient($smtpServer,$SMTPPort)om
- $smtp.EnableSSL = $true
- $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
- #Email structure
- $msg.From = "$env:COMPUTERNAME@domain.com"
- $msg.ReplyTo = "No-Reply@domain.com"
- $msg.To.Add("ADMIN@domain.com")
- $msg.Subject = "Dell OMSA $AlertType Alert on $env:COMPUTERNAME"
- $msg.body = $body
- #Sending email
- $smtp.Send($msg)
- }
- # Kicks Off OM Alert Config Commands for all Warnings/Failures
- Function Setup(){
- # Define our command String
- $ScriptPath = (Get-Variable MyInvocation -Scope 1).Value.MyCommand.Definition
- $command = "powershell "+$ScriptPath+" -eventType"
- # Set Up OpenManage Alert handlers
- SetOMAlert "powersupply" $command;
- SetOMAlert "powersupplywarn" $command;
- SetOMAlert "tempwarn" $command;
- SetOMAlert "tempfail" $command;
- SetOMAlert "fanwarn" $command;
- SetOMAlert "fanfail" $command;
- SetOMAlert "voltwarn" $command;
- SetOMAlert "voltfail" $command;
- SetOMAlert "Intrusion" $command;
- SetOMAlert "redundegrad" $command;
- SetOMAlert "redunlost" $command;
- SetOMAlert "memprefail" $command;
- SetOMAlert "memfail" $command;
- SetOMAlert "hardwarelogwarn" $command;
- SetOMAlert "hardwarelogfull" $command;
- SetOMAlert "processorwarn" $command;
- SetOMAlert "processorfail" $command;
- SetOMAlert "watchdogasr" $command;
- SetOMAlert "batterywarn" $command;
- SetOMAlert "batteryfail" $command;
- SetOMAlert "systempowerwarn" $command;
- SetOMAlert "systempowerfail" $command;
- SetOMAlert "storagesyswarn" $command;
- SetOMAlert "storagesysfail" $command;
- SetOMAlert "storagectrlwarn" $command;
- SetOMAlert "storagectrlfail" $command;
- SetOMAlert "pdiskwarn" $command;
- SetOMAlert "pdiskfail" $command;
- SetOMAlert "vdiskwarn" $command;
- SetOMAlert "vdiskfail" $command;
- SetOMAlert "enclosurewarn" $command;
- SetOMAlert "enclosurefail" $command;
- SetOMAlert "storagectrlbatterywarn" $command;
- SetOMAlert "storagectrlbatteryfail" $command;
- # Register Our Event Log Source
- if ([System.Diagnostics.EventLog]::SourceExists("OMSANotify") -eq $false) {
- [System.Diagnostics.EventLog]::CreateEventSource("OMSANotify", "System")
- }
- }
- # OMCONFIG Runner for individual Alert config
- Function SetOMAlert($event, $cmdString){
- invoke-command -scriptblock {omconfig system alertaction event=$Event execappath="$cmdString $event"}
- }
- # Lets Generate A Test case Email, so we can be sure it works
- Function Test(){
- ProcessAlert "test";
- }
- # Logs OMSA Event and Email in Windows Event Log
- Function logEvent($event)
- {
- $EventMsg = "OMSA Notify Processed Dell Open Manage Event $event"
- Write-EventLog -Logname System -Source OMSANotify -eventId 1 -entryType Warning -message $EventMsg
- }
- # Handles All Alert Processing.
- Function ProcessAlert($alert) {
- $AlertMessageString = ""
- # Check if it's a known OMSA Alert
- If($Alerts.containsKey($alert)){
- $AlertMessageString = $Alerts.Get_Item($alert) + " was reported on $Env:COMPUTERNAME. Please log in ASAP and check OMSA for further details."
- }
- Else {
- "Unknown Alert - $alert was reported at $Date on $Env:COMPUTERNAME. Please log in ASAP and check OMSA for further details."
- }
- sendMail $alert $AlertMessageString;
- #Register our event in Windows Event Log.
- logEvent $alert;
- }
- if($eventType) {
- ProcessAlert $event;
- }
- else {
- if($Setup) {
- Setup;
- }
- if($Test) {
- Test;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement