IncidentsCheck-Widget-CommandsNames

Data output script for populating the dashboard pie graph widget with the top failing incident commands.

python · Integrations & Incidents Health Check

Details

IDIncidentsCheck-Widget-CommandsNames
Languagepython
From Version6.0.0
Docker Imagedemisto/python3:3.12.13.10116658
Tagswidget failedIncidents

README

Data output script for populating the dashboard pie graph widget with the top failing incident commands.

Script Data


Name Description
Script Type python3
Tags widget, failedIncidents
Cortex XSOAR Version 6.0.0

Inputs


There are no inputs for this script.

Outputs


There are no outputs for this script.

import demistomock as demisto  # noqa: F401
from CommonServerPython import *  # noqa: F401
import collections
import random
from collections import Counter


def parse_data(list_content):
    lists_data = []

    list_collections: Counter = collections.Counter(list_content)
    top_lists = list_collections.most_common(10)
    lists_number = len(top_lists)
    list_number = 0

    while list_number < lists_number:
        for list_element in top_lists:
            random_number = random.randint(0, 16777215)
            hex_number = str(hex(random_number))  # convert to hexadecimal
            color = f"#{hex_number[2:].zfill(6)}"  # remove 0x and prepend '#'

            list_widget_data = {"data": [list_element[1]], "name": str(list_element[0]), "color": color}

            lists_data.append(list_widget_data)
            list_number += 1

    return lists_data


def main():
    list_data = demisto.executeCommand("getList", {"listName": "XSOAR Health - Failed Incident Commands"})
    list_content = list_data[0].get("Contents", "").split(",")

    if list_content != [""]:
        data = parse_data(list_content)
    else:
        data = [{"data": [0], "name": "N/A", "color": "#00CD33"}]

    demisto.results(json.dumps(data))


if __name__ in ["__main__", "builtin", "builtins"]:
    main()