Last active
March 7, 2018 13:03
-
-
Save gomasy/1a232e87d2f5ea214edd336d700cf20a 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
require "net/https" | |
require "ipaddr" | |
require "json" | |
require "uri" | |
slack_url = URI.parse("") # slack webhook url | |
user = ENV["USER"] | |
remote_ip = IPAddr.new(ENV["SSH_CONNECTION"].split(" ")[0]) | |
local_ip = IPAddr.new(ENV["SSH_CONNECTION"].split(" ")[2]) | |
hostname = `echo #{local_ip} | xargs dig +short -x`.chomp.chop | |
body = { | |
"username" => "SSH Login Alert", | |
"icon_emoji" => ":shield:", | |
"attachments" => [ | |
{ | |
"text" => "SSH connection has established", | |
"color" => "good", | |
"fields" => [ | |
{ | |
"title" => "From", | |
"value" => remote_ip, | |
"short" => true, | |
}, | |
{ | |
"title" => "To", | |
"value" => !hostname.empty? ? hostname : local_ip, | |
"short" => true, | |
}, | |
{ | |
"title" => "User", | |
"value" => user, | |
"short" => true, | |
}, | |
], | |
}, | |
], | |
} | |
Net::HTTP.post(slack_url, JSON.generate(body)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment