ACTIVEMQ Judgment Queue Survival Script (ii)

Source: Internet
Author: User

#脚本用途: Detection of port monitoring ACTIVEMQ cluster and its queue patency #!/usr/bin/env python#coding=utf-8 import paramikoimport  timeimport sysimport stompaip =  ("First MQ server") bip =  ("Second MQ server") cip =  (" Third MQ server ") List = []def checknetstat ():    for i in  (Aip,Bip, CIP):        hostname=i         username= "root"         password= "Server password"     # Here the default three server passwords are the same         paramiko.util.log_to_file ("Syslogin.log")         ssh=paramiko. Sshclient ()         ssh.load_system_host_keys ()          ssh.connect (Hostname=hostname,username=username,password=password)          stdin,stdout,stderr=ssh.exec_command ("netStat -ntpl | grep 61613 | wc -l ")          word=str (Stdout.read (). strip (' \ n '))         list.append (word)     #把for循环的结果变成一个list         ssh.close ()      print list    def golisten (XIP):    class  MyListener (object):         def on_error (self, headers,  Message):             print (' received an  error %s '  % message)         def on_message (self,  headers, message):             print (' received a message %s '  % message)     conn = stomp. Connection ([(xip,61613)]) &NBsp;   conn.set_listener (",  mylistener ())     conn.start ()      conn.connect (' MQ account ', ' MQ password ')     conn.subscribe (destination= '/queue/queue name ',  id=1, ack= ' auto ')     conn.send (body= ' specific message content ',  destination= '/queue/queue name ')     time.sleep (2)     conn.disconnect ()     def  remotecommand ():     if list == [' 1 ',  ' 0 ',  ' 0 ']:         print  ("61613 ports on the first machine are listening, now try to send messages to the queue ...")          golisten (AIP)      #这里应该加一个try语句     elif  list == [' 0 ',  ' 1 ',  ' 0 ']:        print  (" The second machine's 61613 port is listening, now trying to send a message to the queue ... ")         golisten (BIP)      elif list == [' 0 ',  ' 0 ',  ' 1 ']:        print  (" The third machine's 61613 port is listening, now trying to send a message to the queue ... ")         golinten (CIP)      else:        print  ("Activemq 61613 port is in an exception, now reboot these three MQ ... ")         pass     #这一段补上远程restart   ACTIVEMQ process         if __name__ ==  "__main__":         checknetstat ()          Remotecommand () print ("End of entire script execution, thank you for using!") ")


Basically, the structure of the entire script is such that the content of Chinese characters can be filled in according to the actual situation.


Currently, because there is no full try statement, the effect of starting this script under normal circumstances is this:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/8B/CC/wKiom1hY_Q3xIV3jAAA-X3gEd9Y997.png "title=" 1.png " alt= "Wkiom1hy_q3xiv3jaaa-x3ged9y997.png"/>

This article is from "Life is waiting for Gordo" blog, please make sure to keep this source http://chenx1242.blog.51cto.com/10430133/1884415

ACTIVEMQ Judgment Queue Survival Script (ii)

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.