kubernetes-app
kubernetes-app copied to clipboard
automatic plugin provisioning via API
We try to deploy grafana with kubernetes-app plugin. Installing plugins is easy but I can't see any simple way to: a) Enabling plugin b) Configure plugin via API call ( i.e datasource )
Additonally as we modify default dashboards it should be possible to not import default ones when plugin is enabled ( maybe additional option for it )
Workaround:
Enable plugin:
curl -v --basic -XPOST "admin:admin@localhost:3000/api/plugins/grafana-kubernetes-app/settings?enabled=true"
Configure datasource:
curl -v --basic -XPOST "admin:admin@localhost:3000/api/datasources" -d '{"type":"grafana-kubernetes-datasource","name":"k8s.dev.io","url":"https://api.k8s.dev.io","access":"proxy","jsonData":{"keepCookies":[],"ds":"prometheus","tlsSkipVerify":true},"basicAuth":true,"basicAuthUser":"admin","basicAuthPassword":"admin"}' -H "Content-Type: application/json"
Ansible example:
- name: Install grafana plugins
grafana_plugin:
name: "{{ item }}"
version: latest
state: present
with_items: "{{ grafana_plugins }}"
notify: restart grafana
ignore_errors: true
- name: Enable grafana kubernetes plugin
uri:
url: "http://{{ grafana_local_ip }}:{{ grafana_port }}/api/plugins/grafana-kubernetes-app/settings?enabled=true"
method: POST
user: "{{ grafana_user }}"
password: "{{ grafana_password }}"
body: ''
body_format: json
force_basic_auth: yes
headers:
Content-Type: "application/json"
- name: Configure grafana kubernetes plugin datasource
uri:
url: "http://{{ grafana_local_ip }}:{{ grafana_port }}/api/datasources"
method: POST
user: "{{ grafana_user }}"
password: "{{ grafana_password }}"
body: '{"type":"grafana-kubernetes-datasource","name":"k8s.dev.shedul.io","url":"https://api.k8s.dev.shedul.io","access":"proxy","jsonData":{"keepCookies":[],"ds":"prometheus","tlsSkipVerify":true},"basicAuth":true,"basicAuthUser":"admin","basicAuthPassword":"7GPfUrkCobA98nGWxL8liTyXYCXUFejN"}'
body_format: json
force_basic_auth: yes
status_code: 200,409
headers:
Content-Type: "application/json"
I get this,
* Trying 100.66.212.213...
* Connected to grafana-service (100.66.212.213) port 80 (#0)
* Server auth using Basic with user 'admin'
> POST /api/plugins/grafana-kubernetes-app/settings?enabled=true HTTP/1.1
> Authorization: Basic xxxxxxxxxxxxxxxxxxx
> User-Agent: curl/7.29.0
> Host: grafana-service
> Accept: */*
>
< HTTP/1.1 415 Unsupported Media Type
< Cache-Control: no-cache
< Content-Type: application/json; charset=utf-8
< Expires: -1
< Pragma: no-cache
< X-Frame-Options: deny
< Date: Tue, 04 Jun 2019 07:54:21 GMT
< Content-Length: 70
<
{ [data not shown]
100 70 100 70 0 0 222 0 --:--:-- --:--:-- --:--:-- 222
* Connection #0 to host grafana-service left intact
[{"classification":"ContentTypeError","message":"Empty Content-Type"}]