summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2009-07-24 15:51:57 +0200
committerDavid Sommerseth <davids@redhat.com>2009-07-24 15:51:57 +0200
commit90dd1069b00b6d384be52b91e66c9ccd569fc408 (patch)
treec504a26c5c83145a825c15a18c72d69b9d651306 /server
parent005ddc4fa751547325a8357ed6f48c755f37380e (diff)
Began implementing XML parser for rteval reports
Diffstat (limited to 'server')
-rw-r--r--server/xmlparser.py104
-rw-r--r--server/xmlparser.xsl89
2 files changed, 193 insertions, 0 deletions
diff --git a/server/xmlparser.py b/server/xmlparser.py
new file mode 100644
index 0000000..c7a11b9
--- /dev/null
+++ b/server/xmlparser.py
@@ -0,0 +1,104 @@
+#
+# xmlparser.py
+# Library for parsing rteval XML files
+#
+# Copyright 2009 David Sommerseth <davids@redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# For the avoidance of doubt the "preferred form" of this code is one which
+# is in an open unpatent encumbered format. Where cryptographic key signing
+# forms part of the process of creating an executable the information
+# including keys needed to generate an equivalently functional executable
+# are deemed to be part of the source code.
+#
+
+import libxml2
+import libxslt
+import psycopg2
+import hashlib
+import StringIO
+
+class rtevalXMLparser(object):
+ "Class for parsing XML data from rteval runs"
+
+ def __init__(self, fname):
+ self.xml = libxml2.parseFile(fname)
+
+ # Verify that this is a valid rteval XML file
+ try:
+ ver = float(self.xml.xpathEval('/rteval/@version')[0].content)
+ if ver < 0.8:
+ raise Exception, "Unsupported rteval XML version"
+ except Exception, err:
+ raise Exception, "Input file was unparsable or not a valid rteval XML file (%s)" % str(err)
+
+
+ def GetSysID(self):
+ try:
+ uuid = self.xml.xpathEval('/rteval/HardwareInfo/@SystemUUID')[0].content
+ serno = self.xml.xpathEval('/rteval/HardwareInfo/@SerialNo')[0].content
+ except:
+ raise Exception, "Could not retrieve SystemUUID or SerialNo from XML data"
+
+ return hashlib.sha1("%s:%s" % (uuid,serno)).hexdigest()
+
+
+ def GetDMIdata(self):
+ try:
+ dmi = self.xml.xpathEval('/rteval/HardwareInfo')[0]
+ if dmi == None:
+ raise Exception, "Could not locate HardwareInfo in XML data"
+ except:
+ raise Exception, "Could not locate HardwareInfo in XML data"
+
+ # Create a new XML document and put the /rteval/HardwareInfo as doc root
+ doc = libxml2.newDoc("1.0")
+ doc.setRootElement(dmi)
+
+ # Dump this XMLdoc as a string
+ fbuf = StringIO.StringIO()
+ xmlbuf = libxml2.createOutputBuffer(fbuf, 'UTF-8')
+ doc.saveFormatFileTo(xmlbuf, 'UTF-8', 0)
+ retstr = fbuf.getvalue()
+ doc.free()
+ del xmlbuf
+ del fbuf
+ del doc
+
+ # Return the information as a string
+ return retstr
+
+ def GetNodeName(self):
+ try:
+ nodename = self.xml.xpathEval('/rteval/uname/node')[0].content
+ except Exception, err:
+ raise Exception, "Could not retrieve node name (%s)" % str(err)
+
+ return nodename
+
+ def GetSQLdata_systems(self):
+ return {"table": "systems",
+ "columns": ["sysid","dmidata"],
+ "values: ", [self.GetSysID(), self.GetDMIdata()]}
+
+ def GetSQLdata_syshostname(self, syskey, ipaddr):
+ return {"table": "systems",
+ "columns": ["syskey", "hostname", "ipaddr"],
+ "values: ", [syskey, self.GetNodeName, ipaddr]}
+
+
+
+
diff --git a/server/xmlparser.xsl b/server/xmlparser.xsl
new file mode 100644
index 0000000..79279be
--- /dev/null
+++ b/server/xmlparser.xsl
@@ -0,0 +1,89 @@
+<?xml version="1.0"?>
+<!--
+ *
+ * GPLv2 - Copyright (C) 2009
+ * David Sommerseth <davids@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+-->
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" indent="no"/>
+
+ <xsl:template match="/">
+ <xsl:choose>
+ <xsl:when test="$table = 'rtevalruns_sql'">
+ <xsl:if test="$syskey = ''">
+ <xsl:message terminate="yes">
+ <xsl:text>Invalid 'table' parameter: </xsl:text><xsl:value-of select="$table"/>
+ </xsl:message>
+ </xsl:if>
+ <xsl:apply-templates select="/rteval" mode="rtevalruns"/>
+ </xsl:when>
+ <xsl:when test="$table = 'rtevalruns_details'">
+ <xsl:apply-templates select="/rteval" mode="rtevalruns_details"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message terminate="yes">
+ <xsl:text>Invalid 'table' parameter: </xsl:text><xsl:value-of select="$table"/>
+ </xsl:message>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match="/rteval" mode="rtevalruns">
+ <xsl:variable name="insert">
+ <xsl:text>INSERT INTO rtevalruns (syskey, kernel_ver, kernel_rt, arch,</xsl:text>
+ <xsl:text> run_start, run_duration, load_avg, version)</xsl:text>
+ </xsl:variable>
+ <xsl:variable name="values">
+ <xsl:value-of select="$syskey"/>
+ <xsl:text>,'</xsl:text>
+ <xsl:value-of select="uname/kernel"/>
+ <xsl:text>',</xsl:text>
+ <xsl:choose>
+ <xsl:when test="uname/kernel/@is_RT = '1'">true</xsl:when>
+ <xsl:otherwise>False</xsl:otherwise>
+ </xsl:choose>
+ <xsl:text>,'</xsl:text>
+ <xsl:value-of select="uname/arch"/>
+ <xsl:text>','</xsl:text>
+ <xsl:value-of select="concat(run_info/date,' ',run_info/time)"/>
+ <xsl:text>',</xsl:text>
+ <xsl:value-of select="(run_info/@days*86400)+(run_info/@hours*3600)
+ +(run_info/@minutes*60)+(run_info/@seconds)"/>
+ <xsl:text>,</xsl:text>
+ <xsl:value-of select="loads/@load_average"/>
+ <xsl:text>,'</xsl:text>
+ <xsl:value-of select="@version"/>
+ <xsl:text>'</xsl:text>
+ </xsl:variable>
+
+ <xsl:value-of select="concat($insert,' VALUES (', $values,')&#10;')"/>
+ </xsl:template>
+
+ <xsl:template match="/rteval" mode="rtevalruns_details">
+ <xsl:text disable-output-escaping="yes">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</xsl:text>
+ <rtevalruns_details>
+ <xsl:copy-of select="clocksource|loads|cyclictest/command_line"/>
+ </rtevalruns_details>
+ </xsl:template>
+
+ <xsl:template match="/rteval" mode="cyclic_stats_sql">
+
+ </xsl:template>
+
+</xsl:stylesheet>