Skip to content
Merged
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
21 changes: 14 additions & 7 deletions promgen/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from http import HTTPStatus

import requests
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponse, JsonResponse
from django.utils.translation import gettext as _
from django.views.generic import View
from django.views.generic.base import TemplateView
from requests.exceptions import HTTPError
from rest_framework import permissions
Expand All @@ -21,7 +21,8 @@
logger = logging.getLogger(__name__)


class PrometheusProxy(View):
class PrometheusProxy(APIView):
permission_classes = [permissions.IsAuthenticated]
proxy_headers = {"HTTP_REFERER": "Referer"}

@property
Expand Down Expand Up @@ -53,7 +54,7 @@ def proxy(self, request):
yield from concurrent.futures.as_completed(futures)


class ProxyGraph(TemplateView):
class ProxyGraph(LoginRequiredMixin, TemplateView):
template_name = "promgen/graph.html"

def get_context_data(self, **kwargs):
Expand Down Expand Up @@ -156,7 +157,9 @@ def get(self, request):
)


class ProxyAlerts(View):
class ProxyAlerts(APIView):
permission_classes = [permissions.IsAuthenticated]

def get(self, request):
try:
url = util.join_url(util.setting("alertmanager:url"), "/api/v2/alerts")
Expand Down Expand Up @@ -266,7 +269,9 @@ def get_queryset_for_matcher(matcher, klass):
return affected_projects, affected_services


class ProxySilences(View):
class ProxySilences(APIView):
permission_classes = [permissions.IsAuthenticated]

def get(self, request):
try:
url = util.join_url(util.setting("alertmanager:url"), "/api/v2/silences")
Expand Down Expand Up @@ -407,7 +412,7 @@ def get_uneditable_for_user(affected_projects, affected_services, user):


class ProxySilencesV2(APIView):
permission_classes = [permissions.AllowAny]
permission_classes = [permissions.IsAuthenticated]

def post(self, request, *args, **kwargs):
serializer = serializers.SilenceSerializer(
Expand Down Expand Up @@ -503,7 +508,9 @@ def post(self, request, *args, **kwargs):
)


class ProxyDeleteSilence(View):
class ProxyDeleteSilence(APIView):
permission_classes = [permissions.IsAuthenticated]

def delete(self, request, silence_id):
url = util.join_url(util.setting("alertmanager:url"), f"/api/v2/silence/{silence_id}")
# First, check if the silence exists
Expand Down
7 changes: 6 additions & 1 deletion promgen/static/js/promgen.vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ const app = Vue.createApp({
tgt.classList.toggle('collapse');
},
expireSilence(id) {
fetch(`/proxy/v1/silences/${id}`, { method: 'DELETE' })
fetch(`/proxy/v1/silences/${id}`, {
method: 'DELETE',
headers: {
"X-CSRFToken": document.querySelector('input[name="csrf_token"]').value,
},
})
.then(response => {
if (response.ok) {
location.reload();
Expand Down
2 changes: 1 addition & 1 deletion promgen/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
crossorigin="anonymous"
></script>
<script
src="{% static 'js/promgen.vue.js' %}?v=7"
src="{% static 'js/promgen.vue.js' %}?v=8"
integrity="{% sri_integrity_static 'js/promgen.vue.js' %}"
crossorigin="anonymous"
></script>
Expand Down