第 28 章 Triggering scripts for cluster events


A Pacemaker cluster is an event-driven system, where an event might be a resource or node failure, a configuration change, or a resource starting or stopping. You can configure Pacemaker cluster alerts to take some external action when a cluster event occurs by means of alert agents, which are external programs that the cluster calls in the same manner as the cluster calls resource agents to handle resource configuration and operation.

The cluster passes information about the event to the agent by means of environment variables. Agents can do anything with this information, such as send an email message or log to a file or update a monitoring system.

  • Pacemaker provides several sample alert agents, which are installed in /usr/share/pacemaker/alerts by default. These sample scripts may be copied and used as is, or they may be used as templates to be edited to suit your purposes. Refer to the source code of the sample agents for the full set of attributes they support.
  • If the sample alert agents do not meet your needs, you can write your own alert agents for a Pacemaker alert to call.

28.1. Installing and configuring sample alert agents

When you use one of the sample alert agents, you should review the script to ensure that it suits your needs. These sample agents are provided as a starting point for custom scripts for specific cluster environments. Note that while Red Hat supports the interfaces that the alert agents scripts use to communicate with Pacemaker, Red Hat does not provide support for the custom agents themselves.

28.1.1. Prerequisites

  • Install the agent on each node in the cluster

    # install --mode=0755 /usr/share/pacemaker/alerts/alert_file.sh.sample /var/lib/pacemaker/alert_file.sh

    After you have installed the script, you can create an alert that uses the script.

You can install the alert_file.sh alert agent and configure an alert to log events to a file. Alert agents run as the user hacluster, which has a minimal set of permissions.

Procedure

  1. On each node in the cluster, install the alert_file.sh.sample script as alert_file.sh.

    # install --mode=0755 /usr/share/pacemaker/alerts/alert_file.sh.sample /var/lib/pacemaker/alert_file.sh
  2. On each node in the cluster, create the log file that will be used to record the events.

    # touch /var/log/pcmk_alert_file.log
    1. Change the ownership of the file pcmk_alert_file.log to user hacluster.

      # chown hacluster:haclient /var/log/pcmk_alert_file.log
    2. Change the permissions for the file pcmk_alert_file.log to read and write for the user hacluster.

      # chmod 600 /var/log/pcmk_alert_file.log
  3. On one node in the cluster, create the alert.

    # pcs alert create id=alert_file description="Log events to a file." path=/var/lib/pacemaker/alert_file.sh
  4. Add the path to the log file as the recipient for the alert.

    # pcs alert recipient add alert_file id=my-alert_logfile value=/var/log/pcmk_alert_file.log

You can install the alert_snmp.sh.sample script as alert_snmp.sh and configure an alert that uses the installed alert_snmp.sh alert agent to send cluster events as SNMP traps. By default, the script will send all events except successful monitor calls to the SNMP server.

Procedure

  1. On each node in the cluster, install the alert_snmp.sh.sample script as alert_snmp.sh.

    # install --mode=0755 /usr/share/pacemaker/alerts/alert_snmp.sh.sample /var/lib/pacemaker/alert_snmp.sh
  2. On one node in the cluster, configure an alert that uses the alert_snmp.sh agent, configuring the timestamp format as a meta option.

    # pcs alert create id=snmp_alert path=/var/lib/pacemaker/alert_snmp.sh meta timestamp-format="%Y-%m-%d,%H:%M:%S.%01N"
  3. Configure a recipient for the alert

    # pcs alert recipient add snmp_alert value=192.168.1.2
  4. Display the alert configuration.

    # pcs alert
    Alerts:
     Alert: snmp_alert (path=/var/lib/pacemaker/alert_snmp.sh)
      Meta options: timestamp-format=%Y-%m-%d,%H:%M:%S.%01N.
      Recipients:
       Recipient: snmp_alert-recipient (value=192.168.1.2)

You can install the alert_smtp.sh agent and then configure an alert that uses the installed alert agent to send cluster events as email messages.

Procedure

  1. On each node in the cluster, install the alert_smtp.sh.sample script as alert_smtp.sh.

    # install --mode=0755 /usr/share/pacemaker/alerts/alert_smtp.sh.sample /var/lib/pacemaker/alert_smtp.sh
  2. On one node in the cluster, configure an alert to send cluster events as email messages.

    # pcs alert create id=smtp_alert path=/var/lib/pacemaker/alert_smtp.sh options email_sender=donotreply@example.com
  3. Configure a recipient for the alert.

    # pcs alert recipient add smtp_alert value=admin@example.com
  4. Display the alert configuration.

    # pcs alert
    Alerts:
     Alert: smtp_alert (path=/var/lib/pacemaker/alert_smtp.sh)
      Options: email_sender=donotreply@example.com
      Recipients:
       Recipient: smtp_alert-recipient (value=admin@example.com)
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部