You are browsing the documentation for iTop 2.0 which is not the current version.

Consider browsing to iTop 3.2 documentation

Extensions API

In addition to modifying the XML data model, it is possible to implement specific behaviors in iTop by the mean of so-called extensions.

Overview

An extension is made of PHP code. Your code will be invoked by iTop when building the answer to HTTP requests. For instance, it is possible to hook the display of an object to show more information.

In practice, your code consists in declaring a PHP class implementing an interface known by iTop as being an extension interface. iTop detects automatically the existence of your class and invokes the methods at some specific moments during its execution.

To make this happen, the code of your class must be in a file included by iTop. The recommended way for doing so is to put your code into a main.my-module.php file (see Content of a module).

An example

Let's imagine that we have web based application which provides some advanced reporting on the availability of Servers. We would like to provide an hyperlink so that end-users can quickly jump from the details of a Server in iTop into the corresponding report in the monitoring application.

One possible solution is to show this an hyperlink to the monitoring application into the “Actions” popup-menu on all Servers.

The implementation consists in implementing the interface iPopupMenuExtension:

main.mymodule.php
class MyPopupExtension implements iPopupMenuExtension
{
   public static function EnumItems($iMenuId, $param)
   {
      if ($iMenuId == self::MENU_OBJDETAILS_ACTIONS)
      {
         $oObject = $param;
         if ($oObject instanceof Server)
         {
             $sUID = 'MyPopupExtension-Monitoring'; // Make sure that each menu item has a unique "ID"
             $sLabel = 'Monthly report';
             $sURL = 'http://myapp/show_report?server_fqdn='.$oObject->Get('name');
             $sTarget = '_blank';
             $oMenuItem = new URLPopupMenuItem($sUID, $sLabel, $sURL, $sTarget);
             return array($oMenuItem);
         }
      }
      return array();
   }
}

The method EnumItems will be called by iTop in several circumstances. When displaying the details of an object, $params is the target object.

As our method will be called for any kind of object, we have to filter out the classes of objects that are not relevant for this action.

As you can see, one can handle several types of objects and several types of menus with the same extension (depending on $iMenuId and $param).

The outcome of this plugin is an additional menu entry on the details page of any server:

Interfaces reference documentation

API Reference for extensions

There are several interfaces for extending iTop. Each interface corresponds to a specific type of extension, as shown on the table below:

Interface Description
iApplicationUIExtension Implement this interface to change the behavior of the GUI for some objects (when displaying the details or editing an object).
iApplicationObjectExtension Implement this interface to perform specific actions when objects are created, updated or deleted
iPageUIExtension Implement this interface to add content to any iTopWebPage (web pages containing the iTop menu on the left)
iPopupMenuExtension Add menu items in the “popup” menus inside iTop.
2_0_2/customization/extensions_api.txt · Last modified: 2018/12/19 11:40 by 127.0.0.1
Back to top
Contact us