我正在使用电子邮件脚本发送Nagios警报。 命令是
define command{
command_name notify-host-by-email
command_line bash /etc/nagios/servers/email.sh /usr/local/aws/bin/aws from_email@abc.com to_email@abc.com 'NAGIOS Alert : $NOTIFICATIONTYPE$' 'Notification Type: $NOTIFICATIONTYPE$<br />Host: $HOSTNAME$<br />State: $HOSTSTATE$<br />Address: $HOSTADDRESS$<br />Info:$HOSTOUTPUT$<br />Date/Time: $LONGDATETIME$\n<br />'
}
我的电子邮件脚本文件说:
#!/bin/bash
echo "____Sending Mail___ "
echo "To : "$2
echo "From: "$3
echo "Subject: "$4
echo "Message: "$5
source /etc/environment
echo '{"Subject":{"Data":"'"$4"'","Charset":"UTF-8"},"Body":{"Html":{"Data":"'"$5"'","Charset":"UTF-8"}}}' > /etc/nagios/servers/template.json
$1 ses send-email --region "us-west-2" --destination ToAddresses=$2 --from $3 --message file:///etc/nagios/servers/template.json
我使用AWS Email服务CLI发送邮件
但我收到的邮件说:
Notification Type: $NOTIFICATIONTYPE$
Host: $HOSTNAME$
State: $HOSTSTATE$
Address: $HOSTADDRESS$
Info:$HOSTOUTPUT$
Date/Time: $LONGDATETIME$
答案 0 :(得分:0)
解决了......
这是命令:
define command{
command_name notify-host-by-email
command_line bash /etc/nagios/servers/email.sh /usr/local/aws/bin/aws from_email@abc.com to_email@abc.com "NAGIOS $NOTIFICATIONTYPE$ Alert : $HOSTNAME$" "Notification Type: '$NOTIFICATIONTYPE$'<br />Host: '$HOSTNAME$'<br />State: '$HOSTSTATE$'<br />Address: '$HOSTADDRESS$'<br />Info:'$HOSTOUTPUT$'<br />Date/Time: '$LONGDATETIME$'\n<br />"
}
另一个问题出现了,它反复发送相同的邮件通知,我想这是因为多个通知使用相同的template.json。所以我在这里创建一个临时json并在发送邮件后删除它。还在syslog中添加了日志记录。它帮助很大。
email.sh:
#!/bin/bash
logger -i "____Sending Mail___ To : '$2' From: '$3'"
logger -i " With Subject: '$4'"
logger -i " With Message: '$5'"
logger -i "User : '$USER'"
temp_file_name=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
source /etc/environment
touch /tmp/$temp_file_name.json |& logger
echo '{"Subject":{"Data":"'"$4"'","Charset":"UTF-8"},"Body":{"Html":{"Data":"'"$5"'","Charset":"UTF-8"}}}' > /tmp/$temp_file_name.json
$1 ses send-email --region "us-east-1" --destination ToAddresses=$2 --from $3 --message file:///tmp/$temp_file_name.json |& logger
rm /tmp/$temp_file_name.json |& logger