Tutorial

Alarm Extension

SuperMap iManager currently is built in email to send the alarm. In order to meet the needs of users to diversify the arlarm mode, SuperMap iManager provides the Notification interface for the alarm service extension. The extension will configure your implementation class currently to SuperMap iManager, which will enable you to implement your own alarms.

The use of Notification interface is briefly introduced in the form of a console.

Introduce of Notification Interface

The Notification interface is mainly responsible for the transmission of the system alarm, alarm recovery, etc.

public interface Notification {
  /**
  * <p>
  * Send a notification
  * </p>
  * @param entity The entity of notification
  * @since 9.0.1
  */
public void send(NotificationEntity entity);

}

Expand and configure the process

  1. Download notification-api.jar
  2. Edit ConsoleNotification class,implement Notification interface

    package com.supermap.imanager.notification.impl;
    
    import java.util.List;
    
    import com.supermap.imanager.notification.Notification;
    import com.supermap.imanager.notification.commontypes.AppAlarmItemEntity;
    import com.supermap.imanager.notification.commontypes.AppRecoveredAlarmItemEntity;
    import com.supermap.imanager.notification.commontypes.NotificationEntity;
    import com.supermap.imanager.notification.commontypes.NotificationItemEntity;
    import com.supermap.imanager.notification.commontypes.URLAlarmItemEntity;
    import com.supermap.imanager.notification.commontypes.URLRecoveredAlarmItemEntity;
    public class ConsoleNotification implements Notification {
    
       private boolean enable = false;
    
       public void setEnable(boolean enable) {
            this.enable = enable;
       }
    
            @Override
       public void send(NotificationEntity entity) {
            if (enable) {
            // The title of notification
                System.out.println("title:" + entity.title);
            // The type of notification content
               System.out.println("type:" + entity.type.toString());
               System.out.println("contents:");
               List<NotificationItemEntity> contents = entity.contents;
               contents.forEach((content) -> {
               printItem(content);
               });
           }
       }
    
       private void printItem(NotificationItemEntity content) {
            // Print alarm description information
               System.out.println("description:" + content.description);
            // You can also get detailed information about the notification as needed:
            // app alarm item
           if (content instanceof AppAlarmItemEntity) {
              AppAlarmItemEntity item = (AppAlarmItemEntity) content;
              System.out.println("appId:" + item.appId);// app id
              System.out.println("name:" + item.name);// app name
              System.out.println("address:" + item.address);// app address
              System.out.println("type:" + item.type);// app type: iServer/iPortal
              System.out.println("suggest:" + item.suggest);// the proposals
              System.out.println("description:" + item.description);// the description information of alarm
           } // app alarm recovery item
           else if (content instanceof AppRecoveredAlarmItemEntity) {
              AppRecoveredAlarmItemEntity item = (AppRecoveredAlarmItemEntity) content;
              System.out.println("appId:" + item.appId);// app id
              System.out.println("name:" + item.name);// app name
              System.out.println("address:" + item.address);// app address
              System.out.println("type:" + item.type);// app type: iServer/iPortal
              System.out.println("alarmValue:" + item.alarmValue);// alarm threshold
              System.out.println("startTime:" + item.startTime);// start time
              System.out.println("endTime:" + item.endTime);// end time
              System.out.println("durationTime:" + item.durationTime);// the duration
              System.out.println("description:" + item.description);// the description information of alarm
            } // URL alarm item
            else if (content instanceof URLAlarmItemEntity) {
              URLAlarmItemEntity item = (URLAlarmItemEntity) content;
              System.out.println("name:" + item.name);// alarm name
              System.out.println("address:" + item.address);// URL address
              System.out.println("expectedStatus:" + item.expectedStatus);// expected state
              System.out.println("actualStatus:" + item.actualStatus);// actual state
              System.out.println("suggest:" + item.suggest);// the proposals
              System.out.println("description:" + item.description);// the description information of alarm
            } // URL alarm recovery item
            else if (content instanceof URLRecoveredAlarmItemEntity) {
              URLRecoveredAlarmItemEntity item = (URLRecoveredAlarmItemEntity) content;
              System.out.println("description:" + item.name);// alarm name
              System.out.println("description:" + item.url);// URL address
              System.out.println("expectedStatus:" + item.expectedStatus);// expected state
              System.out.println("startTime:" + item.startTime);// start time
              System.out.println("endTime:" + item.endTime);// end time
              System.out.println("durationTime:" + item.durationTime);// the duration
              System.out.println("description:" + item.description);// the description information of alarm
            }
       }
    
    }
  3. Configure bean

    Configure bean in %SuperMap iManager_HOME%/WEB-INF/config/notificationBeans.xml.

    <bean id="consoleNotification"    class="com.supermap.imanager.notification.impl.ConsoleNotification">
       <property name="enable" value="true"/>
    </bean>
  4. Integrate the code into SuperMap iManager

    • Method One: Copy the files under the classes folder to the %supermap="" imanager_home%/webapps/imanager/web-inf/classes.
    • Method Two: Put jar package into %SuperMap iManager_HOME%/webapps/imanager/WEB-INF/lib.
  5. Restart SuperMap iManager service to achieve a customized alarm.