From e5a812082ae033afb1eed82c0f2df3d0f6bdc93f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 08:53:20 +0200 Subject: Adding upstream version 2.1.6. Signed-off-by: Daniel Baumann --- agents/alerts/alert_smtp.sh.sample | 118 +++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 agents/alerts/alert_smtp.sh.sample (limited to 'agents/alerts/alert_smtp.sh.sample') diff --git a/agents/alerts/alert_smtp.sh.sample b/agents/alerts/alert_smtp.sh.sample new file mode 100644 index 0000000..62bfc41 --- /dev/null +++ b/agents/alerts/alert_smtp.sh.sample @@ -0,0 +1,118 @@ +#!/bin/sh +# +# Copyright 2016-2021 the Pacemaker project contributors +# +# The version control history for this file may have further details. +# +# This source code is licensed under the GNU General Public License version 2 +# or later (GPLv2+) WITHOUT ANY WARRANTY. +# +############################################################################## +# +# Sample configuration (cib fragment in xml notation) +# ================================ +# +# +# +# +# +# +# +# +# +# +# +# + +# Explicitly list all environment variables used, to make static analysis happy +: ${CRM_alert_version:=""} +: ${CRM_alert_recipient:=""} +: ${CRM_alert_timestamp:=""} +: ${CRM_alert_kind:=""} +: ${CRM_alert_node:=""} +: ${CRM_alert_desc:=""} +: ${CRM_alert_task:=""} +: ${CRM_alert_rsc:=""} +: ${CRM_alert_attribute_name:=""} +: ${CRM_alert_attribute_value:=""} + +email_client_default="sendmail" +email_sender_default="hacluster" +email_recipient_default="root" + +: ${email_client=${email_client_default}} +: ${email_sender=${email_sender_default}} +email_recipient="${CRM_alert_recipient-${email_recipient_default}}" + +node_name=`uname -n` +cluster_name=`crm_attribute --query -n cluster-name -q` +email_body=`env | grep CRM_alert_` + +if [ ! -z "${email_sender##*@*}" ]; then + email_sender="${email_sender}@${node_name}" +fi + +if [ ! -z "${email_recipient##*@*}" ]; then + email_recipient="${email_recipient}@${node_name}" +fi + +if [ -z ${CRM_alert_version} ]; then + email_subject="Pacemaker version 1.1.15 or later is required for alerts" +else + case ${CRM_alert_kind} in + node) + email_subject="${CRM_alert_timestamp} ${cluster_name}: Node '${CRM_alert_node}' is now '${CRM_alert_desc}'" + ;; + fencing) + email_subject="${CRM_alert_timestamp} ${cluster_name}: Fencing ${CRM_alert_desc}" + ;; + resource) + if [ ${CRM_alert_interval} = "0" ]; then + CRM_alert_interval="" + else + CRM_alert_interval=" (${CRM_alert_interval})" + fi + + if [ ${CRM_alert_target_rc} = "0" ]; then + CRM_alert_target_rc="" + else + CRM_alert_target_rc=" (target: ${CRM_alert_target_rc})" + fi + + case ${CRM_alert_desc} in + Cancelled) ;; + *) + email_subject="${CRM_alert_timestamp} ${cluster_name}: Resource operation '${CRM_alert_task}${CRM_alert_interval}' for '${CRM_alert_rsc}' on '${CRM_alert_node}': ${CRM_alert_desc}${CRM_alert_target_rc}" + ;; + esac + ;; + attribute) + # + email_subject="${CRM_alert_timestamp} ${cluster_name}: The '${CRM_alert_attribute_name}' attribute of the '${CRM_alert_node}' node was updated in '${CRM_alert_attribute_value}'" + ;; + *) + email_subject="${CRM_alert_timestamp} ${cluster_name}: Unhandled $CRM_alert_kind alert" + ;; + + esac +fi + +if [ ! -z "${email_subject}" ]; then + case $email_client in + # This sample script supports only sendmail for sending the email. + # Support for additional senders can easily be added by adding + # new cases here. + sendmail) + sendmail -t -r "${email_sender}" <<__EOF__ +From: ${email_sender} +To: ${email_recipient} +Return-Path: ${email_sender} +Subject: ${email_subject} + +${email_body} +__EOF__ + ;; + *) + ;; + esac +fi -- cgit v1.2.3