Getting MoSKito to mail to you


Leon - June 1, 2013 - 0 comments

So you’ve set up all the accumulators and thresholds you wanted. Now it’s time to get some rest, but you don’t want to miss your thresholds getting red? No problem, with Notification Providers, you can handle the alerting in highly customizable way. And here is how.

MoSKito offers notifications on Threshold status change via the net.anotheria.moskito.core.threshold.alerts.NotificationProvider and internal AlertDispatcher. You can implement your own NotificationProvider, but there are some builtin providers, we want talk about first. The most common case I’ve been asked is getting a mail on threshold change, aka monitoring the state of the system and get alerted when it changes. To enable email notification I simply have to add following parameters to moskito.json

"@thresholdsAlertsConfig": {
  "@notificationProviders": [
    {
	"className": "net.anotheria.moskito.core.threshold.alerts.notificationprovider.MailNotificationProvider",
	"parameter": "blub@example.com",
	"guardedStatus": "RED"
    }
  ],

As you see notificationProviders is an array, so it’s possible to configure multiple notification providers to setup different groups of alerts. The fields in the above sniplet mean:

  • className – the name of a class implementing NotificationProvider. The class should have an empty constructor.
  • parameter – this depends on concrete implementation. In our example its the comma separated list of recipients.
  • guardedStatus – status change that should trigger the update. If the current status change in the system is below the guarded status no alert will be triggered. In above example only threshold changes from/to RED will fire an alert.

So this it. This is how you configure an email for your MoSKito Thresholds.

However, some people already have notification systems that they use, and they don’t want to configure additional one, or use mail instead of sms or pager. Well in this case you still have plenty of options. Easiest option would be to take LogFileNotificationProvider, and connect the logs to your notification system via a log reader. Or to create your own NotificationProvider implementation, which is totally easy, as this example shows:

public class SysoutNotificationProvider  implements NotificationProvider {

	@Override
	public void configure(String parameter) {
		//nothing to configure here.
	}

	@Override
	public void onNewAlert(ThresholdAlert alert) {
		System.out.println("NEW ThresholdAlert: "+alert);
	}
}

You only need to implement two methods: configure(parameter) is called right after the initialization of the application, at the time the configuration is read. The value of the parameter is the configuration element parameter in the json file and is only interpreted by your class. It can contain email addresses, phone numbers, log file name. The other method that you have to implement is onNewAlert(alert). It is called whenever a new alert aka threshold state change is registered in the system and it corresponds to your configured level. This is the method where you do actual work.

That’s all you need to configure your notifications with MoSKito Thresholds. Enjoy 😉

More details on configuration can be found in the configuration guide.

Post a Comment

Your email address will not be published.