Skip to content

Commit

Permalink
feat: manual_recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
dawnwinterLiu committed Apr 21, 2023
1 parent a72d31e commit d4870b0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
12 changes: 12 additions & 0 deletions apps/dgiot_device/src/dgiot_notification_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ init(?TYPE, ChannelId, Args) ->
},
dgiot_notification:save_configuration(),
dgiot_parse_hook:subscribe(<<"Notification">>, get, ChannelId),
dgiot_parse_hook:subscribe(<<"Notification/*">>, put, ChannelId, [<<"status">>]),
dgiot_parse_hook:subscribe(<<"Maintenance">>, post, ChannelId),
%% dgiot_parse_id:get_channelid(?BACKEND_CHL, ?TYPE, <<"dgiot_notification">>),
{ok, State, []}.
Expand Down Expand Up @@ -130,6 +131,17 @@ handle_message({sync_parse, Pid, 'after', get, _Token, <<"Notification">>, #{<<"
dgiot_parse_hook:publish(Pid, NewResBody),
{ok, State};

handle_message({sync_parse, _Pid, 'after', put, _Token, <<"Notification">>, #{<<"objectId">> := ObjectId} = QueryData}, State) ->
%% io:format("~s ~p ~p ~n", [?FILE, ?LINE, QueryData]),
case maps:find(<<"status">>, QueryData) of
{ok, 2} ->
%% 告警手动恢复
dgiot_umeng:manual_recovery(ObjectId);
_ ->
pass
end,
{ok, State};

handle_message({sync_parse, _Pid, 'after', post, _Token, <<"Maintenance">>, QueryData}, State) ->
dgiot_maintenance:init_inspection(QueryData),
{ok, State};
Expand Down
10 changes: 10 additions & 0 deletions apps/dgiot_http/src/umeng/dgiot_umeng.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
test_broadcast/0,
test_customizedcast/0,
add_notification/3,
manual_recovery/1,
save_notification/4,
update_notification/2,
create_maintenance/2,
Expand Down Expand Up @@ -219,6 +220,15 @@ add_notification(Ruleid, _DevAddr, _Payload) ->
?LOG(error, "Ruleid ~p", [Ruleid]),
ok.

%% 手动恢复
manual_recovery(ObjectId) ->
case dgiot_parse:get_object(<<"Notification">>, ObjectId) of
{ok, #{<<"content">> := #{<<"_deviceid">> := DeviceId}, <<"type">> := Ruleid}} ->
dgiot_data:insert(?NOTIFICATION, {DeviceId, Ruleid}, {stop, dgiot_datetime:now_secs(), <<>>});
_ ->
pass
end.

save_notification(Ruleid, DeviceId, Payload, NotificationId) ->
Alarm_createdAt = dgiot_datetime:format("YYYY-MM-DD HH:NN:SS"),
case binary:split(Ruleid, <<$_>>, [global, trim]) of
Expand Down
10 changes: 5 additions & 5 deletions apps/dgiot_parse/etc/dgiot_parse.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ parse.delete_field = ACL,objectId,updatedAt,createdAt
##--------------------------------------------------------------------
## parse config
##--------------------------------------------------------------------
parse.parse_server = http://dev.dgiotcloud.cn:1337
parse.parse_server = http://prod.dgiotcloud.cn:1337
parse.parse_path = /parse/
parse.parse_appid = 434511aaf315b9cd30dfa4115b83148a
parse.parse_master_key = 00ee00579f9577f0aad6661a1fa948ec
parse.parse_js_key = 37d679c52858cb624120365029b159eb
parse.parse_rest_key = f28f70ea0aae4006cfd11d77e92152cc
parse.parse_appid = c15005097b3eea431d5b334ee8ace1a3
parse.parse_master_key = 349910a0e70a0deace2f5b0ccb30e897
parse.parse_js_key = 8ef8e49492098ceb871c2c0cc486f00b
parse.parse_rest_key = 782482b57aa77215bbf7ee031a82c20a

##--------------------------------------------------------------------
## parse cache
Expand Down
1 change: 0 additions & 1 deletion apps/dgiot_parse/include/dgiot_parse.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

-define(DEFAULT, <<"default">>).
-define(SLAVE, <<"slave">>).
-define(TIMESCALE, <<"timescale">>).
-define(TYPE, <<"PARSE">>).
-define(CACHE(Channel), binary_to_atom(<<?TYPE/binary, Channel/binary>>, utf8)).
-define(CLASS(ClassName), binary_to_atom(<<?TYPE/binary, "_class_", ClassName/binary>>, utf8)).
Expand Down

0 comments on commit d4870b0

Please sign in to comment.