Last active
January 15, 2023 12:04
-
-
Save todashuta/0810be68039a6da2df64439eefad9b52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os, sys | |
if os.environ.get("PAM_TYPE") != "open_session": | |
sys.exit(0) | |
WEBHOOK_URL = "<DiscordのWebhook URL>" | |
from datetime import datetime | |
import pytz, locale, requests | |
locale.setlocale(locale.LC_TIME, "ja_JP.UTF-8") | |
tz = pytz.timezone("Asia/Tokyo") | |
nowstr = tz.localize(datetime.now()).strftime("%Y-%m-%d (%a) %H:%M:%S %Z") | |
server_name = os.uname().nodename | |
pam_user = os.environ.get("PAM_USER") | |
pam_rhost = os.environ.get("PAM_RHOST") | |
message = f""" | |
{pam_user} が {server_name} にログインしました。 | |
* ログイン時刻: {nowstr} | |
* アクセス元: {pam_rhost} | |
""".strip() | |
#print(message) | |
data = { "content": message } | |
#print(data) | |
requests.post(WEBHOOK_URL, json=data, timeout=3.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment