Path: blob/master/src/Snippets/Snippets.json
3253 views
{1"Microsoft Sentinel - Get Configuration parameters": {2"prefix": [ "get-sentinelconfiguration", "get-sentinelconfig" ],3"body": [4"########################################################################",5"# Microsoft Sentinel - Get Microsoft Sentinel Configuration parameters #",6"########################################################################",7"import json",8"def read_config_values(file_path):",9" 'This loads pre-generated parameters for Microsoft Sentinel Workspace'",10" with open(file_path) as json_file:",11" if json_file:",12" json_config = json.load(json_file)",13" return (json_config['${1:tenant_id}'],",14" json_config['${2:subscription_id}'],",15" json_config['${3:resource_group}'],",16" json_config['${4:workspace_id}'],",17" json_config['${5:workspace_name}'],",18" json_config['${6:user_alias}'],",19" json_config['${7:user_object_id}'])",20" return None",21"",22"# Calling the above function to populate Microsoft Sentinel workspace parameters",23"# The file, config.json, was generated by the system, however, you may modify the values, or manually set the variables",24"tenant_id, subscription_id, resource_group, workspace_id, workspace_name, user_alias, user_object_id = read_config_values('config.json')"25],26"description": "Get Microsoft Sentinel configuration parameters from config.json"27},2829"Microsoft Sentinel - Set up environment for MSTICPy": {30"prefix": [ "msticpy-setup" ],31"body": [32"#######################################################",33"# Microsoft Sentinel - Set up environment for MSTICPy #",34"#######################################################",35"# import some modules needed in this cell",36"from pathlib import Path",37"from IPython.display import display, HTML",38"",39"display(HTML('Checking upgrade to latest msticpy version'))",40"%pip install --upgrade --quiet msticpy[azsentinel]",41"",42"display(HTML('<h3>Starting Notebook setup...</h3>'))",43"# intialize msticpy",44"try:",45" from msticpy.nbtools import nbinit",46" nbinit.init_notebook(",47" namespace=globals(),",48" extra_imports=[]",49" )",50"except ImportError:",51" print('MSTICPy not installed, please restart the kernel to ensure MSTICPy is installed.')"52],53"description": "Set up the execution environment for MSTICPy"54},5556"Microsoft Sentinel - Authenticate with MSTICPy": {57"prefix": [ "msticpy-azs-connect" ],58"body": [59"##############################################",60"# Microsoft Sentinel - Authenticate with MSTICPy #",61"##############################################",62"",63"from msticpy.data.data_providers import QueryProvider",64"from msticpy.common.wsconfig import WorkspaceConfig",65"",66"ws_config = WorkspaceConfig()",67"if not ws_config.config_loaded:",68"ws_config.prompt_for_ws()",69"",70"qry_prov = QueryProvider(data_environment='AzureSentinel')",71"qry_prov.connect(ws_config)",72""73],74"description": "Load a Microsoft Sentinel query provider and connect to the default workspace with MSTICPy"75},7677"Microsoft Sentinel - Set up MSTICPy Pivots": {78"prefix": [ "msticpy-azs-pivots" ],79"body": [80"##########################################",81"# Microsoft Sentinel - Set up MSTICPy Pivots #",82"##########################################",83"",84"from msticpy.data.data_providers import QueryProvider",85"from msticpy.common.wsconfig import WorkspaceConfig",86"",87"ws_config = WorkspaceConfig()",88"if not ws_config.config_loaded:",89"ws_config.prompt_for_ws()",90"",91"qry_prov = QueryProvider(data_environment='AzureSentinel')",92"qry_prov.connect(ws_config)",93"",94"from msticpy.datamodel.pivot import Pivot",95"Pivot(namespace=globals())",96"Pivot.browse()"97],98"description": "Set is MSTICPy Pivots to use Microsoft Sentinel"99},100101"Microsoft Sentinel - Set up MSTICNb": {102"prefix": [ "msticnb-setup" ],103"body": [104"###################################",105"# Microsoft Sentinel - Set up MSTICNb #",106"###################################",107"from IPython.display import display, HTML",108"",109"display(HTML('Checking upgrade to latest msticnb version'))",110"%pip install --upgrade --quiet msticnb",111"",112"display(HTML('<h3>Starting Notebooklet setup...</h3>'))",113"# intialize msticnb",114"try:",115" import msticnb as nb",116" nb.init(query_provider='AzureSentinel')",117" nb.browse()",118"except ImportError:",119" print('MSTICNb not installed, please restart the kernel to ensure MSTICNb is installed.')"120],121"description": "Install and load MSTICNb and display a browser showing avaliable notebooklets."122},123124"Microsoft Sentinel - Authenticate into Azure Log Analytics": {125"prefix": [ "login-loganalytics" ],126"body": [127"########################################################",128"# Microsoft Sentinel - Authenticate to Azure Log Analytics #",129"########################################################",130"# Azure CLI is used to get device code to login into Azure, you need to copy the code and open the DeviceLogin site.",131"# !!! You need [tenant_id] and [subscription_id] to login into Azure !!!",132"from azure.common.client_factory import get_client_from_cli_profile",133"from azure.common.credentials import get_azure_cli_credentials",134"from azure.loganalytics import LogAnalyticsDataClient",135"from azure.mgmt.loganalytics import LogAnalyticsManagementClient",136"from azure.loganalytics.models import QueryBody",137"",138"!az login --use-device-code",139"la_client = get_client_from_cli_profile(LogAnalyticsManagementClient, subscription_id = subscription_id)",140"creds, _ = get_azure_cli_credentials(resource='https://api.loganalytics.io')",141"la_data_client = LogAnalyticsDataClient(creds)",142" ",143"# Query sample: ",144"# query = 'union withsource = SentinelTableName * | distinct SentinelTableName | sort by SentinelTableName asc'",145"# result = la_data_client.query(workspace_id, QueryBody(query=query))",146"# print(result.as_dict())"147],148"description": "Using AZCLI to login to Azure Log Analytics"149}150}151152153