SMS alerts for your team: a server down, low stock or a failed task, sent from a script

WhatsApp & APIs·· 17 views· 3 min read

The short answer: any script that already watches something (a website, a server, stock levels, a backup) can text your team with one request to our API. SMS reaches people even with mobile data switched off, which makes it a good fit for alerts that cannot wait.

What you need

1 SMS activated on the SMS page in Meu MozOut, with credits in the balance.
2 An API key with only the sms:write permission, created on the API page in Meu MozOut. If the script always runs from the same server, restrict the key to its IP.
3 Your team's numbers, written with or without the country code, because the system can tell the country from the first digit: 841234567 goes to Mozambique and 923456789 to Angola. So +258 84 123 4567 and 258841234567 are the same number as 841234567.

A minimal script

This example sends an alert to two numbers. Keep the key in an environment variable, never in the file itself:

#!/bin/sh
# alert.sh: sends the text in the 1st argument to each number on the team
for N in 841234567 ANOTHER_NUMBER; do
curl -s https://api.mozout.co.mz/v1/sms/messages \
-H "Authorization: Bearer $RLX_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"number\": \"$N\", \"text\": \"ALERT: $1\"}"
done

Run it like this: ./alert.sh "the website has not answered since 14:38". With a sandbox_ key the request is validated but nothing is sent and no credits are used: test with it, then switch to the prod_ key. For many numbers at once there is the batch send.

When to fire

What you watch When it alerts
Website or server When it stops answering, and again when it is back
Stock When a product drops below the minimum you set
Backups and scheduled jobs When a job fails or does not run
Disk space or quotas When usage passes a threshold of yours

To run the script on its own at regular intervals, see cron schedule examples. To watch a website, an alert when your site goes down.

Alert once per problem, not once per minute. A script that runs every minute and texts every time it sees the fault burns credits and hits the account's daily sending limit. Write down in a file that you already alerted, and only send again when the problem changes or ends.
Start the text with ALERT and name the system, the problem and the time. Whoever is on duty understands at a glance.

Want your team to know straight away when something stops? See the API page and create your first key.

See the API page

SEE ALSO

Sending SMS through the API: key, permissions, Sandbox and your first request

Internal SMS notices for your staff: shifts, rosters and urgent messages to a contact group

Sending many SMS notices in one API request: the batch endpoint and its results

Getting an alert when your site goes down: a simple uptime check

Cron schedule examples: every 15 minutes, weekdays at 8, the first of the month

SMS API errors and message statuses: what each one means and what to do

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $6.60/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.