Fixed
Details
Assignee
Jonathan SartinJonathan SartinReporter
Joakim KasimirJoakim KasimirComponents
Fix versions
Affects versions
Priority
Minor
Details
Details
Assignee
Jonathan Sartin
Jonathan SartinReporter
Joakim Kasimir
Joakim KasimirComponents
Fix versions
Affects versions
Priority
PagerDuty
PagerDuty
PagerDuty
Created May 18, 2005 at 2:25 AM
Updated January 27, 2017 at 4:32 PM
Resolved February 6, 2006 at 8:03 AM
Just a simple modification for XMPPNotificationStrategy.java file.
Intead of sendng a XMPP message to a jabber ID this modification join a group
chat and send all notifications. The user where the notification destination
path use has to change the XMPP Adress to the group chat adress.
I think this is more usefull because then everybody in the staff can tune in to
the group chat and read and comment all notifications.
Maybe you can modify so we can choose type of XMPP message; chat or groupChat.
-----------8X--------------------------------------------------- /*
Created on Mar 7, 2005
Copyright (C) 2005, The OpenNMS Group, Inc..
*
*/
package org.opennms.netmgt.notifd;
import java.io.FileInputStream;
import java.util.List;
import java.util.Properties;
import org.apache.log4j.Category;
import org.opennms.core.utils.Argument;
import org.opennms.core.utils.ThreadCategory;
import org.opennms.netmgt.ConfigFileConstants;
import org.opennms.netmgt.config.NotificationManager;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.GroupChat;
/**
Implements NotificationStragey pattern used to send notifications using the
XMPP message protocol.
*
@author <A HREF="opennms@obado.net">Chris Abernethy </A>
*
*/
public class XMPPNotificationStrategy implements NotificationStrategy {
/**
String used to identify the user to whom the XMPP
message will be sent.
*/
private static final int XMPP_TO;
/**
Text of XMPP Message to be sent.
*/
private static final int XMPP_MESSAGE;
/**
The value of this constant indicates the number of
XMPP constants defined.
*/
private static final int XMPP_MAX;
/**
Mapping of index values to meaningful strings.
*/
private static final String[] INDEX_TO_NAME;
private Properties props = new Properties();
private Category log = null;
// Initialize constant class data
static {
XMPP_TO = 0;
XMPP_MESSAGE = 1;
XMPP_MAX = 2;
INDEX_TO_NAME = new String[XMPP_MAX];
INDEX_TO_NAME[XMPP_TO] = "To";
INDEX_TO_NAME[XMPP_MESSAGE] = "Message";
}
/**
*
*/
public XMPPNotificationStrategy() {
}
/*
(non-Javadoc)
*
@see org.opennms.netmgt.notifd.NotificationStrategy#send(java.util.List)
*/
public int send(List arguments) {
try {
this.props.load(new
FileInputStream(ConfigFileConstants.getFile(ConfigFileConstants.XMPP_CONFIG_FILE_NAME)));
String[] parsedArgs = this.parseArguments(arguments);
String server = this.props.getProperty("xmpp.server");
String user = this.props.getProperty("xmpp.user");
String pass = this.props.getProperty("xmpp.pass");
XMPPConnection connection = new XMPPConnection(server);
connection.login(user, pass);
/*
connection.createChat(parsedArgs[XMPP_TO]).sendMessage(parsedArgs[XMPP_MESSAGE]); */
GroupChat newGroupChat =
connection.createGroupChat(parsedArgs[XMPP_TO]);
newGroupChat.join("OpenNMS");
newGroupChat.sendMessage(parsedArgs[XMPP_MESSAGE]);
} catch (Exception e) {
ThreadCategory.getInstance(getClass()).error(e.getMessage());
return 1;
}
return 0;
}
/**
This method extracts the xmpp address and message text from the
parameters passed in the notification.
*
@param arguments
@return String[]
@throws Exception
*/
private String[] parseArguments(List arguments) throws Exception {
String[] parsedArgs = new String[XMPP_MAX];
for (int i = 0; i < arguments.size(); i++) {
Argument arg = (Argument) arguments.get
;
if (NotificationManager.PARAM_XMPP_ADDRESS.equals(arg.getSwitch())) {
parsedArgs[XMPP_TO] = arg.getValue();
} else if (NotificationManager.PARAM_TEXT_MSG.equals(arg.getSwitch())) {
parsedArgs[XMPP_MESSAGE] = arg.getValue();
}
}
for (int i = 0; i < XMPP_MAX; ++i) {
if (parsedArgs[i] == null) {
throw( new Exception("Incomplete argument set, missing
argument: " + INDEX_TO_NAME[i] ) );
}
}
return parsedArgs;
}
}