forked from Hydrosys4/Master
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebuggingmod.py
executable file
·80 lines (62 loc) · 1.62 KB
/
debuggingmod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from __future__ import print_function
from builtins import str
import logging
import subprocess
import filestoragemod
logger = logging.getLogger("hydrosys4."+__name__)
SENTERRORTEXT=""
def createfiletailsyslog(dstfile):
rownumber="100"
data=tailsyslogcmd(rownumber)
if data:
filestoragemod.savefiledata_plaintext(dstfile,data)
return True
else:
print("data empty")
return False
def searchsyslogkeyword(keyword):
rownumber="300"
data=tailsyslogcmd(rownumber)
numrowafter=10
countdown=0
extract=[]
for row in data:
if keyword.lower() in row.lower():
countdown=numrowafter
if countdown:
extract.append(row)
countdown=countdown-1
return extract
def searchLOGkeyword(filename,keyword):
print("debugging check errors in: ", filename)
rownumber="300"
data=tailLOGcmd(filename,rownumber)
numrowafter=10
countdown=0
extract=[]
for row in data:
if keyword.lower() in row.lower():
countdown=numrowafter
if countdown:
extract.append(row)
countdown=countdown-1
return extract
def tailsyslogcmd(rownumber):
syslogfile="/var/log/syslog"
cmd = ['tail', syslogfile , '-n '+ str(rownumber)]
return execcommand(cmd)
def tailLOGcmd(filename,rownumber):
cmd = ['tail', filename , '-n '+ str(rownumber)]
return execcommand(cmd)
def execcommand(cmd):
try:
scanoutput = subprocess.check_output(cmd).decode('utf-8')
except:
print("error to execute the command" , cmd)
logger.error("error to execute the command %s",cmd)
return []
return scanoutput.split('\n')
if __name__ == '__main__':
# comment
#a=[]
print("Hello")