-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsecurity_monitor.erl
More file actions
40 lines (36 loc) · 1.23 KB
/
Copy pathsecurity_monitor.erl
File metadata and controls
40 lines (36 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-module(security_monitor).
-export([start/0, log_event/2, slack_alert/1]).
start() ->
spawn(fun() ->
ets:new(security_events, [ordered_set, public, named_table]),
monitor_loop()
end).
log_event(Type, Details) ->
Timestamp = os:system_time(millisecond),
ets:insert(security_events, {Timestamp, Type, Details}).
%% Implementasi fungsi slack_alert/1 yang sebelumnya missing
slack_alert(Message) ->
WebhookUrl = os:getenv("SLACK_WEBHOOK_URL"),
case WebhookUrl of
false ->
io:format("[SLACK] Alert suppressed (no webhook): ~s~n", [Message]);
_ ->
Body = io_lib:format("{\"text\":\"Security Alert: ~s\"}", [Message]),
httpc:request(post,
{WebhookUrl, [], "application/json", Body},
[],
[])
end.
monitor_loop() ->
receive
{analyze, From} ->
Suspicious = ets:match_object(security_events, {'_', brute_force, '_'}),
From ! {analysis, length(Suspicious)},
monitor_loop()
after 5000 ->
case ets:info(security_events, size) > 100 of
true -> slack_alert("High activity detected!");
false -> ok
end,
monitor_loop()
end.