Thank you! I tried your suggested solution, and it works exactly the way expected.
Original Message:
Sent: Tue April 02, 2024 08:26 AM
From: Bo Bleckel
Subject: Output key-value pairs value to Note in single Note dialog box
Hi there -
So each time that you call incident.addNote
, a Note will be created on the incident. In order to combine your notes into one, you'd have to combine the content into one string and then call incident.addNote
just once.
Something like this will probably do the trick:
import jsonresults = playbook.functions.results.rest_responsedata = results.content.jsonkey_value_list = []for vulnerability in data['vulnerabilities']: key_value_pairs = [ f"plugin_name: {vulnerability['plugin_name']}", f"severity: {vulnerability['severity']}", f"cvss_base_score: {vulnerability['cvss_base_score']}" ] key_value_list.append(key_value_pairs)# create a string to concatenate each line of the notenote_text = ""for key_values in key_value_list: note_text += ', '.join(key_values) + "\n" # add a new line here to separate each itemincident.addNote(note_text)
------------------------------
Bo Bleckel
Original Message:
Sent: Mon April 01, 2024 09:19 PM
From: Ray Tam
Subject: Output key-value pairs value to Note in single Note dialog box
Anyone has experience extract the key-value pairs to the Note field? I am using an output script below. it is able to output the key-value pairs but it creates a new Note for each key-value pairs. Is there a way I can have all the key-value pairs output in the same Note instead of multiple Notes?
Rest API Result:
json': {'vulnerabilities': [{'count': 1, 'plugin_family': 'Windows', 'plugin_id': 163974, 'plugin_name': 'Security Updates for Microsoft .NET Core (August 2022)', 'vulnerability_state': 'Active', 'vpr_score': 4.4, 'severity': 2, 'accepted_count': 0, 'recasted_count': 0, 'counts_by_severity': [{'count': 1, 'value': 2}], 'cvss_base_score': 5.4, 'cvss3_base_score': 5.9}, {'count': 1, 'plugin_family': 'Windows : Microsoft Bulletins', 'plugin_id': 165076, 'plugin_name': 'Security Updates for Microsoft ASP.NET Core (September 2022)', 'vulnerability_state': 'Active', 'vpr_score': 4.4, 'severity': 3, 'accepted_count': 0, 'recasted_count': 0, 'counts_by_severity': [{'count': 1, 'value': 3}], 'cvss_base_score': 7.8, 'cvss3_base_score': 7.5}, {'count': 1, 'plugin_family': 'Windows', 'plugin_id': 165077, 'plugin_name': 'Security Updates for Microsoft .NET Core (September 2022)', 'vulnerability_state': 'Active', 'vpr_score': 4.4, 'severity': 3, 'accepted_count': 0, 'recasted_count': 0, 'counts_by_severity': [{'count': 1, 'value': 3}], 'cvss_base_score': 7.8, 'cvss3_base_score': 7.5}, {'count': 1, 'plugin_family': 'Windows', 'plugin_id': 166054, 'plugin_name': 'Security Updates for Microsoft .NET Core (October 2022)', 'vulnerability_state': 'Active', 'vpr_score': 7.4, 'severity': 3, 'accepted_count': 0, 'recasted_count': 0, 'counts_by_severity': [{'count': 1, 'value': 3}], 'cvss_base_score': 6.8, 'cvss3_base_score': 7.8}, {'count': 1, 'plugin_family': 'Windows : Microsoft Bulletins', 'plugin_id': 166555, 'plugin_name': 'WinVerifyTrust Signature Validation CVE-2013-3900 Mitigation (EnableCertPaddingCheck)', 'vulnerability_state': 'Active', 'vpr_score': 8.9, 'severity': 3, 'accepted_count': 0, 'recasted_count': 0, 'counts_by_severity': [{'count': 1, 'value': 3}], 'cvss_base_score': 7.6, 'cvss3_base_score': 7.8}, {'count': 1, 'plugin_family': 'Windows', 'plugin_id': 168747, 'plugin_name': 'Security Updates for Microsoft .NET Core (December 2022)', 'vulnerability_state': 'Active', 'vpr_score': 6.7, 'severity': 3, 'accepted_count': 0, 'recasted_count': 0, 'counts_by_severity': [{'count': 1, 'value': 3}], 'cvss_base_score': 7.2, 'cvss3_base_score': 7.8}}
Output Script:
import json
results = playbook.functions.results.rest_response
data = results.content.json
key_value_list = []
for vulnerability in data['vulnerabilities']:
key_value_pairs = [
f"plugin_name: {vulnerability['plugin_name']}",
f"severity: {vulnerability['severity']}",
f"cvss_base_score: {vulnerability['cvss_base_score']}"
]
key_value_list.append(key_value_pairs)
for key_values in key_value_list:
incident.addNote(', '.join(key_values))
Sample Output from the script:
Note Dialog Box #1
plugin_name: Windows Speculative Execution Configuration Check, severity: 2, cvss_base_score: 5.4
Note Dialog Box #2
plugin_name: Windows Speculative Execution Configuration Check, severity: 2, cvss_base_score: 5.4
------------------------------
Ray Tam
------------------------------