diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3d57e55..dda37b9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,13 +1,25 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception helper_method :current_user protected def current_user @current_user ||= User.last end + + def fetch_logs + days_ago = params.fetch(:days_back, 7).to_i rescue 7 + + if @client + @logs = Log.includes(:job).joins(job: :client).where(Client: { ClientId: @client.id }) + else + @logs = Log.includes(:job).joins(job: { client: { host: :users } }). + where(users: { id: current_user.id }) + end + @logs = @logs.where('Time > ?', days_ago.days.ago).order(Time: :desc)#.limit(10) + end end diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 46bc189..b958e7b 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -1,30 +1,31 @@ class ClientsController < ApplicationController before_action :set_client, only: :show + before_action :fetch_logs # GET /clients def index @client_ids = Client.for_user(current_user.id).pluck(:ClientId) @clients = Client.where(ClientId: @client_ids).includes(:jobs) @active_jobs = Job.running.where(ClientId: @client_ids).group(:ClientId).count @hosts = current_user.hosts.not_baculized get_charts end # GET /clients/1 def show @client_ids = [@client.id] get_charts end private def set_client @client = Client.for_user(current_user.id).find(params[:id]) end def get_charts days_ago = params.fetch(:days_back, 7).to_i rescue 7 @job_status = ChartGenerator.job_statuses(@client_ids, days_ago) @job_stats = ChartGenerator.job_stats(@client_ids, days_ago - 1) end end diff --git a/app/models/log.rb b/app/models/log.rb index 7eba933..3955614 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -1,11 +1,17 @@ class Log < ActiveRecord::Base self.table_name = :Log self.primary_key = :LogId alias_attribute :log_id, :LogId alias_attribute :job_id, :JobId alias_attribute :time, :Time alias_attribute :log_text, :LogText belongs_to :job, foreign_key: :JobId + + def time_formatted + if time + I18n.l(time, format: :long) + end + end end diff --git a/app/views/clients/_log.html.erb b/app/views/clients/_log.html.erb new file mode 100644 index 0000000..589a415 --- /dev/null +++ b/app/views/clients/_log.html.erb @@ -0,0 +1,8 @@ + + <%= log.log_id %> + <%= log.job.name %> + <%= log.time_formatted %> +
+<%= log.log_text %>
+  
+ diff --git a/app/views/clients/_logs.html.erb b/app/views/clients/_logs.html.erb new file mode 100644 index 0000000..adcfe45 --- /dev/null +++ b/app/views/clients/_logs.html.erb @@ -0,0 +1,23 @@ +
+
+

Logs

+
+ +
+
+ + + + + + + + + + + <%= render partial: 'log', collection: @logs %> + +
LogIdJobTimeText
+
+
+
diff --git a/app/views/clients/index.html.erb b/app/views/clients/index.html.erb index a218eff..e948e59 100644 --- a/app/views/clients/index.html.erb +++ b/app/views/clients/index.html.erb @@ -1,53 +1,54 @@
<%= link_to 'New Client', new_host_path, class: 'btn btn-primary', role: 'button' %>

My Bacula Clients

<%= render partial: 'client', collection: @clients %>
Name Uname Active Jobs Last Backup FileRetention (days) JobRetention (days) Space Used File count AutoPrune
<% if @hosts.any? %>

My Pending Hosts

<%= render partial: 'hosts/host', collection: @hosts %>
Name FQDN Port Password FileRetention (days) JobRetention (days) AutoPrune Created At
<% end %> <%= render partial: 'client_graphs', locals: { path: clients_path } %> +<%= render partial: 'logs' %> diff --git a/app/views/clients/show.html.erb b/app/views/clients/show.html.erb index 4febfeb..d134858 100644 --- a/app/views/clients/show.html.erb +++ b/app/views/clients/show.html.erb @@ -1,40 +1,44 @@

<%= notice %>

<% if @client.host %>
<%= link_to 'Manage Client', host_path(@client.host), class: "btn btn-primary", role: "button" %>
<% end %>

<%= @client.name %>

Client Details

Bacula Jobs

<%= render partial: 'client_details' %>
<%= render partial: 'jobs' %>

Recent Jobs

<%= render partial: 'recent_jobs' %>

<%= link_to 'Back to clients', clients_path %> <%= render partial: 'client_graphs', locals: { path: client_path(@client) } %> + +
+ +<%= render partial: 'logs' %>