Article
· Mar 9, 2018 3m read

Sending Alerts to Mobile Phone using Pushover from HTTP.OutboundAdapter

I wanted to see some alerts that occur in my Productions in a Mobile Device, I came across Pushover.net recently that although has an upfront cost  $5 you can send as many messages as you like after that, there is a 7 day free trial to check it out.

To Integrate this with a production I did the following.

Create an account and set up a device on https://pushover.net/

Record the following API Keys from the web site on the main page you will see

Your User Key   example: ueh3t7478foi3ruf2ogb3syu4fs34s

You then need to create an application I set

Name : Cache

Type : Application

And left the oter settings blank.

This will give you a 

API Token/Key  example: auh000es1aaaa7ddeb3i4jfkgwswero

I then created this class to add an operation to the production, replace your Key, token and device name into

 Do httprequest.SetParam("token","auh000es1aaaa7ddeb3i4jfkgwswero")
 Do httprequest.SetParam("user","ueh3t7478foi3ruf2ogb3syu4fs34s")

Do httprequest.SetParam("device","motogplay")
Class TrustDev.TrustMon.Operations.PushOverSender Extends Ens.BusinessOperation
{

Parameter ADAPTER = "EnsLib.HTTP.OutboundAdapter";

Property Adapter As EnsLib.HTTP.OutboundAdapter;

Parameter INVOCATION = "Queue";

Method OnD03Alert(pReq As TrustDev.TrustMon.Messages.Alert, Output pResp As %String) As %Status
{
    
        Set Message = "Server = <b>"_pReq.ServerName_"</b>"
        
        Set Message = Message _ "Alert Code = "_pReq.EventDescription
        
        Set title = pReq.EventCode_" : Priority "_pReq.EventAlertValue
        
        Set httprequest = ##class(%Net.HttpRequest).%New()
        
        Set httprequest.SSLConfiguration = "pushover"
        
        Set httprequest.Https = $$$YES
        
        Set httprequest.Server = "api.pushover.net"
        
        Set httprequest.Location = "/1/messages.json"
        
        Set httprequest.ContentType = "application/x-www-form-urlencoded"
        
        Do httprequest.SetParam("token","auh000es1aaaa7ddeb3i4jfkgwswero")
        
        Do httprequest.SetParam("user","ueh3t7478foi3ruf2ogb3syu4fs34s")
        
        Do httprequest.SetParam("device","motogplay")
        
        Do httprequest.SetParam("title",title)
        
        Do httprequest.SetParam("html",1)
        
        Do httprequest.SetParam("message",Message)
        
        Do httprequest.Post(,0)
        
        set stream = httprequest.HttpResponse.Data
            
        while 'stream.AtEnd {
                Set pResp = stream.Read($$$MaxStringLength)
        }
    
    Quit $$$OK
}

XData MessageMap
{
<MapItems>
    <MapItem MessageType="TrustDev.TrustMon.Messages.Alert"> 
        <Method>OnD03Alert</Method>
    </MapItem>
</MapItems>
}

}

The message I pass into this class is the following, but you could adapt this to your own requirements.

Class TrustDev.TrustMon.Messages.Alert Extends Ens.Request
{

Property SiteName As %String;

Property ServerName As %String;

Property ServerId As %Integer;

Property ProductionName As %String;

Property EventDateTime As %DateTime;

Property EventCode As %String;

Property EventItem As %String;

Property EventCodeId As %String;

Property EventDescription As %String(MAXLEN = 50, TRUNCATE = 1);

Property EventValue As %Double;

Property EventValueUnits As %String;

Property EventSD25 As %Double;

Property EventAlertValue As %Double;

Property EventAlertNow As %Boolean;

Property ErrorCode As %String;

Property EventValue2 As %Double;

Property EventValue3 As %Double;

Property EventValue4 As %Double;

Property EventValue5 As %Double;

}

Your going to need a empty SSL Client Configuration

In Ensemble go to System > Security Management > SSL/TLS Configurations 

Click Create New Configuration

Name it Pushover and leave all the other fields as default and click save

On a Production add a new Operation using the class TrustDev.TrustMon.Operations.PushOverSender

In the basic settings set

HTTP Server = https://api.pushover.net/1/messages.json

In Connection Setting set the SSL Configuration to pushover, as created above

Uncheck SSL Check Server Identity

This should now be working, click Actions -> test and add some values to the Request Details and you should get your first notification through.

Good Luck! :)

Discussion (5)0
Log in or sign up to continue

Hi Julian

To send a priority to pushover you need to add

Do httprequest.SetParam("priority", pReq.EventPriority)

set the value between -2 and 1, if you want to set it to Emergency Priority (2) you will also need to send retry and expire parameters like this

Do httprequest.SetParam("retry", pReq.EventRetry)

Do httprequest.SetParam("expire", pReq.EventExpire)

Do httprequest.SetParam("priority", pReq.EventPriority)

The defaults for Expire is 60 and retry 3600

I added these values to the inbound message pReq As TrustDev.TrustMon.Messages.Alert

Property EventPriority As %Integer [ InitialExpression = ];

Property EventRetry As %Integer [ InitialExpression = 60 ];

Property EventExpire As %Integer [ InitialExpression = 3600 ];

Hi Mark.

After throwing in an if statement for the Priority variation and some other local tweaks I have this working perfectly, so thank you for sharing.

I also added the Token and User Key as a setting to be set from the Operation within Ensemble.

It would be good to catch up outside of the Intersystems forums sometime soon.

Cheers!


For anyone interested in adding the Token and User Key

So I included before the method:

Property Token As %String;

Property User As %String;

Parameter SETTINGS = "Token, User";

And then the http request parameter became:

        Do httprequest.SetParam("token",..Token)
        
        Do httprequest.SetParam("user",..User)

This leaves the token and user key to be configured within Ensemble via the Management Portal: