[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] conga/luci/site/luci/Extensions cluster_adapte ...



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe sourceware org	2006-10-25 00:43:48

Modified files:
	luci/site/luci/Extensions: cluster_adapters.py ricci_bridge.py 

Log message:
	fix logging

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.127&r2=1.128
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ricci_bridge.py.diff?cvsroot=cluster&r1=1.32&r2=1.33

--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/10/24 15:05:28	1.127
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/10/25 00:43:48	1.128
@@ -2594,27 +2594,43 @@
 		try:
 			nodename = request.form['nodename']
 		except:
-			return "Unable to resolve node name %s to retrieve logging information" % nodename
+			luci_log.debug_verbose('Unable to get node name to retrieve logging information')
+			return 'Unable to get node name to retrieve logging information'
 
+	clustername = None
 	try:
 		clustername = request['clustername']
 	except KeyError, e:
 		try:
 			clustername = request.form['clusterName']
+			if not clustername:
+				raise
 		except:
-			return "Unable to resolve node name %s to retrieve logging information" % nodename
-
-	try:
-		nodename_resolved = resolve_nodename(self, clustername, nodename)
+			clustername = None
+			luci_log.debug_verbose('Unable to find cluster name while retrieving logging information for %s' % nodename)
 	except:
-		return "Unable to resolve node name %s to retrieve logging information" % nodename
+		pass
+
+	if clustername is None:
+		nodename_resolved = nodename
+	else:
+		try:
+			nodename_resolved = resolve_nodename(self, clustername, nodename)
+		except:
+			luci_log.debug_verbose('Unable to resolve node name %s/%s to retrieve logging information' \
+				% (nodename, clustername))
+			return 'Unable to resolve node name for %s in cluster %s' % (nodename, clustername)
 
 	try:
 		rc = RicciCommunicator(nodename_resolved)
-		if not rc:
-			raise
-	except:
-		return "Unable to resolve node name %s to retrieve logging information" % nodename_resolved
+	except RicciError, e:
+		luci_log.debug_verbose('Ricci error while getting logs for %s: %s' \
+			% (nodename_resolved, str(e)))
+		return 'Ricci error while getting logs for %s' % nodename_resolved
+	except:
+		luci_log.debug_verbose('Unexpected exception while getting logs for %s' \
+			% nodename_resolved)
+		return 'Ricci error while getting logs for %s' % nodename_resolved
 
 	if not rc.authed():
 		try:
@@ -2622,7 +2638,15 @@
 			setNodeFlag(snode, CLUSTER_NODE_NEED_AUTH)
 		except:
 			pass
-		return "Luci is not authenticated to node %s. Please reauthenticate first." % nodename
+
+		if clustername:
+			try:
+				cnode = getClusterNode(self, nodename, clustername)
+				setNodeFlag(cnode, CLUSTER_NODE_NEED_AUTH)
+			except:
+				pass
+
+		return 'Luci is not authenticated to node %s. Please reauthenticate first.' % nodename
 
 	return getNodeLogs(rc)
 
--- conga/luci/site/luci/Extensions/ricci_bridge.py	2006/10/23 19:24:39	1.32
+++ conga/luci/site/luci/Extensions/ricci_bridge.py	2006/10/25 00:43:48	1.33
@@ -1,4 +1,5 @@
 import xml
+from time import time, ctime
 from xml.dom import minidom
 from ricci_communicator import RicciCommunicator
 
@@ -284,10 +285,52 @@
 	batch_str = '<module name="log"><request sequence="1254" API_version="1.0"><function_call name="get"><var mutable="false" name="age" type="int" value="18000"/><var mutable="false" name="tags" type="list_str"><listentry value="cluster"/></var></function_call></request></module>'
 
 	ricci_xml = rc.batch_run(batch_str, async=False)
-	doc = getPayload(ricci_xml)
-	if not doc or not doc.firstChild:
+	if not ricci_xml:
 		return errstr
-	return doc.firstChild
+	try:
+		log_entries = ricci_xml.getElementsByTagName('logentry')
+		if not log_entries or len(log_entries) < 1:
+			raise Exception, 'no log data is available.'
+	except Exception, e:
+		'Error retrieving log data from %s: %s' \
+			% (rc.hostname(), str(e))
+		return None
+	time_now = time()
+	entry = ''
+	for i in log_entries:
+		try:
+			log_msg = i.getAttribute('msg')
+		except:
+			log_msg = ''
+
+		if not log_msg:
+			continue
+
+		try:
+			log_age = int(i.getAttribute('age'))
+		except:
+			log_age = 0
+
+		try:
+			log_domain = i.getAttribute('domain')
+		except:
+			log_domain = ''
+
+		try:
+			log_pid = i.getAttribute('pid')
+		except:
+			log_pid = ''
+
+		if log_age:
+			entry += ctime(time_now - log_age) + ' '
+		if log_domain:
+			entry += log_domain
+		if log_pid:
+			entry += '[' + log_pid + ']' + ': '
+		else
+			entry += ': '
+		entry += log_msg + '<br/>'
+	return entry
 
 def nodeReboot(rc):
 	batch_str = '<module name="reboot"><request sequence="111" API_version="1.0"><function_call name="reboot_now"/></request></module>'


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]