Community
Zenoss Newsletter

Monitored by Zenoss
SourceForge.net Logo
Views

Most of the functions have an exportXML() function, so inside of /zport/portal_skins/custom, create a wrapper script to gather the objects and get the XML representations, another wrapper script to make the XML output pretty and a Zope Page Template to display the results.

To use, simply go to the object that you would like to see the XML representation of, remove any function or arguments at the end of the URL, and put the name 'showXML' at the end. For example, for devices:

http://zenoss_server:8080/zport/dmd/Devices/showXML

Script (Python)

Create a "Script (Python)" object from the ZMI under /zport/portal_skins/custom, and call it 'showXMLpy'.

class FakeFile:
     """Steal the output that we would normally print to a file and store it into a buffer for later retrieval"""

    def init( self ):
        self.contents= []

    def write( self, data=None ):
        if data is not None:
           self.contents.append( data )

        return( len( data ) )

    def dump( self ):
        #
        # NB: XML parsing function explodes if it sees
        #     more than one object.  Guarantee that it
        #     will only see one object by wrapping other
        #     elements around it.
        #
        return "<objects>" + "".join( self.indent() ) + "</objects>"

fakeout= FakeFile()
fakeout.init()

for device in context.objectValues():
    device.exportXml( fakeout )

print context.xml_pretty_print( fakeout.dump() )

return printed

Zope Page Template

Create a "Page Template" object from the ZMI under /zport/portal_skins/custom, and call it 'showXML'.

<h2>XML Source</h2>
<!--  NB: The 'tal:content' attribute means that the text within
the elements is replaced with the function's output eg context.absolute_url()  -->
<p tal:content="python: context.absolute_url()"> Displays the URL of where we are </p>
<p></p>
<!--  Call our Script (Python) function  -->
<pre tal:content="here/showXMLpy">
Hello world
</pre>

Python External Method

On the Zenoss server, go to the $ZENHOME/Extensions directory, and add the python script below to a file called 'xml_pretty_print.py'

Create an "External Method" object from the ZMI under /zport/portal_skins/custom, and give it the arguments:

  • id xml_pretty_print
  • Module Name xml_pretty_print
  • Function Name xml_pretty_print

#!/usr/bin/env python

from xml.dom.minidom import parseString

def xml_pretty_print( data ):
    tree= parseString( data )
    return tree.toprettyxml( "    ", "" )