def read_config_values(file_path):
"This loads pre-generated parameters for Microsoft Sentinel Workspace"
with open(file_path) as json_file:
if json_file:
json_config = json.load(json_file)
return (json_config["tenant_id"],
json_config["subscription_id"],
json_config["resource_group"],
json_config["workspace_id"],
json_config["workspace_name"],
json_config["user_alias"],
json_config["user_object_id"])
return None
def has_valid_token():
"Check to see if there is a valid AAD token"
try:
error = "Please run 'az login'"
expired = "AADSTS70043: The refresh token has expired or is invalid"
failed = "failed"
validator = !az account get-access-token
if any(expired in item for item in validator.get_list()):
return '**The refresh token has expired. <br> Please continue your login process. Then: <br> 1. If you plan to run multiple notebooks on the same compute instance today, you may restart the compute instance by clicking "Compute" on left menu, then select the instance, clicking "Restart"; <br> 2. Otherwise, you may just restart the kernel from top menu. <br> Finally, close and re-load the notebook, then re-run cells one by one from the top.**'
elif any(error in item for item in validator.get_list()) or any(failed in item for item in validator.get_list()):
return "Please run 'az login' to setup account"
else:
return None
except:
return "Please login"
def call_azure_rest_api_for_list(token, resource_name, api_version):
"Calling Microsoft Sentinel REST API"
headers = {"Authorization": token, "content-type":"application/json" }
provider_name = "Microsoft.OperationalInsights"
provider2_name = "Microsoft.SecurityInsights"
target_resource_name = resource_name
api_version = api_version
root_url = "https://management.azure.com"
arm_rest_url_template_for_list = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/{3}/workspaces/{4}/providers/{5}/{6}?api-version={7}"
arm_rest_url = arm_rest_url_template_for_list.format(root_url, subscription_id, resource_group, provider_name, workspace_name, provider2_name, target_resource_name, api_version)
response = requests.get(arm_rest_url, headers=headers, verify=True)
return response
def display_result_name(response):
"Default to display column - name, you may change it to other columns"
column_name = "name"
if response != None:
entries = [item[column_name] for item in response.json()["value"]]
display(entries)
def display_result(response):
"Display the result set as pandas.DataFrame"
if response != None:
df = pandas.DataFrame(response.json()["value"])
display(df)