728x90
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 /etc/profile.d/ec2-info-send.sh
slack 알람
728x90
'퍼블릭 클라우드' 카테고리의 다른 글
AWS S3 버킷의 액세스를 IP 주소로 제한하는 방법 (0) | 2021.11.03 |
---|---|
Amazon Linux 2에서 rc-local(rc.local) 서비스를 활성화하는 방법 (0) | 2021.10.30 |
[draft] Amazon EC2 인스턴스에 정적 호스트 이름을 할당하는 방법 (0) | 2021.10.30 |
AWS 리소스의 네이밍 규칙(태그 이름) (0) | 2021.10.30 |
[aws] Amazon Linux 2 인스턴스에 도커(Docker)를 설치하는 방법(docker install) (0) | 2021.10.29 |