EZAlert.me Blog

Use cases, facts and tutorials about EZAlert.me

About EZAlert.me

EZAlert.me offers a simple API to allow your programs or devices send you alerts via popular instant messages applications like Telegram, Skype, Facebook Messenger or Slack.
Here we publish posts about use cases, samples and stuffs related to EZAlert.me use and configuration.
If you like to share notes about how you use EZAlert.me, just sent us an email to ezalert(at)ezalert.me.
EZAlert.me home

How to send an instant message from Linux command line

Do you want to be alerted on Telegram or Skype about a problem in your server? Or do you want to receive an alert on Facebook Messenger every time a team member commits to your git server? Need to get a notification on Slack when you batch script completed?

https://EZALert.me makes all this very easy, or even trivial.

A bash script to call EZAlert.me api

Here follows a bash script to call EZALert.me api:

ezalert-send.sh:

#!/bin/sh

# Replace with your EZAlert.me api key:
APIKEY='YY-YYYYYYYYYY'

# URLENCODE parameter
str="${1}"
slen="${#str}"
out=''
i=1
while [ "${i}" -le "${slen}" ]; do
c=$(expr substr "$str" "$i" 1)
#echo "c: ${c}"
cc=$(printf '%%%02X' \'${c})
case "${c}" in
    [a-zA-Z0-9.~_-]) out="${out}${c}" ;;
            ' ') out="${out}+";;
            *) out="${out}${cc}"  ;;
        esac
    i=$((${i} + 1))
done

# EZALert.me call
wget -q -O - "https://ezalert.me/v1/sendAlert?apikey=${APIKEY}&text=${out}"
# Done

You need to change the APIKEY variable with your EZALert.me channel api key. To find it just login to EZAlert.me, enter you channel and get it from the top panel: Where is your api key

Replace the YY-YYYYYYYYYY in the above script, make it executable and give it a try. Pass as first argument the string you want to send, and don't forget the quotes!

$ ./ezalert-send.sh 'This is a test alert!'
{"status":"OK","nsent":4,"apilimit":"1\/70"}

Script shout output a json with a status:ok value. In case of error it will output what error happened.

How to use this script

You can use the send script in many ways. Here are some ideas:

  • Run it at the end of a batch process execution to be informed it has finished (it can be as simple as ./batchprocess.sh && ./ezalert-send.sh 'Finished'
  • Create a cron job to analyze your server logs and launch it to alert you about abnormal events
  • Create a cron job that daily sends you satistics about disk free space
  • ... put your example here! :-)