Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Some cleanup and externalization of settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
pilhuhn committed Apr 30, 2014
1 parent cd310d3 commit b778af0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,26 @@
/**
* Persistent component used to send alert notifications via Aerogear
* Unified Push Server
*
* @author Heiko W. Rupp
*/
public class UpsAlertComponent implements ServerPluginComponent {

private final Log log = LogFactory.getLog(UpsAlertComponent.class);

String targetHost;
String masterSecret;
String pushId;
int port;

public void initialize(ServerPluginContext context) throws Exception {
Configuration preferences = context.getPluginConfiguration();


targetHost = preferences.getSimpleValue("server");
masterSecret = preferences.getSimpleValue("masterSecret");
pushId = preferences.getSimpleValue("pushId");
String tmp = preferences.getSimpleValue("port","8080");
port = Short.valueOf(tmp);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,25 @@
import org.rhq.enterprise.server.plugin.pc.alert.AlertSender;

/**
* Sends an alert notification via IRC.
* Sends an alert notification via Aerogear Unified Push Server.
*
* @author Justin Harris
* @author Heiko Rupp
* @author Matze Wessendorf
*/
@SuppressWarnings("unused")
public class UpsSender extends AlertSender<UpsAlertComponent> {

private final Log log = LogFactory.getLog(UpsSender.class);

public UpsSender() {
// Disable those extensions as they prevent SSL usage in most cases
// where self-signed certs are in play.
// TODO revisit
System.setProperty("jsse.enableSNIExtension", "false");
}

@Override
public SenderResult send(Alert alert) {
String channel = this.alertParameters.getSimpleValue("channel", null);
String server = preferences.getSimpleValue("server", "-not set-");

StringBuilder b = new StringBuilder();
b.append("Alert on");
Expand All @@ -62,14 +64,17 @@ public SenderResult send(Alert alert) {


UnifiedMessage unifiedMessage = new UnifiedMessage.Builder()
.pushApplicationId("b0a1b452-b749-4dc3-b789-bf2cefd28398")
.masterSecret("45b65fc9-2947-4735-ad73-b18e4518b406")
.pushApplicationId(pluginComponent.pushId)
.masterSecret(pluginComponent.masterSecret)
.alert(b.toString()) // TODO nicer max 160 chars
.sound("default") // iOS specific
.build();


SenderClient sender = new SenderClient("https://" + pluginComponent.targetHost);
String rootServerURL = "https://" + pluginComponent.targetHost;
if (pluginComponent.port!=80) {
rootServerURL += ":" + pluginComponent.port;
}
SenderClient sender = new SenderClient(rootServerURL);

final SenderResult[] result = new SenderResult[1];
sender.send(unifiedMessage, new MessageResponseCallback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@

<!-- Global preferences -->
<serverplugin:plugin-configuration>
<c:simple-property name="server" type="string" description="UPS server to connect to." default="summit-pushee.rhcloud.com" />
<c:simple-property name="port" type="integer" default="8080" required="false" description="Port number on the ups server"/>
<c:simple-property name="pushId" type="string" default="b0a1b452-b749-4dc3-b789-bf2cefd28398" description="Id of the push app you use"/>
<c:simple-property name="server" type="string" description="UPS server to connect to." />
<c:simple-property name="port" type="integer" default="8080" required="false" description="Port number on the ups server (default 8080)"/>
<c:simple-property name="pushId" type="string" description="Id of the push app you use"/>
<c:simple-property name="masterSecret" type="password" description="Master secret for the push sender"/>

</serverplugin:plugin-configuration>

<!-- How does this sender show up in drop downs etc -->
Expand Down

0 comments on commit b778af0

Please sign in to comment.