diff --git a/salt_observer/assets/js/events.js b/salt_observer/assets/js/events.js index 417032c896fbaaa14d1813b5b03e55c5910a728d..a075e91fd54633d3991d553840cd2da06ce00c91 100644 --- a/salt_observer/assets/js/events.js +++ b/salt_observer/assets/js/events.js @@ -2,7 +2,7 @@ $(function() { // ATTENTION: set the token before importing this script - var socket = new WebSocket('ws://localhost:8002/all_events/' + token); + var socket = new WebSocket('wss://' + host + ':' + port + '/all_events/' + token); // Get Salt's "real time" event stream. socket.onopen = function() { diff --git a/salt_observer/private_settings.example.py b/salt_observer/private_settings.example.py index a77bc23e229f7243108e2de10132f22b4beb84e5..1d1dd0d9a3cbb6f87c1b4ac371beb60283285dd4 100644 --- a/salt_observer/private_settings.example.py +++ b/salt_observer/private_settings.example.py @@ -33,7 +33,7 @@ SESSION_COOKIE_NAME = "cookie_session_salt_observer" SALT_API = { 'cherrypy': { 'host': 'localhost', - 'port': 8989, + 'port': 8001, 'protocol': 'http', }, 'tornado': { diff --git a/salt_observer/static/js/events.min.js b/salt_observer/static/js/events.min.js index 3090029bf3427e84ae945183a7877255472696c8..031ab670c6b9a84f17ecbee8f222d8bfcb9a8e57 100644 --- a/salt_observer/static/js/events.min.js +++ b/salt_observer/static/js/events.min.js @@ -1 +1 @@ -$(function(){function t(t){var e=$("#event-template").clone();e.removeAttr("id"),e.find(".icon").html('<i class="fa fa-fw fa-2x fa-bug"></i>'),e.find(".title").text(t.data.id),e.find(".message").html("<pre>"+JSON.stringify(t.data)+"</pre>"),e.find(".tag").text(t.tag),e.find(".minion-id").text(t.data.id),$("#eventholder").prepend(e),setTimeout(function(){e.remove()},3e5)}function e(t){var e=$("#job-template").clone();e.removeAttr("id"),e.find(".timestamp").text(t.data._stamp),e.find(".tag").text(t.tag),$("#jobholder").prepend(e),setTimeout(function(){e.remove()},6e4)}var n=new WebSocket("ws://localhost:8002/all_events/"+token);n.onopen=function(){n.send("websocket client ready"),console.log("Connected!"),$("#conn_status").html('<i class="fa fa-fw fa-check"></i> Connected!')},n.onerror=function(t){console.debug("Error!",t),$("#conn_status").html('<i class="fa fa-fw fa-times"></i> Connection failed!')},n.onmessage=function(n){console.log(n);var o=JSON.parse(n.data.substring(6));o.tag.startsWith("salt/job/")?e(o):t(o)}}); \ No newline at end of file +$(function(){function t(t){var e=$("#event-template").clone();e.removeAttr("id"),e.find(".icon").html('<i class="fa fa-fw fa-2x fa-bug"></i>'),e.find(".title").text(t.data.id),e.find(".message").html("<pre>"+JSON.stringify(t.data)+"</pre>"),e.find(".tag").text(t.tag),e.find(".minion-id").text(t.data.id),$("#eventholder").prepend(e),setTimeout(function(){e.remove()},3e5)}function e(t){var e=$("#job-template").clone();e.removeAttr("id"),e.find(".timestamp").text(t.data._stamp),e.find(".tag").text(t.tag),$("#jobholder").prepend(e),setTimeout(function(){e.remove()},6e4)}var n=new WebSocket("wss://"+host+":"+port+"/all_events/"+token);n.onopen=function(){n.send("websocket client ready"),console.log("Connected!"),$("#conn_status").html('<i class="fa fa-fw fa-check"></i> Connected!')},n.onerror=function(t){console.debug("Error!",t),$("#conn_status").html('<i class="fa fa-fw fa-times"></i> Connection failed!')},n.onmessage=function(n){console.log(n);var o=JSON.parse(n.data.substring(6));o.tag.startsWith("salt/job/")?e(o):t(o)}}); \ No newline at end of file diff --git a/salt_observer/templates/events.html b/salt_observer/templates/events.html index 4faa4637bbac336445b4cb6f335480a7c0ad83d6..76a02b8b22e12ce3a343ee4a706cd57966d15537 100644 --- a/salt_observer/templates/events.html +++ b/salt_observer/templates/events.html @@ -11,6 +11,8 @@ {% block post-script %} <script> + var host = "{{ tornado_host }}"; + var port = "{{ tornado_port }}"; var token = "{{ request.session.salt_tornado_token }}"; </script> <script src="{% static 'js/events.min.js' %}"></script> diff --git a/salt_observer/views.py b/salt_observer/views.py index c5b3f47b2e6b3cd16dbe418497363d2aa080491d..05ad8bd36eb49d07e9122f70c85ab93d35d7db3c 100644 --- a/salt_observer/views.py +++ b/salt_observer/views.py @@ -158,3 +158,11 @@ class DomainEdit(MarkdownEditMixin, UpdateView, DomainDetail): class EventView(TemplateView): template_name = 'events.html' + + def get_context_data(self, *args, **kwargs): + context = super().get_context_data(*args, **kwargs) + context.update({ + 'tornado_host': settings.SALT_API['tornado']['host'], + 'tornado_port': settings.SALT_API['tornado']['port'], + }) + return context