Introduction
Update - the serverstats script is no longer required. You can get the xml info page from http://info.voxtreme.com/index.xml.
voxinfo comprises of two scripts, serverstats.php and voxinfo.php which can be used to format and display status information about Voxtreme's web servers, as displayed on their information page.
serverstats.php *no longer used* just grabs the information page, parses it with a few regular expressions, and outputs xml containing the information.
voxinfo.php gets the xml file from voxtreme, parses it into simple structures, and optionally formats and displays the output according to any html template you give it.
Installation
voxinfo.php should be somewhere on the server you intend to use it on where you can include() it in your own scripts.
Usage
voxinfo.php is the file you should include in your own scripts. It contains the voxinfo class, which at its simplest, can be used like this:
<?php
include("voxinfo.php");
/*
define an html template
this is just a variable containing normal html code, with special tags for where to display information
*/
$tpl = '
<table>
<tr><td colspan="7" align="center"><b>Announcements</b></td></tr>
<announcements><tr><td colspan="7">{date} : <i>{announcement}</i></td></tr></announcements>
<tr><td colspan="7"><br><br></td></tr>
<tr><td><b><u>Server</u></b></td>
<td><b><u>ftp</u></b></td>
<td><b><u>http</u></b></td>
<td><b><u>smtp</u></b></td>
<td><b><u>pop3</u></b></td>
<td><b><u>mysql</u></b></td>
<td><b><u>uptime</u></b></td></tr>
<servers>
<tr>
<td><b>{name}</b><br><i><ip></i></td>
<td>{ftp}</td>
<td>{http}</td>
<td>{smtp}</td>
<td>{pop3}</td>
<td>{MySql}</td>
<td>{uptime}</td>
</tr>
</servers>
</table>
';
// create the voxinfo object
$vi = new voxinfo();
// get the information and display it
$vi->doit($tpl);
// thats all folks
?>
The output of this code would look something like this:
Output:
Limiting the information displayed
If you don't need the stats for all the servers, you can limit the information retrieved by passing an array containing the server names you want to the constructor function like so:<?php $vi = new voxinfo(array("Swordfish", "Dolphin"));?>
This will only retrieve information about the named servers, including the announcements.
The output of the previous example would then look something like this:
Output:
Only retrieve the announcements (or only the server status)
*** this section has been removed because it is no longer supported (or neccessary) ***
If you only want one or the other, just only include the html template for what you want to display.
Other methods available
There is a more 'low-level' api for the programmers amongst you who want to get your hands dirty. The doit() method described above is the simplest way to use the class. If you want to access the information returned with php (for formatting or whatever nefarious purpose), you should use the getinfo() method instead.
This returns true on success, or false if it couldn't get the info xml document, or if another error occurred.
If successful, the voxinfo object contains two arrays or information, announcements and servers. Each has one entry for each of the items of information retrieved.
Here's a print_r dump of the two arrays:
Output:Oh dear, an error has occurred.
The other functions available include displayservers($template) which just prints out info on the servers according to the html template you give it, displayannouncements($template) which I'm not going to tell you what it does.
Templates are just normal html with special tags for where the information should be inserted.
Server Information Tags
{name} inserts the server name
{ip} ip address
{uptime} the uptime message
{ftp}, {http}, {MySql}, {pop3}, {smtp} - all either on or off. So if you are using a template to display the information and want to use images, call them something like 'on.gif' and 'off.gif', and in the template, use:
...<img src="/{http}.gif">... for example.
*** Note these tags are case-sensitive (I think?) - all lowercase except the MySql one ***
Announcement Information Tags
{date} the date in yyyy-mm-dd hh:ii:ss format
{announcement} the text of the announcement
Tags for the template used with doit()
Additional tags are used with the template for this function to determine which sections of the template to use for announcements and which for server info.
Very simple, just enclose the relevant bit of template in <announcements>.... template goes here...</announcements> or <servers>...template...</servers> tags.
Function Reference
voxinfo( $servers, $url) This is the constructor function for the class. Both its parameters are optional.
$servers is an array of server names that you want information for. If empty (default) information on all servers is returned.
$url is the url to get the xml info document from. It is optional (defaults to this url. anyway) and is only included to make it easy to change if vox move their info page. You do not need to pass this parameter.
doit($template) This function retrieves the information and displays it according to the template. See here for the template format.
getinfo() Retrieve the information but don't display anything.
displayservers($template) Displays the server information retrieved with getinfo() with a template.
displayannouncements($template) Displays the announcement information retrieved with getinfo() with a template.
Other functions are internal to the class.
If you have any comments or questions about these scripts, you can contact me here or try the samscripts support forums (not very busy at present :).
|