Skip to content

Zabbix alarm on Signal

GKaveH edited this page May 3, 2020 · 3 revisions

Signal Messenger for Zabbix 4.4.7

Overview

how to Integrate Signal to Zabbix for notification with Signal-cli which is a command line interface for Signal app. for us It’s used to register a new signal account in zabbix server.

you can see more information about signal-cli on https://github.com/AsamK/signal-cli

Step 1 – Prerequisites

Log in to your system with root privilege account using shell access, to which you need to install Signal-Cli.

ssh root@remote

On Ubuntu/Debian, you have to install below package

root@zabbix:~# apt-get install libunixsocket-java
root@zabbix:~# apt-get install default-jre

Step 2 – Installing Signal-Cli

Get latest version from https://github.com/AsamK/signal-cli/releases, e.g. to opt directory.

root@zabbix:~# wget -c https://github.com/AsamK/signal-cli/releases/download/v0.6.7/signal-cli-0.6.7.tar.gz
root@zabbix:~# tar xfv signal-cli-0.6.7.tar.gz -C /opt
root@zabbix:~# ln -sf /opt/signal-cli-0.6.7/bin/signal-cli /usr/local/bin/

Step 3 – Give access to Zabbix user

you must give accsess to Zabbix user so you can register your number with Zabbix user with sudoers. so we need edit sudoers file.

root@zabbix:~# vim /etc/sudoers

add this to sudoers file.

zabbix  ALL=(root) NOPASSWD: /opt/signal-cli-0.6.7/bin/signal-cli

Step 4 – Register your number

you can use Signal without a smartphone and To be able to use Signal you have to register yourself with a phone number (doesn’t has to be a mobile number). So we execute this command.

root@zabbix:~# sudo -u zabbix signal-cli -u Yournumber register

Note : Your number should like this +Country Code Your number without space like +981111......

on the command line. If all goes well, there is no reply. Execution takes a few seconds. +981111...... After a few seconds, you will receive an SMS on your cell phone that contains the verification code like (123-456)

Your Signal verification code: 123-456

Note: You can register Signal using a land line number. In this case you can skip SMS verification process and jump directly to the voice call verification by adding the --voice switch at the end of above register command.

Then we must verify our registration with this command.

root@zabbix:~# signal-cli -u Yournumber verify 123-456

Step 5 – Send a first message from the command line

We assume that the receiver of the message has the phone number +982222...... . Enter

root@zabbix:~# sudo -u zabbix signal-cli -u +981111...... send -m "Hello this is test message " +982222......

on the command line. Again, no reply if all is fine. Within a few seconds, the Signal App on the cell phone +982222...... will receive the message.

Step 6 – Create Signal script for Sending message automatically

I must say this script was wrote by one of my best Friend Pejman Moghadam.

#!/bin/bash
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

sanitize() {
        echo "$1" | sed -e 's,&,#,g'
}

# This is for shamsi date with Jcal you can replace jdate with date 
DATE_EXEC="$(jdate "+%Y.%m.%d % on %T")"

A=$(sanitize "$2")
B=$(sanitize "$3")
C=$(sanitize "$1")

TEXT="$A
$B
Sent: $DATE_EXEC"

echo "$TEXT" | grep -q 'Zabbix agent was unreachable'
if [ "$?" == "0" ]; then
        echo "MAIN($DATE_EXEC):$C 'Zabbix agent was unreachable' Bypass" >> /tmp/signal.log
        exit
fi

echo "$TEXT" | /usr/local/bin/signal-cli -u YourNumber send $C

echo "MAIN:$C $TEXT" >> /tmp/signal.log

Note : Remember to Replace your registration number with "YourNumber"

Then we must give our script permission to be executable with below command

root@zabbix:~# chmod +x signal.sh

Note : Move your script to Alert Scripts Path in your Zabbix_server.conf by default this path is

AlertScriptsPath=/usr/lib/zabbix/alertscripts

Step 7 – Create media type in Zabbix frontend

In your frontend and go to [Administration] tab and then click on [Media types] select [Create media type], and fill it for example like this

Name : Signal

Type : Script

Script name : signal.sh

Script parameters :

{ALERT.SENDTO}

{ALERT.SUBJECT}

{ALERT.MESSAGE}

Step 8 – Create Action in Zabbix frontend

In your frontend and go to [Configuratin] tab and then click on [Action] select [Create action], and fill it for example like this.

  • in Conditions Filed you should add you desirable Condition

Name : Signale Report Problems

in Conditions Filed you should add you desirable Condition

  • Then in Operations Tab do as below

Default subject :

{EVENT.STATUS}

Default message :

Host : {HOST.NAME} Event: {EVENT.NAME} Severity : {EVENT.SEVERITY} Value : {EVENT.VALUE} Acknowledge: {EVENT.ACK.STATUS} Fired : {EVENT.DATE} on {EVENT.TIME}

Note : In Send to User Filed Please select your User's for getting alarm via signal app.

  • also in Recovery operations Tab do as below

Default subject :

{EVENT.STATUS}

Default message :

Host : {HOST.NAME} Event: {EVENT.NAME} Severity : {EVENT.SEVERITY} Value : {EVENT.VALUE} Acknowledge: {EVENT.ACK.STATUS} Fired : {EVENT.DATE} on {EVENT.TIME}

and at the end click on Update button and your done.