5.4. Summary

The eBox user interface has a "Summary" page where status information for every module is displayed. This page has two parts:

Summary information is gathered by calling two abstract methods defined in EBox::Module, if you don't implement them then no information will be displayed about your module. statusSummary populates the table that will display the status of network services and summary creates the summary section for your module.

The way the summary is built is quite similar to they way the menu is built, as shown in Section 5.3. There are a bunch of classes in the EBox::Summary namespace that you can use to build your summary information, statusSummary should return an object of type EBox::Summary::Status while summary is free to return any object that is a subtype of EBox::Summary::Item, although most modules just return a EBox::Summary::Module.

Each one of the EBox::Summary::Item subclasses has some attributes and can contain other EBox::Summary::Item objects, and they all print some HTML code. EBox::Summary::Module has a title attribute, when it is time to generate the page it prints the title and the html for its children below it.

To see how the summary section is built, we are going to take a look at the network module. The output of its summary is a title and one section per network interface, with a bold title and a table that displays its MAC address, IP addresses, netmask, etc. Example 5.16 shows the important bits of its summary method.

Example 5.16. summary sample implementation

my $item = new EBox::Summary::Module(__("Network interfaces"));

foreach my $iface (@{$ifaces}) {
	my $status = __("down");
	my $section = new EBox::Summary::Section($iface);
	$item->add($section);

	if (iface_is_up($iface)) {
		$status = __("up");
	}
	$section->add(new EBox::Summary::Value (__("Status"), $status));

	my $ether = iface_mac_address($iface);
	if ($ether) {
		$section->add(new EBox::Summary::Value(
			__("MAC address"), $ether));
	}

	my @ips = iface_addresses($iface);
	foreach my $ip (@ips) {
		$section->add(new EBox::Summary::Value(
			__("IP address"), "$ip"));
	}
}
return $item;

First an EBox::Summary::Module item is created, this object will hold all the summary information.

Then an EBox::Summary::Section is created for each network interface, a section has a title (passed as an argument to its constructor) and it contains several EBox::Summary::Value objects, which display a name and an associated value as rows in a table within the section. So each several values are added to each section and the sections are added to the EBox::Summary::Module object. The result is a tree of objects, and its root is the EBox::Summary::Module, when it is asked to print itself it prints its title and asks each of its children to print itself. To see what it looks like just open the summary page in an eBox installation.

summary may return any object as long as it inherits from EBox::Summary::Item, you can create your own if your needs are not covered by the standard items that come with the framework.

statusSummary is easier, it just has to return an EBox::Summary::Status object. The constructor for this class needs three arguments:

The reason for this third argument is that services that the user should not be able to use the summary page to start services that have not been configured, so if, for example, the squid service is disabled, the user will have to go to the squid configuration page and enable the service there. Example 5.17 shows the statusSummary implementation in the squid module, along with some related methods.

Example 5.17. statusSummary sample implementation

sub statusSummary
{
	my $self = shift;
	return new EBox::Summary::Status('squid', __('HTTP Proxy'),
					$self->isRunning, $self->service);
}

sub isRunning
{
	my $self = shift;
	return $self->pidFileRunning(PIDFILE);
}

sub service
{
	my $self = shift;
	return $self->get_bool('active');
}

Again, you can see what it looks like by checking out the Summary page in an eBox installation that has the squid module included.