Skip to content

Commit

Permalink
Merge pull request #185 from databricks-industry-solutions/feature/SF…
Browse files Browse the repository at this point in the history
…E-3030-dashboard-improvements

Changes to the dashboard and improvements to the queries
  • Loading branch information
arunpamulapati authored Dec 12, 2024
2 parents 9f99b60 + d7cfa51 commit 14c7611
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dashboards/SAT_Dashboard_definition.json

Large diffs are not rendered by default.

16 changes: 6 additions & 10 deletions notebooks/Setup/5. import_dashboard_template_lakeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

# COMMAND ----------

# COMMAND ----------

dfexist = readWorkspaceConfigFile()
dfexist.filter((dfexist.analysis_enabled==True) & (dfexist.connection_test==True)).createOrReplaceTempView('all_workspaces')

Expand Down Expand Up @@ -75,7 +77,6 @@
import requests

DOMAIN = ws.deployment_url
loggr.info(f"Looking for data_source_id for : {json_['sql_warehouse_id']}!")
response = requests.get(
'https://%s/api/2.0/preview/sql/data_sources' % (DOMAIN),
headers={'Authorization': 'Bearer %s' % token},
Expand All @@ -88,13 +89,11 @@
for resource in resources:
if resource['endpoint_id'] == json_['sql_warehouse_id']:
data_source_id = resource['id']
loggr.info(f"Found data_source_id for : {json_['sql_warehouse_id']}!")
found = True
break
if (found == False):
dbutils.notebook.exit("The configured SQL Warehouse Endpoint is not found.")
else:
loggr.info(f"Error with token, {response.text}")
dbutils.notebook.exit("Invalid access token, check configuration value for this workspace.")


Expand Down Expand Up @@ -146,9 +145,8 @@ def replace_string(obj, old_str, new_str):

import requests

BODY = {'path': f'{basePath()}/[SAT] Security Analysis Tool - Workspace In-Depth.lvdash.json'}
BODY = {'path': f'{basePath()}/[SAT] Security Analysis Tool - Assessment Results.lvdash.json'}

loggr.info(f"Getting Dashboard")
response = requests.get(
'https://%s/api/2.0/workspace/get-status' % (DOMAIN),
headers={'Authorization': 'Bearer %s' % token},
Expand All @@ -172,7 +170,6 @@ def replace_string(obj, old_str, new_str):

if exists != False:

loggr.info(f"Deleting Dashboard")
response = requests.delete(
'https://%s/api/2.0/lakeview/dashboards/%s' % (DOMAIN, dashboard_id),
headers={'Authorization': 'Bearer %s' % token},
Expand All @@ -197,9 +194,8 @@ def replace_string(obj, old_str, new_str):

json_string = json_string = json.dumps(json_data)

BODY = {'display_name': '[SAT] Security Analysis Tool - Workspace In-Depth','warehouse_id': json_['sql_warehouse_id'], 'serialized_dashboard': json_string, 'parent_path': f"{basePath()}/dashboards"}
BODY = {'display_name': '[SAT] Security Analysis Tool - Assessment Results','warehouse_id': json_['sql_warehouse_id'], 'serialized_dashboard': json_string, 'parent_path': f"{basePath()}/dashboards"}

loggr.info(f"Creating Dashboard")
response = requests.post(
'https://%s/api/2.0/lakeview/dashboards' % (DOMAIN),
headers={'Authorization': 'Bearer %s' % token},
Expand All @@ -211,7 +207,8 @@ def replace_string(obj, old_str, new_str):

if 'RESOURCE_ALREADY_EXISTS' not in response.text:
json_response = response.json()
dashboard_id = json_response['dashboard_id']
dashboard_id = json_response['dashboard_id']
serialized_dashboard = json_response['serialized_dashboard']
else:
exists = True
print("Lakeview Dashboard already exists")
Expand All @@ -231,7 +228,6 @@ def replace_string(obj, old_str, new_str):
URL = "https://"+DOMAIN+"/api/2.0/lakeview/dashboards/"+dashboard_id+"/published"
BODY = {'embed_credentials': 'true', 'warehouse_id': json_['sql_warehouse_id']}

loggr.info(f"Publishing the Dashboard using the SAT SQL Warehouse")
response = requests.post(
URL,
headers={'Authorization': 'Bearer %s' % token},
Expand Down

0 comments on commit 14c7611

Please sign in to comment.