-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* storm_ref_lift.ipynb * Allow storm() calls to suppress logging in certain loggers. * storm_ref_lift.ipynb * call supppress logging once * storm_ref_lift.ipynb * storm_ref_lift.ipynb Co-authored-by: reign <[email protected]> Co-authored-by: epiphyte <[email protected]> Co-authored-by: Nic Watson <[email protected]> Try lift section added to user doc lift section.
- Loading branch information
Showing
3 changed files
with
229 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ | |
"Lift operations retrieve a set of nodes from a Synapse Cortex based on specified criteria. While all lift operations are retrieval operations, they can be broken down into “types” of lifts based on the criteria, comparison operator, or special handler used:\n", | ||
"\n", | ||
"- `Simple Lifts`_\n", | ||
"- `Try Lifts`_\n", | ||
"- `Lifts Using Standard Comparison Operators`_\n", | ||
"- `Lifts Using Extended Comparison Operators`_\n", | ||
"\n", | ||
|
@@ -623,6 +624,170 @@ | |
"_ = await core.fini()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"hideCode": true, | ||
"hideOutput": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Create a cortex for the Safe Lifts section\n", | ||
"core = await getTempCoreCmdr()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "raw", | ||
"metadata": { | ||
"hideCode": false | ||
}, | ||
"source": [ | ||
"Try Lifts\n", | ||
"---------\n", | ||
"\n", | ||
"Try lifts refer to lifts that \"try\" to perform a Cortex lift operation, and fail silently if :ref:`data-type` normalization is not successful. Try lifts prevent a Cortex from throwing a runtime execution error, and terminating query execution if an invalid Type is encountered.\n", | ||
"\n", | ||
"When lifting nodes by property value using the equals (``=``) comparator, if Type validation fails for a supplied property value, the Cortex will throw a ``BadTypeValu`` error, and terminate the query as shown below." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"hideCode": true, | ||
"hideOutput": true, | ||
"hidePrompt": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Make a FQDN, MD5, IPv4, and email nodes:\n", | ||
"q = '[ inet:fqdn=evil.com inet:dns:a=(evil.com,192.168.0.100) hash:md5=174cc541c8d9e1accef73025293923a6 inet:ipv4=8.8.8.8 inet:[email protected] inet:[email protected]]'\n", | ||
"# Execute query and test\n", | ||
"podes = await core.eval(q, num=6, cmdr=False)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"hideCode": true, | ||
"hideOutput": false, | ||
"hidePrompt": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Define and print test query\n", | ||
"q = 'inet:ipv4 = evil.com inet:ipv4 = 8.8.8.8'\n", | ||
"# Execute the query and test\n", | ||
"podes = await core.storm(q, num=0, cmdr=True, suppress_logging=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "raw", | ||
"metadata": { | ||
"hidePrompt": false | ||
}, | ||
"source": [ | ||
"To suppress errors, and prevent premature query termination, Storm supports the use of the try operator (``?=``) when performing property value lifts. This operator is useful when you are performing multiple Cortex operations in succession within a single query, lifting nodes using external data that has not been normalized, or lifting nodes during automation, and do not want a query to terminate if an invalid Type is encountered.\n", | ||
"\n", | ||
"\n", | ||
"**Syntax:**\n", | ||
"\n", | ||
"*<form>[:<prop>]* ?= *<pval>*\n", | ||
"\n", | ||
"**Examples:**\n", | ||
"\n", | ||
"- Try to lift the MD5 node ``174cc541c8d9e1accef73025293923a6``:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"hideCode": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Define and print test query\n", | ||
"q = 'hash:md5 ?= 174cc541c8d9e1accef73025293923a6'\n", | ||
"print(q)\n", | ||
"# Execute the query and test\n", | ||
"podes = await core.eval(q, num=1, cmdr=False)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "raw", | ||
"metadata": { | ||
"hideCode": false, | ||
"hideOutput": false | ||
}, | ||
"source": [ | ||
"- Try to lift the DNS nodes whose ``inet:dns:a:ipv4`` secondary property value equals ``'192.168.0.100'``. Notice that an error message is not displayed, despite an invalid IPv4 address ``'192.168.0.1000'`` being entered:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"hideCode": true, | ||
"hideOutput": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Define and print test query\n", | ||
"q = 'inet:dns:a:ipv4 ?= 192.168.0.1000'\n", | ||
"print(q)\n", | ||
"# Execute the query and test\n", | ||
"podes = await core.eval(q, num=0, cmdr=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "raw", | ||
"metadata": {}, | ||
"source": [ | ||
"- Try to lift the email address nodes ``'[email protected]'`` and ``'[email protected]'``. Notice that despite the first email address being entered incorrectly, the error message is suppressed, and the query executes to completion." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"hideCode": true, | ||
"hideOutput": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Define and print test query\n", | ||
"q = 'inet:email ?= \"jack[at]soso.net\" inet:email ?= \"[email protected]\"'\n", | ||
"print(q)\n", | ||
"# Execute the query and test\n", | ||
"podes = await core.eval(q, num=1, cmdr=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "raw", | ||
"metadata": {}, | ||
"source": [ | ||
"**Usage Notes:**\n", | ||
"\n", | ||
"- The try operator should be used when you want Storm query execution to continue even if an invalid Type is encountered. \n", | ||
"- It is not recommended to use the try operator when you want to raise an error, or stop query execution if an invalid Type is encountered." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"hideCode": true, | ||
"hideOutput": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Close cortex for Safe Lifts section\n", | ||
"_ = await core.fini()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "raw", | ||
"metadata": {}, | ||
|
@@ -2182,7 +2347,7 @@ | |
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.1" | ||
"version": "3.7.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters