feat(microsoft-sentinel): new Microsoft Sentinel integration
19 commands (Azure Resource Manager API): incident ingestion + CRUD, comments, related alerts/entities/relations, watchlists, and threat indicators. Azure AD OAuth 2.0 client-credentials, stdlib-only. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
import uuid
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
incident_id = inputs.get("incident_id")
|
||||
comment = inputs.get("comment")
|
||||
if not incident_id:
|
||||
raise Exception("incident_id is required")
|
||||
if not comment:
|
||||
raise Exception("comment is required")
|
||||
comment_id = str(uuid.uuid4())
|
||||
res = request("PUT", "/incidents/" + q(incident_id) + "/comments/" + comment_id,
|
||||
body={"properties": {"message": comment}})
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,86 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
import uuid
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
title = inputs.get("title")
|
||||
severity = inputs.get("severity")
|
||||
if not title:
|
||||
raise Exception("title is required")
|
||||
if not severity:
|
||||
raise Exception("severity is required")
|
||||
status = inputs.get("status") or "New"
|
||||
description = inputs.get("description")
|
||||
assigned_to = inputs.get("assigned_to")
|
||||
|
||||
props = {"title": title, "severity": severity, "status": status}
|
||||
if description:
|
||||
props["description"] = description
|
||||
if assigned_to:
|
||||
props["owner"] = {"assignedTo": assigned_to}
|
||||
|
||||
new_guid = str(uuid.uuid4())
|
||||
res = request("PUT", "/incidents/" + new_guid, body={"properties": props})
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,102 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
value = inputs.get("value")
|
||||
pattern_type = inputs.get("pattern_type")
|
||||
if not value:
|
||||
raise Exception("value is required")
|
||||
if not pattern_type:
|
||||
raise Exception("pattern_type is required")
|
||||
|
||||
display_name = inputs.get("display_name") or value
|
||||
threat_types_raw = inputs.get("threat_types")
|
||||
if threat_types_raw:
|
||||
threat_types = [t.strip() for t in str(threat_types_raw).split(",") if t.strip()]
|
||||
else:
|
||||
threat_types = ["malicious-activity"]
|
||||
confidence = inputs.get("confidence")
|
||||
valid_until = inputs.get("valid_until")
|
||||
|
||||
if str(pattern_type).startswith("file"):
|
||||
pattern = "[" + str(pattern_type) + " = '" + str(value) + "']"
|
||||
else:
|
||||
pattern = "[" + str(pattern_type) + ":value = '" + str(value) + "']"
|
||||
|
||||
props = {
|
||||
"pattern": pattern,
|
||||
"patternType": pattern_type,
|
||||
"displayName": display_name,
|
||||
"threatTypes": threat_types,
|
||||
"source": "Riposte",
|
||||
}
|
||||
if confidence is not None and confidence != "":
|
||||
props["confidence"] = int(confidence)
|
||||
if valid_until:
|
||||
props["validUntil"] = valid_until
|
||||
|
||||
body = {"kind": "indicator", "properties": props}
|
||||
res = request("POST", "/threatIntelligence/main/createIndicator", body=body)
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,74 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
incident_id = inputs.get("incident_id")
|
||||
if not incident_id:
|
||||
raise Exception("incident_id is required")
|
||||
request("DELETE", "/incidents/" + q(incident_id))
|
||||
print(json.dumps({"ok": True, "incident_id": incident_id}))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,74 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
indicator_name = inputs.get("indicator_name")
|
||||
if not indicator_name:
|
||||
raise Exception("indicator_name is required")
|
||||
request("DELETE", "/threatIntelligence/main/indicators/" + q(indicator_name))
|
||||
print(json.dumps({"ok": True, "indicator_name": indicator_name}))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,74 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
incident_id = inputs.get("incident_id")
|
||||
if not incident_id:
|
||||
raise Exception("incident_id is required")
|
||||
res = request("GET", "/incidents/" + q(incident_id))
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,105 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
from datetime import datetime, timezone
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
def _normalize_iso(s):
|
||||
s = str(s)
|
||||
if s.isdigit():
|
||||
ts = int(s)
|
||||
if ts > 10 ** 12:
|
||||
ts = ts / 1000.0
|
||||
return datetime.fromtimestamp(ts, tz=timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
try:
|
||||
dt = datetime.fromisoformat(s.replace("Z", "+00:00")).astimezone(timezone.utc)
|
||||
return dt.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
except Exception:
|
||||
return s
|
||||
|
||||
|
||||
def _flatten(item):
|
||||
flat = dict(item.get("properties", {}))
|
||||
flat["name"] = item.get("name")
|
||||
flat["id"] = item.get("id")
|
||||
return flat
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
filt = inputs.get("filter")
|
||||
created_after = inputs.get("created_after")
|
||||
limit = inputs.get("limit") or 50
|
||||
|
||||
filter_parts = []
|
||||
if filt:
|
||||
filter_parts.append(str(filt))
|
||||
if created_after:
|
||||
filter_parts.append("properties/createdTimeUtc ge " + _normalize_iso(created_after))
|
||||
filter_str = " and ".join(filter_parts) if filter_parts else None
|
||||
|
||||
res = request("GET", "/incidents", params={
|
||||
"$filter": filter_str,
|
||||
"$top": limit,
|
||||
"$orderby": "properties/createdTimeUtc asc",
|
||||
})
|
||||
print(json.dumps({"result": [_flatten(i) for i in res.get("value", [])]}))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,75 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
incident_id = inputs.get("incident_id")
|
||||
if not incident_id:
|
||||
raise Exception("incident_id is required")
|
||||
limit = inputs.get("limit") or 50
|
||||
res = request("GET", "/incidents/" + q(incident_id) + "/comments", params={"$top": limit})
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,74 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
incident_id = inputs.get("incident_id")
|
||||
if not incident_id:
|
||||
raise Exception("incident_id is required")
|
||||
res = request("POST", "/incidents/" + q(incident_id) + "/alerts")
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,74 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
incident_id = inputs.get("incident_id")
|
||||
if not incident_id:
|
||||
raise Exception("incident_id is required")
|
||||
res = request("POST", "/incidents/" + q(incident_id) + "/entities")
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,74 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
incident_id = inputs.get("incident_id")
|
||||
if not incident_id:
|
||||
raise Exception("incident_id is required")
|
||||
res = request("GET", "/incidents/" + q(incident_id) + "/relations")
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,72 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
res = request("GET", "/incidents", params={
|
||||
"$filter": inputs.get("filter"),
|
||||
"$orderby": inputs.get("orderby"),
|
||||
"$top": inputs.get("limit") or 50,
|
||||
})
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,70 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
filt = inputs.get("filter")
|
||||
limit = inputs.get("limit") or 50
|
||||
res = request("GET", "/threatIntelligence/main/indicators", params={"$filter": filt or None, "$top": limit})
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,75 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
watchlist_alias = inputs.get("watchlist_alias")
|
||||
if not watchlist_alias:
|
||||
raise Exception("watchlist_alias is required")
|
||||
limit = inputs.get("limit") or 50
|
||||
res = request("GET", "/watchlists/" + q(watchlist_alias) + "/watchlistItems", params={"$top": limit})
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,69 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
limit = inputs.get("limit") or 50
|
||||
res = request("GET", "/watchlists", params={"$top": limit})
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,69 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
def main():
|
||||
res = request("GET", "/incidents", params={"$top": 1})
|
||||
if "value" not in res:
|
||||
raise Exception("unexpected response")
|
||||
print(json.dumps({"ok": True}))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,94 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
incident_id = inputs.get("incident_id")
|
||||
if not incident_id:
|
||||
raise Exception("incident_id is required")
|
||||
|
||||
existing = request("GET", "/incidents/" + q(incident_id))
|
||||
props = dict(existing.get("properties", {}))
|
||||
|
||||
if inputs.get("title"):
|
||||
props["title"] = inputs["title"]
|
||||
if inputs.get("status"):
|
||||
props["status"] = inputs["status"]
|
||||
if inputs.get("severity"):
|
||||
props["severity"] = inputs["severity"]
|
||||
if inputs.get("description"):
|
||||
props["description"] = inputs["description"]
|
||||
if inputs.get("classification"):
|
||||
props["classification"] = inputs["classification"]
|
||||
if inputs.get("classification_reason"):
|
||||
props["classificationReason"] = inputs["classification_reason"]
|
||||
if inputs.get("assigned_to"):
|
||||
props["owner"] = {"assignedTo": inputs["assigned_to"]}
|
||||
|
||||
body = {"properties": props, "etag": existing.get("etag")}
|
||||
res = request("PUT", "/incidents/" + q(incident_id), body=body)
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,88 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
indicator_name = inputs.get("indicator_name")
|
||||
if not indicator_name:
|
||||
raise Exception("indicator_name is required")
|
||||
|
||||
existing = request("GET", "/threatIntelligence/main/indicators/" + q(indicator_name))
|
||||
props = dict(existing.get("properties", {}))
|
||||
|
||||
if inputs.get("display_name"):
|
||||
props["displayName"] = inputs["display_name"]
|
||||
if inputs.get("confidence") is not None and inputs.get("confidence") != "":
|
||||
props["confidence"] = int(inputs["confidence"])
|
||||
if inputs.get("valid_until"):
|
||||
props["validUntil"] = inputs["valid_until"]
|
||||
if inputs.get("threat_types"):
|
||||
props["threatTypes"] = [t.strip() for t in str(inputs["threat_types"]).split(",") if t.strip()]
|
||||
|
||||
body = {"kind": "indicator", "properties": props, "etag": existing.get("etag")}
|
||||
res = request("PUT", "/threatIntelligence/main/indicators/" + q(indicator_name), body=body)
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,83 @@
|
||||
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||
import uuid
|
||||
|
||||
API_VERSION = "2023-11-01"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _token():
|
||||
cfg = _cfg()
|
||||
data = urllib.parse.urlencode({
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": str(cfg.get("client_id") or ""),
|
||||
"client_secret": str(cfg.get("client_secret") or ""),
|
||||
"scope": "https://management.azure.com/.default",
|
||||
}).encode("utf-8")
|
||||
url = "https://login.microsoftonline.com/" + str(cfg.get("tenant_id") or "") + "/oauth2/v2.0/token"
|
||||
req = urllib.request.Request(url, data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
||||
method="POST")
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
tok = json.loads(r.read())
|
||||
if not tok.get("access_token"):
|
||||
raise Exception("Token request failed: " + json.dumps(tok))
|
||||
return tok["access_token"]
|
||||
|
||||
|
||||
def _si_base():
|
||||
cfg = _cfg()
|
||||
for key in ("subscription_id", "resource_group", "workspace_name"):
|
||||
if not str(cfg.get(key) or ""):
|
||||
raise Exception(key + " is not set")
|
||||
return ("https://management.azure.com/subscriptions/" + str(cfg["subscription_id"])
|
||||
+ "/resourceGroups/" + str(cfg["resource_group"])
|
||||
+ "/providers/Microsoft.OperationalInsights/workspaces/" + str(cfg["workspace_name"])
|
||||
+ "/providers/Microsoft.SecurityInsights")
|
||||
|
||||
|
||||
def request(method, path, params=None, body=None, token=None):
|
||||
url = _si_base() + path
|
||||
q = {k: str(x) for k, x in (params or {}).items() if x not in (None, "")}
|
||||
q["api-version"] = API_VERSION
|
||||
url += ("&" if "?" in url else "?") + urllib.parse.urlencode(q)
|
||||
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||
headers = {"Accept": "application/json", "Authorization": "Bearer " + (token or _token())}
|
||||
if data is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=90) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||
|
||||
|
||||
def main():
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
watchlist_alias = inputs.get("watchlist_alias")
|
||||
item_json = inputs.get("item_json")
|
||||
if not watchlist_alias:
|
||||
raise Exception("watchlist_alias is required")
|
||||
if not item_json:
|
||||
raise Exception("item_json is required")
|
||||
item = json.loads(item_json)
|
||||
if not isinstance(item, dict):
|
||||
raise Exception("item_json must be a JSON object")
|
||||
item_id = inputs.get("item_id") or str(uuid.uuid4())
|
||||
res = request("PUT", "/watchlists/" + q(watchlist_alias) + "/watchlistItems/" + q(item_id),
|
||||
body={"properties": {"itemsKeyValue": item}})
|
||||
print(json.dumps(res))
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user