How To Send Alerts from the Database

Rupert Harwood -

Should you need to, you can send an alert from SQL with the following syntax.

select alert(<alert level>, '<alert text>');

The alert levels are as listed:

0 - CRITICAL
1 - ERROR
2 - WARNING
3 - INFO

The alert text can be anything you desire.

Example:

mysql> select alert(3,'I am a test alert');
+------------------------------+
| alert(3,'I am a test alert') |
+------------------------------+
|                            0 |
+------------------------------+
1 row in set (0.00 sec)

This will cause an alert to be sent with the following output:

Severity: INFO
Date: 2016-03-29 22:36:13.084133 UTC
Host: node001
HWID: 00:30:48:be:63:88
Cluster: Clustrix_cluster
Version: 5.0.45-clustrix-7.0.1
Image Version: CentOS release 6.5 (Final)
Message: [SQL] I am a test alert

If needed this functionality can be added to a script with the mysql -e bash command.

Example:

shell> mysql -uroot -e "select alert(2,'Beware of virtual dogs, they havent been fed yet')"
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk