wazuh-notify/wazuh-discord-notifier.py

67 lines
2.1 KiB
Python
Raw Normal View History

2024-04-28 20:27:23 +02:00
#!/usr/bin/env python3
# This script is free software.
#
# Copyright (C) 2024, Rudi Klein.
# All rights reserved.
#
# This program is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License (version 2) as published by the FSF - Free Software
# Foundation.
#
2024-05-04 22:05:41 +02:00
# This script is executed by the active response script (wazuh-active-response.py), which is triggered by rules firing.
2024-04-28 20:27:23 +02:00
#
# Discord is a voice, video and text communication service used by over a hundred million people to hang out and talk
# with their friends and communities. It allows for receiving message using webhooks.
# For more information: https://discord.com.
2024-04-30 21:50:03 +02:00
import requests
2024-05-11 19:59:49 +02:00
from wazuh_notifier_module import color_mapping
from wazuh_notifier_module import get_arguments
from wazuh_notifier_module import get_config
from wazuh_notifier_module import get_env
from wazuh_notifier_module import set_environment
from wazuh_notifier_module import set_time
2024-04-28 20:27:23 +02:00
# Get path values
2024-05-11 19:59:49 +02:00
wazuh_path, ar_path, config_path, notifier_path = set_environment()
2024-05-07 17:08:03 +02:00
2024-04-28 20:27:23 +02:00
# Get time value
2024-05-11 19:59:49 +02:00
now_message, now_logging = set_time()
2024-05-03 16:33:38 +02:00
2024-05-11 19:59:49 +02:00
# Get some paths.
discord_url, ntfy_url = get_env()
2024-05-04 22:05:41 +02:00
2024-05-11 19:59:49 +02:00
# Get the yaml config
config: dict = get_config()
2024-04-28 20:27:23 +02:00
# the POST builder. Prepares https and sends the request.
2024-05-11 19:59:49 +02:00
def discord_command(n_url, n_sender, n_destination, n_priority, n_message, n_tags, n_click):
color = color_mapping(n_priority)
2024-04-28 20:27:23 +02:00
x_message = (now_message +
2024-04-30 21:50:03 +02:00
"\n\n" + n_message + "\n\n" +
2024-04-28 20:27:23 +02:00
"Priority: " + n_priority + "\n" +
"Tags: " + n_tags + "\n\n" + n_click
)
2024-05-11 19:59:49 +02:00
n_data = {"username": n_sender, "embeds": [{"color": color, "description": x_message, "title": n_destination}]}
2024-04-28 20:27:23 +02:00
2024-05-11 19:59:49 +02:00
requests.post(n_url, json=n_data)
2024-04-28 20:27:23 +02:00
# Remove 1st argument from the list of command line arguments
2024-05-07 17:08:03 +02:00
# argument_list: list = sys.argv[1:]
2024-04-28 20:27:23 +02:00
2024-05-07 17:08:03 +02:00
notifier = "discord"
2024-04-28 20:27:23 +02:00
2024-05-11 19:59:49 +02:00
url, sender, destination, priority, message, tags, click = get_arguments()
2024-04-28 20:27:23 +02:00
# Finally, execute the POST request
2024-05-11 19:59:49 +02:00
discord_command(discord_url, sender, destination, priority, message, tags, click)