python 远程巡检多台服务器ogg状态信息

因为工作中对ogg数据一致性,实时性要求不高,同步异常时有充足修复时间,未配置ogg异常监控,但仍需定期检查运行状态,因此写了这个小脚本,在Windows上一键执行即可。
1
#!/usr/bin/env python 2 # -*-coding: utf-8 -*- 3 # @Time:2020/7/13 9:47 4 # @Author: WSN 5 6 import paramiko 7 import re 8 from hostlist import * 9 10 ''' 11 hostlist config example: 12 hostlist=[{'host': 'x.x.x.x', 'port': '22', 'user': 'xxxx', 'pwd': 'xxxxx', 'oggdir': '/ogg'}] 13 ''' 14 15 16 class SshOgg: 17 def __init__(self, host, port, username, pwd): 18 self.host = host 19 self.port = port 20 self.username = username 21 self.pwd = pwd 22 self.ssh = paramiko.SSHClient() 23 self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 24 self.ssh.connect(self.host, self.port, self.username, self.pwd) 25 26 def check_ogg_status(self, oggdir): 27 cmd = '''su - oracle -c \'echo "info all" |%s/./ggsci\'''' % oggdir 28 stdin, stdout, stderr = self.ssh.exec_command(cmd) 29 for i in stdout.readlines(): 30 if re.search(r'REPLICAT', i): 31 print(i) 32 33 def closed(self): 34 self.ssh.close() 35 36 37 if __name__ == '__main__': 38 for con_info in hostlist: 39 host = con_info['host'] 40 port = con_info['port'] 41 username = con_info['user'] 42 pwd = con_info['pwd'] 43 oggdir = con_info['oggdir'] 44 ssh = SshOgg(host, port, username, pwd) 45 print('-------%s上ogg进程运行状态信息-------' % host) 46 ssh.check_ogg_status(oggdir) 47 ssh.closed()

 

posted @ 2020-10-12 15:26  白菜叶叶  阅读(579)  评论(0编辑  收藏  举报