I know this is old but I wrote something to monitor successful and failed ssh connections/attempts. As well as banned IPs if you're using sshguard. I wrote it in Python and in Ruby. It will email you when someone successfully connects via ssh, when someone gets the ssh password wrong or when someone is banned due to to many failed attempts. Hopefully this will help someone in the future who searches for this issue and finds my code!
Python Implementation:
https://github.com/amboxer21/SSHMonitorPy
Ruby implementation:
https://github.com/amboxer21/SSHMonitor
For the python script, I wrote a bash script to monitor the process. It checks if it's running every minute via root cron task. If it is not running, it starts another process.
Bash script:
/home/anthony/.ssh/is_sshm_running.sh
#!/bin/bash
if [[ `ps aux | egrep --color -i "root.*[0-9]*:[0-9]* sudo /usr/bin/python /usr/bin/SSHMonitor.py" | wc -l` < 1 ]]; then
sudo /usr/bin/python /usr/bin/SSHMonitor.py -e "[email protected]" -p "password" &
fi
if [[ `ps aux | egrep --color -i "root.*[0-9]*:[0-9]* sudo /usr/bin/python /usr/bin/SSHMonitor.py" | wc -l` > 1 ]]; then
sudo kill -9 `ps aux | egrep --color -i "root.*[0-9]*:[0-9]* sudo /usr/bin/python /usr/bin/SSHMonitor.py" | awk '{print $2}'`;
fi
Which is called by this root cron task every minute:
[anthony@ghost ImageCapturePy]$ sudo crontab -l
[sudo] password for anthony:
* * * * * /bin/bash /home/anthony/.ssh/is_sshm_running.sh