IMC
cancel
Showing results for 
Search instead for 
Did you mean: 

Delay email from Alarm Notification

 
bmckeand
Occasional Contributor

Delay email from Alarm Notification

Do any of you know of a way to delay the emails from Alarm Notification?
To get around issues with alerting devices on reboot, is it possible to build in a delay for the alert notification?

e.g. Wait 5 minutes, re-test and if still down then send?

 

I've looked in a few places but cannot find anything that looks like it will help.  This is a feature we have in previous monitoring software and we'd like to continue with it in IMC.

 

Any help gratefully appreciated

 

2 REPLIES
Dape_
Occasional Contributor

Re: Delay email from Alarm Notification

This is an important feature that IMC is lacking.  Our WAN connections take a hit from time to time and I'll get an email the moment it happens and another email a minute later telling me that it's back up again.  I've been looking everywhere for a solution to this problem so I hope you get an answer soon!

Peter_Debruyne
Honored Contributor

Re: Delay email from Alarm Notification

Hi,

 

Through the eAPI, you would have some options. Last year I started making this, but never had time to finish.

So the powershell script below is just part of a solution (I hope someone can help to complete it :) ).

* eAPI is separate license, but have a chat with your HP account manager if you want to purchase

* script principle:

- use eAPI to query all unrecovered (major/critical) alarms (recovered alarms excluded)

- compare the fault date with current date, if more than x seconds, send mail (now mail text can be customized :) )

- MISSING SECTION: the script needs to keep track of which alarms have been notified by mail. Otherwise, whenever the script runs (e.g. once every minute), a new mail would be sent for the same alarm. I was looking at an interim csv file at the time, but had no time to finish it.

- compare the fault date with current date, if more than x days, set alarm to recovered (cleanup)

- SUGGESTED CHANGE: current script will query all alarms first, and then filter on the date. It is probably better to have a date based query (e.g. all unrecovered alarms of last day), and then continue the normal script.

 

 

#########################################

$imchost = "10.0.1.100"
$imcport = "8080"
$imcprot = "http"

$ImcApiBaseUrl = $imcprot + "://" + $imchost + ":" + $imcport + "/imcrs/"
$ImcBaseUrl = $imcprot + "://" + $imchost + ":" + $imcport + "/imc/"


# interactive password prompt
#if(!$imcadmin){ $imcadmin = Get-Credential }

# password in script (unsafe)
$username = 'admin'
$password = 'admin'

$imcadmin = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))


$DeviceList = @()
$DevInt = @()

[datetime]$currentTime = Get-Date
 
 # imc stores alarm dates in epoch date, sample conversion function  
Function get-epochdate ($epochdate) { [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($epochdate)) }

 # smtp send function with smtp auth and ssl enabled (sample for gmail smtp)
function Sendmail
{
param ($fsubject,$fbody)
$From = "account@gmail.com"
$To = "target-address@gmail.com"
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$Username = "account@gmail.com"
$Password = "password-here"
$subject = $fsubject
$body = $fbody

$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);

$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.Send($From, $To, $subject, $body);
}

 # main function to query alarms
Function imcAlarmLookup
{  
param ($imcFilterType, $imcFilter )                    
 # checking if input filter parameters exist, else use all devices
 if ($imcFilterType -eq $null)
 {
  # recstatus 0 = unrecovered
  # level 1 = critical / 2 = major
$url = $ImcApiBaseUrl + "fault/alarm?recStatus=0&alarmLevel=2"
 }
 else
 {
$url = $ImcApiBaseUrl + "fault/alarm?recStatus=0&alarmLevel=2&" + $imcFilterType + "=" + $imcFilter
 }
 
 # get output
$result = Invoke-RestMethod -Uri $url -method GET -Credential $imcadmin -ContentType "application/xml"
 # process xml output - list - alarm list
$imcalarms = $result.list.alarm
 # prepare temp work arrays
$falarmlist = @()
$falarmrecover = @()

 # parse the retrieved alarm list
foreach($i in $imcalarms) {
 write-host "
 "

  # get fault date
[datetime]$alertStart = get-epochdate $i.faultTime
write-host $alertStart

  # compare fault date with current time
 $AlertDuration = (New-TimeSpan -Start $alertStart -End $currentTime).TotalSeconds
   # more than delay time ?
 if ($AlertDuration -gt 600)
 {
     # ok, found matching alarm
    Write-Output " ### New Alert :"
    write-output $i.deviceName  $i.recStatusDesc  $i.alarmDesc $AlertDuration $i.alarmDetail
     # add it to the alarm list of alarms which have been processed (to prevent future duplicate notification)
    $falarmlist += $i.id
     #ok, send the mail now
    
    $mailsubject = ""
    $mailsubject2 = "HP iMC " + $i.alarmLevelDesc +" Alert : " + $i.devicename + "(" + $i.deviceIP + ") " + $i.alarmDesc
    [string]$falarmparas = $i.paras

    $falarmparas
    $imcfaulturl = $ImcBaseUrl + "fault/browser/faultInfo.jsf?faultId=" + $i.id
    $mailbody = "
    " + $imcfaulturl + "
    " + $falarmparas
    
    sendmail $mailsubject $mailbody
 }
 
  # check if alarm unrecovered for long time
 if ($AlertDuration -gt 86400 )
 {
    Write-Output " ### Recovering Alert :"
  #  write-output $i.deviceName  $i.recStatusDesc  $i.alarmDesc $AlertDuration $i.alarmDetail
    $falarmrecover += $i.id
    $i.id
    imcAlarmRecover $i.id

 }  
}
$falarmlist.count
$falarmrecover.count
$falarmrecover
 # TODO : save processed alarms to csv file. Read csv file at startup  to check if alarm already processed
}


Function imcAlarmRecover
{
param ($AlarmID)
 
 $url = $ImcApiBaseUrl + "fault/alarm/recover/" + $AlarmID
 

$result = Invoke-RestMethod -Uri $url -method PUT -Credential $imcadmin -ContentType "application/xml"
}




imcalarmlookup
#######################################################