# Monitoring Client Connection

**URL:** <https://forum.openwrt.org/t/monitoring-client-connection/177422>\
**Category:** Installing and Using OpenWrt\
**Created:** [November 13, 2023, 2:48am UTC](https://forum.openwrt.org/t/monitoring-client-connection/177422 "2023-11-13T02:48:54Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![pavelgl](https://forum.openwrt.org/user_avatar/forum.openwrt.org/pavelgl/32/33073_2.png) [@pavelgl](https://forum.openwrt.org/u/pavelgl)\
**Post date:** [November 14, 2023, 7:53am UTC](https://forum.openwrt.org/t/monitoring-client-connection/177422/7 "2023-11-14T07:53:45Z")

</div>

> [@sumrando](#):
>
> I cannot ping it from the router when the client goes offline.

> [@sumrando](#):
>
> I need an alert when the client goes offline or becomes unavailable so I know there is a problem.

Install the `msmtp` package and create a google [app password](https://support.google.com/accounts/answer/185833?hl=en) in order to use gmail as a relay host .

```bash
opkg update; opkg install msmtp

#/etc/msmtprc

# Gmail
account gmail
host smtp.gmail.com
port 465
auth on
tls on
tls_starttls off
from <user>@gmail.com
user <username>
password <16char_app_pass>

account default : gmail

syslog LOG_MAIL

```

Modify the script variables and execution period according to your needs.

```bash
cat << "EOF" > /etc/email_notification.sh

#!/bin/sh
IP=192.168.1.101 # Host IP address
email_addr="user@example.com" # email address to send the notification to
FAILURE=/tmp/failure

if ! ping -c 5 -W 1 $IP >/dev/null; then
    [-f "$FAILURE"] && exit 0
    msg="Host does not respond to ping on $(date)"
    echo -e "To:$email_addr \nSubject:Notification\n\n$msg" | msmtp "$email_addr"
    touch "$FAILURE"
else
    [-f "$FAILURE"] || exit 0
    rm -f "$FAILURE"
fi

exit 0
EOF

chmod 755 /etc/email_notification.sh

cat << "EOF" >> /etc/crontabs/root
*/5 * * * * /etc/email_notification.sh
EOF
uci set system.@system[0].cronloglevel="9"
uci commit system
/etc/init.d/cron restart

```

---

_[View the full topic](https://forum.openwrt.org/t/monitoring-client-connection/177422)._
