-
Notifications
You must be signed in to change notification settings - Fork 0
De widget #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
De widget #4
Changes from all commits
10983c1
7000efb
4affd1b
f54c3b6
4aa3791
3d50bd0
515e438
c7dca90
d38b5e9
b84049f
6f7ebc5
7528838
4af651b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
map_to_file_context, | ||
alert_get_command, | ||
alert_resolve_command, | ||
alert_search_command, | ||
departingemployee_add_command, | ||
departingemployee_remove_command, | ||
departingemployee_get_all_command, | ||
|
@@ -994,6 +995,12 @@ def test_alert_resolve_command(code42_alerts_mock): | |
assert res["id"] == "36fb8ca5-0533-4d25-9763-e09d35d60610" | ||
|
||
|
||
def test_alert_search_command(code42_alerts_mock): | ||
client = create_client(code42_alerts_mock) | ||
_, _, res = alert_search_command(client, {"username": "[email protected]"}) | ||
assert res == json.loads(MOCK_ALERTS_RESPONSE)["alerts"] | ||
|
||
|
||
def test_departingemployee_add_command(code42_sdk_mock): | ||
client = create_client(code42_sdk_mock) | ||
_, _, res = departingemployee_add_command( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
## [Unreleased] | ||
- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import demistomock as demisto | ||
from CommonServerPython import * | ||
|
||
|
||
def main(): | ||
res = {"total": 0} | ||
res_data = [] | ||
top = demisto.args().get("top") or 10 | ||
|
||
try: | ||
employees = demisto.executeCommand("code42-departingemployee-get-all", {})[0]["Contents"] | ||
res["total"] = len(employees) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are ignoring certain employees later, should we not set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depending on what the count represents, if it represents all employees irrespective of whether they have alerts or not then this is ok. |
||
|
||
# Get each employee on the Departing Employee List and their total alerts. | ||
for employee in employees: | ||
username = employee["userName"] | ||
alerts = demisto.executeCommand("code42-alert-search", {"username": username})[0]["Contents"] | ||
alerts_count = len(alerts) | ||
|
||
# Ignores employees without alerts | ||
if alerts_count: | ||
employee_res = {"Username": username, "Alerts Count": alerts_count} | ||
res_data.append(employee_res) | ||
|
||
# Sort such that highest alert counts are first and get top. | ||
res["data"] = sorted(res_data, key=lambda x: x["Alerts Count"], reverse=True)[:top] | ||
demisto.results(res) | ||
except Exception as e: | ||
res["total"] = -1 | ||
res["data"] = str(e) | ||
|
||
# Submit final results to Cortex XSOAR | ||
demisto.results(res) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need line 27, seems redundant, |
||
|
||
if __name__ in ("__main__", "__builtin__", "builtins"): | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
args: | ||
- defaultValue: 10 | ||
description: To limit results to x number of employees with the highest alert count. | ||
name: top | ||
type: number | ||
comment: Gets all departing employees and alerts for each. | ||
commonfields: | ||
id: 468c8e6f-6f50-486f-8cde-7dabe4cbeb2b | ||
version: -1 | ||
dependson: | ||
must: | ||
- Code42|||code42-departingemployee-get-all | ||
- Code42|||code42-alerts-search | ||
dockerimage: demisto/py42:1.0.0.9242 | ||
enabled: true | ||
name: Code42GetDepartingEmployeeAlerts | ||
pswd: "" | ||
runas: DBotWeakRole | ||
runonce: false | ||
script: '' | ||
scripttarget: 0 | ||
subtype: python3 | ||
tags: ['dynamic-section', 'widget'] | ||
type: python |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"category": "", | ||
"dataType": "scripts", | ||
"dateRange": { | ||
"fromDate": "0001-01-01T00:00:00Z", | ||
"fromDateLicense": "0001-01-01T00:00:00Z", | ||
"period": { | ||
"by": "", | ||
"byFrom": "days", | ||
"byTo": "", | ||
"field": "", | ||
"fromValue": null, | ||
"toValue": null | ||
}, | ||
"toDate": "0001-01-01T00:00:00Z" | ||
}, | ||
"id": "570ec235-7ee4-43ea-8fc7-eba94a0cca71", | ||
"isPredefined": false, | ||
"name": "Departing Employee Alerts", | ||
"params": { | ||
"tableColumns": [ | ||
{ | ||
"displayed": true, | ||
"isDefault": true, | ||
"key": "Username" | ||
}, | ||
{ | ||
"displayed": true, | ||
"isDefault": true, | ||
"key": "Alerts Count" | ||
} | ||
] | ||
}, | ||
"query": "Code42GetDepartingEmployeeAlerts", | ||
"size": 0, | ||
"sort": null, | ||
"sortValues": null, | ||
"version": -1, | ||
"widgetType": "table" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
room for list comprehension....
alert_context = [map_to_code42_alert_context(alert) for alert in alerts]