emqttd_time to replace emqttd_util
This commit is contained in:
parent
ea887c8eee
commit
a5116c7fa6
|
@ -14,15 +14,12 @@
|
||||||
%% limitations under the License.
|
%% limitations under the License.
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
%% @doc Copy alarm_handler
|
|
||||||
-module(emqttd_alarm).
|
-module(emqttd_alarm).
|
||||||
|
|
||||||
-author("Feng Lee <feng@emqtt.io>").
|
-behaviour(gen_event).
|
||||||
|
|
||||||
-include("emqttd.hrl").
|
-include("emqttd.hrl").
|
||||||
|
|
||||||
-behaviour(gen_event).
|
|
||||||
|
|
||||||
-define(ALARM_MGR, ?MODULE).
|
-define(ALARM_MGR, ?MODULE).
|
||||||
|
|
||||||
%% API Function Exports
|
%% API Function Exports
|
||||||
|
@ -93,12 +90,12 @@ handle_event({set_alarm, Alarm = #mqtt_alarm{id = AlarmId,
|
||||||
{severity, Severity},
|
{severity, Severity},
|
||||||
{title, iolist_to_binary(Title)},
|
{title, iolist_to_binary(Title)},
|
||||||
{summary, iolist_to_binary(Summary)},
|
{summary, iolist_to_binary(Summary)},
|
||||||
{ts, emqttd_util:now_to_secs(Timestamp)}]),
|
{ts, emqttd_time:now_to_secs(Timestamp)}]),
|
||||||
emqttd_pubsub:publish(alarm_msg(alert, AlarmId, Json)),
|
emqttd_pubsub:publish(alarm_msg(alert, AlarmId, Json)),
|
||||||
{ok, [Alarm#mqtt_alarm{timestamp = Timestamp} | Alarms]};
|
{ok, [Alarm#mqtt_alarm{timestamp = Timestamp} | Alarms]};
|
||||||
|
|
||||||
handle_event({clear_alarm, AlarmId}, Alarms) ->
|
handle_event({clear_alarm, AlarmId}, Alarms) ->
|
||||||
Json = mochijson2:encode([{id, AlarmId}, {ts, emqttd_util:now_to_secs()}]),
|
Json = mochijson2:encode([{id, AlarmId}, {ts, emqttd_time:now_to_secs()}]),
|
||||||
emqttd_pubsub:publish(alarm_msg(clear, AlarmId, Json)),
|
emqttd_pubsub:publish(alarm_msg(clear, AlarmId, Json)),
|
||||||
{ok, lists:keydelete(AlarmId, 2, Alarms), hibernate};
|
{ok, lists:keydelete(AlarmId, 2, Alarms), hibernate};
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
%% @doc Authentication with username and password
|
%% @doc Authentication with username and password
|
||||||
-module(emqttd_auth_username).
|
-module(emqttd_auth_username).
|
||||||
|
|
||||||
-author("Feng Lee <feng@emqtt.io>").
|
|
||||||
|
|
||||||
-include("emqttd.hrl").
|
-include("emqttd.hrl").
|
||||||
|
|
||||||
-include("emqttd_cli.hrl").
|
-include("emqttd_cli.hrl").
|
||||||
|
@ -126,5 +124,5 @@ md5_hash(SaltBin, Password) ->
|
||||||
erlang:md5(<<SaltBin/binary, Password/binary>>).
|
erlang:md5(<<SaltBin/binary, Password/binary>>).
|
||||||
|
|
||||||
salt() ->
|
salt() ->
|
||||||
emqttd:seed_now(), Salt = random:uniform(16#ffffffff), <<Salt:32>>.
|
emqttd_time:seed(), Salt = random:uniform(16#ffffffff), <<Salt:32>>.
|
||||||
|
|
||||||
|
|
|
@ -1,93 +0,0 @@
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
%% Copyright (c) 2012-2016 Feng Lee <feng@emqtt.io>.
|
|
||||||
%%
|
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
%% you may not use this file except in compliance with the License.
|
|
||||||
%% You may obtain a copy of the License at
|
|
||||||
%%
|
|
||||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
%%
|
|
||||||
%% Unless required by applicable law or agreed to in writing, software
|
|
||||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
%% See the License for the specific language governing permissions and
|
|
||||||
%% limitations under the License.
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
|
|
||||||
%% @doc Utility functions.
|
|
||||||
%% @author Feng Lee <feng@emqtt.io>
|
|
||||||
-module(emqttd_util).
|
|
||||||
|
|
||||||
-export([apply_module_attributes/1, all_module_attributes/1, cancel_timer/1,
|
|
||||||
now_to_secs/0, now_to_secs/1, now_to_ms/0, now_to_ms/1]).
|
|
||||||
|
|
||||||
-export([integer_to_binary/1]).
|
|
||||||
|
|
||||||
%% only {F, Args}...
|
|
||||||
apply_module_attributes(Name) ->
|
|
||||||
[{Module, [apply(Module, F, Args) || {F, Args} <- Attrs]} ||
|
|
||||||
{_App, Module, Attrs} <- all_module_attributes(Name)].
|
|
||||||
|
|
||||||
%% copy from rabbit_misc.erl
|
|
||||||
all_module_attributes(Name) ->
|
|
||||||
Targets =
|
|
||||||
lists:usort(
|
|
||||||
lists:append(
|
|
||||||
[[{App, Module} || Module <- Modules] ||
|
|
||||||
{App, _, _} <- ignore_lib_apps(application:loaded_applications()),
|
|
||||||
{ok, Modules} <- [application:get_key(App, modules)]])),
|
|
||||||
lists:foldl(
|
|
||||||
fun ({App, Module}, Acc) ->
|
|
||||||
case lists:append([Atts || {N, Atts} <- module_attributes(Module),
|
|
||||||
N =:= Name]) of
|
|
||||||
[] -> Acc;
|
|
||||||
Atts -> [{App, Module, Atts} | Acc]
|
|
||||||
end
|
|
||||||
end, [], Targets).
|
|
||||||
|
|
||||||
%% copy from rabbit_misc.erl
|
|
||||||
module_attributes(Module) ->
|
|
||||||
case catch Module:module_info(attributes) of
|
|
||||||
{'EXIT', {undef, [{Module, module_info, _} | _]}} ->
|
|
||||||
[];
|
|
||||||
{'EXIT', Reason} ->
|
|
||||||
exit(Reason);
|
|
||||||
V ->
|
|
||||||
V
|
|
||||||
end.
|
|
||||||
|
|
||||||
ignore_lib_apps(Apps) ->
|
|
||||||
LibApps = [kernel, stdlib, sasl,
|
|
||||||
syntax_tools, ssl, crypto,
|
|
||||||
mnesia, os_mon, inets,
|
|
||||||
goldrush, lager, gproc,
|
|
||||||
runtime_tools, snmp, otp_mibs,
|
|
||||||
public_key, asn1, ssh,
|
|
||||||
common_test, observer, webtool,
|
|
||||||
xmerl, tools, test_server,
|
|
||||||
compiler, debugger, eunit,
|
|
||||||
et, gen_logger, wx,
|
|
||||||
hipe, esockd, mochiweb],
|
|
||||||
[App || App = {Name, _, _} <- Apps, not lists:member(Name, LibApps)].
|
|
||||||
|
|
||||||
|
|
||||||
cancel_timer(undefined) ->
|
|
||||||
undefined;
|
|
||||||
cancel_timer(Ref) ->
|
|
||||||
catch erlang:cancel_timer(Ref).
|
|
||||||
|
|
||||||
integer_to_binary(I) when is_integer(I) ->
|
|
||||||
list_to_binary(integer_to_list(I)).
|
|
||||||
|
|
||||||
now_to_secs() ->
|
|
||||||
now_to_secs(os:timestamp()).
|
|
||||||
|
|
||||||
now_to_secs({MegaSecs, Secs, _MicroSecs}) ->
|
|
||||||
MegaSecs * 1000000 + Secs.
|
|
||||||
|
|
||||||
now_to_ms() ->
|
|
||||||
now_to_ms(os:timestamp()).
|
|
||||||
|
|
||||||
now_to_ms({MegaSecs, Secs, MicroSecs}) ->
|
|
||||||
(MegaSecs * 1000000 + Secs) * 1000 + round(MicroSecs/1000).
|
|
||||||
|
|
Loading…
Reference in New Issue