msticpy.init.nbinit module
Initialization for Jupyter Notebooks.
This module performs several steps to initialize MSTICPy: - imports a number of standard packages (e.g. pandas) into the notebook - imports a number of modules and functions from msticpy - checks the version of MSTICPy - checks for presence and validates msticpyconfig.yaml
In the Azure ML and Azure Synapse environments, some additional initialization and checks are performed.
One frequent problem in bootstrapping MSTICPy is obtaining or creating a valid msticpyconfig.yaml. This is needed for many configuration settings such as MS Sentinel workspaces, Threat Intelligence (TI) providers, Azure authentication, Key Vault settings and more.
If you are having trouble with this, you should check out the following resources:
The basic structure of msticpyconfig.yaml
https://msticpy.readthedocs.io/en/latest/getting_started/msticpyconfig.html
Using the msticpy settings editor to create or modify msticpyconfig.yaml
https://msticpy.readthedocs.io/en/latest/getting_started/SettingsEditor.html
MS Sentinel and Azure ML resources:
Getting started notebook https://github.com/Azure/Azure-Sentinel-Notebooks/blob/master/A%20Getting%20Started%20Guide%20For%20Azure%20Sentinel%20ML%20Notebooks.ipynb
Configuring your environment notebook https://github.com/Azure/Azure-Sentinel-Notebooks/blob/master/ConfiguringNotebookEnvironment.ipynb
- msticpy.init.nbinit.init_notebook(namespace: Dict[str, Any] | None = None, def_imports: str = 'all', additional_packages: List[str] | None = None, extra_imports: List[str] | None = None, **kwargs)
Initialize the notebook environment.
- Parameters:
namespace (Dict[str, Any], optional) – Namespace (usually globals()) into which imports are to be populated. By default, it will use the ipython user_global_ns.
def_imports (str, optional) – Import default packages. By default “all”. Possible values are: - “all” - import all packages - “nb” - import common notebook packages - “msticpy” - import msticpy packages - “none” (or any other value) don’t load any default packages.
additional_packages (List[str], optional) – Additional packages to be pip installed, by default None. Packages are specified by name only or version specification (e.g. “pandas>=0.25”)
user_install (bool, optional) – Install packages in the “user” rather than system site-packages. Use this option if you cannot or do not want to update the system packages. You should usually avoid using this option with standard Conda environments.
extra_imports (List[str], optional) – Additional import definitions, by default None. Imports are specified as up to 3 comma-delimited values in a string: “{source_pkg}, [{import_tgt}], [{alias}]” source_pkg is mandatory - equivalent to a simple “import xyz” statement. {import_tgt} specifies an object to import from the package equivalent to “from source_pkg import import_tgt” alias allows renaming of the imported object - equivalent to the “as alias” part of the import statement. If you want to provide just source_pkg and alias include an additional placeholder comma: e.g. “pandas, , pd”
friendly_exceptions (Optional[bool]) – Setting this to True causes msticpy to hook the notebook exception handler. Any exceptions derived from MsticpyUserException are displayed but do not produce a stack trace, etc. Defaults to system/user settings if no value is supplied.
verbose (Union[int, bool], optional) – Controls amount if status output, by default 1 0 = No output 1 or False = Brief output (default) 2 or True = Detailed output
verbosity (int, optional) – alias for verbose
config (Optional[str]) – Use this path to load a msticpyconfig.yaml. Defaults are MSTICPYCONFIG env variable, home folder (~/.msticpy), current working directory.
no_config_check (bool, optional) – Skip the check for valid configuration. Default is False.
detect_env (Union[bool, List[str]], optional) – By default init_notebook tries to detect environments and makes additional configuration changes if it finds one of the supported notebook environments. Passing False for this parameter disables environment detection. Alternatively, you can pass a list of environments that you want to detect. Current supported environments are ‘aml’ (Azure Machine Learning) and ‘synapse’ (Azure Synapse).
- Raises:
MsticpyException : – If extra_imports data format is incorrect. If package with required version check has no version information.
Notes
This module performs several steps to initialize MSTICPy: - imports a number of standard packages (e.g. pandas) into the notebook - imports a number of modules and functions from msticpy - checks the version of MSTICPy - checks for presence and validates msticpyconfig.yaml
In the Azure ML and Azure Synapse environments, some additional initialization and checks are performed.
One frequent problem in bootstrapping MSTICPy is obtaining or creating a valid msticpyconfig.yaml. This is needed for many configuration settings such as MS Sentinel workspaces, Threat Intelligence (TI) providers, Azure authentication, Key Vault settings and more.
If you are having trouble with this, you should do the following: 1. Run init_notebook again using the verbosity=2 parameter This will print out additional status and debugging information
Run mp.MpConfigEdit() to edit (or create) a msticpyconfig file.
Check out the following resources:
The basic structure of msticpyconfig.yaml
https://msticpy.readthedocs.io/en/latest/getting_started/msticpyconfig.html
Using the msticpy settings editor to create or modify msticpyconfig.yaml
https://msticpy.readthedocs.io/en/latest/getting_started/SettingsEditor.html
MS Sentinel and Azure ML resources:
Getting started notebook https://github.com/Azure/Azure-Sentinel-Notebooks/blob/master/A%20Getting%20Started%20Guide%20For%20Azure%20Sentinel%20ML%20Notebooks.ipynb
Configuring your environment notebook https://github.com/Azure/Azure-Sentinel-Notebooks/blob/master/ConfiguringNotebookEnvironment.ipynb
- msticpy.init.nbinit.list_default_imports()
List the default imports for init_notebook.
- msticpy.init.nbinit.reset_ipython_exception_handler()
Remove MSTICPy custom exception handler.