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
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ WORKDIR /home/powsybl
COPY scripts/ ./

RUN pip3 install -r requirements.txt
# We call a script here, but it's overwritten at job execution by the way
# depending at which script should be applied
# it's a dry-run call by default to avoid unexpected impact with this image
CMD [ "python", "delete_indexed_equipments.py", "--dry-run" ]

ENTRYPOINT ["python"]
# We call a dummy code by default to avoid unexpected impact with this image
# It's overwritten at job execution by the way depending at which script should be applied
CMD ["-c", "print('Please specify the script to run in the container CMD.')"]
101 changes: 55 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,98 +11,107 @@ Use locally by settings the `DEV` property to in `scripts/constant.py`

Then

```py
```shell
python3 [scriptName] [parameters]
```

> **_NOTE:_**
> [!NOTE]
> Please be sure to exclude 172.17.0.1 from your proxy configuration.
> ```shell
> export NO_PROXY=localhost,172.17.0.1
> ```

some example :
Some examples:

Check Loadflow results number :
```py
python3 scripts/delete_computation_results.py -lf -n
```
* Check Loadflow results number :
```shell
python3 scripts/delete_computation_results.py -lf -n
```

* Delete Loadflow results definitively :
```shell
python3 scripts/delete_computation_results.py -lf
```

Delete Loadflow results definitively :
```py
python3 scripts/delete_computation_results.py -lf
```

## How to use locally with a container

If 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.

```py
```python
DEV = True
```
And finally:
```docker
```shell
docker build . < Dockerfile --tag admin-tools
docker run admin-tools python [SCRIPT_NAME].py [...OPTIONS]
docker run admin-tools [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 |
**SCRIPT_NAME**: script file name in 'scripts/' folder
**OPTIONS** :
_(see individual scripts)_
Common options is :
| Parameter | Description |
| -------------- | ------------------------------------------------------------------- |
| -n, --dry-run | test mode (default) will not execute any deletion or saving request |

## Elasticsearch scripts

## Scripts

### Elasticsearch scripts

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:
```py
```shell
python3 scripts/ES_requests.py -m GET -u /_cat/indices?v
```

## Grafana scripts
### Grafana scripts
All post requests are sent with the header "X-Disable-Provenance" set to "true". Without it, all created entities would be read-only.
### Import existing alert-rules JSON

#### Import existing alert-rules JSON
First, we need to create a folder.
Execute this command :
```py
```shell
python3 scripts/grafana_create_folder.py {{FOLDER_NAME}}
```

This command should return a json with a field "uid" which will be {{FOLDER_UID}} for the next command
This command should return a json with a field "uid" which will be {{FOLDER_UID}} for the next command.

Then we can create alert-rules in the previously created folder.
**Default interval value for rule-group is 60s. If you want a different value, use "-i" option (run "python3 scripts/grafana_create_alerts.py -h" for more infos**
Then we can create alert-rules in the previously created folder.
**Default interval value for rule-group is 60s. If you want a different value, use "-i" option _(run `python3 scripts/grafana_create_alerts.py -h` for more infos_).**
Execute this command :
```py
```shell
python3 scripts/grafana_create_alerts.py -f {{PATH_TO_ALERT_RULES_1}} -f {{PATH_TO_ALERT_RULES_2}} -d {{DATASOURCE_UID}} -p {{FOLDER_UID}}
```

*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
> [!NOTE]
> - `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

### Create a new alert-rule JSON file
#### Create a new alert-rule JSON file
From local grafana, create the alert you want to export as a JSON file
Once done, export it using this curl command :
```
```shell
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*
> [!NOTE]
> You can find alert rule UID in the URL when inspecting/editing it from grafana UI.

Edit "new_alert.json" file, then :
- replace all "folderUID" values by "{{FOLDER_UID}}
- replace all "datasourceUid" values by "{{DATASOURCE_UID}}"
Edit `new_alert.json` file, then :
- replace all `folderUID` values by `{{FOLDER_UID}}`
- replace all `datasourceUid` values by `{{DATASOURCE_UID}}`
- remove all those properties :
- "uid"
- "id"
- "updated"
- "provenance"
- `uid`
- `id`
- `updated`
- `provenance`

*Note: check **resources/grafana/alert-rules/computation-alert-rule.json** for a working template file*
> [!NOTE]
> Check `/scripts/resources/grafana/alert-rules/computation-alert-rule.json` for a working template file.

Save it in **resources/grafana/alert-rules** directory
Save it in `/scripts/resources/grafana/alert-rules` directory.

### Edit an existing alert-rule from a JSON file
There is currently no script to update an existing alert-rule
#### Edit an existing alert-rule from a JSON file
There is currently no script to update an existing alert-rule.