import os
#填入企业微信web请求地址
webhook_url = 'https://qyapi.weixin.qq.com/cgi-bin'
# 发送消息的函数
def send_message(msg):
headers = {'Content-Type': 'application/json'}
data = {'msgtype': 'text', 'text': {'content': msg}}
r = requests.post(webhook_url, headers=headers, data=json.dumps(data))
return r.json()
#获取当前登录用户的连接IP地址
def get_local_user_ip():
cmd = "who am i | awk '{print $NF}'"
output = os.popen(cmd).read().strip()
return output
user_ip = get_local_user_ip()
mes = f"IP {user_ip} 已登录服务器"
send_message(mes)
Centos实时监控SSH登录用户并企微通知
原创
©著作权归作者所有:来自51CTO博客作者51CTO邓鹏的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
实时监控 Odoo 日志并通过企业微信通知
报警机器人
Python 微信 错误日志 odoo -
自动登录Centos7并获取数据
通过python脚本,自动登录设备并获取数据,为后续数据消费和数据治理以及自动化运维做铺垫。
运维 数据消费 自动化运维 python 模拟ssh登录 -
SSH利用pam chroot限制登录用户
利用SSH限制用户登录的一个简单的示例
SSH PAM chroot pam_chroot.s