blob: dee575e7a3c33596c7d049ac611a13f6e38487b8 (
plain) (
blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# `hook` A command line webhook utility.
It's not likely of much use on its own. The real power comes when you tie
it together with your shell scripts to run a command, or send the output
of something to your chat server if things go wrong.
With an example configuration file:
```
backups:
url: https://discordapp.com/api/webhooks/fill/me/in
schema:
username: 'backups@{{.Vars.Hostname}}'
content: '{{.Vars.Message}} ```{{.Stdin}}```'
```
Placed in `$HOME/.hook.yml`
We can then call say our backup script:
```bash
$ bin/backup.sh | hook -n backups -V Hostname "$(hostname)" -v Message "Backup output"
```
Which will yield a webhook being sent out with the output from your
`bin/backup.sh` script
A slightly more complex example might be to use it in a shell script:
```bash
#!/bin/sh
output="$(mktemp)"
restic backup /var/www 2>&1 > "$output"
if [ $? -ne 0 ] ; then
hook -n backups \
-v Hostname "$(hostname)" \
-v Message "Backup failure! :bomb:" \
< "$output"
fi
rm "$output"
```
The above example would only send out a webhook if the backup had a failure
by using `$?` to check the status code.
|