Webtogether SysInfo

Setup

The directory structure for this particular example is as depicted on the picture below.

directory_structure.PNG

You can place an empty file into the "Show Process" directory called ps. Into its .metadata directory insert the executable shell script from the "Show Process" chapter. Do the same with the Disk Free example (comes into the Disk Usage directory). The .icon directory contains the icons for the directories. This is used by the sysinfo xslt transformation to create a kind of GUI where you can select the task.

Show Process

This transforms the output of the unix command ps into a simple table. The executable script file contains the simple bash commands to invoke the ps command and to transform it into xml.

#!/opt/bin/ash
ps | sed -e 's/&/\&amp;/g' -e 's/>/\&lt;/g' -e 's/</\&gt;/g'|\
awk '{\
  if ( $1 ~ /PID/ ) {\
    printf "<th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th>", $1, $2, $3, $4, $5;\
  } else {\
    printf "<tr><td>%s</td><td>%s</td>", $1, $2;\
    if ( $3 ~ /[0-9]+/ ) {\
      printf "<td>%s</td><td>%s</td><td>", $3, $4;\
      j = 5;\
    } else {\
      printf "<td></td><td>%s</td><td>", $3;\
      j = 4;\
    }\
    for (i = j; i < NF+1; i++) printf "%s ", $i;\
    printf "</td></tr>\n";\
  }\
}'

And below a sample of the output
sysinfo_processshow.PNG

Disk Free

This one transforms the output of the unix command df into a simple table. The executable script file contains the simple bash commands to invoke the df command and to transform it into xml.

#!/opt/bin/ash
/bin/df | /opt/bin/awk '{\
  if ( $1 ~ /Filesystem/ ) {
    print "      <th>"$1"</th><th>"$2"</th><th>"$3"</th><th>"$4"</th><th>"$5"</th><th>"$6"</th>";\
  } else {\
    print "      <tr><td>"$1"</td><td>"$2"</td><td>"$3"</td><td>"$4"</td><td>"$5"</td><td>"$6"</td></tr>";\
  }\
}

The reendered table from the df command is now like this:
sysinfo_diskfree.PNG

Transformation and stylesheet

Both examples above use the same stylesheet snif.css and the same transformation to present the information.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="ISO-8859-1" indent="yes" />
 
    <xsl:template match="/">
        <html>
            <head>
                <title>
                    <xsl:text>System information</xsl:text>
                </title>
                <link rel="stylesheet" type="text/css" href="snif.css" />
            </head>
            <body class="snif">
                <table cellpadding="0" cellspacing="0" class="snif">
                    <tr class="snHeading">
                        <xsl:for-each select="list/e/m/th">
                            <th>
                                <xsl:value-of select="."/>
                            </th>
                        </xsl:for-each>
                    </tr>
                    <xsl:for-each select="list/e/m/tr">
                        <tr>
                            <xsl:choose>
                                <xsl:when test="(position() mod 2) = 0">
                                    <xsl:attribute name="class">snF snEven</xsl:attribute>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:attribute name="class">snF snOdd</xsl:attribute>
                                </xsl:otherwise>
                            </xsl:choose>
                            <xsl:for-each select="td">
                                <td>
                                    <xsl:value-of select="."/>
                                </td>
                            </xsl:for-each>
                        </tr>
                        <xsl:text>
                        </xsl:text>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>
 
</xsl:stylesheet>

GUI

One level up in the sysinfo directory we use a different transformation to create a kind of GUI. The output looks like below.

sysinfo_main.PNG

This is the xslt which creates the GUI menu.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="ISO-8859-1" indent="yes" />
 
    <xsl:template match="/">
        <html>
            <body>
                <xsl:for-each select="list/e">
                    <a>
                        <xsl:attribute name="href">
                            <xsl:text>?d=</xsl:text>
                            <xsl:value-of select="l"/>
                            <xsl:text>&amp;x=sysinfo_table</xsl:text>
                        </xsl:attribute>
                        <img>
                            <xsl:attribute name="src">
                                <xsl:text>?d=</xsl:text>
                                <xsl:value-of select="/list/@d"/>
                                <xsl:text>.icons/</xsl:text>
                                <xsl:value-of select="n"/>
                                <xsl:text>-128x128.png</xsl:text>
                            </xsl:attribute>
                        </img>
                    </a>
                </xsl:for-each>
            </body>
        </html>
    </xsl:template>
 
</xsl:stylesheet>

Extensions

To add further commands with tabular output you just have to do the following

  • Add a new directory into the sysinfo folder with the desired name
  • In the new directory create the .metadata directory
  • In the new directory create a file
  • In the .metadata of the new directory create the file with the same name
  • The content of the new file in the .metadata directory must produce a valid xml output
  • Set the executable permissions for the new script in the .metadata directory
  • Add a new icon in the .icon directory of the sysinfo folder
  • Name the icon file as <new directory>-128x128.png
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.