第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/alertsby 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.shAfter 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
On each node in the cluster, install the
alert_file.sh.samplescript asalert_file.sh.# install --mode=0755 /usr/share/pacemaker/alerts/alert_file.sh.sample /var/lib/pacemaker/alert_file.shOn each node in the cluster, create the log file that will be used to record the events.
# touch /var/log/pcmk_alert_file.logChange the ownership of the file
pcmk_alert_file.logto userhacluster.# chown hacluster:haclient /var/log/pcmk_alert_file.logChange the permissions for the file
pcmk_alert_file.logto read and write for the userhacluster.# chmod 600 /var/log/pcmk_alert_file.log
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.shAdd 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
On each node in the cluster, install the
alert_snmp.sh.samplescript asalert_snmp.sh.# install --mode=0755 /usr/share/pacemaker/alerts/alert_snmp.sh.sample /var/lib/pacemaker/alert_snmp.shOn one node in the cluster, configure an alert that uses the
alert_snmp.shagent, 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"Configure a recipient for the alert
# pcs alert recipient add snmp_alert value=192.168.1.2Display 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
On each node in the cluster, install the
alert_smtp.sh.samplescript asalert_smtp.sh.# install --mode=0755 /usr/share/pacemaker/alerts/alert_smtp.sh.sample /var/lib/pacemaker/alert_smtp.shOn 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.comConfigure a recipient for the alert.
# pcs alert recipient add smtp_alert value=admin@example.comDisplay 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)