Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brian-dashboard-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
brian
brian-dashboard-manager
Commits
bf829c21
Commit
bf829c21
authored
4 years ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
Delete dashboards/folders if excluded
parent
e23f74c0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
brian_dashboard_manager/grafana/provision.py
+51
-13
51 additions, 13 deletions
brian_dashboard_manager/grafana/provision.py
with
51 additions
and
13 deletions
brian_dashboard_manager/grafana/provision.py
+
51
−
13
View file @
bf829c21
...
...
@@ -13,10 +13,12 @@ from brian_dashboard_manager.grafana.organization import \
get_organizations
,
create_organization
,
create_api_token
,
\
delete_api_token
,
delete_expired_api_tokens
,
set_home_dashboard
from
brian_dashboard_manager.grafana.dashboard
import
\
get_dashboard_definitions
,
create_dashboard
,
find_dashboard
get_dashboard_definitions
,
create_dashboard
,
find_dashboard
,
\
delete_dashboard
from
brian_dashboard_manager.grafana.datasource
import
\
check_provisioned
,
create_datasource
from
brian_dashboard_manager.grafana.folder
import
find_folder
from
brian_dashboard_manager.grafana.folder
import
find_folder
,
\
delete_folder
from
brian_dashboard_manager.inventory_provider.interfaces
import
\
get_interfaces
from
brian_dashboard_manager.templating.nren_access
import
generate_nrens
...
...
@@ -42,7 +44,8 @@ def generate_all_nrens(token_request, nrens, folder_id, datasource_name):
def
provision_folder
(
token_request
,
folder_name
,
dash
,
excluded_interfaces
,
datasource_name
):
dash
,
excluded_interfaces
,
datasource_name
,
excluded_dashboards
):
folder
=
find_folder
(
token_request
,
folder_name
)
...
...
@@ -59,9 +62,19 @@ def provision_folder(token_request, folder_name,
data
=
get_interface_data
(
relevant_interfaces
,
parse_func
)
dash_data
=
get_dashboard_data
(
data
,
datasource_name
,
tag
,
errors
)
if
not
isinstance
(
excluded_dashboards
,
list
):
excluded_dashboards
=
[]
else
:
excluded_dashboards
=
list
(
map
(
lambda
s
:
s
.
lower
(),
excluded_dashboards
))
with
ThreadPoolExecutor
(
max_workers
=
4
)
as
executor
:
for
dashboard
in
dash_data
:
rendered
=
render_dashboard
(
dashboard
)
if
rendered
.
get
(
'
title
'
).
lower
()
in
excluded_dashboards
:
executor
.
submit
(
delete_dashboard
,
token_request
,
rendered
,
folder
[
'
id
'
])
continue
executor
.
submit
(
create_dashboard
,
token_request
,
rendered
,
folder
[
'
id
'
])
...
...
@@ -211,14 +224,25 @@ def provision(config):
}
# Provision dashboards, overwriting existing ones.
datasource_name
=
datasource
.
get
(
'
name
'
,
'
PollerInfluxDB
'
)
excluded_folders
=
org_config
.
get
(
'
excluded_folders
'
,
{})
with
ProcessPoolExecutor
(
max_workers
=
4
)
as
executor
:
for
folder_name
,
dash
in
dashboards
.
items
():
exclude
=
excluded_folders
.
get
(
folder_name
)
if
exclude
:
if
isinstance
(
exclude
,
bool
):
# boolean True -> entire folder excluded
# list -> dashboard names not to provision
executor
.
submit
(
delete_folder
,
token_request
,
folder_name
)
continue
logger
.
info
(
f
'
Provisioning
{
org
[
"
name
"
]
}
/
{
folder_name
}
dashboards
'
)
executor
.
submit
(
provision_folder
,
token_request
,
folder_name
,
dash
,
excluded_interfaces
,
datasource_name
)
excluded_interfaces
,
datasource_name
,
exclude
)
aggregate_dashboards
=
{
'
CLS PEERS
'
:
{
...
...
@@ -243,15 +267,27 @@ def provision(config):
}
}
with
ProcessPoolExecutor
(
max_workers
=
4
)
as
executor
:
aggregate_folder
=
find_folder
(
token_request
,
'
Aggregates
'
)
for
agg_type
,
dash
in
aggregate_dashboards
.
items
():
logger
.
info
(
f
'
Provisioning
{
org
[
"
name
"
]
}
'
+
f
'
/Aggregate
{
agg_type
}
dashboards
'
)
executor
.
submit
(
provision_aggregate
,
token_request
,
agg_type
,
aggregate_folder
,
dash
,
excluded_interfaces
,
datasource_name
)
exclude_agg
=
excluded_folders
.
get
(
'
Aggregates
'
,
[])
if
isinstance
(
exclude_agg
,
bool
)
and
exclude_agg
:
# don't provision aggregate folder
delete_folder
(
token_request
,
'
Aggregates
'
)
pass
else
:
with
ProcessPoolExecutor
(
max_workers
=
4
)
as
executor
:
agg_folder
=
find_folder
(
token_request
,
'
Aggregates
'
)
for
agg_type
,
dash
in
aggregate_dashboards
.
items
():
if
agg_type
in
exclude_agg
:
dash_name
=
f
'
Aggregates -
{
agg_type
}
'
executor
.
submit
(
delete_dashboard
,
token_request
,
dash_name
,
agg_folder
[
'
id
'
])
continue
logger
.
info
(
f
'
Provisioning
{
org
[
"
name
"
]
}
'
+
f
'
/Aggregate
{
agg_type
}
dashboards
'
)
executor
.
submit
(
provision_aggregate
,
token_request
,
agg_type
,
agg_folder
,
dash
,
excluded_interfaces
,
datasource_name
)
# NREN Access dashboards
# uses a different template than the above.
...
...
@@ -269,6 +305,8 @@ def provision(config):
if
dashboard
[
'
title
'
].
lower
()
==
'
home
'
:
dashboard
[
'
uid
'
]
=
'
home
'
create_dashboard
(
token_request
,
dashboard
)
else
:
delete_dashboard
(
token_request
,
dashboard
)
# Home dashboard is always called "Home"
# Make sure it's set for the organization
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment