forked from PanDAWMS/pilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSysLog.py
53 lines (42 loc) · 1.17 KB
/
SysLog.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
import syslog
from commands import getoutput
from pUtil import tolog
def sysLog(message):
""" Write message to syslog """
status = False
try:
if message != "":
syslog.syslog(syslog.LOG_ERR, message)
else:
tolog("!!WARNING!!4444!! Will not write empty message to syslog")
except Exception, e:
tolog("!!WARNING!!4444!! Failed to write to syslog: %s" % (e))
else:
status = True
return status
def getSysLogTail():
""" Return the tail of the syslog """
out = ""
path = "/var/log/messages"
cmd = "tail %s" % (path)
tolog("Executing command: %s" % (cmd))
try:
out = getoutput(cmd)
except Exception, e:
tolog("!!WARNING!!4444!! Could not read path %s, %s" % (path, e))
return out
def dumpSysLogTail():
""" Dump the syslog tail to the pilot log """
tolog("syslog tail:\n%s" % (getSysLogTail()))
if __name__ == "__main__":
message = "hi"
if sysLog(message):
tolog("ok")
out = getSysLogTail()
if out != "":
print out
else:
print "NOT ok"
else:
tolog("not ok")
dumpSysLogTail()