This is a simple slackbot to post successful SSH logins to a slack channel to help you keep track of server access.
Create an incoming webhook for your slack community.
Create /etc/ssh/sshslack.sh
Copy sshslack.sh code and replace URL with webhook URL.
Add the following line to /etc/pam.d/sshd
:
session optional pam_exec.so seteuid /etc/ssh/sshslack.sh
Here is for telegram it work but im not sure my way is good or not ..
#!/bin/sh
API Config
chat_id=""
token=""
###############
host=$(hostname)
Message="Someone+Logged+Into+Host+:+$host+with+Username+:+$PAM_USER+From+IP+Address:+$PAM_RHOST"
url="https://api.telegram.org/bot$token/sendMessage?chat_id=$chat_id&text=$Message"
if [ "$PAM_TYPE" != "close_session" ]; then
curl -s -X POST $url
fi