Browse Source

Added http log support.

Martin Edenhofer 9 years ago
parent
commit
e42e373de4

+ 10 - 11
app/assets/javascripts/app/controllers/_integration/_base.coffee

@@ -16,6 +16,8 @@ class App.ControllerIntegrationBase extends App.Controller
     return if !@authenticate(false, 'Admin')
     @title @featureName, true
 
+    @initalRender = true
+
     @subscribeId = App.Setting.subscribe(@render, initFetch: true, clear: false)
 
   switch: =>
@@ -23,17 +25,14 @@ class App.ControllerIntegrationBase extends App.Controller
     App.Setting.set(@featureIntegration, value)
 
   render: =>
-    localEl = $( App.view('integration/base')(
-      header: @featureName
-      description: @description
-      feature: @featureIntegration
-      featureEnabled: App.Setting.get(@featureIntegration)
-    ))
-    @form localEl
-    @html localEl
-
-  form: (localEl) ->
-    console.log('implement own form method')
+    if @initalRender
+      @html App.view('integration/base')(
+        header: @featureName
+        description: @description
+        feature: @featureIntegration
+        featureEnabled: App.Setting.get(@featureIntegration)
+      )
+      @initalRender = false
 
   submit: (e) =>
     e.preventDefault()

+ 3 - 2
app/assets/javascripts/app/controllers/_integration/icinga.coffee

@@ -7,10 +7,11 @@ class Index extends App.ControllerIntegrationBase
     ['If the host and service is recovered again, the ticket will be closed automatically.']
   ]
 
-  form: (localeEl) ->
+  render: =>
+    super
     new App.SettingsForm(
       area: 'Integration::Icinga'
-      el: localeEl.find('.js-form')
+      el: @$('.js-form')
     )
 
 class State

+ 3 - 2
app/assets/javascripts/app/controllers/_integration/nagios.coffee

@@ -7,10 +7,11 @@ class Index extends App.ControllerIntegrationBase
     ['If the host and service is recovered again, the ticket will be closed automatically.']
   ]
 
-  form: (localeEl) ->
+  render: =>
+    super
     new App.SettingsForm(
       area: 'Integration::Nagios'
-      el: localeEl.find('.js-form')
+      el: @$('.js-form')
     )
 
 class State

+ 11 - 5
app/assets/javascripts/app/controllers/_integration/slack.coffee

@@ -7,7 +7,8 @@ class Index extends App.ControllerIntegrationBase
     ['To setup this Service you need to create a new |"Incoming webhook"| in your %s integration panel, and enter the Webhook URL below.', 'Slack']
   ]
 
-  form: (localEl) =>
+  render: =>
+    super
 
     params = App.Setting.get(@featureConfig)
     if params && params.items
@@ -24,10 +25,10 @@ class Index extends App.ControllerIntegrationBase
       { name: 'types',    display: 'Trigger',  tag: 'checkbox', options: options, 'null': false, class: 'vertical', note: 'Where notification is sent.' },
       { name: 'group_id', display: 'Group',    tag: 'select', relation: 'Group', multiple: true, 'null': false, note: 'Only for this groups.' },
       { name: 'webhook',  display: 'Webhook',  tag: 'input', type: 'text', limit: 200, 'null': false, placeholder: 'https://hooks.slack.com/services/...' },
-      { name: 'username', display: 'username', tag: 'input', type: 'text', limit: 100, 'null': false, placeholder: 'username' },
-      { name: 'channel',  display: 'channel',  tag: 'input', type: 'text', limit: 100, 'null': true, placeholder: '#channel' },
+      { name: 'username', display: 'Username', tag: 'input', type: 'text', limit: 100, 'null': false, placeholder: 'username' },
+      { name: 'channel',  display: 'Channel',  tag: 'input', type: 'text', limit: 100, 'null': true, placeholder: '#channel' },
     ]
-    console.log('p', params)
+
     settings = []
     for item in configureAttributes
       setting =
@@ -54,7 +55,12 @@ class Index extends App.ControllerIntegrationBase
         params: localParams
       )
 
-    localEl.find('.js-form').html(formEl)
+    @$('.js-form').html(formEl)
+
+    new App.HttpLog(
+      el: @$('.js-log')
+      facility: 'slack_webhook'
+    )
 
 class State
   @current: ->

+ 55 - 0
app/assets/javascripts/app/controllers/widget/http_log.coffee

@@ -0,0 +1,55 @@
+class App.HttpLog extends App.Controller
+  events:
+    'click .js-record': 'show'
+
+  constructor: ->
+    super
+    @fetch()
+    @records = []
+
+  fetch: =>
+    @ajax(
+      id:    'http_logs'
+      type:  'GET'
+      url:   "#{@apiPath}/http_logs/#{@facility}"
+      data:
+        limit: @limit || 50
+      processData: true
+      success: (data) =>
+        @records = data
+        @render()
+    )
+
+  render: =>
+    @html App.view('widget/http_log')(
+      records: @records
+    )
+    #@delay(message, 2000)
+
+  show: (e) =>
+    e.preventDefault()
+    record_id = $(e.currentTarget).data('id')
+    for record in @records
+      if record_id.toString() is record.id.toString()
+        new Show(
+          record: record
+          container: @el.closest('.content')
+        )
+        return
+
+class Show extends App.ControllerModal
+  authenticateRequired: true
+  large: true
+  head: 'HTTP Log'
+  buttonClose: true
+  buttonCancel: false
+  buttonSubmit: false
+
+  constructor: ->
+    super
+
+  content: ->
+    console.log('cont')
+    App.view('widget/http_log_show')(
+      record: @record
+    )

+ 1 - 0
app/assets/javascripts/app/views/integration/base.jst.eco

@@ -14,4 +14,5 @@
     <% end %>
   <% end %>
   <div class="js-form"></div>
+  <div class="js-log"></div>
 </div>

+ 21 - 0
app/assets/javascripts/app/views/widget/http_log.jst.eco

@@ -0,0 +1,21 @@
+<hr>
+
+<%- @T('Recent logs') %>
+  <div class="settings-entry">
+    <table class="settings-list" style="width: 100%;">
+      <thead>
+        <tr>
+          <th width="10%"><%- @T('Direction') %>
+          <th><%- @T('Request') %>
+          <th width="15%"><%- @T('Created at') %>
+      </thead>
+      <tbody>
+<% for record in @records: %>
+        <tr data-id="<%= record.id %>" class="js-record">
+          <td><%- @T(record.direction) %>
+          <td><a href="#"><%= record.status %> <%= record.method %> <%= record.url %></a>
+          <td><%- @datetime(record.created_at) %>
+<% end %>
+      </tbody>
+    </table>
+  </div>

+ 27 - 0
app/assets/javascripts/app/views/widget/http_log_show.jst.eco

@@ -0,0 +1,27 @@
+<div class="settings-entry">
+  <table class="settings-list" style="width: 100%;">
+    <tbody>
+      <tr>
+        <td width="20%"><%- @T('Direction') %>
+        <td><%- @T(@record.direction) %>
+      <tr>
+        <td><%- @T('URL') %>
+        <td><%= @record.url %>
+      <tr>
+        <td><%- @T('Method') %>
+        <td><%= @record.method %>
+      <tr>
+        <td><%- @T('Status') %>
+        <td><%= @record.status %>
+      <tr>
+        <td><%- @T('Request') %>
+        <td><%- App.Utils.text2html(@record.request.content) %>
+      <tr>
+        <td><%- @T('Response') %>
+        <td><%- App.Utils.text2html(@record.response.content) %>
+      <tr>
+        <td><%- @T('Created at') %>
+        <td><%- @datetime(@record.created_at) %>
+    </tbody>
+  </table>
+</div>

+ 4 - 1
app/assets/stylesheets/zammad.scss

@@ -6929,7 +6929,9 @@ output {
   background: white;
   table-layout: auto;
   margin-bottom: 20px;
-  
+  word-break: break-all;
+  word-wrap: break-word;
+
   &.is-invalid {
     border-radius: 3px;
     box-shadow: 
@@ -6975,6 +6977,7 @@ output {
     letter-spacing: 0.05em;
     background: hsl(197,20%,93%);
     border-bottom: none;
+    word-break: normal;
   }
 
   td.empty-cell {

+ 23 - 0
app/controllers/http_logs_controller.rb

@@ -0,0 +1,23 @@
+# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
+
+class HttpLogsController < ApplicationController
+  before_action :authentication_check
+
+  # GET /http_logs/:facility
+  def index
+    return if deny_if_not_role(Z_ROLENAME_ADMIN)
+    list = if params[:facility]
+             HttpLog.where(facility: params[:facility]).order('created_at DESC').limit(params[:limit] || 50)
+           else
+             HttpLog.order('created_at DESC').limit(params[:limit] || 50)
+           end
+    model_index_render_result(list)
+  end
+
+  # POST /http_logs
+  def create
+    return if deny_if_not_role(Z_ROLENAME_ADMIN)
+    model_create_render(HttpLog, params)
+  end
+
+end

Some files were not shown because too many files changed in this diff