Skip to content

Commit

Permalink
Remove GRAFANA_USERNAME and GRAFANA_PASSWORD from grafana-init
Browse files Browse the repository at this point in the history
Signed-off-by: Dobroslaw Zybort <[email protected]>
  • Loading branch information
matrixik committed Jan 19, 2018
1 parent c7def85 commit 3497559
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 0 additions & 2 deletions grafana-init/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ from alpine:3.5

env LOG_LEVEL=INFO \
GRAFANA_URL=http://grafana:3000 \
GRAFANA_USERNAME=mini-mon \
GRAFANA_PASSWORD=password \
GRAFANA_ADMIN_USERNAME=admin \
GRAFANA_ADMIN_PASSWORD=password \
DATASOURCE_TYPE=monasca \
Expand Down
15 changes: 8 additions & 7 deletions grafana-init/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ Configuration
|--------------------|------------------------|---------------------------------|
| `LOG_LEVEL` | `INFO` | Logging level, e.g. `DEBUG` |
| `GRAFANA_URL` | `http://grafana:3000` | Location of Grafana server |
| `GRAFANA_USERNAME` | `mini-mon` | Agent Keystone username |
| `GRAFANA_PASSWORD` | `password` | Agent Keystone password |
| `GRAFANA_USERS` | `'[{"user": GRAFANA_USERNAME, "password": GRAFANA_PASSWORD, "email": "", "project": "mini-mon", "domain": "Default"}]'` | Agent Keystone users. Read more in [Grafana users](#grafana-users) **NOTE: Set this variable in String type** |
| `GRAFANA_USERS` | `'[{"user": "mini-mon", "password": "password", "email": "", "project": "mini-mon", "domain": "Default"}]'` | Agent Keystone users configuration. Read more in [Grafana users](#grafana-users) **NOTE: Set this variable as String type** |
| `DATASOURCE_TYPE` | `monasca` | Agent Keystone user domain |
| `GRAFANA_ADMIN_USERNAME` | `admin` | Agent Keystone admin username |
| `GRAFANA_ADMIN_PASSWORD` | `password` | Agent Keystone admin username |
Expand All @@ -60,10 +58,13 @@ datasources should be simple to implement as needed by adding logic to

Default data source and dashboard are created for multiple
users if this variable is set as proper JSON format. e.g.
`'[{"user": "mini-mon", "password": "password", "email": "", "project": "mini-mon", "domain": "Default"}, {"user": "other-user", "password": "password", "email": "", "project": "monasca", "domain": "Default"}]'`.

When `GRAFANA_USERS` is not overwritten and you are using only one user you
can configure his details with `GRAFANA_USERNAME` and `GRAFANA_PASSWORD`.
```
'[{"user": "mini-mon", "password": "password", "email": "", "project": "mini-mon", "domain": "Default"}, {"user": "other-user", "password": "password", "email": "", "project": "monasca", "domain": "Default"}]'
```
In the same place you could provide user project and domain that will be used
to set proper organization in Grafana. If you does not provide them dashboards
will be uploaded to random organization if user is assigned to more than one
(that's how Grafana API is doing by default).

`GRAFANA_ADMIN_USERNAME` and `GRAFANA_ADMIN_PASSWORD`

Expand Down
15 changes: 7 additions & 8 deletions grafana-init/grafana.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@
logger = logging.getLogger(__name__)

GRAFANA_URL = os.environ.get('GRAFANA_URL', 'http://grafana:3000')
GRAFANA_USERNAME = os.environ.get('GRAFANA_USERNAME', 'mini-mon')
GRAFANA_PASSWORD = os.environ.get('GRAFANA_PASSWORD', 'password')
GRAFANA_ADMIN_USERNAME = os.environ.get('GRAFANA_ADMIN_USERNAME', 'admin')
GRAFANA_ADMIN_PASSWORD = os.environ.get('GRAFANA_ADMIN_PASSWORD', 'password')
GRAFANA_USERS = [{
'user': GRAFANA_USERNAME,
'password': GRAFANA_PASSWORD,
'user': "mini-mon",
'password': "password",
'email': '',
'project': 'mini-mon',
'domain': 'Default',
Expand Down Expand Up @@ -109,8 +107,8 @@ def change_user_context(admin_session, user_session, organisation):
logging.debug('Organisation "%s" id = %r', organisation, org_id)

r = user_session.post('{url}/api/user/using/{org}'.
format(url=GRAFANA_URL, org=org_id),
timeout=5)
format(url=GRAFANA_URL, org=org_id),
timeout=5)
r.raise_for_status()


Expand Down Expand Up @@ -177,12 +175,12 @@ def main():
# Grafana org name is created from Kestone project+"@"+domain
org_name = user['project'] + '@' + user['domain']
logging.info('Setting user "%s" organisation to "%s"',
user['user'], org_name)
user['user'], org_name)
change_user_context(admin_session, session, org_name)

logging.info('Attempting to add configured datasource...')
r = session.post('{url}/api/datasources'.format(url=GRAFANA_URL),
json=create_datasource_payload())
json=create_datasource_payload())
logging.debug('Response: %r', r.json())
r.raise_for_status()

Expand All @@ -201,5 +199,6 @@ def main():

logging.info('Finished successfully.')


if __name__ == '__main__':
main()

0 comments on commit 3497559

Please sign in to comment.