You know those pesky collaboration notifications you're always trying to keep track of? Who's to know if they're really getting sent off to the people you think they are? Unfortunately, the notification logs themselves aren't much help, since they only log errors, not successes. What that means is you have to wait for the notification queue to fill on Collaboration server or an error to occur if you want to see something go wrong.
But what if we could send out our own notifications without using the UI, so they could be controlled and monitored via a script? What indeed...
import com.plumtree.collaboration.messaging.notification.messages.NotificationUtil; import java.util.ArrayList; public class TestNotifications { public static void main(String args[]) { if (args.length <= 0) { System.out.println("usage: TestNotifications {userIds..}"); return; } System.out.println("Initializing notification utility..."); NotificationUtil nUtil = NotificationUtil.getInstance(); // parse each argument as a user id and add it to the recipients list System.out.println("Creating new recipient list..."); ArrayList emails = new ArrayList(); for (int i = 0; i < args.length; i++) { try { Integer ix = new Integer(args[i]); emails.add(ix); System.out.println("Added userid: " + args[i]); } catch (Exception ex) { System.out.println("Could not parse userid: " + args[i]); } } System.out.println("Sending error notification email..."); nUtil.sendEmailErrorNotification("This is a test notification.", emails); System.out.println("Mail send completed."); try { Thread.sleep(10000); // sleep long enough to send the message (10s) } catch (InterruptedException iex) { } finally { // we need to kill all threads, since notification is event driven System.exit(0); } } }
The code above will allow you to send notifications (it's written in Java) via a command line. You simply need to include the jar's in $PT_HOME/ptnotification/4.x/lib/java in your classpath (probably not all of them, but I haven't bothered to figure out which ones). The notification itself will be an error message with the text "This is a test notification." in the body.
Here is the script I used to launch it (DOS users will need to do some conversion).
Here is the jar file with source.
You can set up a simple notification monitor by creating a new user in the portal and changing the email address property to the email account or distribution list of your choice. Next, record the user ID and pass it on the command line to this utility. Have fun!
(generic disclaimer: I make no guarantees this code will work, properly, etc, etc)
Leave a comment