mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 10:27:09 +00:00
Make send_alert usable as a module
This commit is contained in:
@@ -10,19 +10,7 @@ import configuration
|
|||||||
import requests
|
import requests
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def send_alert (data):
|
||||||
|
|
||||||
ap = argparse.ArgumentParser()
|
|
||||||
ap.add_argument("-t", "--title", required=True, default=None, help="The title of the incident.")
|
|
||||||
ap.add_argument("-d", "--description", required=False, default=None, help="A high-level summary of the problem.")
|
|
||||||
ap.add_argument("-s", "--service", required=False, default=None, help="The affected service.")
|
|
||||||
ap.add_argument("-l", "--severity", required=False, default="critical", help="The severity of the alert. Must be one of critical, high, medium, low, info, unknown. Default is critical.")
|
|
||||||
ap.add_argument("-I", "--stdin", required=False, default=None, help="Contents of standard input")
|
|
||||||
ap.add_argument("-O", "--stdout", required=False, default=None, help="Contents of standard output")
|
|
||||||
ap.add_argument("-E", "--stderr", required=False, default=None, help="Contents of standard error")
|
|
||||||
|
|
||||||
|
|
||||||
args = vars(ap.parse_args())
|
|
||||||
|
|
||||||
cfg = configuration.read()
|
cfg = configuration.read()
|
||||||
|
|
||||||
@@ -40,6 +28,23 @@ if __name__ == '__main__':
|
|||||||
"Authorization": "Bearer " + authkey
|
"Authorization": "Bearer " + authkey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
requests.post(url, headers=headers, json=data)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
ap = argparse.ArgumentParser()
|
||||||
|
ap.add_argument("-t", "--title", required=True, default=None, help="The title of the incident.")
|
||||||
|
ap.add_argument("-d", "--description", required=False, default=None, help="A high-level summary of the problem.")
|
||||||
|
ap.add_argument("-s", "--service", required=False, default=None, help="The affected service.")
|
||||||
|
ap.add_argument("-l", "--severity", required=False, default="critical", help="The severity of the alert. Must be one of critical, high, medium, low, info, unknown. Default is critical.")
|
||||||
|
ap.add_argument("-I", "--stdin", required=False, default=None, help="Contents of standard input")
|
||||||
|
ap.add_argument("-O", "--stdout", required=False, default=None, help="Contents of standard output")
|
||||||
|
ap.add_argument("-E", "--stderr", required=False, default=None, help="Contents of standard error")
|
||||||
|
|
||||||
|
|
||||||
|
args = vars(ap.parse_args())
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"title": args["title"],
|
"title": args["title"],
|
||||||
"description": args["description"],
|
"description": args["description"],
|
||||||
@@ -51,6 +56,6 @@ if __name__ == '__main__':
|
|||||||
"error": args["stderr"]
|
"error": args["stderr"]
|
||||||
}
|
}
|
||||||
|
|
||||||
requests.post(url, headers=headers, json=data)
|
send_alert(data)
|
||||||
|
|
||||||
print("Done")
|
print("Done")
|
||||||
|
|||||||
Reference in New Issue
Block a user