### HostList Parameter Structure Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00030.html Example structure for the HostList parameter, showing how to identify hosts by name or display name and set preliminary start flags. ```text +---0 (paramParams) +---HostName = (paramString)"295ce3ac-f4b7-47e9-a7a5-b6aa7cb74e66" +---1 (paramParams) +---HostName = (paramString)"638168dc-735d-40af-88a5-b2f28eea6e99" +---2 (paramParams) +---HostDispName = (paramString)"Host3" +---Preliminary = (paramBool)true +---3 (paramParams) +---HostDispName = (paramString)"Host4" +---Preliminary = (paramBool)false ``` -------------------------------- ### Chart Parameter Configuration Example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00447.html An example demonstrating the structure of chart data, series definitions, and visual configuration parameters. ```text +--- (paramParams) +---KLRPT_CHART_DATA (paramArray) | +---0 (paramParams) | | +---data (paramArray) | | | +---0 = (paramInt)0 | | | +---1 = (paramInt)4 | | | +---2 = (paramInt)0 | | +---name = (paramString)"631B52B3A5263BCC29026B87EFEFC78C" | +---1 (paramParams) | | +---data (paramArray) | | | +---0 = (paramInt)1 | | | +---1 = (paramInt)3 | | | +---2 = (paramInt)0 | | +---name = (paramString)"8092899C5F60B2580BE1EEBDD7F48742" | +---2 (paramParams) | +---data (paramArray) | | +---0 = (paramInt)1 | | +---1 = (paramInt)1999 | | +---2 = (paramInt)0 | +---name = (paramString)"A123-E56789-027F1F3F" +---KLRPT_CHART_DATA_DESC = (paramString)"Number of licensing units:" +---KLRPT_CHART_LGND_DESC = (paramString)"Key usage:" +---KLRPT_CHART_SERIES (paramArray) | +---0 = (paramString)"In use" | +---1 = (paramString)"Vacant" | +---2 = (paramString)"Exceeded" +---KLRPT_CHART_SERIES_COLORS (paramArray) | +---0 = (paramInt)9557089 | +---1 = (paramInt)13620370 | +---2 = (paramInt)8947967 +---KLRPT_CHART_STACK_SERIES = (paramBool)true +---KLRPT_HORIZONTAL_COLUMNS = (paramBool)true ``` -------------------------------- ### KLHST_APP_INFO structure example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00473.html This example illustrates the hierarchical structure of the KLHST_APP_INFO container, showing product IDs, versions, and their associated state and timestamp variables. ```text +--- (PARAMS_T) +---KLHST_APP_INFO (PARAMS_T) +---1093 (PARAMS_T) | +---1.0.0.0 (PARAMS_T) | +---KLHST_APP_STATE = (INT_T)3 | +---KLHST_APP_STATE_TIME = (DATE_TIME_T)25-01-2018 09:10:27 +---1103 (PARAMS_T) | +---1.0.0.0 (PARAMS_T) | +---KLHST_APP_STATE = (INT_T)3 | +---KLHST_APP_STATE_TIME = (DATE_TIME_T)25-01-2018 09:10:27 +---ConnProd (PARAMS_T) +---1.0.0.0 (PARAMS_T) +---KLHST_APP_STATE = (INT_T)3 +---KLHST_APP_STATE_TIME = (DATE_TIME_T)25-01-2018 09:10:27 ``` -------------------------------- ### File download request example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html An example of an HTTP GET request to download a file, specifying the range and encoding. ```http GET /PRFX/Some/test/file HTTP/1.1 Accept-Encoding: identity Range: bytes=0-99 ``` -------------------------------- ### Install License to All Child Servers (Python KlAkOAPI) Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00432.html This sample shows how to install a specified license from the main server's license storage to all child servers. It connects to the main server, loads the license key data, enumerates child servers, and installs the key on each. The script accepts optional -address, -cert, and -serial arguments. ```python # #!/usr/bin/python -tt # -*- coding: utf-8 -*- """This module presents samples of usage KlAkOAPI package to enumerate child servers""" import time import socket import argparse from sys import platform from KlAkOAPI.AdmServer import KlAkAdmServer from KlAkOAPI.ServerHierarchy import KlAkServerHierarchy from KlAkOAPI.LicenseKeys import KlAkLicenseKeys from KlAkOAPI.Params import KlAkParams, KlAkArray, paramParams, strToBin from KlAkOAPI.CgwHelper import KlAkCgwHelper from KlAkOAPI.GatewayConnection import KlAkGatewayConnection def ConnectMainServer(server_url, cert): """Connects to main KSC server""" username = None # for Windows use NTLM by default password = None server = KlAkAdmServer.Create(server_url, username, password, verify = cert) return server def ConnectToSlave(server_main, server_main_url, slave_id): cgwHelper = KlAkCgwHelper(server_main) slaveLocation = cgwHelper.GetSlaveServerLocation(slave_id).RetVal() arrLocation = [] arrLocation.append(paramParams(slaveLocation)) gatewayConnection = KlAkGatewayConnection(server_main) response = gatewayConnection.PrepareGatewayConnection(arrLocation) token_on_slave = response.OutPar('wstrAuthKey') slaveServer = KlAkAdmServer.CreateGateway(server_main_url, token_on_slave, False) if slaveServer.connected: print ('Slave connected successfully!') return slaveServer print ('Slave connection failed') return None def InstallKey(slaveServer, keyInfo): licenseKeys = KlAkLicenseKeys(slaveServer) lic_serial = licenseKeys.InstallKey(KlAkParams(keyInfo)).RetVal() licenseKeys.SaasTryToInstall(KlAkParams({"KLLIC_SERIAL": lic_serial}), True) def LoadKeyBody(server_main, lic_serial): licenseKeys = KlAkLicenseKeys(server_main) return licenseKeys.GetKeyData(KlAkParams({"KLLIC_SERIAL": lic_serial, "KLLICSRV_KEYDATA": True})).RetVal() def AddArgs(parser): group_address = parser.add_argument_group() group_address.add_argument('-address', action='store', help='(optional) address and port of main server, for example "server.avp.ru:13299". If no -address option is used, suppose to use current machine') group_address.add_argument('-cert', action='store', help='Path to certificate file of main server') group_address.add_argument('-serial', action='store', help='License serial number') return def main(): """ This sample shows how you can install specified license from main server's licenses storage to all child servers """ parser = argparse.ArgumentParser(description='This sample shows how you can set license to all child servers') group_auth_type = parser.add_mutually_exclusive_group(required=False) AddArgs(parser) args = parser.parse_args() server_address = args.address if server_address == None: server_address = socket.getfqdn() + ':13299' server_url = 'https://' + server_address server = ConnectMainServer(server_url, args.cert) keyInfo = LoadKeyBody(server, args.serial) oServerHierarchy = KlAkServerHierarchy(server) oChildServers = oServerHierarchy.GetChildServers(-1).RetVal() if oChildServers == None or len(oChildServers) == 0: print('No slave servers found') else: for oObj in oChildServers: print('Server''s "' + oObj['KLSRVH_SRV_DN'] + '", id=' + str(oObj['KLSRVH_SRV_ID'])) InstallKey(ConnectToSlave(server, server_url, oObj['KLSRVH_SRV_ID']), keyInfo) if __name__ == '__main__': main() ``` -------------------------------- ### Session Start Response Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html Example of a successful authentication response containing the session ID. ```json {"PxgRetVal":"n4QFPNjYK2oXRMYkis5CMcg=="} ``` -------------------------------- ### Session.StartSession Request and Response Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html Example of an authenticated session start request and the corresponding server response. ```http POST /api/v1.0/Session.StartSession HTTP/1.1 Accept-Encoding: gzip, deflate Authorization: KSCBasic user="0LvQvtCz0LjQvQ==", pass="0L/QsNGA0L7Qu9GM", internal="0" Content-Type: application/json Content-Length: 2 {} HTTP/1.1 200 OK Transfer-Encoding: chunked Content-Length: 41 ``` -------------------------------- ### paramLong Example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html Example of a 64-bit integer represented as an object. ```json {"type": "long", "value": 13} ``` -------------------------------- ### Install License Key with Error Handling Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00535_a42d0b5d83d540627d8cfe770f514c2d5.html Attempts to install a license key, with a fallback to download key files if specific server or license errors occur. ```python try: wstrSerial = oLicenseKeys.InstallKey(KlAkOAPI.Params.KlAkParams({"KLLICSRV_KEYDATA": {"KLLIC_LICFILE": wstrActivationCode.encode('ascii'), "KLLIC_IFKEYFILE": False} })).RetVal() except KlAkOAPI.Error.KlAkError as err: if err.code == 2351 and (err.subcode == 3 or err.subcode == 34): # code KLOLA::KLOLA_ERR_SERVER (2351), subcode KLOLAEL_ERR_SERVER_1_REQUIRED (3) or KLOLAEL_ERR_LICENSE_NOT_FOUND (34) arrKeys = oLicenseKeys.DownloadKeyFiles(wstrActivationCode).RetVal() for arrKey in arrKeys: oLicenseKeys.InstallKey(KlAkOAPI.Params.KlAkParams({"KLLICSRV_KEYDATA": {"KLLIC_LICFILE": arrKey, "KLLIC_IFKEYFILE": False} })) else: raise ``` -------------------------------- ### KLHST_WKS_HSDP_REASON examples Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00011.html Two example values for the KLHST_WKS_HSDP_REASON attribute. ```text "1103/1.0.0.0/DBD500D3F6F04541910AD14C5CA47AE0" ``` ```text "1093/1.0.0.0/D2152D6328CE4328BCB3192632670E58" ``` -------------------------------- ### TryToInstallLicForSaas2 Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00534.html Install the Administration Server license key. ```APIDOC ## TryToInstallLicForSaas2 ### Description Install the Administration Server license key. ### Method TryToInstallLicForSaas2 ### Parameters #### Parameters - **pKeyInfo** (params) - Required - Description not provided. - **bAsCurrent** (boolean) - Required - Description not provided. ### Response None ``` -------------------------------- ### HostGroup::GetHostProducts Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00517_a3462eed9c19e7c832333a09301a044aa.html Returns information about installed products on a host, including product names, versions, and installation details. ```APIDOC ## HostGroup::GetHostProducts ### Description Returns information about installed products on the host. ### Method N/A (SDK method) ### Endpoint HostGroup::GetHostProducts ### Parameters #### Path Parameters - **strHostName** (wstring) - Required - host name (GUID-like ID). ### Response #### Success Response Returns a `params` container with names and versions of the products. The format is: - `` (paramParams) - `` (paramParams) - InstallTime - InstallationId - DisplayName - BaseRecords - ConnDisplayName - ConnProdVersion - ConnectorComponentName ### See Also - Product informative attributes - Local settings and policy format for some products ``` -------------------------------- ### Create administration group with KlAkOAPI Python package Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00517_a7f52d6b70986751de7453a1daa7308e0.html Connects to a Kaspersky Security Center server, retrieves the root group ID, and creates a new group named 'Test group' under it. The server connection uses verify=False for SSL certificate verification. The example assumes the KlAkOAPI package is installed and the server is accessible at the specified URL. ```python server = KlAkOAPI.AdmServer.KlAkAdmServer.Create("https://ksc.example.com:13299", "username", "password", verify = False) oHostGroup = KlAkOAPI.HostGroup.KlAkHostGroup(server) nRootGroupId = oHostGroup.GroupIdGroups().RetVal() nNewGroupId = oHostGroup.AddGroup({'name': 'Test group', 'parentId': nRootGroupId}).RetVal() ``` -------------------------------- ### KLVSRV_PRODUCTS structure example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00021.html Shows the container hierarchy for KLVSRV_PRODUCTS: product name, version, and three attributes (KLVSRV_PROD_DN, KLVSRV_PROD_DV, KLVSRV_PROD_CNT). The example uses placeholder values in angle brackets. ```text +--- (paramParams) +--- (paramParams) +--- KLVSRV_PROD_DN = (paramString)<"display name one of the builds"> +--- KLVSRV_PROD_DV =(paramString)<"display version one of the builds"> +--- KLVSRV_PROD_CNT =(paramInt) ``` -------------------------------- ### LicenseKeys::SaasTryToInstall Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00535_af67ac6ced311efd847c6f0f078853b87.html Installs an adm. server's license. Takes input data container and a boolean flag indicating whether to install as current or reserved license. ```APIDOC ## LicenseKeys::SaasTryToInstall ### Description Installs an adm. server's license. ### Method SaasTryToInstall ### Parameters - **pInData** (params) - Required - Input data container. Attributes allowed: "KLLIC_SERIAL" (paramString) - serial number of the license being checked, mandatory. The license must be placed in the license store before installing (see InstallKey). - **bAsCurrent** (boolean) - Required - true if license should be installed in place of active one, false to install it as a reserved one. ### Exceptions Throws exception in case of error. ### See Also - SaasTryToUninstall ``` -------------------------------- ### paramDate Example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html Example of a date object. ```json {"type": "date", "value": "2016-09-19"} ``` -------------------------------- ### paramParams Example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html Example of a universal container object. ```json {"type": "params", "value": {"var1": 23, "var2": "str12", "var3": {"type": "date", "value": "2016-09-19"}}} ``` -------------------------------- ### SaasTryToInstall Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00535.html Installs an administration server's license. ```APIDOC ## SaasTryToInstall ### Description Installs an administration server's license. ### Method SaasTryToInstall ### Parameters #### Input Parameters - **pInData** (params) - Required - Input data. - **bAsCurrent** (boolean) - Required - Whether to install as current. ### Response No explicit response schema provided. ``` -------------------------------- ### Start Host Task and Wait for Completion (Python) Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00434.html This snippet shows the main function of a sample script that starts a host task and waits for its completion. It parses command-line arguments, connects to the KSC server, finds the host and task, and then starts and waits for the task. The script uses the KSC API and requires the host address and task name as arguments. ```python def main(): """ Starts host task and waits its completion. Samples of usage: >> python.exe sample_run_host_task.py -task "Task to execute" """ #argument parsing parser = argparse.ArgumentParser(description='This module provides samples of execution of host\'s task') group_auth_type = parser.add_mutually_exclusive_group(required=False) AddArgs(parser) args = parser.parse_args() server_address = socket.getfqdn() server_port = 13299 server_url = 'https://' + server_address + ':' + str(server_port) #KSC connection server = GetServer(server_url) hostaddress = args.hostaddress if hostaddress is None: hostaddress = socket.getfqdn() hostId = GetHostNameByHostFQDN(server, hostaddress) pTaskData = FindHostTask(server, hostId, args.task) taskTsId = pTaskData['TASK_UNIQUE_ID'] strProductName = pTaskData['TASKID_PRODUCT_NAME'] strProductVersion = pTaskData['TASKID_VERSION'] nagent = CreteGatewayToHost(server, server_url, hostId) nagHstCtl = KlAkNagHstCtl(nagent) StartHostTask(nagHstCtl, taskTsId, strProductName, strProductVersion) WaitTaskCompletion(nagHstCtl, taskTsId, strProductName, strProductVersion) if __name__ == '__main__': main() ``` -------------------------------- ### paramFloat Example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html Example of a real number object. ```json {"type": "float", "value": 1.23} ``` -------------------------------- ### Install KlAkOAPI package with pip Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00444.html Installs the KlAkOAPI package from the tar.gz archive. Pip automatically downloads and installs dependencies from PyPI (default https://pypi.org/). ```bash >pip install KlAkOAPI-1.0.0.0.tar.gz ``` -------------------------------- ### paramDateTime Example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html Example of a UTC datetime object. ```json {"type": "datetime", "value": "2016-09-19T15:22:35Z"} ``` -------------------------------- ### Certificate Parameters Example Structure Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00390.html Shows the structure of certificate parameters with sample values for CertExtensions, CertIssuer, CertPublicKey, CertSerial, CertSigAlgo, CertSignature, CertSubject, CertSubjectAltNames, CertValidFrom, CertValidTo, and CertVersion. The example illustrates the format of these parameters as described in the table above. ```text +--- (paramParams) +---CertExtensions = (paramString)": X509v3 Basic Constraints: critical CA:TRUE X509v3 Key Usage: Digital Signature, Key Encipherment, Certificate Sign, CRL Sign X509v3 Subject Alternative Name: DNS:server1.example.com, DNS:mail.example.com, DNS:www.example.com" +---CertIssuer = (\ref kloapi_type_paramString)"commonName = MyCommonName emailAddress = MyEmail@mail.com" +---CertPublicKey = (\ref kloapi_type_paramString)"Public-Key: (1024 bit) Modulus: 00:d9:43:99:65:2d:28:67:4a:e3:97:2f:15:1b:ac: 48:57:07:59:f5:b8:81:e9:6b:74:91:43:a8:0b:90: b7:8f:e4:83:04:02:a2:df:33:dc:f2:ad:75:21:a8: 71:dc:0f:b5:5e:72:78:0b:90:5f:b1:1b:f6:0c:61: eb:76:7f:e0:cc:ba:61:cf:eb:ee:35:41:24:68:17: 49:b4:ea:ff:0a:d6:11:65:20:e8:60:d9:22:65:c1: 1f:af:a0:80:b3:3c:a6:64:3a:24:94:1a:5e:ec:b0: de:11:45:08:ab:be:a9:b4:90:2a:94:50:6e:ca:7d: 3d:fd:d7:00:12:6c:ef:29:3f Exponent: 65537 (0x10001)" +---CertSerial = (\ref kloapi_type_paramString)"089E083D1A39DD08F1FF892C4F0D32CC" +---CertSigAlgo = (\ref kloapi_type_paramString)"sha1WithRSAEncryption" +---CertSignature = (\ref kloapi_type_paramString)"Signature Algorithm: sha1WithRSAEncryption b4:81:57:66:4a:84:01:6f:ae:15:2d:3e:f8:a1:d1:b6:ad:e1: 13:e2:3a:cd:7e:9c:48:d1:df:3e:c5:73:8a:2a:14:86:f1:e4: 9e:f6:83:f9:45:fe:39:9b:0e:7b:db:bc:53:59:ef:ae:03:b2: 48:c6:84:1e:de:83:39:78:43:a1:32:57:32:05:9a:dd:2d:0b: 5d:6e:ef:ce:86:06:c3:53:12:d3:27:fc:ee:14:2f:55:89:bc: e1:ac:c0:21:de:0f:c5:78:73:91:bb:37:9b:4b:2d:57:e9:27: 37:af:d8:e6:97:bb:20:ec:cd:05:b6:fe:43:ba:a1:49:a8:09: ad:ae" +---CertSubject = (\ref kloapi_type_paramString)"commonName = MyCommonName emailAddress = MyEmail@mail.com" +---CertSubjectAltNames = (\ref kloapi_type_paramString)"DNS:server1.example.com DNS:mail.example.com DNS:www.example.com" +---CertValidFrom = (\ref kloapi_type_paramString)"May 19 19:49:35 2017 GMT" +---CertValidTo = (\ref kloapi_type_paramString)"Sep 16 19:49:35 2017 GMT" +---CertVersion = (paramInt)3 ``` -------------------------------- ### ImportHWInvStorage2 Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00523.html Starts the import of hardware inventory data. ```APIDOC ## ImportHWInvStorage2 ### Description Start import of hardware inventory. ### Parameters #### Path Parameters - **eImportType** (int) - Required - The import type. ### Returns - **wstring** - The asynchronous operation ID. ``` -------------------------------- ### Search filter example for product tag Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00011.html Example search filter using KLHST_WKS_PRODUCT_TAG_NAME to find hosts with a specific tag. ```text (KLHST_WKS_PRODUCT_TAG_NAME="KATA:*") ``` -------------------------------- ### GetHostProducts Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00517.html Returns information about installed products on the host. ```APIDOC ## GetHostProducts ### Description Returns information about installed products on the host. ### Method GetHostProducts ### Parameters - **strHostName** (wstring) - Required - Host name. ### Returns - **params** - Product information. ``` -------------------------------- ### paramArray Example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html Example of an ordered collection of different types. ```json [{"type": "date", "value": "2016-09-19"}, {"type": "datetime", "value": "2016-09-19T15:22:35Z"}] ``` -------------------------------- ### Policy Profile Data Format Example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00102.html Shows the structure of policy profile data as returned in the policy format. The example illustrates the attributes EXPRESSION, KLSSPOL_PRF_ENABLED, and KLSSPOL_PRF_PROTECTED with their corresponding value fields. ```text +---"KLSSPOL_PRF_PROTECTED" | +---"KLPRSS_Val"= bProtected | +---"KLPRSS_Mnd" | +---"KLPRSS_ValLck" | +---"KLPRSS_ValLckPolicy" | +---"KLPRSS_ValLckGroup" +---"EXPRESSION" | +---"KLPRSS_Val"=value1 the only entry contains parameters with logical expression [0]= Logical Expression | +---"KLPRSS_Mnd" | +---"KLPRSS_ValLck" | +---"KLPRSS_ValLckPolicy" | +---"KLPRSS_ValLckGroup" +---"KLSSPOL_PRF_ENABLED" +---"KLPRSS_Val"=bEnabled +---"KLPRSS_Mnd" +---"KLPRSS_ValLck" +---"KLPRSS_ValLckPolicy" +---"KLPRSS_ValLckGroup" ``` -------------------------------- ### paramDouble Example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html Example of a double precision real number object. ```json {"type": "double", "value": 1.23} ``` -------------------------------- ### GeneratePackageAsync2 Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00539.html Asynchronously publishes installation packages for users. ```APIDOC ## GeneratePackageAsync2 ### Description Publishes installation packages for users asynchronously. ### Method Async operation ### Parameters - **pPackageInfo** (params) - Required - Package information. - **pCertificate** (params) - Required - Certificate data. - **pRecipients** (params) - Required - Recipient list. - **pNotification** (params) - Required - Notification settings. - **wstrRequestId** ([out] wstring) - Required - Output request identifier. ### Response Returns a request ID via the output parameter. ``` -------------------------------- ### GetHostRuntimeInfo filter example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00547_a6fb116573d7301f84a16c33203c86056.html Example filter for the GetHostRuntimeInfo method. It requests information about running tasks (klhst-rt-TskInfo), running PRCI component instances (klhst-rt-InstInfo), and KL products (KLHST_APP_INFO). The klhst-rt-PrdNamesArray contains the product identifier "1103". ```text +--- (PARAMS_T) +---klhst-rt-TskInfo (PARAMS_T) | +---klhst-ProductVersion = (STRING_T)"" | +---taskState = (INT_T)0 | +---taskStorageId = (STRING_T)"" +---klhst-rt-InstInfo (PARAMS_T) | +---instStatistics (PARAMS_T) | +---klhst-ComponentName = (STRING_T)"" | +---klhst-InstanceId = (STRING_T)"" | +---klhst-rt-PrdNamesArray (ARRAY_T) | +---0 = (STRING_T)"1103" +---KLHST_APP_INFO (PARAMS_T) ``` -------------------------------- ### paramBinary Example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html Example of a binary data object with base64 encoded value. ```json {"type": "binary", "value": "c29tZXRleHQ="} ``` -------------------------------- ### paramString Example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html Example of a string value with escaped double quotes. ```json "Some text with \"double quotes\" must be like this" ``` -------------------------------- ### Boolean search examples: OR, AND, and exclusion Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00002.html Boolean search examples for host descriptions. OR (||) finds hosts with either term, AND (&&) requires both terms in the same attribute, and minus (-) excludes terms. The first example finds hosts with 'samba' or 'suse', the second requires both, and the third requires 'myhost' while excluding 'samba' and 'suse'. ```text samba suse samba OR suse samba || suse ``` ```text +samba +suse samba && suse samba AND suse ``` ```text myhost -samba -suse ``` -------------------------------- ### PluginDataStorage::ReplaceValues pValues example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00558_ad204785d3ce007d21426c7daa292aeab.html Example of the pValues parameter structure for PluginDataStorage::ReplaceValues. Each element name is a key and its value is associated with that key. ```text pValues (PARAMS_T) +---Key_0 = (INT_T)0 +---Key_10 = (INT_T)10 +---Key_11 = (INT_T)11 +---Key_12 = (INT_T)12 +---Key_14 = (INT_T)14 +---Key_2 = (INT_T)2 +---Key_4 = (INT_T)4 +---Key_6 = (INT_T)6 +---Key_8 = (INT_T)8 ``` -------------------------------- ### JSON error response example with PxgError Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html Example JSON object containing an error description in the PxgError field, with code, module, file, line, and message fields. This is shown as an example of an error response. ```json { "PxgError": { "code": 1681, "module": "KLFT", "file": "kca/ft/filetransferimp.cpp", "line": 1234, "message": "File not found. File name - 'JobId-5771bdab-dfdd-4e6a-ad52-536ef095813f'." } } ``` -------------------------------- ### main: Sample entry point to enumerate licenses Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00440.html Connects to the KSC server using KlAkAdmServer.Create, checks for an active license on the main server, and then enumerates licenses on all virtual servers. ```python def main(): """ This sample shows how you can see licenses in use """ print (main.__doc__) #connect to KSC server using basic auth by default server = KlAkAdmServer.Create(server_url, username, password, verify = SSLVerifyCert) print('Main server licenses:') if not FindActiveLicense(server): print('FAILURE! There''s no active license on server') EnumVServersAndTheirLicenses(server) if __name__ == '__main__': main() ``` -------------------------------- ### GetTaskStartEvent Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00521.html Get task start event. ```APIDOC ## GetTaskStartEvent ### Description Get task start event. ### Method GetTaskStartEvent ### Parameters - **strSrvObjId** (wstring) - Required - Server object ID. - **strTask** (wstring) - Required - Task identifier. ### Response Returns task start event as params. ``` -------------------------------- ### Create Python virtual environment for KlAkOAPI Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00444.html Optional step to create and activate a Python virtual environment before installing the KlAkOAPI package. This isolates the installation to the 'klakoapi-env' folder. ```bash >python3 -m venv klakoapi-env >klakoapi-env\Scripts\activate.bat ``` -------------------------------- ### Search filter example for included product tag Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00011.html Example search query combining KLHST_WKS_PRODUCT_TAG_NAME and KLHST_INCLUDED_WKS_PRODUCT_TAG_NAME to filter hosts by tag inclusion. ```text (&(KLHST_WKS_PRODUCT_TAG_NAME="KATA:*")(KLHST_INCLUDED_WKS_PRODUCT_TAG_NAME<>"KATA:myserver")) ``` -------------------------------- ### HTTP Request Headers Example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html An example of the required HTTP headers for a KSC API request, including the method path, content type, and encoding preferences. ```http POST /api/v1.0/TestInterface.ScMethod1 HTTP/1.1 Content-Type: application/json Content-Length: 56 Accept-Encoding: gzip, deflate ``` -------------------------------- ### Python example: Get items count from accessor Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00517_a5b76f3c6aa7737a9bb502a12c6186820.html Creates a KlAkChunkAccessor and retrieves the number of records in the result set, printing the count. ```python oChunkAccessor = KlAkOAPI.ChunkAccessor.KlAkChunkAccessor(server) lRecords = oChunkAccessor.GetItemsCount(strAccessor).RetVal() print("Found", lRecords, "host incidents") ``` -------------------------------- ### Distribution Point Information Structure Example Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00184.html An example showing the hierarchical structure of distribution point information, represented as a paramArray containing paramParams objects for each host. ```text +---pUaInfo (paramArray) +---0 (paramParams) | +---UaHostDisplayName = (paramString)"ubuntu-x64-dev_13~~72" | +---UaHostId = (paramString)"730433d4-930a-48c1-b4b1-f3d7650f5635" | +---UaIsCg = (paramBool)true +---1 (paramParams) +---UaHostDisplayName = (paramString)"TESTHOST-UACTL-2A74CE4E-7155-4FF8-87D0-E7A0F75EAAA8" | +---UaHostId = (paramString)"5c6a4c53-8d8f-44e4-ac16-1a3121e44b05" | +---UaIsCg = (paramBool)false ``` -------------------------------- ### Run KlAkOAPI sample script Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00444.html Executes a sample script after installation. The samples are ready to run, and any modules written with KlAkOAPI can be used similarly. ```bash >.\.\samples\sample_connect.py ``` -------------------------------- ### PatchParameters::GetValues Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00555_a260efb5157a2011d02250d1dde47a5e1.html Gets the install command for a patch by providing the patch ID and locale ID. Returns an array of command line parameter values. ```APIDOC ## PatchParameters::GetValues ### Description Retrieves the install command for a specified patch. The method takes a patch ID and a locale ID and returns an array of command line parameter values. ### Method Not specified (SDK/RPC method) ### Parameters - **patchID** (long) - Required - Identification of patch in VAPM. - **locID** (int) - Required - Identification of localization of patch in VAPM. ### Returns - **parsValues** (params) - Array of command line parameter values. See PatchParameters::SetValues for parameter values description. ### See Also - PatchParameters::SetValues ``` -------------------------------- ### Multitenancy Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00544.html This section provides documentation for the Multitenancy class, which manages multitenancy products. It includes methods to retrieve products, get tenant ID, get authentication token, and check authentication token. ```APIDOC ## GetProducts ### Description Retrieves multitenancy products available for current tenant. ### Method Not specified ### Endpoint Not specified ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **strProdName** (wstring) - Required - Product name - **strProdVersion** (wstring) - Required - Product version ### Request Example Not specified ### Response #### Success Response (200) - **array** - Description not specified #### Response Example Not specified ## GetTenantId ### Description Retrieves tenant identity. ### Method Not specified ### Endpoint Not specified ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example Not specified ### Response #### Success Response (200) - **wstring** - Description not specified #### Response Example Not specified ## GetAuthToken ### Description Not specified ### Method Not specified ### Endpoint Not specified ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example Not specified ### Response #### Success Response (200) - **binary** - Description not specified #### Response Example Not specified ## CheckAuthToken ### Description Not specified ### Method Not specified ### Endpoint Not specified ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **wstrTenantId** (wstring) - Required - Tenant identifier - **binToken** (binary) - Required - Authentication token ### Request Example Not specified ### Response #### Success Response (200) - **boolean** - Description not specified #### Response Example Not specified ``` -------------------------------- ### JSON response examples with PxgRetVal and output variables Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/index.html Three JSON object examples showing possible successful responses: one with a numeric PxgRetVal and output variables, one with a string PxgRetVal, and one empty object when no result or output variables are present. ```json { "PxgRetVal": 15, "OutVar1": "value1", "OutVar2": "value2" } ``` ```json { "PxgRetVal": "abc" } ``` ```json { } ``` -------------------------------- ### Python example: Main function to run FindHostIncidents Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00517_a5b76f3c6aa7737a9bb502a12c6186820.html Creates a KlAkAdmServer connection and calls FindHostIncidents with a filter for handled incidents. ```python def main(): server = KlAkOAPI.AdmServer.KlAkAdmServer.Create("https://ksc.example.com:13299", "username", "password", verify = False) FindHostIncidents(server, "KLINCDT_IS_HANDLED=1") ``` -------------------------------- ### UserDevicesApi::GetDevicesExtraData Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00596_af66b0a0912d64f2ea9101b2758e7975e.html Gets additional data from devices such as installed applications, profiles, certificates and etc. Accepts an array of device IDs and an array of categories, and returns an array containing the additional data. ```APIDOC ## UserDevicesApi::GetDevicesExtraData ### Description Gets additional data from devices such as installed applications, profiles, certificates and etc. ### Method UserDevicesApi::GetDevicesExtraData ### Parameters - **pDeviceIds** (array) - Required - array of device's integer identities - **pCategories** (array) - Required - array of categories such as installed applications, profiles, certificates (see Extra Data Categories) ### Returns (array) contains additional data from devices like this: Extra Data Example ``` -------------------------------- ### Sample: Enumerating tasks, querying task statistics and running task Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00434.html Sample script demonstrating how to enumerate tasks, query task statistics, and run a task using the KlAkOAPI package. ```python # #!/usr/bin/python -tt # -*- coding: utf-8 -*- """This module presents sample of usage KlAkOAPI package to perform task on host """ import sys import os import argparse import socket import time import getpass from sys import platform from urllib.parse import urlparse from KlAkOAPI.Params import KlAkParams, KlAkArray, paramParams, strToBin from KlAkOAPI.AdmServer import KlAkAdmServer from KlAkOAPI.Error import KlAkError, KlAkResponseError from KlAkOAPI.CgwHelper import KlAkCgwHelper from KlAkOAPI.GatewayConnection import KlAkGatewayConnection from KlAkOAPI.HostGroup import KlAkHostGroup from KlAkOAPI.ChunkAccessor import KlAkChunkAccessor from KlAkOAPI.Tasks import KlAkTasks from KlAkOAPI.HostTasks import KlAkHostTasks from KlAkOAPI.NagHstCtl import KlAkNagHstCtl # For basic auth connection you should either state '-user' and '-password' arguments or the following credentials are applied: KSCServerUserAccountDefault / KSCServerUserPasswordDefault # You should create internal user with these credentials in advance on KSC using WC or MMC console and grant it certain privileges, such as 'Main Administrator' role # For Windows platform NTLM auth is applied when user and password arguments are omitted KSCServerUserAccountDefault = 'klakoapi_test' KSCServerUserPasswordDefault = 'test1234!' def GetHostNameByHostFQDN(server, strHostFQDN): """ Find (internal) host name by host display name; the returned wsHostName is required for gateway connection to nagent """ hostGroup = KlAkHostGroup(server) hostInfo = hostGroup.FindHosts('(KLHST_WKS_FQDN="' + strHostFQDN + '")', ['KLHST_WKS_HOSTNAME', 'KLHST_WKS_DN', 'name'], [], {'KLGRP_FIND_FROM_CUR_VS_ONLY': True}, 100) strAccessor = hostInfo.OutPar('strAccessor') # get search result (in case of ambiguity first found host is taken) chunkAccessor = KlAkChunkAccessor (server) items_count = chunkAccessor.GetItemsCount(strAccessor).RetVal() if items_count < 1: raise KlAkError('no gateway host found by name ' + strHostFQDN) res_chunk = chunkAccessor.GetItemsChunk(strAccessor, 0, 1) res_array = KlAkParams(res_chunk.OutPar('pChunk'))['KLCSP_ITERATOR_ARRAY'] res_host = res_array[0] wsHostName = res_host['KLHST_WKS_HOSTNAME'] print('Host for nagent gateway connection is:', strHostFQDN, 'correspondent to device', res_host['KLHST_WKS_DN'], 'in group', res_host['name']) return wsHostName def GetServer(server_url): """Connects to KSC server""" # server details - connect to server installed on current machine, use default port ``` -------------------------------- ### Python example: Call FindIncidents to get accessor Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00517_a5b76f3c6aa7737a9bb502a12c6186820.html Calls the FindIncidents method on a KlAkHostGroup instance to obtain the result set accessor (strAccessor) with specified fields and a maximum lifetime of one hour. ```python strAccessor = KlAkOAPI.HostGroup.KlAkHostGroup(server).FindIncidents(strFilter, ["KLINCDT_ID", "KLINCDT_SEVERITY", "KLINCDT_ADDED", "KLINCDT_BODY", "KLINCDT_IS_HANDLED", "KLHST_WKS_HOSTNAME", "GNRL_EXTRA_PARAMS"], [], lMaxLifeTime = 60 * 60).OutPar("strAccessor") ``` -------------------------------- ### RunTask Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00588.html Starts a specified task. ```APIDOC ## RunTask ### Description Starts the specified task. ### Method RunTask ### Parameters - **strTask** (wstring) - Required - The task identifier. ### Returns - None. ``` -------------------------------- ### GetHostInvProducts Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00524_a0f464854ef7836666be83a7fede55279.html Acquires software applications which are installed on a specified host. ```APIDOC ## GetHostInvProducts ### Description Acquires software applications which are installed on a specified host. ### Method GET ### Endpoint InventoryApi::GetHostInvProducts ### Parameters #### Path Parameters - **szwHostId** (wstring) - Required - Host name, a unique server-generated string (see KLHST_WKS_HOSTNAME attribute). It is not the same as computer network name (DNS-, FQDN-, NetBIOS-name). #### Query Parameters - **pParams** (params) - Optional - Reserved. ### Response #### Success Response (200) - **KLEVP_EA_PARAM_1** (paramArray|paramParams) - List of software applications. Each element contains attributes from List of attributes of software inventory application. #### Response Example { "KLEVP_EA_PARAM_1": [ { "attribute": "value" } ] } ``` -------------------------------- ### HWInvStorage::ImportHWInvStorageSetData Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00523_a3d5f1550e4f213cca99f8f7dce72a59b.html Sends a chunk of importing data to the server. If pChunk is NULL, data sending is finished and data processing and importing to DB starts. Use AsyncActionStateChecker.CheckActionState to get status; lStateCode '0' means OK. ```APIDOC ## HWInvStorage::ImportHWInvStorageSetData ### Description Sends a chunk of importing data to the server. If pChunk is NULL, data sending is finished and data processing and importing to DB starts. To get status use AsyncActionStateChecker.CheckActionState, lStateCode "0" means OK. ### Method ImportHWInvStorageSetData ### Signature HWInvStorage::ImportHWInvStorageSetData(wstring _wstrAsyncId_, binary _pChunk_) ### Parameters - **wstrAsyncId** (wstring) - [in] Request id used in HWInvStorage.ImportHWInvStorage2 method - **pChunk** (binary) - [in] Chunk of importing data ### Remarks If pChunk is NULL, data sending is finished and data processing and importing to DB starts. ### Related Methods - HWInvStorage.ImportHWInvStorage2 - AsyncActionStateChecker.CheckActionState ``` -------------------------------- ### Connect to Administration Server and Initialize LicenseKeys Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00535_a42d0b5d83d540627d8cfe770f514c2d5.html Initializes the connection to the KSC Administration Server and creates an instance of the LicenseKeys class. ```python server = KlAkOAPI.AdmServer.KlAkAdmServer.Create("https://ksc.example.com:13299", "username", "password", verify = False) oLicenseKeys = KlAkOAPI.LicenseKeys.KlAkLicenseKeys(server) ``` -------------------------------- ### GetPackages Source: https://support.kaspersky.com/help/KSC/14.2/KSCAPI/a00554.html Gets information about all packages. ```APIDOC ## GetPackages ### Description Get packages information. ### Method GetPackages ### Returns - **array** - List of package information. ```