Skip to content

Instantly share code, notes, and snippets.

@lmasikl
Forked from feroda/django-grafana-proxy.py
Created May 23, 2018 06:15
Show Gist options
  • Save lmasikl/87369234db4f1d161a76b6374dd21069 to your computer and use it in GitHub Desktop.
Save lmasikl/87369234db4f1d161a76b6374dd21069 to your computer and use it in GitHub Desktop.
Django reverse proxy for Grafana SSO
"""
## Install the Django reverse proxy package: `pip install django-revproxy`
## Enable auth.proxy authentication in Grafana like the following
```
[auth.proxy]
enabled = true
header_name = X-WEBAUTH-USER
header_property = username
auto_sign_up = true
ldap_sync_ttl = 60
whitelist = 127.0.0.1
```
The whitelist parameter can be set if Django and Grafana are in the same host.
After that add this line in the Django project `urls.py`:
```
url(r'^dashboard/(?P<path>.*)$', views.GraphanaProxyView.as_view(), name='graphana-dashboards')
```
"""
from revproxy.views import ProxyView
class GraphanaProxyView(ProxyView):
upstream = 'http://localhost:8891/dashboard/'
def get_proxy_request_headers(self, request):
headers = super(GraphanaProxyView, self).get_proxy_request_headers(request)
headers['X-WEBAUTH-USER'] = request.user.username
return headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment