Receiving phone calls with Centreon notifications

Well, Well… Curves are coming… if you have a Centreon monitoring system, or based on Nagios or similar, You may be interested in this post. What we are going to see is how to generate the traditional alerts of our monitoring, but this time we will not use alerts by email or Telegram, but it will make a phone call using an IP PBX that we have in the organization, with it it will call us at the phone number we indicate and in perfect Spanish it will indicate the problem that exists.

 

So what I said, if you have an IP Voice PBX and you want the monitoring to be able to make phone calls to warn you with a message that Service or Server has gone down, just follow these simple steps. If you don't have a VoIP switchboard, I encourage you to FreePBX Mounts, you will see how quickly you will be able to make voice IP calls within your organization, or external if, for example, you use Movistar fibre, Vodafone… Here are the steps you need to follow on your Centreon machine if you want her to be able to make calls automatically.

 

We started by installing Festival and PJPROJECT that we will compile:

[SourceCode]Yum Install Expect Festival
WGET HTTP://www.pjsip.org/release/2.8/pjproject-2.8.tar.bz2
tar xjf pjproject-2.8.tar.bz2
CD PJPROJECT-2.8
./Set
Make dep
Make[/SourceCode]

 

It will generate this binary for us:

[SourceCode]/root/pjproject-2.8/pjsip-apps/bin/pjsua-x86_64-unknown-linux-gnu[/SourceCode]

 

We will need to create a configuration file for PJSUA, where we will indicate access to our IP switchboard with the correct credentials to register and be able to make calls. In my case I leave it here '/root/pjproject-2.8/pjsip-apps/bin/pjsua.conf’ and this is its content:

[SourceCode]–null-audio
–Register SIP:DIRECCION_IP_CENTRALITA
–realm=*
–Go yes:USUARIO@DIRECCION_IP_CENTRALITA
–username USER
–password PASSWORD[/SourceCode]

 

Now, What we will do is create a script that we will use to make the call, in my case a super intuitive name 'llama.sh', this script will be executed by Centreon when it has to notify, to whom he will pass as an argument the message that he has to read us in the call. We indicate the directories for Expect, PJSUA and its configuration file that we have just created; We can also add a WAV file with the sound of an alert that will sound before the audio, we will indicate the path of the Text2wave binary, the maximum call duration and of course, The phone number you need to dial to make the call, finally the IP address of the IP PBX. So what I said, The content of 'llama.sh’

[SourceCode]#! /bin/bash
EXPECT=/usr/bin/expect
PJSUA=/root/pjproject-2.8/pjsip-apps/bin/pjsua-x86_64-unknown-linux-gnu
PJSUACONFIG=/root/pjproject-2.8/pjsip-apps/bin/pjsua.conf
SOUNDFILE=/tmp/alert.wav
TEXT2WAVE=/usr/bin/text2wave
DURATION=20
NUMBER=NUMERO_DE_TELEFONO_A_MARCAR
ECU = DIRECCION_IP_DE_LA_CENTRALITA
MESSAGE="Monitoring Alert"

# Setting a lock file
# We can't make more than one call
# at a time, because pjsua blocks the port
# so we have to make sure that nobody else tries to call
# If there is already a call we have to wait.

locked=false
while $locked == false ; do
if ! -f /tmp/caller.lock ; then
touch /tmp/caller.lock
locked=true
else
sleep 5
fi
Done

# Generating the message
$TEXT2WAVE -o $SOUNDFILE -f 8000 << EOF
$MESSAGE
EOF

# Making the call it self.
# Expect will start pjsua and work with
# it so that it will end it self automatically

$EXPECT << EOF
spawn $PJSUA –config-file $PJSUACONFIG –play-file $SOUNDFILE –auto-play –duration $DURATION –max-calls 1 yes:$NUMBER@$CENTRALITA
expect "VAD re-enabled"
sleep $DURATION
send "qn"
EOF

# Cleaning up
rm $SOUNDFILE

# Removing the lock file
rm /tmp/caller.lock[/SourceCode]

 

Podremos hacer si queremos una prueba ahora para ver si va todo bien, it will be enough to execute the previous script and put the message we want it to tell us on the phone as an argument:

[SourceCode]./llama.sh "Hello, This is a test message you will hear in English from death."[/SourceCode]

 

If we want the call to be in Spanish or Spanish, we must also carry out these last steps. We will install the voices of HISPAVOCES, a project of Guadalinex where they leave us 2 voices that speak Spanish perfectly, they don't sound like a robot 🙂 We will choose whether to use the female or male voice.

[SourceCode]Yum install hispavoces-pal-diphone hispavoces-sfl-diphone[/SourceCode]

 

We edit the Festival file, where we will indicate that it uses the new voices, We edit '/usr/share/festival/lib/voices.scm’ and on the line 328 We can directly modify and add one of these two voices

[SourceCode]…
(defvar default-voice-priority-list
‘(JuntaDeAndalucia_es_pa_diphone
nitech_us_slt_arctic_hts
…[/SourceCode]

 

And if I tell you the truth, I don't remember the following notes because I have them written down… Maybe he wouldn't recognize the 2 Voices… But wow, what we see here is how to install the voices that the good people of Guadalinex give us through RPM (remember that Centreon's distro is based on a CentOS), But of course, what we can download from them is in DEB, So what we do is download, Build and install Alien (and its requirements) and then download the voice in . DEB and convert it to . RPM and install it. At the end we move the files that it will have generated for us to the correct path of Festival and its voices in Spanish

[SourceCode]Yum Install RPM-Build
cd /usr/src
WGET HTTP://ftp.de.debian.org/debian/pool/main/a/alien/alien_8.92.tar.gz
tar -xf alien_8.92.tar.gz
alien cooldown
Pearl Makefile.PL
Make
make install

wget https://github.com/guadalinex-archive/hispavoces/raw/master/packages/festvox-palpc16k_1.0-1_all.deb
Alien -VR festvox-palpc16k_1.0-1_all.deb
rpm -ivh festvox-palpc16k-1.0-2.noarch.rpm

mv /usr/share/festival/voices/spanish/ /usr/share/festival/lib/voices/es/[/SourceCode]

 

Now again you can try to make the call as before and you will see how now a man or woman speaks to us perfectly in Spanish,

[SourceCode]./llama.sh "Hello, This is a test message that you will hear perfectly."[/SourceCode]


After having all the configuration ready and the script working, we have to tell Centreon that when it generates a notification call us by phone, for this, the first thing will be to register the Notifications Comados, So we created 2, one for when you notify us of the Hosts and one for the Services. Since “Configuration” > “Commands” > “Notifications” We define them, Staying:

 

Llamadas_servicios

[SourceCode]/home/llama.sh "On the $HOSTNAME$ device, the $SERVICEDESC$ Service is in $SERVICESTATE$ status"[/SourceCode]

 

Llamadas_hosts

[SourceCode]/home/llama.sh "The $HOSTNAME$ team is in $HOSTSTATE$ status"[/SourceCode]

 

And then there is nothing left to do but associate it, For example, to the user or group we want to receive the call, we associate them with you in “Host Notification Commands” and in “Service Notification Commands”. As usual, after any configuration change, we export and record the Centreon config and from this moment on, when there is an alert in our data center or in our company, We will receive phone calls telling us what the problem is. Don't tell me it's not great for when we have staff on duty and we want to wake them up at any time to take action, A marvel!

As always, I hope you have been interested and thank you for sharing on social networks.

 

Recommended Posts

Author

nheobug@bujarra.com
Autor del blog Bujarra.com Cualquier necesidad que tengas, Do not hesitate to contact me, I will try to help you whenever I can, Sharing is living ;) . Enjoy documents!!!