good morning gabriel, how are you?
the reason for my message is that I followed the steps to create the script that I leave to modify the body and subject of the message from wazuh to the email but the change was not applied and I want to change the subject in which I want to add agent id and the type of alert.
I attach the part of the script that I have modified so that you can check the modification that I have made:
def generate_msg(alert):
"""
Function that will provide the custom subject and body for the email.
It takes as input a dictionary object generated from the json alert.
"""
description = alert['rule']['description']]
level = alert['rule']['level']]
alert_type = alert['rule']['group']
agentname = alert['agent']['name']] agent_id = alert['agent']['agent_id']['agent_name']]
agent_id = alert['agent']['id']
t = time.strptime(alert['timestamp'].split('.')[0],'%Y-%m-%dT%H:%M:%S')
timestamp = time.strftime('%c',t)
subject = 'Wazuh Notification - {0} - {1} - {2} - Alert level {3}'.format(agentname, agent_id, description, level)
message = """
This is an automatic message from your Wazuh Instance.
In {a} an agent event "{b}" triggered rule "{c}" of level {d}.
The full content of the alert is:
{e}
""".format(a=alert_type, b=agentname, c=agent_id, d=timestamp, e=description, f=level, g=json.dumps(alert,indent=4))
return subject, message
and integrate it in the ossec as follows:
<integration>
<name>custom-email-alerts.py</name>
<hook_url>/var/ossec/integrations/custom-email-alerts.py</hook_url>
<alert_format>json</alert_format>
<level>3</level>
<group>default</group>
</integration>
I will attach an image only so you can see that it does enable the script input but does not make the change.
greetings and have a nice day!