anchor.diff:  terminate(_, _) ->
       ok.
   
  +code_change(_OldVsn, State, _Extra) ->
  +    {ok, State}.
  +
  +%%%=============================================================================
  +%%% Internal functions
  +%%%=============================================================================
  +
   alarm_msg(Type, AlarmId, Json) ->
       Msg = emqttd_message:make(alarm,
                                 topic(Type, AlarmId),
  
positive.code: topic(clear, AlarmId) ->
      emqttd_topic:systop(<<"alarms/", AlarmId/binary, "/clear">>).
  
  
  
negative.code: 
  -spec set_alarm(mqtt_alarm()) -> ok.
  set_alarm(Alarm) when is_record(Alarm, mqtt_alarm) ->
      gen_event:notify(?ALARM_MGR, {set_alarm, Alarm}).
  
  -spec clear_alarm(any()) -> ok.
  clear_alarm(AlarmId) when is_binary(AlarmId) ->
      gen_event:notify(?ALARM_MGR, {clear_alarm, AlarmId}).
  
  -spec get_alarms() -> list(mqtt_alarm()).
  get_alarms() ->
      gen_event:call(?ALARM_MGR, ?MODULE, get_alarms).
  
  add_alarm_handler(Module) when is_atom(Module) ->
      gen_event:add_handler(?ALARM_MGR, Module, []).
  
  add_alarm_handler(Module, Args) when is_atom(Module) ->
      gen_event:add_handler(?ALARM_MGR, Module, Args).
  
  delete_alarm_handler(Module) when is_atom(Module) ->
      gen_event:delete_handler(?ALARM_MGR, Module, []).
  
  %%%=============================================================================
  %%% Default Alarm handler
  %%%=============================================================================
  
  init(_) ->
      {ok, []}.
      
  handle_event({set_alarm, Alarm = #mqtt_alarm{id       = AlarmId,
                                               severity = Severity,
                                               title    = Title,
                                               summary  = Summary}}, Alarms)->
      Timestamp = os:timestamp(),
      Json = mochijson2:encode([{id, AlarmId},
                                {severity, Severity},
  