XMPP Jabber notification to a GroupChat modification

Description

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.getInfo;

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;

}

}

Environment

Operating System: Linux Platform: PC

Acceptance / Success Criteria

None

Attachments

1
  • 18 May 2005, 02:28 AM

Lucidchart Diagrams

Activity

Jonathan Sartin February 6, 2006 at 7:03 AM

This is in both stable (1.2 line) and head (1.3 line) now. There is a new
XMPPGroupNotificationStrategy, which you can use. Add the following to
notificationCommands.xml:

<command binary="false">
<name>xmppGroupMessage</name>
<execute>org.opennms.netmgt.notifd.XMPPGroupNotificationStrategy</execute>
<comment>class for sending XMPP Group Chat notifications</comment>
<argument streamed="false">
<switch>-xmpp</switch>
</argument>
<argument streamed="false">
<switch>-tm</switch>
</argument>
</command>

Then create a new OpenNMS user with and xmppAddress contact of the room which
you want to send the messages to, thus:

<contact info="operators@conference.opennms.org" type="xmppAddress" />

Finally, add a destinationPath entry that uses the xmppGroupMessage command to
send the message via xmpp to that user.

Jonathan Sartin October 12, 2005 at 9:48 AM

I meant to say fixed in HEAD. Apologies

Jonathan Sartin October 12, 2005 at 9:46 AM

This should be fixed in CVS. Added new XMPPGroupNotificationStrategy for group
chat notifications. Needs a bit of testing...

Former user September 30, 2005 at 10:44 AM

Thanks Jonathan!

Jonathan Sartin September 30, 2005 at 9:23 AM

I have some a fix to 1329, which reworks this somewhat (xmpp notifications to
groups are not reliable with the current implementation).

If you want to assign this to me, I roll group chat support into the change.

.... J

Fixed

Details

Assignee

Reporter

Fix versions

Affects versions

Priority

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

Flag notifications