第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.

28.1.2. Configuring an alert that uses the alert_file.sh alert agent

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

28.1.3. Configuring an alert that uses the alert_snmp.sh alert agent

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)

28.1.4. Configuring an alert that uses the alert_smtp.sh alert agent

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

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2026 Red Hat
トップに戻る