diff --git a/attributes/default.rb b/attributes/default.rb index dfbb1db..8b4a641 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -57,3 +57,10 @@ default[:pacemaker][:stonith][:per_node][:mode] = "all" # For instance: # default[:pacemaker][:stonith][:per_node][:nodes][$node][:params] = 'hostname="foo" password="bar"' default[:pacemaker][:stonith][:per_node][:nodes] = {} + +default[:pacemaker][:notifications][:agent] = "ocf:heartbeat:ClusterMon" +default[:pacemaker][:notifications][:smtp][:enabled] = false +default[:pacemaker][:notifications][:smtp][:to] = "" +default[:pacemaker][:notifications][:smtp][:from] = "" +default[:pacemaker][:notifications][:smtp][:server] = "" +default[:pacemaker][:notifications][:smtp][:prefix] = "" diff --git a/recipes/default.rb b/recipes/default.rb index 2aca330..b51d94a 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -81,3 +81,4 @@ if platform_family? "rhel" end include_recipe "pacemaker::stonith" +include_recipe "pacemaker::notifications" diff --git a/recipes/notifications.rb b/recipes/notifications.rb new file mode 100644 index 0000000..ae4d3f3 --- /dev/null +++ b/recipes/notifications.rb @@ -0,0 +1,66 @@ +# +# Author:: Vincent Untz +# Cookbook Name:: pacemaker +# Recipe:: notifications +# +# Copyright 2014, SUSE +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +smtp_resource = "smtp-notifications" +clone_smtp_resource = "cl-#{smtp_resource}" + +if node[:pacemaker][:notifications][:smtp][:enabled] + raise "No SMTP server for mail notifications!" if node[:pacemaker][:notifications][:smtp][:server].empty? + raise "No sender address for mail notifications!" if node[:pacemaker][:notifications][:smtp][:to].empty? + raise "No recipient address for mail notifications!" if node[:pacemaker][:notifications][:smtp][:from].empty? + + require 'shellwords' + + server = Shellwords.shellescape(node[:pacemaker][:notifications][:smtp][:server]) + to = Shellwords.shellescape(node[:pacemaker][:notifications][:smtp][:to]) + from = Shellwords.shellescape(node[:pacemaker][:notifications][:smtp][:from]) + + options = "-H #{server}" + options += " -T #{to}" + options += " -F #{from}" + + unless node[:pacemaker][:notifications][:smtp][:prefix].nil? || node[:pacemaker][:notifications][:smtp][:prefix].empty? + prefix = Shellwords.shellescape(node[:pacemaker][:notifications][:smtp][:prefix]) + options += " -P #{prefix}" + end + + pacemaker_primitive smtp_resource do + agent node[:pacemaker][:notifications][:agent] + params ({ "extra_options" => options }) + action :create + end + + pacemaker_clone clone_smtp_resource do + rsc smtp_resource + action [:create, :start] + end +else + pacemaker_clone clone_smtp_resource do + rsc smtp_resource + action [:stop, :delete] + only_if "crm configure show #{clone_smtp_resource}" + end + + pacemaker_primitive smtp_resource do + agent node[:pacemaker][:notifications][:agent] + action [:stop, :delete] + only_if "crm configure show #{smtp_resource}" + end +end diff --git a/spec/helpers/provider.rb b/spec/helpers/provider.rb index 38f8fc3..f06da02 100644 --- a/spec/helpers/provider.rb +++ b/spec/helpers/provider.rb @@ -6,6 +6,9 @@ require File.expand_path('cib_object', this_dir) shared_context "a Pacemaker LWRP" do before(:each) do + stub_command("crm configure show smtp-notifications") + stub_command("crm configure show cl-smtp-notifications") + runner_opts = { :step_into => [lwrp_name] }