How can I receive a notification if one of my services (eg. MariaDB) dies?
Platform.sh DevRel
I’d like to get an alert if a service dies or is unreachable.
0
Comments
One way of doing this would be to set up a
cronjob to periodically ping MariaDB and send an e-mail to a specified address based on that ping status.Allow outgoing emails in environment configuration (if necessary)
Email support can be set up in each environment, and by default it is already enabled on
masterand disabled elsewhere. You can enable email through the environment configuration settings in the Web UI, or by using the Platform.sh CLI:You can find more information about email on Platform.sh in the documentation.
Set up a cron job in
.platform.app.yamlto ping MariaDBIn your
.platform.app.yamlset up acronjob for the service you want to check the status of. Here an exit code0means our ping was successful and MariaDB is running fine.If you named your relationships differently, you will need to modify
mysql.internalto the correct name. (For example,database.internal, etc.)ping()may not be the most robust test case, and is only used here for a simple example. Check themysqladmindocumentation to find the test that best suits your needs.Write a php file that handles
mail()for thepingstatusIn the project directory, create a subdirectory called
notifications, and within that subdirectory write aservice_notify.phpfile:Verify
Our project is set up to email
you@example.comwith the status of a successfulpingonmysql.internalevery 10 minutes. That status email will look like this.Set up MySQL down notifications
The preceeding steps send out an e-mail that includes the status message of a successful ping on
mysql.internal. That is, it will e-mail us every ten minutes to let us know everything is fine.To modify the notification to let us know that MySQL has died or is unreachable, modify the if statement in
.platform.app.yamlcronjob to:This way, when a ping delivers an exit code of
1, an email is sent!Please sign in to leave a comment.