[tool development] Change nagios monitoring script to keepalived Monitor script

Source: Internet
Author: User
<span id="Label3"></p><p><p>Recently in the development and office environment of High availability, using the keepalived;keepalived based on the Linux kernel support lvs, both high availability, and load balancing, very practical.</p></p><p><p>Keepalived Monitoring Service status can be used in a variety of ways, such as: http_get| Ssl_get| tcp_check| smtp_check| Misc_check (custom scripting), in order to accurately monitor the state of the service, we need to write a custom monitoring script.</p></p><p><p>Many companies now deploy Nagios as a monitoring platform for services, and Nagios also needs to monitor scripts or programs, and if the keepalived monitoring script can apply naigios, It can save a lot of trouble. But Nagios monitoring scripts or programs are somewhat different from keepalived:</p></p><p><p>Nagios script or program return value: 0-ok,1-warn, 2-critical, 3-unknown</p></p><p><p>keepalived script return value: 0-ok,1-fail,2~255-ok and exit code-2</p></p><p><p>As you can see, you just need to change the return value of the Nagios script or program to use it on Keepalived. If it is a text format Nagios script, You can directly change the return value, if it is a binary format program, it cannot be changed directly. My approach is to put the Nagios monitoring program into Python and modify its return value so that it can be used for Keepalived.</p></p><p><p>The following example uses Python to change the Nagios check_dns binary monitor program to a keepalived-capable script, noting that the command in Commands.getstatusoutput is called the Nagios binary monitor program:</p></p><p><p>(since My service does not need to modify the exit status code, it only returns 0 or 1)</p></p><pre class="brush:python;gutter:true;">#!/usr/bin/python#coding:utf-8# return 0: Health Check ok, weight hold # return 1: Health Check failed, weight set to 0# return 2-255: health Check ok, weight set to: exit status code -2import Commandsimport sys, getoptimport os.pathdef check_dns (server= ", timeout=", name= ", address="): status, output = com Mands.getstatusoutput ("/usr/lib64/nagios/plugins/check_dns-s" + server + "-t" + timeout + "-h" + name + "-a" + add Ress) return statusif __name__ = = ' __main__ ': server, timeout, name, address = ', ', ', ' script = os.path.sp Lit (os.path.realpath (__file__)) [1] try:opts, args = getopt.getopt (sys.argv[1:], "s:n:a:t:", ["server=", "name=" , "address=", "timeout="]) except Getopt. getopterror, err: #print str (err) sys.exit (3) for o, A in opts:if o in ("-s", "--server"): Server = a elif o in ("-n", "--name"): name = a elif o in ("-a", "--address"): ad Dress = a elif o in ("-t", "--timeout"): timeout = a else: #print "usage:" + script + " -s server-n name-a address-t timeout "sys.exit (3) if server = = ' or name = = ' or address = = ' or time out = = ": #print" usage: "+ script +"-s server-n name-a address-t timeout "sys.exit (3) else: Status = Check_dns (server, timeout, name, address) if status: #print status Sys.exit (1) Else: #print Status Sys.exit (0)</pre><p><p></p></p><p><p>[tool development] Change nagios monitoring script to keepalived Monitor script</p></p></span>

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.