Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
904 changes: 904 additions & 0 deletions examples/dashboards/Asset Utilization/Asset Utilization.json

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
194 changes: 194 additions & 0 deletions examples/dashboards/Asset Utilization/Delete Multiple Tags.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "1f236472-b649-4d5e-acdf-cbc32247ca7d",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"import os\n",
"import requests\n",
"import asyncio\n",
"from urllib3.util.retry import Retry\n",
"from requests.adapters import HTTPAdapter\n",
"from IPython.display import clear_output\n",
"from systemlink.clients.nitag.api.tags_api import TagsApi"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "fa71dd56-d7cd-413d-85af-c8186998dc94",
"metadata": {},
"outputs": [],
"source": [
"api_key = os.getenv(\"SYSTEMLINK_API_KEY\")\n",
"http_url = os.getenv('SYSTEMLINK_HTTP_URI')\n",
"os.environ['SKYLINE_USER_SERVICES_URL'] = http_url\n",
"create_tag_selection_endpoint = f\"{http_url}/nitag/v2/selections\"\n",
"delete_tags_in_selection = f\"{http_url}/nitag/v2/update-tags\"\n",
"auth_api_key_endpoint = f\"{http_url}/niauth/v1/auth\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "db09aeb9-158f-433d-896c-877dec3b9680",
"metadata": {},
"outputs": [],
"source": [
"session = requests.Session()\n",
"session.headers.update({\n",
" \"Content-Type\": \"application/json\",\n",
" 'x-ni-api-key': api_key,\n",
"})\n",
" \n",
"retry_strategy = Retry(\n",
" total=3, # total retry attempts\n",
" status_forcelist=[500, 502, 503, 504], # which errors to retry\n",
" allowed_methods=[\"HEAD\", \"GET\", \"OPTIONS\", \"POST\", \"PUT\", \"DELETE\"], # methods to retry\n",
" backoff_factor=2 # wait 1s, 2s, 4s ... between retries\n",
")\n",
"\n",
"# Mount the retry strategy to http and https\n",
"adapter = HTTPAdapter(max_retries=retry_strategy)\n",
"session.mount(\"http://\", adapter)\n",
"session.mount(\"https://\", adapter)\n",
" "
]
},
{
"cell_type": "markdown",
"id": "8aabd583-91b1-4283-8ae9-5a3cebbf47e7",
"metadata": {},
"source": [
"## Get Workspace IDs"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "a249864e-0ef3-4c8a-8352-2c0d6c39be2e",
"metadata": {},
"outputs": [],
"source": [
"def get_workspace_ids():\n",
" response = session.get(url=auth_api_key_endpoint)\n",
" response.raise_for_status()\n",
" data = response.json()\n",
" \n",
" workspaces = data[\"workspaces\"]\n",
"\n",
" enabled = [workspace['id'] for workspace in workspaces if workspace[\"enabled\"] == True]\n",
" return enabled\n",
" return [workspace['id'] for workspace in workspaces]"
]
},
{
"cell_type": "markdown",
"id": "d3425e0b-1c0c-43a9-af58-a351bd2e5097",
"metadata": {},
"source": [
"## Create selection for faster delete tags"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "aa2aaeef-f11c-4015-a943-f5fc64297aa9",
"metadata": {},
"outputs": [],
"source": [
"def create_selection(workspace_id):\n",
" try:\n",
" payload = {\n",
" \"searchPaths\": [\n",
" \"*Utilization*\"\n",
" ],\n",
" \"inactivityTimeout\": 900,\n",
" \"workspace\": workspace_id\n",
" }\n",
" resp = session.post(url=create_tag_selection_endpoint, json=payload)\n",
" resp.raise_for_status()\n",
" data = resp.json()\n",
" \n",
" return data['id']\n",
" except Exception as e:\n",
" print('workspace_id', workspace_id)\n",
" print(e)\n",
" return False"
]
},
{
"cell_type": "markdown",
"id": "55cd0356-3d7d-4caf-bcf1-5a0e115e19fa",
"metadata": {},
"source": [
"## Delete tags in selection"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "74670919-f66c-48dc-bd7d-14feb78d333b",
"metadata": {},
"outputs": [],
"source": [
"def delete_selection(selection_id):\n",
" try:\n",
" resp = session.delete(url=f\"{http_url}/nitag/v2/selections/{selection_id}/tags\")\n",
" resp.raise_for_status()\n",
" if resp.status_code == 204:\n",
" return True\n",
" except Exception as e:\n",
" print('selection_id', selection_id)\n",
" print(e)\n",
" return False"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "d3384b22-e7d9-4886-be68-b6eed56fe2d0",
"metadata": {},
"outputs": [],
"source": [
"workspace_ids = get_workspace_ids()\n",
"\n",
"for ws_id in workspace_ids:\n",
" selection_id = create_selection(ws_id)\n",
" if not selection_id:\n",
" continue\n",
" deleted = delete_selection(selection_id)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading