Skip to content

Instantly share code, notes, and snippets.

@mjnbrn
Last active October 14, 2021 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjnbrn/e4c47dfbbac3516cf029fc90c6465758 to your computer and use it in GitHub Desktop.
Save mjnbrn/e4c47dfbbac3516cf029fc90c6465758 to your computer and use it in GitHub Desktop.
python notes app that sends your note to a Splunk instance via HEC
import argparse
import requests
import json
import logging
logging.captureWarnings(True)
parser = argparse.ArgumentParser(prog="notes.py", description="So you want to take a note?",
usage="python notes.py --course 'A Hard Course' --book 1 --topic 'The Hardest Course' --desc 'a thing that stashs logs'")
parser.add_argument('--course', type=str,
help='course code')
parser.add_argument('--book', type=str, help='book number')
parser.add_argument('--page', type=str, help='page number(s)')
parser.add_argument('--topic', type=str, help='topic of note')
parser.add_argument('--desc', type=str, help='note text')
args = parser.parse_args()
try:
event = {'course': args.course, 'book': args.book,
'page': args.page, 'topic': args.topic.split(", "), 'desc': args.desc}
body = {"event": event}
headers = {"Authorization": "Splunk <TOKEN>"}
url = "https://<HOST>:<PORT>/services/collector/event"
r = requests.post(url=url, headers=headers,
data=json.dumps(body), verify=False)
except Exception as e:
print("Aw shit, we failed...")
print(e)
function Take-Note{
[CmdletBinding()]
param (
[Parameter()]
[String]$desc,
[String]$course= "life",
[String]$book= "0",
[String]$page= "0",
[String[]]$topic= "General"
)
C:\notes\venv\python.exe C:\notes\notes.py --course $course --book $book --page $page --topic ($topic -join ", ") --desc $desc
}
Set-Alias -Name tn -Value Take-Note
@mjnbrn
Copy link
Author

mjnbrn commented Oct 14, 2021

Take-Notes.ps1 is just a ps wrapper around notes.py, because powershell is love

@mjnbrn
Copy link
Author

mjnbrn commented Oct 14, 2021

Now you can pass an COMMA-SPACE separated string to topic and it'll handle it. powershell wrapper takes an actual array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment