2016-07-29 4 views
0

У меня есть два файла, один находится файл «error_dict» и другой «jbosslogfile» файл ошибок ДИКТ содержит известные сообщения об ошибках в каждой строке, как error_dictПоиск часть соответствия строки в Python

"0500 ERROR [org.picketlink.identity.federation]" 
"-0500 ERROR [com.gravitant.cloud.appsportfolio.jsf.architecture.beans.StorageAccountBean]" 
"Invalid Context Code - APP" 

JbossLogFile

2016-06-03 00:19:52,612 -0500 ERROR [org.jboss.as.ejb3.invocation] (EJB default - 3) JBAS014134: EJB Invocation failed on component GraBmsDataLoaderEjbIfc for method public abstract void com.gravitant.bms.common.dataload.GraBmsDataLoaderEjbIfc.loadVMTemplates(java.lang.String,java.lang.String,java.lang.String): javax.ejb.EJBException: com.gravitant.bts.bms.exception.GraException: Display Message:Transaction commit failed - 
2016-06-03 00:20:10,809 -0500 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (EJB default - 4) Duplicate entry '9db562c525e942698c605df2f0c9b26a__FreeBSD10_3-2016-06-02::unreco' for key 'UQ_graresourcetemplate$tmpId_prv_usrGrpId' 
2016-06-03 00:20:10,824 -0500 ERROR [com.gravitant.bts.bms.transaction.BTSTransaction] (EJB default - 4) BmsBaseTransaction:Commit()- Transaction commit failed 
2016-06-03 00:20:11,001 -0500 ERROR [org.jboss.as.ejb3.invocation] (EJB default - 4) JBAS014134: EJB Invocation failed on component GraBmsDataLoaderEjbIfc for method public abstract void com.gravitant.bms.common.dataload.GraBmsDataLoaderEjbIfc.loadVMTemplates(java.lang.String,java.lang.String,java.lang.String): javax.ejb.EJBException: com.gravitant.bts.bms.exception.GraException: Display Message:Transaction commit failed - 
2016-06-03 00:31:56,730 -0500 ERROR [org.picketlink.identity.federation] (http-/10.200.212.143:8081-10) PLFED000263: Service Provider could not handle the request.: java.lang.IllegalArgumentException: PLFED000132: No assertions in reply from IDP 
2016-06-03 00:52:01,379 -0500 ERROR [org.picketlink.identity.federation] (http-/10.200.212.143:8081-1) PLFED000263: Service Provider could not handle the request.: java.lang.IllegalArgumentException: PLFED000132: No assertions in reply from IDP 
2016-06-03 01:11:49,938 -0500 ERROR [org.picketlink.identity.federation] (http-/10.200.212.143:8081-10) PLFED000263: Service Provider could not handle the request.: java.lang.IllegalArgumentException: PLFED000132: No assertions in reply from IDP 
2016-06-03 01:41:59,942 -0500 ERROR [org.picketlink.identity.federation] (http-/10.200.212.143:8081-1) PLFED000263: Service Provider could not handle the request.: java.lang.IllegalArgumentException: PLFED000132: No assertions in reply from IDP 
2016-06-03 02:02:04,783 -0500 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/].[Faces Servlet]] (http-/10.200.212.143:8081-1) JBWEB000236: Servlet.service() for servlet Faces Servlet threw exception: javax.faces.application.ViewExpiredException: viewId:/appsportfolio-main.jsf - View /appsportfolio-main.jsf could not be restored. 
2016-06-03 02:11:57,211 -0500 ERROR [org.picketlink.identity.federation] (http-/10.200.212.143:8081-1) PLFED000263: Service Provider could not handle the request.: java.lang.IllegalArgumentException: PLFED000132: No assertions in reply from IDP 
2016-06-03 02:22:02,739 -0500 ERROR [org.picketlink.identity.federation] (http-/10.200.212.143:8081-10) PLFED000263: Service Provider could not handle the request.: java.lang.IllegalArgumentException: PLFED000132: No assertions in reply from IDP 
201 

Что я пытаюсь сделать, это очень просто, я использую этот файл error_dict каждую известную ошибку в соответствии с моей JBoss лог-файл, в этом случае, если я нашел часть с tring из файла журнала jboss распечатает эту строку на экране, а затем вытащите эту строку из файла журнала jboss.

Очень похоже, что я могу достичь этого, используя блокнот ++, как отметить все строки, а затем удалить закладку будет выполнять операцию yank. Очень похоже, что я пытаюсь реализовать более в питона кода, который является следующим

def MatchCountYankerrors(): 
    ferrorrepo = errorrepopath 
    conclufile = os.path.join(Decompressfilepath,(appservername+'conclusion')) 
    ferrorfile = open(ferrorrepo) 
    confile = open(conclufile) 
    output = [] 

    for errlines in ferrorfile: #Pick each line from error_dict 
     c = 0 
     for eachconline in confile:#pick each line from Jboss log 
      #if re.search(errlines,eachconline,re.M|re.I): 
      newerrliens = errlines.strip().split() #error_dict file each line strip and spilit 
      neweachconline = eachconline.strip().split() #Jbosslog file each line strip and spliting 
      if newerrliens in neweachconline: 
       print neweachconline 

Цель: Как выполнить следующие операции с помощью Python программу enter image description here

ответ

0

Вот код, который перебрать мои файлы ошибок репо и в финальном файле журнала ошибок, если есть совпадение с линией, он будет выдергивать (удалять) эту строку из файла журнала, и перед выполнением этой операции он создаст файл резервной копии.

#This function will be matching error lines from error repo files and if matched it will yank those lines from the files. 
def MatchandYankerrors(): 
    ferrorrepo = errorrepopath 
    conclufile = os.path.join(Decompressfilepath,(appservername+'conclusion')) 
    ferrorfile = open(ferrorrepo) 
    output = [] 

    for errlines in ferrorfile: #Pick each line from error_dict 
     c = 0 
     newerrliens = errlines.strip() # error_dict file each line strip and spilit 
     #confile = open(conclufile,"r+")#This will keep opening file every time when we need new error to search. 
     #confilelines = confile.readlines() #This will read all lines from file. 
     #confile.seek(0) 
     i=0 
     for line in fileinput.input(conclufile,inplace=1,backup='.orig'): 
      line = line.strip() 
      if newerrliens in line: 
       pass 
      else: 
       print line 
     fileinput.close()