Receive Curl Service Notifications
TL;DR: Utilize Rusty Forms to get alerts from your bash scripts or cron jobs.
There are times when you need to be alerted if something goes awry in a bash script or cron job, but you don’t want to deal with the hassle of setting up complex monitoring tools or spending a lot of money—especially if you don’t anticipate frequent issues.
In my experience, I often run a build script that tends to fail due to upstream changes. Previously, I wouldn’t realize there was a problem until my laptop began compiling the Linux kernel during the next update.
To adopt a more proactive strategy, I configured the bash script to report errors via Rusty Forms.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
notify_failure() {
command="$1"
exit_code="$2"
error_message="$3"
time="$(date)"
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"command": "'"$command"'",
"exit_code": "'"$exit_code"'",
"error_message": "'"$error_message"'",
"time": "'"$time"'"
}' \
https://api.rusty-forms.com/v1/digest/e6300c9b-XXX
}
buildARMPackages () {
guix build --system=aarch64-linux -m packages-aarch64.scm || notify_failure "guix build --system=aarch64-linux -m packages-aarch64.scm" "$?" "Build failed"
}
buildX86Packages () {
guix build --system=x86_64-linux -m packages-x86_64.scm || notify_failure "guix build --system=x86_64-linux -m packages-x86_64.scm" "$?" "Build failed"
}
runBuild () {
guix pull --channels=$SCRIPT_DIR/production-channels.scm || notify_failure "guix pull --channels=$SCRIPT_DIR/production-channels.scm" "$?" "Pull failed"
hash guix || notify_failure "hash guix" "$?" "Hash failed"
buildARMPackages
buildX86Packages
}
runBuild
There’s a lot going on here; let’s break it down:
- The build kicks-off with
runBuild
. runBuild
starts by pulling the latest Guix channels and continues to build the ARM and x86 packages.- If any of the commands fail, the
notify_failure
function is called with the command, exit code, and error message as arguments.
Important details related to the failure are send to Rusty Forms:
1
2
3
4
5
6
7
8
9
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"command": "'"$command"'",
"exit_code": "'"$exit_code"'",
"error_message": "'"$error_message"'",
"time": "'"$time"'"
}' \
https://api.rusty-forms.com/v1/digest/e6300c9b-XXX
Then I receive an email notification about the failure:
1
2
3
4
5
6
7
8
command: guix build --system=x86_64-linux -m packages-x86_64.scm
exit_code: 1
error_message: Build failed
time: Tue Mar 5 06:14:55 PM CET 2024
Form: SERVICE NOTIFICATIONS
https://rusty-forms.com/#/account/forms/e6300c9b-XXX
Rusty Forms also supports Webhooks, so you can integrate it with other services like Slack, Discord, or Microsoft Teams.