监控某个进程端口,邮件告警

监控某个进程端口,邮件告警

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
#despcrition:Our MQ server encountered some troubles which sometimes 5672 port was unreachable from this server.So run a shell script to detect the connection
#author:huang yong
#date: 2018-03-12

#define variables
port=5672
host=10.47.115.13
email_user="huangyong@doweidu.com"
#email_title="rabbitmq connection lost"
email_send=0

#send email
function send_email () {
echo "$(nmap -p $port $host)" | mail -s $1 $email_user

}

while true;do
nmap -p $port $host | grep "${port}/tcp open" > /dev/null
if [ $? -ne 0 ];then
if [ $email_send -eq 0 ];then
send_email "rabbitmq connection lost"
email_send=1
fi
else
[ $email_send -eq 1 ] && send_email "rabbitmq connection succeed" && email_send=0
fi

sleep 5

done

本文标题:监控某个进程端口,邮件告警

文章作者:Jesse

发布时间:2018年06月12日 - 22:06

最后更新:2020年06月30日 - 20:06

原始链接:https://jesse.top/2018/06/12/Linux-Basic/shell&shell脚本/监控某个进程端口,邮件告警/

许可协议: 禁止商业用途 转载请保留原文链接及作者。

坚持原创技术分享,您的支持将鼓励我继续创作!