Introduction
Introduction Statistics Contact Development Disclaimer Help
Title: Send XMPP messages from the command line
Author: Solène
Date: 25 May 2023
Tags: xmpp monitoring selfhosting reed-alert
Description: In this blog post, you will learn how to use the program
go-sendxmpp to programmatically send XMPP messages from a script
# Introduction
As a reed-alert user for monitoring my servers, while using emails
works efficiently, I wanted to have more instant notifications for
critical issues. I'm also an happy XMPP user, so I looked for a
solution to send XMPP messages from a command line.
More about reed-alert on the blog
Reed-alert project git repository
I will explain how to use the program go-sendxmpp to send messages from
a command line, this is a newer drop-in replacement for the old perl
sendxmpp that doesn't seem to work anymore.
go-sendxmpp project git repository
# Installation
Following go-sendxmpp documentation, you need go to be installed, and
then run `go install salsa.debian.org/mdosch/go-sendxmpp@latest` to
compile the binary in `~/go/bin/go-sendxmpp`. Because it's a static
binary, you can move it to a directory in `$PATH`.
If I'm satisfied of it, I'll import go-sendxmpp into the OpenBSD ports
tree to make it available as a package for everyone.
# Configuration
Open a shell with the user that is going to run go-sendxmpp, prepare
the configuration file in its default location:
```shell
mkdir -p ~/.config/go-sendxmpp
touch ~/.config/go-sendxmpp/config
chmod 400 ~/.config/go-sendxmpp/config
```
Edit the file `~/.config/go-sendxmpp/config` to add the two lines:
```
username: myuser@myserver
password: hunter2_oryourpassword
```
Now, your user should be ready to use `go-sendxmpp`, I recommend always
enabling the flag `-t` to use TLS to connect to the server, but you
should really choose an XMPP server providing TLS-only.
The program usage is simple: `echo "this is a message for you" |
go-sendxmpp dest@remote`, and you are done. It's easy to integrate it
in shell tasks.
Note that go-sendxmpp allows you to get the password for a command
instead of storing it in plain text, this may be more convenient and
secure in some scenarios.
# Reed-alert configuration
Back to reed-alert, using go-sendxmpp is as easy as declaring a new
alert type, especially using the email template:
```common-lisp
(alert xmpp "echo -n '[%state%] Problem with %function% %date% %params%' | go-s…
;; example of use
(=> xmpp ping :host "dataswamp.org" :desc "Ping to dataswamp.org")
```
# Conclusion
XMPP is a very reliable communication protocol, I'm happy that I found
go-sendxmpp, a modern, working and simple way to programmatically send
me alerts using XMPP.
You are viewing proxied material from dataswamp.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.