Skip to content

Instantly share code, notes, and snippets.

@bwann
Created January 18, 2016 12:40
Show Gist options
  • Save bwann/df167651867e74f99557 to your computer and use it in GitHub Desktop.
Save bwann/df167651867e74f99557 to your computer and use it in GitHub Desktop.
Scribe logging support for anaconda
Python bindings sources (also provides a python /usr/bin/scribe_cat)
fb303-python-0.0-0.el6.20090505svn770888.x86_64.rpm
scribe-python-2.01-2.el6.x86_64.rpm
thrift-python-0.0-0.el6.20090505svn770888.x86_64.rpm
- extract with rpm2cpio
- move directories from python2.6/site-packages to python2.7/site-packages
--- pyanaconda/kickstart.py.orig 2016-01-17 15:28:02.273103882 -0800
+++ pyanaconda/kickstart.py 2016-01-17 16:58:06.840654474 -0800
@@ -78,6 +78,8 @@
stdoutLog = logging.getLogger("anaconda.stdout")
from pyanaconda.anaconda_log import logger, logLevelMap, setHandlersLevel, DEFAULT_LEVEL
+from pyanaconda.scribe_logger import scribe_log
+
class AnacondaKSScript(KSScript):
""" Execute a kickstart script
@@ -2017,8 +2019,10 @@
return
log.info("Running kickstart %%post script(s)")
+ scribe_log("Running kickstart %%post script(s)")
map (lambda s: s.run(iutil.getSysroot()), postScripts)
log.info("All kickstart %%post script(s) have been run")
+ scribe_log("All kickstart %%post script(s) have been run")
def runPreScripts(scripts):
preScripts = filter (lambda s: s.type == KS_SCRIPT_PRE, scripts)
@@ -2027,6 +2031,7 @@
return
log.info("Running kickstart %%pre script(s)")
+ scribe_log("Running kickstart %%pre script(s)")
stdoutLog.info(_("Running pre-installation scripts"))
map (lambda s: s.run("/"), preScripts)
@@ -2035,9 +2040,11 @@
def runTracebackScripts(scripts):
log.info("Running kickstart %%traceback script(s)")
+ scribe_log("Running kickstart %%traceback script(s)")
for script in filter (lambda s: s.type == KS_SCRIPT_TRACEBACK, scripts):
script.run("/")
log.info("All kickstart %%traceback script(s) have been run")
+ scribe_log("All kickstart %%traceback script(s) have been run")
def resetCustomStorageData(ksdata):
cmds = ["partition", "raid", "volgroup", "logvol", "btrfs"]
# progress.py: intercept status messages as they go to console,
# e.g. "Created swap on /dev/sda2"
--- pyanaconda/progress.py.orig 2016-01-17 13:15:34.790773550 -0800
+++ pyanaconda/progress.py 2016-01-17 17:16:25.503135804 -0800
@@ -24,6 +24,7 @@
from contextlib import contextmanager
from pyanaconda.queue import QueueFactory
+from pyanaconda.scribe_logger import scribe_log
# A queue to be used for communicating progress information between a subthread
# doing all the hard work and the main thread that does the GTK updates. This
@@ -56,6 +57,7 @@
def progress_step(message):
progressQ.send_step()
log.info(message)
+ scribe_log(message)
def progress_init(steps):
progressQ.send_init(steps)
#
# scribe_logger.py: log to a scribe category
#
from socket import gethostname
import json
import sys
import time
from scribe import scribe
from thrift.transport import TTransport, TSocket
from thrift.protocol import TBinaryProtocol
# Function for logging to scribe
def scribe_log(message):
m = {
'hostname': gethostname(),
'timestamp': int(time.time()),
'message': message,
'type': 'log'
}
scribe_send(json.dumps(m))
def scribe_traceback(error, stack):
m = {
'hostname': gethostname(),
'timestamp': int(time.time()),
'type': 'traceback'
'error': error,
'stack': stack,
}
scribe_send(json.dumps(m))
# Generic raw sending function
def scribe_send(message):
message = message + "\n"
log_entry = scribe.LogEntry(dict(category='anaconda', message=message))
tsocket = TSocket.TSocket(host='scribe.wann.net', port=1463)
transport = TTransport.TFramedTransport(tsocket)
protocol = TBinaryProtocol.TBinaryProtocol(trans=transport, strictRead=False, strictWrite=False)
client = scribe.Client(iprot=protocol, oprot=protocol)
transport.open()
result = client.Log(messages=[log_entry])
transport.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment