Adding an e-mail alert

The last thing we are going to add should be considered a requirement when building a high-availability PostgreSQL cluster. Any time the status of Pacemaker changes, we can have it transmit an e-mail alerting us to the activity. Not only is this possible with Pacemaker, it's relatively easy to set up.

This recipe will outline the steps necessary to add an e-mail alert to Pacemaker.

Getting ready

As we're continuing to configure Pacemaker, make sure you've followed all the previous recipes.

How to do it...

Perform these steps on any Pacemaker node as the root user:

  1. Add a PostgreSQL primitive to Pacemaker with crm:
    crm configure primitive pg_mail ocf:heartbeat:MailTo 
        params email="[email protected]" 
               subject="Pacemaker cluster status changed: "
    
  2. Clean up any errors that might have accumulated with crm:
    crm resource cleanup pg_mail
    
  3. Display the status of our new e-mail alert with crm:
    crm resource status
    

How it works...

To add an e-mail alert, we need to configure another primitive with crm. We name this resource pg_mail so that it fits in with the other services that we've configured so far. As always, we need a resource agent for Pacemaker to invoke when necessary, and the ocf:heartbeat:MailTo agent works well for our use case.

The MailTo agent is not a regular resource, as it does not represent any actual system service. It's more of a defined action that Pacemaker should invoke while managing other cluster resources. This means it's essentially useless until we associate it with another Pacemaker primitive.

The MailTo agent also has two parameters (params) we are interested in setting. We begin by setting email to an e-mail address for a recipient tasked with monitoring the PostgreSQL cluster. In most cases, this is either a single DBA or the entire team. In any case, we strongly suggest that you transmit these alerts to anyone associated with the PostgreSQL database, in case one or more members of the team are unavailable.

Tip

If you don't already have one, speak with the infrastructure team or whoever is in charge of setting up e-mail lists at your company. Using a generic address that reaches everyone in the team, Pacemaker won't need to be changed whenever you hire or fire a DBA.

The next setting that concerns us is the subject of the message. If we don't set this, Pacemaker uses a suitable default, but it's good to have more control over the messages in case we want to set up e-mail rules or filters. Use any message you like, but there are a couple of important notes:

  • Spaces must be escaped by a backslash (). Otherwise, Pacemaker will print out a lot of errors and refuse to add the primitive.
  • The subject is more of a prefix. Pacemaker will add more detail to the subject and body of the e-mail when the message is sent.

With that said, we are now ready to clean up and view our list of resources. Let's see the output of resource status on our test system:

How it works...

We can see from this output that pg_mail is listed as Started, even though it doesn't do anything by itself. We'll be fixing this soon enough.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.202.61