#! /usr/bin/env python
# -*- coding: UTF-8 -*-

"""
The script is to check whether NE is in syncfail, if it is syncfail, login into CIPS to get login.

"""
import paramiko
import ssh
import os
import re
import time
import appdirs
import packaging
import packaging.version
import packaging.specifiers
import packaging.requirements
import pyasn1.type
import pyasn1.type.univ

paramiko.__version__
appdirs.__version__
packaging.__version__
packaging.version.__doc__
packaging.specifiers.__doc__
packaging.requirements.__doc__
pyasn1.type.__doc__
pyasn1.type.univ.__doc__

#定义syncfail异常类
class Syncfail_Exception(Exception):
def __init__(self,value):
self.value=value
def __str__(self):
return self.value

#定义
class syncfail(object):
def __init__(slef,neip,cipsip,ss=5):
slef.neip = neip
slef.cipsip = cipsip
slef.ss=ss
def __str__(slef):
print "Syncfail or not, is a question!"

def checksyncfail(self):
port = 22
username = 'root'
password = 'root'
#os.chdir(r'C:\Users\cchen\Desktop')
paramiko.util.log_to_file('paramiko.log')
s = paramiko.SSHClient()
s.load_system_host_keys()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(self.neip,port,username,password)
ssh=s.invoke_shell()
self.ss-=2
while(1):
time.sleep(self.ss)
ssh=s.invoke_shell()
ssh.send('cat /var/log/dpkg_cfpal.log|grep syncfail\n')
time.sleep(2)
x = ssh.recv(10000)
#print x
pattern1=re.compile(r'(into syncfail state)')
y=re.findall(pattern1,x)
#y=1 just for test
if y:
print 'Syncfail occurs:\n',x,'\n',time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
else:
print 'No syncfail here.',time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))

if y:
try:
raise Syncfail_Exception('Syncfail occurs')
except Syncfail_Exception,e:
print e
self.getlog(self.neip,self.cipsip)
break
def getlog(self,neip,cipsip):
port = 22
username = 'root'
password = 'root'
s = paramiko.SSHClient()
s.load_system_host_keys()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(self.neip,port,username,password)
ssh=s.invoke_shell()
ssh.send('/etc/init.d/xinetd stop\n\
tcpsvd 0 21 ftpd -w /ftppub &\n\
/etc/init.d/xinetd start\n')
time.sleep(2)
ssh.send('scp -vr root@'+cipsip+': /var/volatile/log/ /sdlog/\n')
time.sleep(1)
x1=ssh.recv(10000)
print x1+'\n'
pattern2=re.compile(r'Are you sure you want to continue connecting')
y1=re.findall(pattern2,x1)
if y1:
ssh.send('yes\n')
time.sleep(1)
x2=ssh.recv(10000)
print x2+'\n'

print 'The log is in sdlog/log/ now.\n'

if __name__=='__main__':
neip=raw_input('Please put in your NE IP, such as 200.200.180.24:')
cipsip=raw_input('Please put in your CIPS IP:')
ss=int(raw_input('Please put in the check interval time(s>3)'))
sync=syncfail(neip,cipsip,ss)
sync.checksyncfail()
raw_input('Print any to quit!')

A python script to check NE syncfail and get log from CIPS的更多相关文章

  1. (copy) Shell Script to Check Linux System Health

    source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...

  2. java + spring (jython\python\script) Error:SyntaxError: no viable alternative at character '\n'

    使用Jython结合java和Python开发功能时,要是遇到如下情况: 2016-03-10 16:16:49 DEBUG [com.freedom.orion.configs.JyhtonConf ...

  3. --- no python application found, check your startup logs for errors

    --- no python application found, check your startup logs for errors 碰到这个问题,请留意下系统执行的python版本和自己的djan ...

  4. Windows 配置Apache以便在浏览器中运行Python script的CGI模式

    打开httpd.conf,找到”#ScriptInterpreterSource Registry “,移除前面的注释# (如果找不到这行,就自己添加进去) 找到“Options Indexes Fo ...

  5. Notepad++插件Emmet和Python Script的安装

    最近在做一个项目,涉及到大量的HTML.CSS代码的编写,手动写代码效率实在 是低下.于是想搜索一下,有没有Notepad++插件可以支持自动生成的,果不其然还真有.Emmet,这款神器其实就是 Ze ...

  6. rc.local 注意事項,call python script, file position

    如果要在 rc.local 呼叫 python script python script 的位置需使用絕對路徑 其 python script 裡的有關 file 的位置也需使用 絕對路徑 如果要在 ...

  7. MS SQL错误:SQL Server failed with error code 0xc0000000 to spawn a thread to process a new login or connection. Check the SQL Server error log and the Windows event logs for information about possible related problems

          早晨宁波那边的IT人员打电话告知数据库无法访问了.其实我在早晨也发现Ignite监控下的宁波的数据库服务器出现了异常,但是当时正在检查查看其它服务器发过来的各类邮件,还没等到我去确认具体情 ...

  8. python+selenium之自定义封装一个简单的Log类

    python+selenium之自定义封装一个简单的Log类 一. 问题分析: 我们需要封装一个简单的日志类,主要有以下内容: 1. 生成的日志文件格式是 年月日时分秒.log 2. 生成的xxx.l ...

  9. NE Upgrade python script. Need to write a Tkinter GUI for it

    # -*- coding: utf-8 -*-#from ftplib import FTP __authour__='CC' import osimport telnetlibimport time ...

随机推荐

  1. iOS XCode启用/关闭Clang Warnings

    前言:warnings是编码中很重要的一个环节,编译器给出合理的warning能帮助开发者找到自己代码的问题,防止很多bug产生.  默认用XCode创建一个工程,会自动开启一些重要的warnings ...

  2. CentOS 7 安装字体库 & 中文字体

    前言 报表中发现有中文乱码和中文字体不整齐(重叠)的情况,首先考虑的就是操作系统是否有中文字体,在CentOS 7中发现输入命令查看字体列表是提示命令无效:  如上图可以看出,不仅没有中文字体,连字体 ...

  3. Spark on Yarn:java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost\\db_instance_name:1433;databaseName=db_name

    本文只是针对当前特定环境下,出现的问题找不到sqljdbc驱动的案例.具体出现原因,可能是spark版本问题,也可能是集群配置问题. yarn-client方式下: 通过--jars参数指定驱动文件位 ...

  4. TIJ——Chapter Eight:Polymorphism

    The twist |_Method-call binding Connecting a method call to a method body is called binding. When bi ...

  5. ferret32位安装

    首先在网上找到解决方案: 1.添加对32位的支持 dpkg --add-architecture i386 2.更新 apt-get clean && apt-get update & ...

  6. csuoj 1116: Kingdoms

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1116 1116: Kingdoms Time Limit: 3 Sec  Memory Limit ...

  7. 夺命雷公狗----Git---6---GitHub基本使用

    github不是git. git是一个版本控制系统,是一个版本控制软件,从而完善共同开发... github是一个网站,基于git的,主要作用是代码托管的.... 托管的几层含义如下: 1:将自己平常 ...

  8. LigerUI 表单和表格中的combobox如何初始化值

    摘要: 在修改基础信息的时候,通常会遇到需要修改值为选择值的时候,这时候,数据库存的一般是value,而不是显示的text值,但页面显示的时候如果显示成数字型的值,通常会给人不够直观的感觉.因此,要求 ...

  9. Centos搭建Python+Nginx+Tornado+Mysql环境[转载]

    Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入 ...

  10. 利用python检测色情图片简易实例

    import sys import os import _io from collections import namedtuple from PIL import Image class Nude( ...