chmod 750 /var/ossec/integrations/custom-jira
chown root:ossec /var/ossec/integrations/custom-jira
# ls -ld /var /var/ossec/ /var/ossec/integrations/drwxr-xr-x. 19 root root 281 Sep 29 09:05 /var
drwxr-x---. 19 root ossec 242 Sep 8 18:39 /var/ossec/
drwxr-x---. 2 root ossec 134 Sep 29 09:02 /var/ossec/integrations/sudo -u ossecm /var/ossec/integrations/custom-jira #!/var/ossec/framework/python/bin/python3#!/var/ossec/framework/python/bin/python3 path = alert_json['syscheck']['path']#!/var/ossec/framework/python/bin/python3
import sys
import json
import requests
from requests.auth import HTTPBasicAuth
# Set the project attributes
project_alias = 'TI'
issue_name ='FIM'
# Read configuration parameters
alert_file = open(sys.argv[1])
user = sys.argv[2].split(':')[0]
api_key = sys.argv[2].split(':')[1]
hook_url = sys.argv[3]
# Read the alert file
alert_json = json.loads(alert_file.read())
alert_file.close()
# Extract issue fields
alert_level = alert_json['rule']['level']
description = alert_json['rule']['description']
# Generate request
msg_data = {}
msg_data['fields'] = {}
msg_data['fields']['project'] = {}
msg_data['fields']['project']['key'] = project_alias
msg_data['fields']['summary'] = 'Wazuh alert: [' + description + ']'
msg_data['fields']['description'] = '- State: ' + description + '\n- Alert level: ' + str(alert_level)
msg_data['fields']['issuetype'] = {}
msg_data['fields']['issuetype']['name'] = issue_name
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
# Send the request
requests.post(hook_url, data=json.dumps(msg_data), headers=headers, auth=(user, api_key))
sys.exit(0)#!/var/ossec/framework/python/bin/python3
import sys
import json
import requests
from requests.auth import HTTPBasicAuth
import time
import os
# Configure logging
debug_enabled = True
pwd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
log_file = '{0}/logs/integrations.log'.format(pwd)
def debug(msg):
if debug_enabled:
now = time.strftime("%a %b %d %H:%M:%S %Z %Y")
msg = "{0}: {1}\n".format(now, msg)
print(msg)
f = open(log_file, "a")
f.write(msg)
f.close()
debug('Starting to run Jira integration')
# Set the project attributes
project_alias = 'TI'
issue_name ='FIM'
# Read configuration parameters
alert_file = open(sys.argv[1])
user = sys.argv[2].split(':')[0]
api_key = sys.argv[2].split(':')[1]
hook_url = sys.argv[3]
debug('Reading alert file ' + sys.argv[1])
# Read the alert file
alert_json = json.loads(alert_file.read())
alert_file.close()
# Extract issue fields
alert_level = alert_json['rule']['level']
description = alert_json['rule']['description']
# Generate request
msg_data = {}
msg_data['fields'] = {}
msg_data['fields']['project'] = {}
msg_data['fields']['project']['key'] = project_alias
msg_data['fields']['summary'] = 'Wazuh alert: [' + description + ']'
msg_data['fields']['description'] = '- State: ' + description + '\n- Alert level: ' + str(alert_level)
msg_data['fields']['issuetype'] = {}
msg_data['fields']['issuetype']['name'] = issue_name
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
debug('Sending message with the content: ' + str(msg_data))
# Send the request
response = requests.post(hook_url, data=json.dumps(msg_data), headers=headers, auth=(user, api_key))
debug('Jira replied: '+ response.text)
sys.exit(0)