Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. READ MORE

Qlik Enterprise Manager: Python command to start task from timestamp

100% helpful (1/1)
cancel
Showing results for 
Search instead for 
Did you mean: 
Steve_Nguyen
Support
Support

Qlik Enterprise Manager: Python command to start task from timestamp

Last Update:

Aug 8, 2023 8:38:46 AM

Updated By:

Sonja_Bauernfeind

Created date:

Aug 8, 2023 8:38:46 AM

This article provides an example on how to use the Qlik Enterprise Manager Python API to start a task from timestamp. The example runs a task by cdcposition using Python API.

This customization is provided as is. Qlik Support cannot provide continued support for the solution. For assistance, reach out to Professional Services.
  1. Create the file cdctimestamp.py with the following content:
    """
    @author: Vinay Vitta
    """
    
    import json, glob, os, sys, base64, requests, re, time, urllib3
    from datetime import datetime
    from datetime import timedelta
    from calendar import monthrange
    from enum import Enum
    from copy import copy
    
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # Don't want to print out warnings
    
    
    RepServer='79' #change Replicate Server name
    RepTask='mysql2file' #change for task name
    
    api_base_url = "https://snsql2014a/attunityenterprisemanager/api/v1/" #change for QEM server
    auth_string = "Basic c25zcWwyMDE0YVxhZG1pbmlzdHJhdG9yOmhheWV6aXJh" # Change for base64 hash user password ,, make sure to keep the Basic
    
    login_headers = {}
    login_headers["Authorization"] = auth_string
    print(login_headers)
    session = requests.Session()
    response = session.get(url=api_base_url + 'login', headers=login_headers, verify=False)
    # print(response.json())
    if response.status_code == 200:
    session_id = response.headers['EnterpriseManager.APISessionID']
    
    api_session_header = {}
    api_session_header["EnterpriseManager.APISessionID"] = session_id
    session.headers.update(api_session_header)
    
    urlResumeTime='servers/' + RepServer + '/tasks/' + RepTask + '?action=run&option=RESUME_PROCESSING_FROM_TIMESTAMP'
    print(api_base_url + urlResumeTime)
    data = {"cdcposition": "2023-07-14T01:01:01"} # change for the CDCposition
    resumeTimeResponse = session.post(url=api_base_url + urlResumeTime, headers=login_headers, json=data, verify=False)
    print(resumeTimeResponse.headers)
  2. Call cdctimestamp.py

    Example: 

    C:\Python37\Scripts>python cdctimestamp.py

    Output:

    {'Authorization': 'Basic c25zcWwyMDE0YVxhZG1pbmlzdHJhdG9yOmhheWV6aXJh'}
    https://snsql2014a/attunityenterprisemanager/api/v1/servers/79/tasks/mysql2file?action=run&option=RE...
    {'Cache-Control': 'no-cache, no-store', 'Content-Length': '38', 'Content-Type': 'application/json; charset=utf-8', 'Server': 'Microsoft-HTTPAPI/2.0', 'Date': 'Mon, 17 Jul 2023 21:57:43 GMT'}

 

Example from the log file of the task executing from timestamp:

00008888: 2023-07-17T16:57:34 [TASK_MANAGER ]I: Task 'mysql2file' running CDC only in fresh start mode, starting from log position: 'timestamp:2023-07-14T01:01:01' (UTC). (replicationtask.c:1770)
00008888: 2023-07-17T16:57:34 [TASK_MANAGER ]I: Feature flags for process are: (ar_feature_flags.c:232)

 

 

Environment

Qlik Enterprise Manager 

 

Labels (2)
Comments
shrikantdhumal
Contributor
Contributor

I have tried to get the session Id with the same code I am getting following error:

"raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='', port=4799): Max retries exceeded with url: /attunityenterprisemanager/api/v1/login (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1122)')))

Process finished with exit code 1"

Sonja_Bauernfeind
Digital Support
Digital Support

Hello @shrikantdhumal 

Looking up the error message, it looks like it is often caused by either using the wrong port number or using HTTPS where HTTP is expected or the other way around. 

If this hint does not help, please post your issue in our Enterprise Manager forum

All the best,
Sonja 

Version history
Last update:
‎2023-08-08 08:38 AM
Updated by: