
I tried the Site Content DataSource on the Tableau server, but it shows that the site Content was last updated a day prior (06/11/2024 11:34 AM). I want something to show the live status of the data sources. for e.g. there were few data sources which were schedule and ran this morning.
@Prachi Dalvi
Hi, you may use a python code like:
#import os
from datetime import datetime, timezone
import datetime as DT
import tableauserverclient as TSC
PAT_NAME = 'yourtokenname'
PAT_VALUE = '/5QvK8pKa/wg==:JAIzqJlHjCMx4tt1'
SITE_NAME = 'yoursitename'
SERVER = 'https://prod-useast-b.online.tableau.com'
literal_date = DT.datetime(2000, 1, 1)
tableau_auth = TSC.PersonalAccessTokenAuth(PAT_NAME,PAT_VALUE,site_id=SITE_NAME)
#tableau_auth = TSC.TableauAuth(username, password, site_id='sitenameurl')
server = TSC.Server(SERVER, use_server_version=True)
with server.auth.sign_in(tableau_auth):
print('Logged in')
now = datetime.now(timezone.utc)
print(now)
datasources = [ds for ds in TSC.Pager(server.datasources) if (now-(ds.updated_at or literal_date)).days>=0 and ds.has_extracts]
for ds in datasources:
print((now-(ds.updated_at or now)).days, ds.name, ds.updated_at, ds.project_name)
You would need to create a PAT and allow PAT to be used in your site:
https://help.tableau.com/current/online/en-us/security_personal_access_tokens.htm
This code uses Tableau Server Client:
https://tableau.github.io/server-client-python/docs/
Change line 21 if you want to know datasources update more than x days ago. In this example I am using >=0 so every data source should be shown.
Finally, I don't remember, but I am like 90% sure, times shown will be in UTC.
If this post resolves the question, would you be so kind to "Select as Best"?. This will help other users find the same answer/resolution and help community keep track of answered questions. Thank you.
Regards,
Diego Martinez
Tableau Visionary and Forums Ambassador