KSC Open API  13.1
Kaspersky Security Center API description
AsyncActionStateChecker::CheckActionState ( wstring  wstrActionGuid,
[out] boolean  bFinalized,
[out] boolean  bSuccededFinalized,
[out] int  lStateCode,
[out] params  pStateData,
[out] int  lNextCheckDelay 
)

Check status of the async action.

Preconditions:

  • action with identifier wstrActionGuid has been added on the same connection where this method is call
  • if there was previous call of this method and it return lNextCheckDelay then there have passed not less than lNextCheckDelay milliseconds from this previous call

Postconditions:

  • if returns bFinalized==true then this action has been removed, and wstrActionGuid is not valid any more. Otherwise in lNextCheckDelay it should be returned delay in msec to do next call of the CheckActionState
Parameters:
wstrActionGuid[in] (wstring) action identifier
bFinalized[out] (boolean) true if action has been finished. false otherwise.
bSuccededFinalized[out] (boolean) This parameter take sense if bFinalized is true. true if action successfully completed.
lStateCode[out] (int) current action state code. The format is depends from action
pStateData[out] (params) current action state data. The format is depends from action. In case of error it typically contains KLBLAG_ERROR_INFO field.
lNextCheckDelay[out] (int) This parameter take sense if bFinalized is false. In that case it is needed to do next call of CheckActionState not earlier then there have passed lNextCheckDelay milliseconds
Exceptions:
STDE_NOTFOUND- the action with identifier wstrActionGuid is not found.
STDE_NOACCESS- the action has been added on other connection.
STDE_UNAVAIL- CheckActionState has been called too early.

See also Python code with use of KlAkOAPI Python package below:

            server = KlAkOAPI.AdmServer.KlAkAdmServer.Create("https://ksc.example.com:13299", "username", "password", verify = False)
            # remove group is asynchronous action
            strActionGuid = KlAkOAPI.HostGroup.KlAkHostGroup(server).RemoveGroup(nGroupId, nFlags = 1).OutPar('strActionGuid')
            # check for result of asynchronous action
            asyncActionStateChecker = KlAkOAPI.AsyncActionStateChecker.KlAkAsyncActionStateChecker(server)
            while True:
                res = asyncActionStateChecker.CheckActionState(strActionGuid)
                if res.OutPar('bFinalized'):
                    if res.OutPar('bSuccededFinalized'):
                        # got asynchronous result: success 
                        print ('Async action is performed successfully')
                    else:
                        # got asynchronous result: some error occurred
                        err_description = KlAkOAPI.Params.KlAkParams(res.OutPar('pStateData'))
                        print('Cannot perform async action:', err_description['GNRL_EA_DESCRIPTION'], '(error code ' + str(err_description['KLBLAG_ERROR_INFO']['KLBLAG_ERROR_CODE']) + ')')
                    break
                else:
                    # asynchronous result is not ready yet - need to wait for lNextCheckDelay milliseconds
                    time.sleep(MillisecondsToSeconds(res.OutPar('lNextCheckDelay')))