Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F1300205
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Nov 19, 12:19 PM
Size
9 KB
Mime Type
text/x-diff
Expires
Fri, Nov 21, 12:19 PM (19 h, 3 m)
Engine
blob
Format
Raw Data
Handle
294806
Attached To
rARCHIVING archiving
View Options
diff --git a/app/models/job_template.rb b/app/models/job_template.rb
index 9d95bc8..acb9030 100644
--- a/app/models/job_template.rb
+++ b/app/models/job_template.rb
@@ -1,114 +1,114 @@
# JobTemplate class is a helper class that enables us to configure Bacula job
# configurations, without messing with Bacula's native models (Job).
# It has a unique:
#
# * host
# * fileset
# * schedule
class JobTemplate < ActiveRecord::Base
establish_connection ARCHIVING_CONF
enum job_type: { backup: 0, restore: 1, verify: 2, admin: 3 }
belongs_to :host
belongs_to :fileset
belongs_to :schedule
validates :name, :fileset_id, presence: true
validates :schedule_id, presence: true, unless: :restore?
validates :name, uniqueness: { scope: :host }
validates_with NameValidator
before_save :set_job_type
after_save :notify_host
scope :enabled, -> { where(enabled: true) }
# Constructs an array where each element is a line for the Job's bacula config
#
# @return [Array]
def to_bacula_config_array
['Job {'] +
options_array.map { |x| " #{x}" } +
job_settings.map { |k,v| " #{k.capitalize} = #{v}" } +
['}']
end
# Fetches the Job's priority
def priority
job_settings[:priority]
end
# Helper method for the job template's enabled status
def enabled_human
enabled? ? 'yes' : 'no'
end
# Helper method for the job template's schedule name
#
# @return [String] The schedule's name or nothing
def schedule_human
schedule.present? ? schedule.name : '-'
end
# Generates a name that will be used for the configuration file.
# It is the name that will be sent to Bacula through the configuration
# files.
#
# @return [String]
def name_for_config
"#{host.name} #{name}"
end
# Sends a hot backup request to Bacula via BaculaHandler
def backup_now
return false if not (enabled? && baculized? && backup?)
host.backup_now(name)
end
private
def name_format
unless name =~ /^[a-zA-Z0-1\.-_ ]+$/
self.errors.add(:name, :format)
end
end
def notify_host
host.recalculate
end
# Sets the default job_type as backup
def set_job_type
self.job_type = :backup if job_type.nil?
end
def options_array
result = [
"Name = \"#{name_for_config}\"",
"Enabled = #{enabled_human}",
"FileSet = \"#{fileset.name_for_config}\"",
"Client = \"#{host.name}\"",
"Type = \"#{job_type.capitalize}\"",
"Schedule = \"#{schedule.name_for_config}\""
]
if client_before_run_file.present?
result += ["Client Run Before Job = \"#{client_before_run_file}\""]
end
if client_after_run_file.present?
result += ["Client Run After Job = \"#{client_after_run_file}\""]
end
result
end
# Fetches and memoizes the general configuration settings for Jobs
#
# @see ConfigurationSetting.current_job_settings
# @return [Hash] containing the settings
def job_settings
- messages = host.email_recipients.any? ? "message_#{host.name}" : :Standard
+ messages = host.email_recipients.any? ? host.message_name : :Standard
@job_settings ||= ConfigurationSetting.current_job_settings.merge(messages: messages)
end
end
diff --git a/app/views/hosts/show.html.erb b/app/views/hosts/show.html.erb
index ee60e5e..ae9961b 100644
--- a/app/views/hosts/show.html.erb
+++ b/app/views/hosts/show.html.erb
@@ -1,49 +1,56 @@
<%= notifier(@host.display_message) unless @host.deployed? %>
<div class="row right">
<% if @host.can_be_disabled? %>
<%= link_to 'Disable client', disable_host_path(@host), method: :post,
data: { confirm: 'This will disable the client. Are you sure?' },
class: "btn btn-warning", role: "button" %>
<% end %>
<%= link_to 'Remove client', host_path(@host), method: :delete,
data: { confirm: 'This will remove the client from Bacula. Are you sure?' },
class: "btn btn-danger", role: "button" %>
</div>
<h2>Configuration for <%= @host.name %>
<small><%= host_status_label(@host) %></small>
</h2>
<br/>
<div class="row">
<div class="col-xs-4">
<h3>Host Details</h3>
</div>
<div class="col-xs-6">
<h3>Jobs</h3>
</div>
</div>
<div class="row">
<%= render partial: "host_details" %>
<%= render partial: "jobs/job_templates" %>
</div>
<div class="row">
<div class="col-xs-4">
<h3>Client FileDeamon Config</h3>
<pre class="pre">
<%= @host.bacula_fd_filedeamon_config %>
</pre>
</div>
<div class="col-xs-4">
<h3>Client Director Config</h3>
<pre class="pre">
<%= @host.bacula_fd_director_config %>
</pre>
</div>
+ <div class="col-xs-4">
+ <h3>Client Messages Config</h3>
+ <pre class="pre">
+<%= @host.bacula_fd_messages_config %>
+ </pre>
+ </div>
+
</div>
<%= render partial: 'jobs/modals' %>
diff --git a/lib/configuration/host.rb b/lib/configuration/host.rb
index 764e620..8559026 100644
--- a/lib/configuration/host.rb
+++ b/lib/configuration/host.rb
@@ -1,124 +1,139 @@
module Configuration
# Helper module to add configuration getters for Host
module Host
# Constructs the final Bacula configuration for the host by appending configs for
#
# * Client
# * Jobs
# * Schedules
# * Filesets
#
# by calling their `to_bacula_config_array` methods.
#
# @return [Array] containing each element's configuration line by line
def baculize_config
templates = job_templates.includes(:fileset, :schedule)
result = [self] + templates.map {|x| [x, x.fileset, x.schedule] }.flatten.compact.uniq
result.map(&:to_bacula_config_array)
end
# Constructs the final Bacula configuration for the host by appending configs for
#
# * Client
# * Jobs
# * Schedules
# * Filesets
#
# by calling their `to_bacula_config_array` methods.
#
# It hides the password.
#
# @return [Array] containing each element's configuration line by line
def baculize_config_no_pass
baculize_config.join("\n").gsub(/Password = ".*"$/, 'Password = "*************"')
end
# Constructs an array where each element is a line for the Client's bacula config
#
# @return [Array]
def to_bacula_config_array
[
"Client {",
" Name = #{name}",
" Address = #{fqdn}",
" FDPort = #{port}",
" Catalog = #{client_settings[:catalog]}",
" Password = \"#{password}\"",
" File Retention = #{file_retention} #{file_retention_period_type}",
" Job Retention = #{job_retention} #{job_retention_period_type}",
" AutoPrune = #{auto_prune_human}",
"}"
] + message_config
end
# Constructs the messages bacula resource
#
# @return [Array]
def message_config
return [] if email_recipients.empty?
[
"Messages {",
- " Name = message_#{name}",
+ " Name = #{message_name}",
" mailcommand = \"#{mail_command}\"",
" operatorcommand = \"#{operator_command}\"",
" mail = root = all, !skipped",
" operator = root = mount",
" console = all, !skipped, !saved",
" append = \"/var/log/bacula/bacula.log\" = all, !skipped",
" catalog = all",
"}"
]
end
# Fetches the Director resource for the file-deamon configuration
# file
def bacula_fd_director_config
[
'Director {',
" Name = \"#{Archiving.settings[:director_name]}\"",
" Password = \"*********\"",
'}'
].join("\n")
end
# Fetches the FileDeamon resource for the file-deamon configuration
def bacula_fd_filedeamon_config
[
'FileDeamon {',
" Name = #{name}",
" FDport = #{port}",
' WorkingDirectory = /var/lib/bacula',
' Pid Directory = /var/run/bacula',
' Maximum Concurrent Jobs = 10',
' FDAddress = 0.0.0.0',
'}'
].join("\n")
end
+ # Fetches the Message resource for the file-deamon configuration file
+ def bacula_fd_messages_config
+ [
+ 'Messages {',
+ " Name = #{message_name}",
+ " director = #{Archiving.settings[:director_name]} = all, !skipped, !restored",
+ '}'
+ ].join("\n")
+ end
+
+ # The name that the client will use for its messages
+ def message_name
+ "message_#{name}_#{Digest::MD5.hexdigest(created_at.to_s + name).first(10)}"
+ end
+
private
def mail_command
"#{mail_general}" <<
" -t #{email_recipients.join(' ')}" <<
" -u \\\"\[Bacula\]: %t %e of %c %l\\\" -m \\\"Bacula Report\\\""
end
def operator_command
"#{mail_general}"
" -t #{settings[:operator_email]}" <<
" -u \\\"\[Bacula\]: Intervention needed for %j\\\" -m \\\"Intervention needed %r\\\""
end
def mail_general
"/usr/bin/sendEmail -f #{settings[:default_sender]}" <<
" -s #{settings[:address]}:#{settings[:port]}" <<
" -o tls=yes -xu #{settings[:user_name]} -xp #{settings[:password]}"
end
def settings
Archiving.settings[:mail_settings]
end
end
end
diff --git a/spec/requests/clients_spec.rb b/spec/requests/clients_spec.rb
deleted file mode 100644
index 485922e..0000000
--- a/spec/requests/clients_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require 'spec_helper'
-
-describe ClientsController do
- let(:host) { FactoryGirl.create(:host, :with_client) }
- let(:user) { FactoryGirl.create(:user) }
-
- before do
- allow_any_instance_of(ApplicationController).to receive(:current_user) { user }
- host.users << user
- end
-
- describe '#index' do
- it 'fetches the host' do
- get clients_path
- expect(response.body).to match(host.name)
- end
- end
-end
Event Timeline
Log In to Comment