KSC Open API
Kaspersky Security Center API description
ReportManager::CreateChartPNG ( params  pChartData,
params  pOptions,
[out] binary  pPngData 
)

Creates an image in the PNG format with the chart data.

Parameters:
pChartData(params) chart data received from the ReportManager.ExecuteReportAsyncGetData method.
pOptions(params) additional options, which are optional. See the description below.
[out]pPngData(binary) image with the chart data. See Chart parameters structure.


Format of the pOptions parameter (if it is not empty):

            +--- (params)
                +---RPT_CHART_WIDTH = (paramInt) chart width, in pixels. Optional if RPT_CHART_HEIGHT is set.
                +---RPT_CHART_HEIGHT = (paramInt) chart height, in pixels. Optional if RPT_CHART_WIDTH is set.
            
            server = KlAkOAPI.AdmServer.KlAkAdmServer.Create("https://ksc.example.com:13299", "username", "password")
            oReportManager = KlAkOAPI.ReportManager.KlAkReportManager(server)
            strResultFolderName = "Result"
            # get the root group ID
            nGroupId = KlAkOAPI.HostGroup.KlAkHostGroup(server).GroupIdGroups().RetVal()
            # compose parameters with information about dashboards that we want to generate
            # dashboard type 20: current state of the most anti-virus protection (number of hosts with the Critical, Warning, or OK status). 
            hostsUUID = str(uuid.uuid4())
            parDashboards = KlAkOAPI.Params.KlAkParams({hostsUUID: {'KLRPT_DSH_TYPE': 20, 'id': nGroupId}})
            # compose one request for three dashboards
            parRequestParams = KlAkOAPI.Params.KlAkParams({'KLPPT_DASHBOARD': parDashboards})
            # gathering statistics requires time, one dashboard can be done earlier than others, so check progress by a timer
            while True:
                # request statistics for dashboards that are not ready yet by this time
                strRequestId = oReportManager.RequestStatisticsData(parRequestParams).OutPar('strRequestId')
                # wait while the statistics is collected and prepared
                time.sleep(5)
                # get a result
                pResultData = oReportManager.GetStatisticsData(strRequestId).OutPar('pResultData')
                if pResultData == None:
                    continue
                if 'KLPPT_DASHBOARD' in pResultData:            
                    # the statistics is ready, now make charts with received data
                    pDashboards = pResultData['KLPPT_DASHBOARD']
                    # create a folder for the result
                    if not os.path.exists(strResultFolderName):
                        os.makedirs(strResultFolderName)
                    if hostsUUID in pDashboards:
                        # compose parameters with the statistics data for a chart
                        hostsDash = pDashboards[hostsUUID]    
                        parChartData = KlAkOAPI.Params.KlAkParams({'data': [hostsDash.GetValue('nOkCount'), hostsDash.GetValue('nWrnCount'), hostsDash.GetValue('nCrtCount')], 'name': hostsUUID})
                        parChartInfo = KlAkOAPI.Params.KlAkParams({})
                        parChartInfo.AddArray('KLRPT_CHART_DATA', [parChartData])
                        parChartInfo.AddString('KLRPT_CHART_DATA_DESC', 'Current state of the most anti-virus protection ')
                        parChartInfo.AddString('KLRPT_CHART_LGND_DESC', 'number of hosts with:')
                        parChartInfo.AddArray('KLRPT_CHART_SERIES', ['Ok protection status', 'Warning protection status', 'Critical protection status'])
                        parChartInfo.AddBool('KLRPT_CHART_PIE', True)
                        # create a chart and download a result file
                        res = oReportManager.CreateChartPNG(parChartInfo, {'RPT_CHART_WIDTH': 600, 'RPT_CHART_HEIGHT': 600})
                        strChartFilename = os.path.join(strResultFolderName, 'hosts_dash.png')
                        with open(strChartFilename, 'wb') as f:
                            packet = base64.b64decode(res.OutPar('pPngData'))
                            f.write(packet)
                        print('Anti-virus protection on hosts chart is ready:', strChartFilename)
                        break