Gridsuite admin tools
Use locally by settings the DEV property to in scripts/constant.py
-DEV = False
+DEV = TrueThen
python3 [scriptName] [parameters]NOTE:
Please be sure to exclude 172.17.0.1 from your proxy configuration.
export NO_PROXY=localhost,172.17.0.1
some example :
Check Loadflow results number :
python3 scripts/delete_computation_results.py -lf -nDelete Loadflow results definitively :
python3 scripts/delete_computation_results.py -lfIf you want to run a python script via a docker container, please edit the Dockerfile CMD content as you wish, be sure to still activate DEV mode.
DEV = TrueAnd finally:
docker build . < Dockerfile --tag admin-tools
docker run admin-tools python [SCRIPT_NAME].py [...OPTIONS]
SCRIPT_NAME: script file name in 'scripts/' folder
OPTIONS :
(see individual scripts)
common option is :
| -n, --dry-run | test mode (default) will not execute any deletion or saving request |
|---|
You could use scripts/ES_requests.py to execute requests on elasticsearch host directly
respecting the REST API documentation (i.e. https://www.elastic.co/guide/en/elasticsearch/reference/current/rest-apis.html)
example:
python3 scripts/ES_requests.py -m GET -u /_cat/indices?vAll post requests are sent with the header "X-Disable-Provenance" set to "true". Without it, all created entities would be read-only. See REST API documentation : https://grafana.com/docs/grafana/v11.3/developers/http_api
Notes:
- DATASOURCE_UID can be found in URL by editing a datasource in grafana UI*
- FOLDER_UID can be found in URL by clicking on a folder in grafana UI, "Dashboard" menu
For example : you can find a folder UID ({{FOLDER_UID}}) in URL when inspecting/editing it from grafana UI for an existing folder :
grafana-ik8s-opf.rte-france.com/dashboards/f/ef9cbq89g8em8a/gridsuite
or
grafana-ik8s-opf.rte-france.com/dashboards/f/applications_ec52bf07-f55c-4f2c/?orgId=20
You can find a datasource UID ({{DATASOURCE_UID}}) in URL by selecting it in explore menu from grafana UI :
//grafana-ik8s-opf.rte-france.com/explore?schemaVersion=1&panes=%7B"jve":%7B"datasource":"cep8b3zww4e0wb"
First, only if the forder does not exist, we need to create a folder. If the folder already exists skip this step. Create a folder from the Grafana GUI or execute this command :
python3 scripts/grafana_create_folder.py {{FOLDER_NAME}}This command should return an "uid" which will be {{FOLDER_UID}} for the next command
Then we can create dashboards in the previously existing or created folder.
To import all dashboards present in resources/grafana/dashboards, execute this command :
python3 scripts/grafana_create_dashboards.py -a -p {{FOLDER_UID}}To import a single dashboard or multiple dashboards from files, execute this command :
python3 scripts/grafana_create_dashboards.py -f {{PATH_TO_DASHBOARD_FILE_1}} [... -f {{PATH_TO_DASHBOARD_FILE_N}}] -p {{FOLDER_UID}}For example :
python3 scripts/grafana_create_dashboards.py -f scripts/resources/grafana/dashboards/applications/computations_metrics.json -p applications_ec52bf07-f55c-4f2cFrom local grafana, create the dashboard you want to export as a JSON file
Once done, export it using this curl command :
curl localhost:7000/api/dashboards/uid/{{DASHBOARD_UID}} > new_dashboard.json
Edit "new_dashboard.json" file, then :
- replace "uid" value by a new value corresponding to a UUID (you can use https://www.uuidgenerator.net/)
- remove all those properties :
- the root "id" (you can set it to null)
- "meta"
- "dashboard" (the content of the "dashboard" field will become the whole JSON)
Note: check resources/grafana/dashboards/users-metrics.json for a working template file
Save it in resources/grafana/dashboards directory You can create a subdirectory or use an existing subdirectory
First, only if the forder does not exist, we need to create a folder. If the folder already exists skip this step. Create a folder from the Grafana GUI or execute this command :
python3 scripts/grafana_create_folder.py {{FOLDER_NAME}}This command should return an "uid" which will be {{FOLDER_UID}} for the next command
Then we can create alert-rules in the previously existing or created folder.
To import all alerts present in resources/grafana/alerts (logs for Loki and metrics for Prometheus):
Execute these commands :
python3 scripts/grafana_create_alerts.py -l -d {{DATASOURCE_LOKI_UID}} -p {{FOLDER_UID}}
python3 scripts/grafana_create_alerts.py -m -d {{DATASOURCE_PROMETHEUS_UID}} -p {{FOLDER_UID}}To import a single alert or multiple alerts from files, execute this command :
Execute this command :
python3 scripts/grafana_create_alerts.py -f {{PATH_TO_ALERT_RULES_1}} -f {{PATH_TO_ALERT_RULES_2}} -d {{DATASOURCE_UID}} -p {{FOLDER_UID}}For example :
python3 scripts/grafana_create_dashboards.py -f scripts/resources/grafana/dashboards/applications/computations_metrics.json -p applications_ec52bf07-f55c-4f2cFrom local grafana, create the alert you want to export as a JSON file
Once done, export it using this curl command :
curl localhost:7000/api/v1/provisioning/alert-rules/{{ALERT_RULE_UID}} > new_alert.json
Note : you can find alert rule UID in URL when inspecting/editing it from grafana UI
Rule-group for evaluation interval must be one of these values : 'alert_eval_group_10s', 'alert_eval_group_30s', 'alert_eval_group_1m', 'alert_eval_group_5m'
Edit "new_alert.json" file, then :
- replace all "folderUID" values by "{{FOLDER_UID}}
- replace all "datasourceUid" values by "{{DATASOURCE_UID}}"
- replace "uid" value by a new value corresponding to a UUID (you can use https://www.uuidgenerator.net/)
- replace "ruleGroup" by a value present in this list : 'alert_eval_group_10s', 'alert_eval_group_30s', 'alert_eval_group_1m', 'alert_eval_group_5m',
- remove all those properties :
- "id"
- "updated"
- "provenance"
Note: check resources/grafana/alerts/computation_queue_alert.json for a working template file
Save it in resources/grafana/alerts directory
There is currently no script to update an existing alert-rule
This python script will send requests to gridsuite services configured in "constant.py" in order to clean orphan elements. Cleans :
- orphan networks
- orphan contingency lists
- orphan filters
- orphan cases
- orphan studies
- orphan root networks
Developed with Python version 3.10.12
Command line to run script using the standard mode (ie will actually remove orphan elements by executing DELETE requests to services) :
python3 scripts/clean_orphan_elements.py
Has a test --dry-run mode : | --dry-run | this test mode will not modify nor remove any element. It will only display which elements will be deleted if the script is ran in standard mode
python3 scripts/clean_orphan_elements.py --dry-run
This python script sends requests to the study server and the network store server configured in "constant.py" to find the networks which are not referenced by any root network of a study, then deletes them by sending DELETE requests to the network store server.
Command line to run script (will actually delete the networks) :
python3 scripts/delete_orphan_networks.py
Has a test --dry-run mode, which only lists the orphan networks :
python3 scripts/delete_orphan_networks.py --dry-run
Has a --limit option to delete only a maximum number of orphan networks :
python3 scripts/delete_orphan_networks.py --limit 150
By default, this script recreates sharing links for all studies. Pass one or more study UUIDs with --study-uuids to process only those studies:
python3 scripts/recreate_network-modifications_sharing_links.py --study-uuids {{STUDY_UUID_1}} {{STUDY_UUID_2}}Use --dry-run to verify the selected studies without sending recreation requests:
python3 scripts/recreate_network-modifications_sharing_links.py --study-uuids {{STUDY_UUID}} --dry-run