반응형
EC2 접속 시 슬랙으로 알림
ec2-info-send.sh 스크립트 생성
$ vim /etc/profile.d/ec2-info-send.sh
#!/bin/bash
V_slackUrl="https://hooks.slack.com/services/TCT4/wkQM"
V_channelName="#zabbix_bot"
V_username="ec2"
V_emoji=":white_check_mark:"
V_color='#0C7BDC'
CDATE=`date '+%Y-%m-%d, %H:%M:%S' `
IPUBIPV4=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4`
IPLOCALIPV4=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4`
IID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
IREGION=`curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region`
ITYPE=`curl -s http://169.254.169.254/latest/meta-data/instance-type`
IHOSTNAME=`aws --region ${IREGION} ec2 describe-instances \
--instance-ids ${IID} \
--query "Reservations[].Instances[].Tags[?Key=='Name'].Value[]" \
--output text`
text=text
subject=$1
message="Instance id: $IID
Hostname: $IHOSTNAME
Public ipv4: $IPUBIPV4
Local ipv4: $IPLOCALIPV4
Instance type: $ITYPE
Date : $CDATE"
###PAYLOAD START###
payload="payload={\"channel\": \"${V_channelName}\", \
\"username\": \"${V_username}\", \
\"attachments\": [{\"fallback\": \"${subject//\"/\\\"}\", \"title\": \"${subject//\"/\\\"}\", \"text\": \"${message//\"/\\\"}\", \"color\": \"${V_color}\"}], \
\"icon_emoji\": \"${V_emoji}\"}"
###PAYLOAD END###
curl \
-X POST \
-H "Accept: application/json" \
--data-urlencode "${payload}" \
${V_slackUrl}
chmod +x ec2-info-send.sh
slack 알람
참고URL
- EC2 인스턴스에 접속할 때마다 슬랙으로 알림을 보내는 방법 : https://scbyun.com/333
728x90
반응형
'퍼블릭 클라우드' 카테고리의 다른 글
AL2022(Amazon Linux 2022) 운영체제 (0) | 2022.04.22 |
---|---|
[aws] Shell 스크립트로 Amazon Machine Image(AMI) 생성하기 (0) | 2022.01.18 |
[aws] Amazon ECR(Amazon Elastic Container Registry) 구성 (0) | 2021.10.30 |
AWS EC2 인스턴스에 웹 브라우저를 통해 연결하기 (0) | 2021.10.26 |
[aws] IAM 사용자가 MFA 디바이스를 스스로 관리하도록 허용 (0) | 2021.10.20 |