I'm working in a Linux-based environment where there are more than 100 servers. I need to get a mail notification and popup notification whenever anyone connects a storage device. How do I configure that?
Asked
Active
Viewed 97 times
1
-
Is the popup notification local to the server or is this appearing on a remote machine like your personal desktop? – rtaft Apr 30 '20 at 14:58
-
when i get both configuration steps . it becomes useful for me. – Paul Salva May 01 '20 at 12:06
-
How quickly do you need to be notified? Immediate? Within a minute? Once an hour? Once a day? – rtaft May 11 '20 at 15:07
1 Answers
0
The simplest way to do this is to monitor for the word 'mount' in /var/log/syslog on a cronjob. This sample would run every 10 minutes.
#!/bin/bash
# Gets the time and date 1 minute ago (00:00 would return 23:59 previous day)
TIME=`date +"%b %d %H:%M" --date '-1 min'`
# Truncate the minutes
TIME=${TIME::-1}
# Gets the past 10 minutes of logs and looks for 'mount'
MOUNT=`grep "$TIME" /var/log/syslog | grep mount`
if [ {{ '${#MOUNT}' }} -ge 1 ]; then
echo -e "$MOUNT" | sendemail -t {{ email_address }} -f {{ from_address }} -u "$(hostname) Mount Detected" -s {{ smtp_server }} > /dev/null
fi
Make sure the date format matches what is in your logs. You can use whatever sendmail command you wish. If you wanted once a minute just remove the time truncate line. If you wanted immediate, you'd need to monitor udisksctl monitor for output. Once the email is sent, you can use any email notification for your popup.
rtaft
- 1,790
- 3
- 13
- 26