Hi Raj,
First of all, thanks for using Wazuh.
I was able to make it work by following the next Google official tutorial: Using incoming webhooks. After following those steps, i used slack integration script as base for this new integration
1- Create /var/ossec/integrations/custom-gchat
file in Wazuh Manager with the next content, replacing GCHAT_URI with the one generated by the Google tutorial
#!/usr/bin/env python
# Copyright (C) 2015-2021, Wazuh Inc.
#
# 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.
import json
import sys
import time
import os
import httplib2
try:
import requests
from requests.auth import HTTPBasicAuth
except Exception as e:
print("No module 'requests' found. Install: pip install requests")
sys.exit(1)
# Global vars
GCHAT_URI = 'https://chat.googleapis.com/v1/spaces/XXXXX/messages?key=XXXX&token=XXXX'
debug_enabled = False
pwd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
json_alert = {}
now = time.strftime("%a %b %d %H:%M:%S %Z %Y")
# Set paths
log_file = '{0}/logs/integrations.log'.format(pwd)
def main(args):
debug("# Starting")
# Read args
alert_file_location = args[1]
webhook = GCHAT_URI
debug("# Webhook")
debug(webhook)
debug("# File location")
debug(alert_file_location)
# Load alert. Parse JSON object.
with open(alert_file_location) as alert_file:
json_alert = json.load(alert_file)
debug("# Processing alert")
debug(json_alert)
debug("# Generating message")
msg = generate_msg(json_alert)
debug(msg)
debug("# Sending message")
send_msg(msg, webhook)
def debug(msg):
if debug_enabled:
msg = "{0}: {1}\n".format(now, msg)
print(msg)
f = open(log_file, "a")
f.write(msg)
f.close()
def generate_msg(alert):
title = alert['rule']['description'] if 'description' in alert['rule'] else "N/A"
cards = {'cards':[{'header':{'title':title}}]}
return json.dumps(cards)
def send_msg(msg, url):
headers = {'Content-Type': 'application/json; charset=UTF-8'}
http_obj = httplib2.Http()
response = http_obj.request(
uri=url,
method='POST',
headers=headers,
body=msg,
)
debug(response)
if __name__ == "__main__":
try:
# Read arguments
bad_arguments = False
if len(sys.argv) >= 4:
msg = '{0} {1} {2} {3} {4}'.format(
now,
sys.argv[1],
sys.argv[2],
sys.argv[3],
sys.argv[4] if len(sys.argv) > 4 else '',
)
debug_enabled = (len(sys.argv) > 4 and sys.argv[4] == 'debug')
else:
msg = '{0} Wrong arguments'.format(now)
bad_arguments = True
# Logging the call
f = open(log_file, 'a')
f.write(msg + '\n')
f.close()
if bad_arguments:
debug("# Exiting: Bad arguments.")
sys.exit(1)
# Main function
main(sys.argv)
except Exception as e:
debug(str(e))
raise
2- Change permissions and ownership: chmod 750 /var/ossec/integrations/custom-gchat; chown root:wazuh /var/ossec/integrations/custom-gchat
3- Add desired integration configuration block into Wazuh Manager’s ossec.conf
<integration>
<name>custom-gchat</name>
<level>10</level>
<alert_format>json</alert_format>
</integration>
4- Restart Wazuh Manager
5- Enjoy!
Feel free to change generate_msg
function to customize your message according your needs and Google Chat API message formats reference.
Regards,
Nico
Hi Raj,
There was an indentation error while copy pasting python script. Here we go again
#!/usr/bin/env python
# Copyright (C) 2015-2021, Wazuh Inc.
#
# 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.
import json
import sys
import time
import os
import httplib2
try:
import requests
from requests.auth import HTTPBasicAuth
except Exception as e:
print("No module 'requests' found. Install: pip install requests")
sys.exit(1)
# Global vars
GCHAT_URI = 'https://chat.googleapis.com/v1/spaces/XXXXX/messages?key=XXXX&token=XXXXXX'
debug_enabled = False
Regards,
Nico
Warm regards,
Raj Vira
Associate Information Security Officer | IS Department
+91 7949006565 [ext :469]
Acute Informatics Pvt. Ltd.| www.acuteinformatics.in
"CONFIDENTIALITY NOTICE: The information transmitted in this email and any attachments herein is confidential and is intended for the addressee(s) only. If you have received this email in error, please notify us immediately, delete the message from your computer system and destroy hard copies if any. If you are not the intended recipient, any unauthorized disclosure, copying, distribution, dissemination, publication, use of or access to the information contained herein is strictly prohibited. The obligation of confidentiality is a binding legal obligation, a proven breach of which will result in the imposition of damages. Although every effort has been made to ensure that this email is virus-free, it is recommended that you scan this email and any attachments thereto for viruses and Acute Informatics Pvt. Ltd. accepts no responsibility for any damage to the recipient’s system caused by this email and/or its attachments. Please note that messages to or from Acute Informatics Pvt. Ltd. may be monitored to ensure compliance with our policies."
--
You received this message because you are subscribed to the Google Groups "Wazuh mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wazuh+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wazuh/6e96990b-034d-47b1-b0be-219c934dfd4cn%40googlegroups.com.
Warm regards,
Raj Vira
Associate Information Security Officer | IS Department
+91 7949006565 [ext :469]
Acute Informatics Pvt. Ltd.| www.acuteinformatics.in
"CONFIDENTIALITY NOTICE: The information transmitted in this email and any attachments herein is confidential and is intended for the addressee(s) only. If you have received this email in error, please notify us immediately, delete the message from your computer system and destroy hard copies if any. If you are not the intended recipient, any unauthorized disclosure, copying, distribution, dissemination, publication, use of or access to the information contained herein is strictly prohibited. The obligation of confidentiality is a binding legal obligation, a proven breach of which will result in the imposition of damages. Although every effort has been made to ensure that this email is virus-free, it is recommended that you scan this email and any attachments thereto for viruses and Acute Informatics Pvt. Ltd. accepts no responsibility for any damage to the recipient’s system caused by this email and/or its attachments. Please note that messages to or from Acute Informatics Pvt. Ltd. may be monitored to ensure compliance with our policies."
You received this message because you are subscribed to a topic in the Google Groups "Wazuh mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wazuh/Qf17CexqJ6U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wazuh+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wazuh/8416550b-8025-4f41-ad44-7a16c4508bb5n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wazuh/ad44e3f3-a72f-427e-a069-e9d1673663c9n%40googlegroups.com.
| |||||||||||||||||||
To view this discussion on the web visit https://groups.google.com/d/msgid/wazuh/cbff2704-47bc-46d4-82ca-a7e69efbc573n%40googlegroups.com.