Shell script monitors server downtime, detection, and alarm programs

Source: Internet
Author: User

Shell script monitors server downtime, detection, and alarm programs
Downtime Monitoring Alarm Program


  • Demand Source
Downtime is the most painful for O & M personnel. How can I check whether a server is still running normally? If the server goes down, how can I promptly monitor and notify frontline O & M personnel for maintenance to minimize losses.

  • Program functions
Monitor the downtime of the specified server. If the server is down, send an email to the 139 mailbox (bind the mobile phone to enable SMS alarms)
The script is as follows:
#! /Bin/bash # author longxibendi # blog http://blog.csdn.net/longxibendi # function ping a host and output to file ping_longxibendi.log # ping destination function_ping () {ping-c 3 172.29.141.115> ping_longxibendi.log} # downtime detection and send email to SA partition () {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 downtime"-xu monitor_sys-xp 123456789-m "'date; echo "172.29.141.115" '"fi} # main function function_main () {while true do function_ping; sleep 2 function_downtime_detection_AND_sendemail; sleep 2 done} function_main;


1. use function_ping to ping the host 172.29.141.115 every four seconds. (Of course, if the host's 172.29.141.115 firewall or internal ICMP packet filtering, this program is obviously unavailable) redirect the output to the ping_longxibendi.log file.

2. Use function_downtime_detection_AND_sendemail to check whether there are any signs of ping at every 4 seconds through ping_longxibendi.log. If yes, call sendEmail to send an alert by SMS.

3. The monitoring interval can be changed to 150 for the first sleep and 150 for the second sleep, so that monitoring is performed every 5 minutes.

Iv. Environment Description

1. host a (172.29.141.112) host B (172.29.141.115 ),
Deploy the Monitoring Program (monitor_down.sh) on A to monitor B

2. Under normal circumstances, A can ping B
Because the ping command is used, if this program is used, A must ping B Normally. For enterprises, this may require firewall and Linux kernel parameters (of course, if net. ipv4.icmp _ echo_ignore_all is not modified before, no adjustment is required)

3. After sendEmail is installed and registered in the 139 mailbox (bound to a mobile phone), you can receive an email (SMS) Alarm prompt.

5. program testing


[Root @ localhost monitor] # sh monitor_down.sh
May 21 20:33:46 localhost sendEmail [9175]: Email was sent successfully!
May 21 20:33:56 localhost sendEmail [9204]: Email was sent successfully!
Terminated
[Root @ localhost monitor] #

6. Program Extension
This program only implements downtime monitoring and alarm, but does not implement failover and automatic failover. In fact, you only need to modify the program to implement failover and automatic failover. Failover. For example, you can deploy the program on the hot standby machine A to monitor B. Once B goes down, A executes floating IP address change and updates the arp list of the underlying server. Refer
Http://blog.csdn.net/longxibendi/archive/2011/05/21/6436606.aspx


Disclaimer: This document can be changed at will, but must be signed by the original author
Author: Phoenix dancer qq: 578989855

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.