Path: blob/master/tutorials-and-examples/feature-tutorials/NotebookWidgets.ipynb
3253 views
Title: msticpy - nbwidgets
Description:
This contains a few aggregated widgets using IPyWidgets that help speed things up during an investigation.
You must have msticpy installed to run this notebook:
MSTICpy versions >= 0.8.5
QueryTime
This widget is used to specify time boundaries - designed to be used with the built-in msticpy queries and custom queries. The start and end times are exposed as datetime properties.
Keep multiple query boundaries aligged by having QueryTime instances reference the time of the same alert or event, or have them chained from one another by referencing the origin_time of an earlier QueryTimes object
Simple alert selector
Selected alert is available as select_alert_widget.selected_alert property
Simple alert selector
Selected alert is available as select_alert_widget.selected_alert
Alert selector with action=SecurityAlert'
You can pass a function that returns one or more displayable objects. You can also pass a class (in this case we're passing SecurityAlert) that produces an IPython displayable object.
The action class/function is passed the raw alert row as a parameter, as it is selected from the list
Or a more detailed display with extracted entities
SelectItem
Similar to AlertSelector but simpler and allows you to use any list or dictionary of items.
GetEnvironmentKey
Get editable value of environment variable. Common use would be retrieving an API key from your environment or allowing you to paste in a value if the environment key isn't set.
Note setting the variable only persists in the python kernel process running at the time. So you can retrieve it later in the notebook but not in other processes.
SelectSubset
Allows you to select one or multiple items from a list to populate an output set.
Progress Indicator
Logon Display
Display logon details for a Windows or Linux logon
Display a list of logons
Registered Widgets
Some of the widgets (QueryTimes, GetText) can register themselves and retain the setting and values previously entered. This can be useful when stepping through a notebook since it is a common mistake to enter text in a text box and then execute the same cell again by mistake. This, of course, usually results in the widget being reset to its default state and erasing the values you just entered.
If you use a registered widget and then create a new copy of the widget with identical parameters it will look in the registry for a previous copy of itself and auto-populate it's values with the previous-entered ones.
Registered widgets can also read their default values from notebook variables - this is mainly useful with notebooks that are programmatically supplied with parameters and executed with something like Papermill.
Several of the additional parameters available in RegisteredWidgets init are for internal use by widgets but three are usable by users:
When we re-execute the cell or use the same widget with identical arguments the value is populated from the registry cache
QueryTime also supports registration
Note the origin, before and after have all been copied from the previous instance
To skip registration add the parameter register=False
Using notebook parameters to populate RegisteredWidgets
Multi-Option buttons with async wait
This widget is pretty simple on the surface but has some useful features for waiting for user input.
Using OptionButtons to wait until an option is chosen (or timeout expires)
Option buttons uses an asynchronous event loop to track both the button state and the timeout simultaneously.
Because this requires the use of asynchronous code you must do the following
call widget
.display_async()method rather than justdisplay()or using the auto-display functionality of Jupyterprefix this call with
await- this tells IPython/Jupyter that you are executing asynchronous code and that it needs to wait until this call has completed before continuing with cell execution.
Note Awaiting the OptionButtons control does not pause the notebook execution. This is a capability that we are still working on.