Any Email Notification Setting when camera goes down

Forum for questions and support relating to the 1.34.x releases only.
Post Reply
aruneshdutta
Posts: 24
Joined: Tue Aug 15, 2017 3:33 am

Any Email Notification Setting when camera goes down

Post by aruneshdutta »

Hello all

Wanted to implement a way to be notified when the camera goes down .Kindly guide how the same can be done. Did searched the forum(attached image) as it mentions that it notifies when camera is online..do let me know as I wanted notifcation when camera goes down
Attachments
capture29597[1].png
capture29597[1].png (26.53 KiB) Viewed 7717 times
tommisgr
Posts: 23
Joined: Mon Aug 31, 2020 6:28 pm

Re: Any Email Notification Setting when camera goes down

Post by tommisgr »

personaly I wrote a script to do ping test and awk the syslog for error and run it every 20 mins.

If a ping fails or an error if found in the syslog an email is sent

eg.

Code: Select all

#!/bin/bash

#set IP address
monitor1=192.168.1.100
#ping test
monitor1_chck=$(ping -c 1 $monitor1 | grep bytes | wc -l)
#write text depending on ping test
[ $monitor1_chck -gt 1 ] &&  monitor1_txt="UP" || monitor1_txt="Down" 
#check syslog for errors
m1=$(tail -n 500 /var/log/syslog | sort -r | awk '/ERR \[zmc_m1\] \[Failed to prime | ERR \[zmc_m1\] \[Unable to/ {print $7; exit}')
# write txt depending of syslog check result
[ "$m1" = "[zmc_m1]" ] && m1txt="Failed" || m1txt="Working"

#make table of results
resultstable() {

echo -e "  Name \t\t Capture\t IP Address\tStatus"
echo "------------------------------------------------------"
echo -e "monitor1 \t" $m1txt "\t"$parking" \t"$monitor1_txt 

}


#do check to sent email
if 
[ "$m1" = "[zmc_m1]" ] || [ $monitor1_chck -eq 1 ] 
then
resultstable | mail -s "Zoneminder Monitor OR ping Failed" user@gmail.com
fi


You need to have email send capability already set up

the tail n -500 limits the syslog to last 500 lines about 4 mins time
Last edited by tommisgr on Sat Sep 26, 2020 6:09 pm, edited 1 time in total.
aruneshdutta
Posts: 24
Joined: Tue Aug 15, 2017 3:33 am

Re: Any Email Notification Setting when camera goes down

Post by aruneshdutta »

tommisgr wrote: Sat Sep 26, 2020 6:01 pm personaly I wrote a script to do ping test and awk the syslog for error and run it every 20 mins.

If a ping fails or an error if found in the syslog an email is sent

eg.

Code: Select all

#!/bin/bash

#set IP address
monitor1=192.168.1.100
#ping test
monitor1_chck=$(ping -c 1 $monitor1 | grep bytes | wc -l)
#write text depending on ping test
[ $monitor1_chck -gt 1 ] &&  monitor1_txt="UP" || monitor1_txt="Down" 
#check syslog for errors
m1=$(tail -n 500 /var/log/syslog | sort -r | awk '/ERR \[zmc_m1\] \[Failed to prime | ERR \[zmc_m1\] \[Unable to/ {print $7; exit}')
# write txt depending of syslog check result
[ "$m1" = "[zmc_m1]" ] && m1txt="Failed" || m1txt="Working"

#make table of results
resultstable() {

echo -e "  Name \t\t Capture\t IP Address\tStatus"
echo "------------------------------------------------------"
echo -e "monitor1 \t" $m1txt "\t"$parking" \t"$monitor1_txt 

}


#do check to sent email
m1=$(tail -n 500 /var/log/syslog | sort -r | awk '/ERR \[zmc_m1\] \[Failed to prime | ERR \[zmc_m1\] \[Unable to/ {print $7; exit}')
if 
[ "$m1" = "[zmc_m1]" ] || [ $monitor1_chck -eq 1 ] 
then
resultstable | mail -s "Zoneminder Monitor OR ping Failed" user@gmail.com
fi


You need to have email send capability already set up

the tail n -500 limits the syslog to last 500 lines about 4 mins time
Thanks for that, anyway through zoneminder the thing can be achieved ?
tommisgr
Posts: 23
Joined: Mon Aug 31, 2020 6:28 pm

Re: Any Email Notification Setting when camera goes down

Post by tommisgr »

Couldnt find a filter for that so I wrote the script.

Was planing on auto setting monitor to none but http call dont work and hadnt had time to look into the API calls
fontiano
Posts: 69
Joined: Wed Dec 25, 2019 10:29 am

Re: Any Email Notification Setting when camera goes down

Post by fontiano »

I did it with a custom config file for rsyslog and a cron script:

01-custom.conf on /etc/rsyslog.d/01-custom-conf

Code: Select all

if $msg contains "Shared data not" then /var/log/zm/lost-signal.log
if $msg contains "Unable to open input" then /var/log/zm/lost-signal.log
/etc/crontab

Code: Select all

*/2 * * * * root /scripts/check-segnale-telecamere.sh >/dev/null 2>&1
/scripts/check-segnale-telecamere.sh

Code: Select all

#!/bin/bash
DATA=`date`
FILE=/var/log/zm/lost-signal.log
if [ -f $FILE ]; then

        PiazzaleGiardino=`grep 'PiazzaleGiardino\|zmc_m1]' $FILE | wc -l`
        CancelloFabbrica=`grep 'CancelloFabbrica\|zmc_m2]' $FILE | wc -l`
        Capanna=`grep 'Capanna\|zmc_m3]' $FILE | wc -l`
        GarageStanza=`grep 'GarageStanza\|zmc_m4]' $FILE | wc -l`
        GarageMacchina=`grep 'GarageMacchina\|zmc_m5]' $FILE | wc -l`
        InternoFabbrica=`grep 'InternoFabbrica\|zmc_m6]' $FILE | wc -l`
        PiazzaleFabbrica=`grep 'PiazzaleFabbrica\|zmc_m7]' $FILE | wc -l`
        VialeSilvia=`grep 'VialeSilvia\|zmc_m8]' $FILE | wc -l`

        if [[ $PiazzaleGiardino > "1" ]];
                then
                        mail -s "PiazzaleGiardino ha perso il segnale." "xxxx@gmail.com" < /dev/null
                        echo "$DATA "PiazzaleGiardino ha perso il segnale. >> /var/log/zm/storico-disconnessioni.log
                else
                        echo "Non ci sono state perdite di segnale dalla telecamera PiazzaleGiardino."
        fi
        if [[ $PiazzaleFabbrica  > "1"  ]];
                then
                        mail -s "PiazzaleFabbrica ha perso il segnale." "xxxx@gmail.com" < /dev/null
                        echo "$DATA "PiazzaleFabbrica ha perso il segnale. >> /var/log/zm/storico-disconnessioni.log
                else
                        echo "Non ci sono state perdite di segnale dalla telecamera PiazzaleFabbrica."
        fi
        if [[ $CancelloFabbrica  > "1"  ]];
                then
                        mail -s "CancelloFabbrica ha perso il segnale." "xxxx@gmail.com" < /dev/null
                        echo "$DATA "CancelloFabbrica ha perso il segnale. >> /var/log/zm/storico-disconnessioni.log
                else
                        echo "Non ci sono state perdite di segnale dalla telecamera CancelloFabbrica."
        fi
        if [[ $Capanna  > "1"  ]];
                then
                        mail -s "Capanna ha perso il segnale." "xxxx@gmail.com" < /dev/null
                        echo "$DATA "Capanna ha perso il segnale. >> /var/log/zm/storico-disconnessioni.log
                else
                        echo "Non ci sono state perdite di segnale dalla telecamera Capanna."
        fi
        if [[ $GarageStanza  > "1"  ]];
                then
                        mail -s "GarageStanza ha perso il segnale." "xxxx@gmail.com" < /dev/null
                        echo "$DATA "GarageStanza ha perso il segnale. >> /var/log/zm/storico-disconnessioni.log
                else
                        echo "Non ci sono state perdite di segnale dalla telecamera GarageStanza."
        fi
        if [[ $GarageMacchina  > "1"  ]];
                then
                        mail -s "GarageMacchina ha perso il segnale." "xxxx@gmail.com" < /dev/null
                        echo "$DATA "GarageMacchina ha perso il segnale. >> /var/log/zm/storico-disconnessioni.log
                else
                        echo "Non ci sono state perdite di segnale dalla telecamera GarageMacchina."
        fi
        if [[ $InternoFabbrica  > "1"  ]];
                then
                        mail -s "InternoFabbrica ha perso il segnale." "xxxx@gmail.com" < /dev/null
                        echo "$DATA "InternoFabbrica ha perso il segnale. >> /var/log/zm/storico-disconnessioni.log
                else
                        echo "Non ci sono state perdite di segnale dalla telecamera Internofabbrica."
        fi
        if [[ $VialeSilvia  > "1"  ]];
                then
                        mail -s "VialeSilvia ha perso il segnale." "xxxx@gmail.com" < /dev/null
                        echo "$DATA "PiazzaleFabbrica ha perso il segnale. >> /var/log/zm/storico-disconnessioni.log
                else
                        echo "Non ci sono state perdite di segnale dalla telecamera VialeSilvia."
        fi

else
   echo "Non ho rilevato perdite di segnale."
fi



echo "" > /var/log/zm/lost-signal.log
chmod 0777 /var/log/zm/lost-signal.log

Production: zm 1.34.26 - Debian 11 | Test: zm 1.36.33 - Debian 12
Post Reply