Server downtime monitoring, detection, alarm procedures (139 binding mobile phone SMS alarm) monitor_down.sh

Source: Internet
Author: User
Tags failover

Downtime Monitoring Alarm Program


A. Source of Demand

Downtime is most painful for ops people. How to check if a server is still performing properly, assuming that the server is down, how to monitor and notify the first-line OPS personnel to maintain, and minimize the loss.

two. Program Functions

perform a downtime test on the specified server, assuming that it is indeed down, send Email to the 139 Email ( binding mobile phone, realize SMS alarm )

Three. SOURCE program

#!/bin/bash#author longxibendi#blog http://blog.csdn.net/longxibendi#function Ping a host and output to file Ping_longxibendi.log#ping destinationfunction_ping () {ping-c 3 172.29.141.115 > Pi Ng_longxibendi.log} #downtime detection and send email to safunction_downtime_detection_and_sendemail () {if [ "' Cat Ping_longxibendi.log | grep unreachable ' "! =" "]; Then/usr/local/bin/sendemail-f monitor_sys@163.com-t longxibendi@139.com-s smtp.163.com-u "Server down Time "-xu monitor_sys-xp 123456789-m" ' Date;echo "172.29.141.115" ' "Fi} #main Functionfunction_main () {while Truedo function_ping; Sleep 2 function_downtime_detection_and_sendemail; Sleep 2done}function_main;

Four. Program Description

1. Through function_ping, ping the host 172.29.141.115 every 4 seconds (assuming, of course, the host 172.29.141.115 's firewall, or the ICMP packet within the filter, the program is obviously not available) to redirect the output to Ping_ In the Longxibendi.log file

2. Through the Function_downtime_detection_and_sendemail, every 4 seconds, through Ping_longxibendi.log inference whether there is no sign of ping, false with, then call SendEmail Mail ( Mobile SMS) alarm.

3. Monitoring interval description, the ability to change the first sleep to 150, the second sleep to 150, so that every 5 minutes monitoring.

Four. Instructions for use of the environment

1. Host A (172.29.141.112) Host B (172.29.141.115),

Deploy the Monitor program (MONITOR_DOWN.SH) on a to monitor B

2. Under normal conditions A can ping through B

Because of the ping command used, it is assumed that the program must be ping B under normal conditions. For businesses, this may require firewalls and Linux kernel parameters (assuming, of course, that Net.ipv4 has not been changed before . ) Icmp_echo_ignore_all, you do not need to adjust )

3. Install the SendEmail and in 139 e-mail register (binding mobile phone), can have the message (SMS) Alarm Alert

Five. Program Test

[Email protected] monitor]# sh monitor_down.sh

20:33:46 localhost sendemail[9175]: Email was sent successfully!

20:33:56 localhost sendemail[9204]: Email was sent successfully!

Terminated

[Email protected] monitor]#

Six. Program Extensions

This program, only to achieve downtime monitoring and alarm, but did not implement failover, self-switching function. In fact, only a slight change of the program can be implemented to failover, and actively switch. Failover, for example, can be done by deploying the program on hot standby A, monitoring B, and once B is down, a runs the floating change IP and updates the downlevel Serverarp list. can participate in

Http://blog.csdn.net/longxibendi/archive/2011/05/21/6436606.aspx

Disclaimer: This document can be changed arbitrarily, but must be signed by the original author

Phoenix Dancer qq:578989855

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.