zoukankan      html  css  js  c++  java
  • python监控服务器的主备模式

    #-*- coding:utf8 -*-
    import paramiko
    import re

    def check_active_ac(intervals=1):
    client = paramiko.Transport(('主备的虚拟ip', 22))
    # paramiko模块提供了ssh及sft进行远程登录服务器执行命令和上传下载文件的功能
    client.connect(username='username', password='password')
    # 打开一个通道
    chan = client.open_session()
    chan.settimeout(5)
    # 获取终端
    chan.get_pty()
    # 激活终端,这样就可以登录到终端了,就和类似于xshell登录系统一样
    chan.invoke_shell()
    chan.recv(65535)
    # 设置缓冲区大小
    chan.send('show high-availability status ')
    # 执行'show high-availability status'命令,查看高可用状态
    output = chan.recv(65535).decode()
    print(output)
    # 退出终端
    chan.send('exit ')
    client.close()
    search_string = output.split(' ')[7]
    '''print(' ')'''
    '''print("4位:", search_string)'''
    if re.search(r'primary', search_string, flags=re.IGNORECASE):
    '''re.IGNORECASE忽略大小写'''
    active_ac = '主ip'
    '''print("主ip: Primary active")'''

    elif re.search(r'secondary', search_string, flags=re.IGNORECASE):
            active_ac = '备ip'
    '''print("备ip: Secondary active")'''
    else:
    #print("0")
    return
    test = check_active_ac()
  • 相关阅读:
    ImageCapOnWeb控件使用说明
    网页摄像头拍照
    js调用ocx控件
    sql中 in 、not in 、exists、not exists 用法和差别
    oracle远程登录解决办法
    oracle导入导出,包括表,表结构,方案,数据库
    字典树
    线段树
    Til the Cows Come Home
    Forgger
  • 原文地址:https://www.cnblogs.com/qfdxxdr/p/7068284.html
Copyright © 2011-2022 走看看