adding my hec_test-er

This commit is contained in:
Orien Vandenbergh
2025-07-29 16:41:39 -04:00
parent bc424c7346
commit 2e7d87fb77

48
scripts/hec_test Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env python3
import argparse
from datetime import datetime
import subprocess
import json
def build_json(field,path):
return json.dumps({field:f"This is a sample json event sent to {path}","hecTest":"yes"})
def build_raw(path):
return f"{datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ')} nowhere This is a sample raw event sent to {path} hecTest=yes"
def test_hec(baseurl,path,data):
url = baseurl+path
cmd = ['curl','-k',url,'-H',f"Authorization: {args.token}",'-d',data]
print(f"Running command:")
print(f">\t{cmd[0]} {cmd[1]} {cmd[2]} \\")
print(f"\t{cmd[3]} {cmd[4]} \\")
print(f"\t{cmd[5]} '{cmd[6]}'")
print()
result = subprocess.run(cmd,capture_output=True,text=True)
#print("stderr")
#print(result.stderr)
print(f"\033[0;32mResult\033[0m: {result.stdout}")
print("")
parser = argparse.ArgumentParser(
prog='hectest',
description='Send a test HEC message to a receiver')
parser.add_argument('-t', '--token', required=True, help='token to use')
parser.add_argument('url', help="base url to send to, example: https://host.com:10080/services/collector/event")
args = parser.parse_args()
# Run an array of hec tests
test_hec(args.url, '/cribl/_bulk', build_json( '_raw', '/cribl/_bulk'))
test_hec(args.url, '/services/collector', build_json('event', '/services/collector'))
test_hec(args.url, '/services/collector/raw', build_json('event', '/services/collector/raw'))
test_hec(args.url,'/services/collector/event', build_json('event','/services/collector/event'))
# Run an array of raw tests
test_hec(args.url, '/services/collector/raw', build_raw( '/services/collector/raw'))
# Can't send raw to /services/collector
# test_hec(args.url, '/services/collector', build_raw( '/services/collector'))