Skip to content

Commit

Permalink
Fix parseCSV markdown output (demisto#25161)
Browse files Browse the repository at this point in the history
* fix parseCSV markdown output

* release notes

* release notes

* conflict

* conflict

* test-upload code owner

* Revert "test-upload code owner"

This reverts commit 9936ec6.

* flake8
  • Loading branch information
yaakovpraisler authored Mar 9, 2023
1 parent 46c9779 commit 4775a2c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Packs/CommonScripts/ReleaseNotes/1_11_47.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#### Scripts
##### ParseCSV
- Fixed an issue in the markdown output where multiple IOC types are in same column.
10 changes: 5 additions & 5 deletions Packs/CommonScripts/Scripts/ParseCSV/ParseCSV.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,28 +203,28 @@ def main():
for row in csv_data:
content += ','.join(row) + '\n'
if parse_ip != -1:
md += (row[parse_ip] + '|' if row[parse_ip] else ' |')
is_ip = re.search(r'([0-9]{1,3}\.){3}[0-9]{1,3}', row[parse_ip])
is_valid = is_ip_valid(row[parse_ip])
if is_ip and is_valid:
ip_list.append(row[parse_ip])
md += '\n'
continue

if parse_hash != -1:
md += (row[parse_hash] + '|' if row[parse_hash] else ' |')
is_hash = re.search(r'[0-9A-Fa-f]{32,128}', row[parse_hash])
if is_hash:
hash_list.append(row[parse_hash])
md += '\n'
continue

if parse_domain != -1:
md += (row[parse_domain] + '|' if row[parse_domain] else ' |')
has_dot = '.' in row[parse_domain]
no_spaces = ' ' not in row[parse_domain]
if has_dot and no_spaces:
domain_list.append(row[parse_domain])

for c in range(max(len(ip_list), len(domain_list), len(hash_list))):
md += ip_list[c] + '|' if len(ip_list) >= c + 1 else ' |'
md += domain_list[c] + '|' if len(domain_list) >= c + 1 else ' |'
md += hash_list[c] + '|' if len(hash_list) >= c + 1 else ' |'
md += '\n'

context = {} # type: dict
Expand Down
3 changes: 2 additions & 1 deletion Packs/CommonScripts/Scripts/ParseCSV/ParseCSV_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def test_parsecsv_with_iocs_same_column(self, mocker):
"parseAll": "no",
"codec": "utf-8",
"ips": "1",
"domains": "1"
"domains": "1",
"hashes": "1"
}
file_obj = self.create_file_object("./test_data/IOCs.csv")
self.mock_demisto(mocker, args_value=args, file_obj=file_obj)
Expand Down
1 change: 1 addition & 0 deletions Packs/CommonScripts/Scripts/ParseCSV/test_data/IOCs.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Domain,www.example.com
Domain,www.example.org
IP,1.1.1.1
IP,8.8.8.8
Hash,c8092abd8d581750c0530fa1fc8d8318
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ContentsFormat": "text",
"HumanReadable": "### Parsed Data Table\nIPs |Domains |\n- |- |\nValue|Value|\nwww.example.com|www.example.com|\nwww.example.org|www.example.org|\n1.1.1.1|\n8.8.8.8|\n",
"HumanReadable": "### Parsed Data Table\nIPs |Domains |Hashes |\n- |- |- |\n1.1.1.1|www.example.com|c8092abd8d581750c0530fa1fc8d8318|\n8.8.8.8|www.example.org| |\n",
"EntryContext": {
"IP": [
{
Expand All @@ -17,8 +17,13 @@
{
"Name": "www.example.org"
}
],
"File": [
{
"MD5": "c8092abd8d581750c0530fa1fc8d8318"
}
]
},
"Type": 1,
"Contents": "\ufeffType,Value\nDomain,www.example.com\nDomain,www.example.org\nIP,1.1.1.1\nIP,8.8.8.8\n"
"Contents": "\ufeffType,Value\nDomain,www.example.com\nDomain,www.example.org\nIP,1.1.1.1\nIP,8.8.8.8\nHash,c8092abd8d581750c0530fa1fc8d8318\n"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"Type": 1,
"ContentsFormat": "text",
"Contents": "randomValues,hashes\nyarden,c8092abd8d581750c0530fa1fc8d8318\nsade,52483514f07eb14570142f6927b77deb7b4da99f\npythonist,503ca1a4fc0d48b18c0336f544ba0f0abf305ae3a3f49b3c2b86b8645d6572dc\n",
"HumanReadable": "### Parsed Data Table\nHashes |\n- |\nhashes|\nc8092abd8d581750c0530fa1fc8d8318|\n52483514f07eb14570142f6927b77deb7b4da99f|\n503ca1a4fc0d48b18c0336f544ba0f0abf305ae3a3f49b3c2b86b8645d6572dc|\n"
"HumanReadable": "### Parsed Data Table\nHashes |\n- |\n | |c8092abd8d581750c0530fa1fc8d8318|\n | |52483514f07eb14570142f6927b77deb7b4da99f|\n | |503ca1a4fc0d48b18c0336f544ba0f0abf305ae3a3f49b3c2b86b8645d6572dc|\n"
}
2 changes: 1 addition & 1 deletion Packs/CommonScripts/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Common Scripts",
"description": "Frequently used scripts pack.",
"support": "xsoar",
"currentVersion": "1.11.46",
"currentVersion": "1.11.47",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit 4775a2c

Please sign in to comment.