Hi Tukaram,
E-mail alerts and integrations such as the one mentioned in that thread can be granularly configured to be triggered either by events of a rule level, rule groups or specific rules ID.
For example, if you wish to use the custom-email-alerts integration for rule 651 you may include this configuration on your Wazuh Managers:
<integration>
<name>custom-email-alerts</name>
<hook_url>em...@example.com</hook_url>
<rule_id>651</rule_id>
<alert_format>json</alert_format>
</integration>
Note that given the flexibility of the integrator daemon you may create specific scripts for different types of alerts and add in several coexisting integrations to the configuration.
As for editing the message's template, if you wish for the IP to be in a specific part of the message then you must adapt the script to use the fields that is specific to your specific rule. For example for Wazuh 4.2.0 or greater, alert 651 ( Host Blocked by firewall-drop Active Response ) provides the IP to be blocked in the data.parameters.alert.data.srcip field.
So the generate_msg function can be modified to be:
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']
agentname = alert['agent']['name']
blockedip = alert['data']['parameters']['alert']['data']['srcip']
t = time.strptime(alert['timestamp'].split('.')[0],'%Y-%m-%dT%H:%M:%S')
timestamp = time.strftime('%c',t)
subject = 'Wazuh Alert: {0} {1}, {2}'.format(blockedip,description, agentname)
msg = """
This is an automatic message from your Wazuh Instance.
On {} an event from agent "{}" triggered the rule "{}" of level {}.
The IP being blocked is {}
The full contents of the alert are:
{}
""".format(timestamp,agentname,description,level,blockedip,json.dumps(alert,indent=4))
return subject, msg
Let us know if you have any more questions,
I hope you're having a great day,
Juan Carlos Tello