创建新的配置项类:监视器

本文档分步说明了如何创建自己的iTop模块以添加配置项的新类:监视器。

学习:添加一个新的配置项类

水平:中间

域:XML,  PresentationDashboardDictionary

最低版本:2.1.0

教程的目标

在本分步教程中,您将学习:

  • 为iTop创建自己的扩展模块
  • 对象的创建类
  • 在现有仪表板中添加新条目

出于此教程的目的,我们将配置项的创建类(称为Monitor)与配件类非常相似,并增加了额外的“技术”以区分CRT和LCD监视器。

The Monitor Class

您将需要什么

  • 将iTop安装在开发机器上,您可以在其上轻松地访问编辑文件。
  • 一个文本编辑器,能够编辑PHP和XML文件并支持U-8。在Windows上,您可以使用写字板(记事本不喜欢Unix行结尾)或出色的免费开发IDE之一,例如PSPad 要么记事本++.

定制流程

定制流程如下:

  1. 安装iTop的开发实例。最好不要在生产中进行试验!
  2. 安装工具包 协助您进行定制
  3. 使用以下命令创建一个新的(空)模块模块创建向导 
  4. 将此新模块复制到iTop上的扩展文件夹,然后再次运行安装程序以安装空模块
  5. 修改扩展中的模块并使用工具包检查您的自定义

重复最后一点,直到对自定义满意为止。完成后,就可以部署新模块了。将模块文件夹复制到生产iTop实例的扩展目录中,然后运行安装程序进行安装。

循序渐进教程

创建您的自定义模块

使用模块创建向导。用以下值填充表单:

标签价值备注
模块名称sample-add-class以itop-和combodo-开头的名称保留供Combodo使用。建议不要在模块名称中添加空格或强调字符。具有相同名称的两个模块不能在同一iTop实例中共存。
模块标签Add Class Sample该标签将显示在设置向导中。允许使用本地化的字符和空格
模块版本1.0.0惯例是使用3位数编号方案:X.Y.Z
类别

business

对数据模型进行修改的模块应位于类别'业务'中
依存关系itop-config-mgmt/2.0.0,itop-endusers-devices-2.0.0我们的定制模块依赖于以下模块:在其中定义了物理设备类的iTop配置管理(版本2.0.0)和在其中定义了“ End用户Devices”菜单的iTop End用户设备(版本2.0.0)

单击生成!将空模块下载为zip文件。

当模块扩展现有类时,必须在声明要扩展该类的模块之后加载它。为此,请确保新模块的依赖项中列出了第一个模块。

例如,如果要从类VirtualMachine派生到创建类,则您的自定义模块必须依赖于itop-virtualization-mgmtt2.0.0

安装空模块

将zip的内容扩展到开发iTop实例的扩展文件夹中。现在,您应该在扩展文件夹中有一个名为sample-add-class的文件夹。此文件夹包含以下文件:

  • datamodel.sample-add-class.xml
  • module.sample-add-class.php
  • en.dict.sample-add-class.php
  • model.sample-add-class.php

确保Web服务器的文件conf/production/config-itop.php是可写的(在Windows上:右键单击以显示文件属性,并取消选中只读标志;在Linux变更上为文件的权利),然后通过以下方式启动iTop安装:将您的浏览器指向http ::: your_itop/setup/

Launching the re-install

单击“继续»”开始重新安装。

https://www.itophub.io/wiki/media?w=300&tok=554538&media=2_7_0%3Acustomization%3Ainstall-extension-2.png

在单击“下一步»”之前,请确保已选择“更新现有实例”。

https://www.itophub.io/wiki/media?w=300&tok=2395b2&media=2_7_0%3Acustomization%3Aupgrade-screenshot2.png

继续执行向导的下一步……

Select the new extension

您的自定义模块应出现在“扩展”列表中。如果不是这种情况,请检查是否在正确的位置复制了模块文件,并且Web服务器具有足够的权利可以读取它们。

在单击“下一步»”之前,请选择您的自定义模块并完成安装。

添加Monitor类

使用常用文本编辑器,打开文件datamodel.sample-add-class.xml。

删除标签<简档(角色)> </简档(角色)>,因为该模块将不包含任何简档(角色)定义。

在标签类中,添加以下代码:

  <class id="Monitor" _delta="define">
      <parent>PhysicalDevice</parent>
      <properties>
        <category>bizmodel,searchable</category>
        <abstract>false</abstract>
        <key_type>autoincrement</key_type>
        <db_table>monitor</db_table>
        <db_key_field>id</db_key_field>
        <db_final_class_field/>
        <naming>
          <format>%1$s</format>
          <attributes>
            <attribute id="name"/>
          </attributes>
        </naming>
        <display_template/>
        <icon>images/monitor.png</icon>
        <reconciliation>
          <attributes>
            <attribute id="name"/>
            <attribute id="org_id"/>
            <attribute id="organization_name"/>
          </attributes>
        </reconciliation>
      </properties>
      <fields>
        <field id="technology" xsi:type="AttributeEnum">
          <values>
            <value>crt</value>
            <value>lcd</value>
          </values>
          <sql>technology</sql>
          <default_value/>
          <is_null_allowed>true</is_null_allowed>
          <display_style>radio_horizontal</display_style>
        </field>
      </fields>
      <methods/>
     </class>

这指示iTop定义一个从PhysicalDevice派生的新类。 SQL中将添加一个额外的表“监视器”,以存储特定于类的数据。 “ Monitor”类向PhysicalDevice类添加了一种额外的字段“技术”。此字段是枚举的价值,具有两个可能的值“ lcd”和“ crt”。该字段将存储在SQL数据库的“技术”列中。

有关class和field标记的各个参数的含义的更多信息,请参见XML引用文档.

还必须定义<presentation>标签以描述如何在iTop中显示对象。定义了三个“表示”:

  • “详细信息”定义用于显示和编辑对象实例的表单
  • “列表”定义了用于显示此类对象列表的默认列
  • “搜索”定义了搜索表单中此类对象的可用字段

在结束的</ fields>标签之后添加以下代码:

 <presentation>
        <details>
          <items>
            <item id="name">
              <rank>10</rank>
            </item>
            <item id="org_id">
              <rank>20</rank>
            </item>
            <item id="status">
              <rank>30</rank>
            </item>
            <item id="business_criticity">
              <rank>40</rank>
            </item>
            <item id="location_id">
              <rank>50</rank>
            </item>
            <item id="brand_id">
              <rank>60</rank>
            </item>
            <item id="model_id">
              <rank>70</rank>
            </item>
            <item id="technology">
              <rank>75</rank>
            </item>
            <item id="serialnumber">
              <rank>80</rank>
            </item>
            <item id="asset_number">
              <rank>90</rank>
            </item>
            <item id="move2production">
              <rank>100</rank>
            </item>
            <item id="purchase_date">
              <rank>110</rank>
            </item>
            <item id="end_of_warranty">
              <rank>120</rank>
            </item>
            <item id="description">
              <rank>130</rank>
            </item>
            <item id="contacts_list">
              <rank>140</rank>
            </item>
            <item id="documents_list">
              <rank>150</rank>
            </item>
            <item id="tickets_list">
              <rank>160</rank>
            </item>
            <item id="providercontracts_list">
              <rank>170</rank>
            </item>
            <item id="services_list">
              <rank>180</rank>
            </item>
          </items>
        </details>
        <search>
          <items>
            <item id="name">
              <rank>10</rank>
            </item>
            <item id="org_id">
              <rank>20</rank>
            </item>
            <item id="status">
              <rank>30</rank>
            </item>
            <item id="business_criticity">
              <rank>40</rank>
            </item>
            <item id="location_id">
              <rank>50</rank>
            </item>
            <item id="brand_id">
              <rank>60</rank>
            </item>
            <item id="model_id">
              <rank>70</rank>
            </item>
            <item id="technology">
              <rank>75</rank>
            </item>
            <item id="serialnumber">
              <rank>80</rank>
            </item>
            <item id="asset_number">
              <rank>90</rank>
            </item>
            <item id="move2production">
              <rank>100</rank>
            </item>
            <item id="purchase_date">
              <rank>110</rank>
            </item>
            <item id="end_of_warranty">
              <rank>120</rank>
            </item>
          </items>
        </search>
        <list>
          <items>
            <item id="org_id">
              <rank>10</rank>
            </item>
            <item id="status">
              <rank>20</rank>
            </item>
            <item id="business_criticity">
              <rank>30</rank>
            </item>
            <item id="location_id">
              <rank>40</rank>
            </item>
            <item id="brand_id">
              <rank>50</rank>
            </item>
            <item id="model_id">
              <rank>60</rank>
            </item>
            <item id="serialnumber">
              <rank>70</rank>
            </item>
          </items>
        </list>
      </presentation>

现在,您应该具有以下XML文件:

datamodel.sample-add-class.xml
 
<?xml version="1.0" encoding="UTF-8"?>
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
  <classes>
    <class id="Monitor" _delta="define">
      <parent>PhysicalDevice</parent>
      <properties>
        <category>bizmodel,searchable</category>
        <abstract>false</abstract>
        <key_type>autoincrement</key_type>
        <db_table>monitor</db_table>
        <db_key_field>id</db_key_field>
        <db_final_class_field/>
        <naming>
          <format>%1$s</format>
          <attributes>
            <attribute id="name"/>
          </attributes>
        </naming>
        <display_template/>
        <icon>images/monitor.png</icon>
        <reconciliation>
          <attributes>
            <attribute id="name"/>
            <attribute id="org_id"/>
            <attribute id="organization_name"/>
          </attributes>
        </reconciliation>
      </properties>
      <fields>
        <field id="technology" xsi:type="AttributeEnum">
          <values>
            <value>crt</value>
            <value>lcd</value>
          </values>
          <sql>technology</sql>
          <default_value/>
          <is_null_allowed>true</is_null_allowed>
          <display_style>radio_horizontal</display_style>
        </field>
      </fields>
      <methods/>
      <presentation>
        <details>
          <items>
            <item id="name">
              <rank>10</rank>
            </item>
            <item id="org_id">
              <rank>20</rank>
            </item>
            <item id="status">
              <rank>30</rank>
            </item>
            <item id="business_criticity">
              <rank>40</rank>
            </item>
            <item id="location_id">
              <rank>50</rank>
            </item>
            <item id="brand_id">
              <rank>60</rank>
            </item>
            <item id="model_id">
              <rank>70</rank>
            </item>
            <item id="technology">
              <rank>75</rank>
            </item>
            <item id="serialnumber">
              <rank>80</rank>
            </item>
            <item id="asset_number">
              <rank>90</rank>
            </item>
            <item id="move2production">
              <rank>100</rank>
            </item>
            <item id="purchase_date">
              <rank>110</rank>
            </item>
            <item id="end_of_warranty">
              <rank>120</rank>
            </item>
            <item id="description">
              <rank>130</rank>
            </item>
            <item id="contacts_list">
              <rank>140</rank>
            </item>
            <item id="documents_list">
              <rank>150</rank>
            </item>
            <item id="tickets_list">
              <rank>160</rank>
            </item>
            <item id="providercontracts_list">
              <rank>170</rank>
            </item>
            <item id="services_list">
              <rank>180</rank>
            </item>
          </items>
        </details>
        <search>
          <items>
            <item id="name">
              <rank>10</rank>
            </item>
            <item id="org_id">
              <rank>20</rank>
            </item>
            <item id="status">
              <rank>30</rank>
            </item>
            <item id="business_criticity">
              <rank>40</rank>
            </item>
            <item id="location_id">
              <rank>50</rank>
            </item>
            <item id="brand_id">
              <rank>60</rank>
            </item>
            <item id="model_id">
              <rank>70</rank>
            </item>
            <item id="technology">
              <rank>75</rank>
            </item>
            <item id="serialnumber">
              <rank>80</rank>
            </item>
            <item id="asset_number">
              <rank>90</rank>
            </item>
            <item id="move2production">
              <rank>100</rank>
            </item>
            <item id="purchase_date">
              <rank>110</rank>
            </item>
            <item id="end_of_warranty">
              <rank>120</rank>
            </item>
          </items>
        </search>
        <list>
          <items>
            <item id="org_id">
              <rank>10</rank>
            </item>
            <item id="status">
              <rank>20</rank>
            </item>
            <item id="business_criticity">
              <rank>30</rank>
            </item>
            <item id="location_id">
              <rank>40</rank>
            </item>
            <item id="brand_id">
              <rank>50</rank>
            </item>
            <item id="model_id">
              <rank>60</rank>
            </item>
            <item id="serialnumber">
              <rank>70</rank>
            </item>
          </items>
        </list>
      </presentation>
    </class>
  </classes>
<menus>
</menus>
</itop_design>

通过运行工具包检查您的修改。将浏览器指向http ::: your_itop/toolkit。

Checking the modifications with the toolkit

如果在此阶段报告了任何错误,请通过编辑XML文件进行修复,然后单击工具包页面中的“刷新”按钮再次检查您的修改。

解决所有错误之后,可以使用工具包的第二个选项卡将修改应用于iTop:

Updating the database schema with the toolkit

击按钮更新iTop代码和数据库!至:

  1. 将XML数据模型编译为PHP类
  2. 更新数据库架构(创建监视器表)。

此时,如果您在iTop中导航并单击“配置管理New配置项”菜单,则可以在下拉列表中看到“监视器”:

New Monitor menu

显示以下表单:

Monitor creation form, not yet complete

如您所见,新的“监视器”类似乎已经可以正常工作。但是,有一些缺失的部分:

  • 该类没有与之关联的图标,
  • “技术”字段(及其值)的标签为小写,
  • 模型无法分配给监视器类型

为该类添加图标

在datamodel.sample-add-class.xml中,类图标定义为:

   <icon>images/monitor.png</icon>

这意味着itop在模块的images子文件夹中需要一个名为monitor.png的文件。

要提供图标,请在extensions/sample-add-class文件夹内创建images文件夹,然后在其中复制一个漂亮的监视器图标-作为monitor.png。

图标文件可以采用Web浏览器通常支持的任何格式(JPEG,GIF,PNG…),但是PNG-24是唯一支持平滑透明度的格式。类图标的建议大小为48×48像素。

漂亮图标的一个很好的来源是http://www.iconfinder.com/ (请注意许可证)

固定标签

为了使新技术字段正确显示,您需要编辑字典。

使用文本编辑器打开文件en.dict.sample-add-class.php。

插入行:

  'Class:Monitor' => 'Monitor',
        'Class:Monitor+' => 'A computer display',
        'Class:Monitor/Attribute:technology' => 'Technology',
        'Class:Monitor/Attribute:technology+' => 'Technology used for the display',
        'Class:Monitor/Attribute:technology/Value:crt' => 'CRT',
        'Class:Monitor/Attribute:technology/Value:lcd' => 'LCD',

在评论下方:

  字典条目去这里

前两行是该类的标签,以及有关该类含义的简短说明。其他行提供了新字段及其值的翻译后的标签。

您应该获取以下文件:

en.dict.sample-add-class.php
 
<?php
/**
 * Localized data
 *
 * @copyright   Copyright (C) 2013 XXXXX
 * @license     http://opensource.org/licenses/AGPL-3.0
 */
 
Dict::Add('EN US', 'English', 'English', (
        // Dictionary entries go here
        'Class:Monitor' => 'Monitor',
        'Class:Monitor+' => 'A computer display',
        'Class:Monitor/Attribute:technology' => 'Technology',
        'Class:Monitor/Attribute:technology+' => 'Technology used for the display',
        'Class:Monitor/Attribute:technology/Value:crt' => 'CRT',
        'Class:Monitor/Attribute:technology/Value:lcd' => 'LCD',
));
?>

再过一次,运行工具包检查您的修改。

Checking the modifications with the toolkit

如果在此阶段报告了错误,请通过编辑PHP文件进行修复,然后单击工具包页面上的“刷新”按钮再次检查您的修改。

解决所有错误后,可以使用工具包的第二个选项卡上的“更新iTop代码”按钮将修改应用于iTop:

Applying the modifications to iTop

如果在iTop中导航到服务器的详细信息,现在应该看到以下内容:

The new Monitor class

在模型。type中添加Monitor类

模型类型在该类的“类型”属性中定义。该属性是AttributeEnum,因此我们需要添加Monitor作为可能的值之一。为此,将其复制粘贴到XML的classes节点中:

  <class id="Model" _delta="must_exist">
      <fields>
        <field id="type" xsi:type="AttributeEnum">
          <values>
            <value id="Monitor" _delta="define">Monitor</value>
          </values>
        </field>
      </fields>
    </class>

添加一个仪表板项目

在此阶段,访问iTop中的监视器的唯一方法是搜索任何配置项,或通过“新建配置项”菜单。

让我们将监视器对象添加到“最终用户设备”部分的“配置管理概述”仪表板中。

为了提供预期的结果,我们的定制模块将不得不更改此仪表板的定义。这可以通过在文件datamodel.sample-add-class.xml中使用以下XML定义替换空的<menus> </ menus>标记来实现:

<menus>
  <menu id="ConfigManagementOverview" xsi:type="DashboardMenuNode" _delta="must_exist">
    <definition>
      <cells>
        <cell id="2" _delta="must_exist">
          <dashlets>
            <dashlet id="99" xsi:type="DashletBadge" _delta="define">
              <rank>8</rank>
              <class>Monitor</class>
            </dashlet>
          </dashlets>
        </cell>
      </cells>
    </definition>
  </menu>
</menus>

概述仪表板在iTop数据模型的多个部分中定义。仪表板的“ End用户Devices”部分由“ itop-enduser-devices”模块定义。为了能够更改此定义,必须在“ itopenduser-devices”上将我们的自定义模块声明为仪表板。它将在此模块之后加载。

再过一次,运行工具包检查您的修改。

Checking the modifications with the toolkit

如果在此阶段报告了错误,请通过编辑PHP文件进行修复,然后单击工具包页面上的“刷新”按钮再次检查您的修改。

解决所有错误后,可以使用工具包的第二个选项卡上的“更新iTop代码”按钮将修改应用于iTop:

Applying the modifications to iTop

如果导航到iTop中的“配置管理概述”菜单,现在应该看到以下内容:

Modified Overview dashboard

最终定制模块

您可以通过单击以下链接下载完整的定制模块:

sample-add-class.zip

下一步

要将定制部署到另一个iTop服务器,只需将文件夹“ sample-add-class”复制到iTop的扩展文件夹,然后再次运行安装程序。

原贴链接:https://www.itophub.io/wiki/page?id=2_7_0%3Acustomization%3Aadd-class-sample


Creating a new class of CI: Monitor

This document explains, step by step, how to create your own iTop module in order to add a new class of CIs: a Monitor.

learning:
Add a new CI class
level:
Intermediate
domains:
XMLPresentationDashboardDictionary
min version:
2.1.0

Goals of this tutorial

In this step-by-step tutorial you will learn to:

  • create your own extension module for iTop

  • create a new class of object

  • add a new entry into an existing dashboard

For the purpose of this tutorial we will create a new class of CI, called Monitor, that will be very similar to the Peripheral class, with the addition of an extra field “technology” to distinguish CRT and LCD monitors.

The Monitor Class

What you will need

  • iTop installed on a development machine, on which you can easily access/edit the files.

  • A text editor capable of editing PHP and XML file and supporting UTF-8. On Windows you can use Wordpad (Notepad does not like Unix line endings) or one of the excellent free development IDEs like PSPad or Notepad++.

Customization process

The customization process is the following:

  1. Install a development instance of iTop. It is always better not to experiment in production !!

  2. Install the toolkit to assist you in the customization

  3. Create a new (empty) module using the module creation wizard

  4. Copy this new module to the extensions folder on iTop and run the setup again to install the empty module

  5. Modify the module in extensions and use the toolkit to check your customizations

Repeat the last point until you are satisfied with your customization. When you are done, your new module is ready to be deployed. Copy the module folder in the extension directory on your production iTop instance and run the setup to install it.

Step by step tutorial

Create your customization module

Use the module creation wizard. Fill the form with the following values:

LabelValueRemarks
Module namesample-add-classNames starting with itop- and combodo- are reserved for use by Combodo. It is recommended not to put spaces or accentuated characters in the name of the module. Two modules with the same name cannot co-exist in the same iTop instance.
Module LabelAdd Class SampleThis label will be displayed in the setup wizard. Localized characters and spaces are allowed
Module Version1.0.0The convention is to use a 3 digits numbering scheme: X.Y.Z
CategorybusinessModules that provide modifications to the data model should be in the category 'business'
Dependenciesitop-config-mgmt/2.0.0,itop-endusers-devices/2.0.0Our customization module depends on the modules: iTop Configuration Management (version 2.0.0) in which the Physical Device class is defined and iTop End User Devices (version 2.0.0) in which the “End User Devices” menu is defined

Click Generate ! to download the empty module as a zip file.

When a module extends an existing class, it must be loaded after the module that declared the class to be extended. To achieve this, make sure that the first module is listed in the dependencies of your new module.

For example if you want to create a new class, dervied from the class VirtualMachine, your custom module must depend on itop-virtualization-mgmt/2.0.0

Install the empty module

Expand the content of the zip into the extensions folder of your development iTop instance. You should now have a folder named sample-add-class inside theextensions folder. this folder contains the following files:

  • datamodel.sample-add-class.xml

  • module.sample-add-class.php

  • en.dict.sample-add-class.php

  • model.sample-add-class.php

Make sure that the file conf/production/config-itop.php is writable for the web server (on Windows: right click to display the file properties and uncheck the read-only flag; on Linux change the rights of the file), then launch the iTop installation by pointing your browser to http://your_itop/setup/

Launching the re-install

Click “Continue »” to start the re-installation.

https://www.itophub.io/wiki/media?w=300&tok=554538&media=2_7_0%3Acustomization%3Ainstall-extension-2.png

Make sure that “Update an existing instance” is selected before clicking “Next »”.

https://www.itophub.io/wiki/media?w=300&tok=2395b2&media=2_7_0%3Acustomization%3Aupgrade-screenshot2.png

Continue to the next steps of the wizard…

Select the new extension

Your custom module should appear in the list of “Extensions”. If it's not the case, check that the module files were copied in the proper location and that the web server has enough rights to read them.

Select your custom module before clicking “Next »” and complete the installation.

Add the Monitor class

Using you favorite text editor, open the file datamodel.sample-add-class.xml.

Remove the tags <profiles></profiles> since the module will not contain any profile definition.

Inside the classes tag, add the following piece of code:

    <class id="Monitor" _delta="define">
      <parent>PhysicalDevice</parent>
      <properties>
        <category>bizmodel,searchable</category>
        <abstract>false</abstract>
        <key_type>autoincrement</key_type>
        <db_table>monitor</db_table>
        <db_key_field>id</db_key_field>
        <db_final_class_field/>
        <naming>
          <format>%1$s</format>
          <attributes>
            <attribute id="name"/>
          </attributes>
        </naming>
        <display_template/>
        <icon>images/monitor.png</icon>
        <reconciliation>
          <attributes>
            <attribute id="name"/>
            <attribute id="org_id"/>
            <attribute id="organization_name"/>
          </attributes>
        </reconciliation>
      </properties>
      <fields>
        <field id="technology" xsi:type="AttributeEnum">
          <values>
            <value>crt</value>
            <value>lcd</value>
          </values>
          <sql>technology</sql>
          <default_value/>
          <is_null_allowed>true</is_null_allowed>
          <display_style>radio_horizontal</display_style>
        </field>
      </fields>
      <methods/>
     </class>

This instructs iTop to define a new class derived from PhysicalDevice. An extra table “monitor” will be added in SQL to store the class specific data. The “Monitor” class adds one extra field “technology” to the PhysicalDevice class. This field is an enumerated value with two possible values “lcd” and “crt”. This field is to be stored in the column “technology” in the SQL database.

For more information about the meaning of the various parameters of the class and field tags, refer to the XML reference documentation.

The <presentation> tag must also be defined to describe how the object should be displayed in iTop. There are three “presentations” to define:

  • The “details” defines the form used to display and edit an instance of the object

  • The “list” defines the default columns to be used for displaying a list of objects of this class

  • The “search” defines the available fields in the search form for this class of objects

Add the following piece of code just after the closing </fields> tag:

      <presentation>
        <details>
          <items>
            <item id="name">
              <rank>10</rank>
            </item>
            <item id="org_id">
              <rank>20</rank>
            </item>
            <item id="status">
              <rank>30</rank>
            </item>
            <item id="business_criticity">
              <rank>40</rank>
            </item>
            <item id="location_id">
              <rank>50</rank>
            </item>
            <item id="brand_id">
              <rank>60</rank>
            </item>
            <item id="model_id">
              <rank>70</rank>
            </item>
            <item id="technology">
              <rank>75</rank>
            </item>
            <item id="serialnumber">
              <rank>80</rank>
            </item>
            <item id="asset_number">
              <rank>90</rank>
            </item>
            <item id="move2production">
              <rank>100</rank>
            </item>
            <item id="purchase_date">
              <rank>110</rank>
            </item>
            <item id="end_of_warranty">
              <rank>120</rank>
            </item>
            <item id="description">
              <rank>130</rank>
            </item>
            <item id="contacts_list">
              <rank>140</rank>
            </item>
            <item id="documents_list">
              <rank>150</rank>
            </item>
            <item id="tickets_list">
              <rank>160</rank>
            </item>
            <item id="providercontracts_list">
              <rank>170</rank>
            </item>
            <item id="services_list">
              <rank>180</rank>
            </item>
          </items>
        </details>
        <search>
          <items>
            <item id="name">
              <rank>10</rank>
            </item>
            <item id="org_id">
              <rank>20</rank>
            </item>
            <item id="status">
              <rank>30</rank>
            </item>
            <item id="business_criticity">
              <rank>40</rank>
            </item>
            <item id="location_id">
              <rank>50</rank>
            </item>
            <item id="brand_id">
              <rank>60</rank>
            </item>
            <item id="model_id">
              <rank>70</rank>
            </item>
            <item id="technology">
              <rank>75</rank>
            </item>
            <item id="serialnumber">
              <rank>80</rank>
            </item>
            <item id="asset_number">
              <rank>90</rank>
            </item>
            <item id="move2production">
              <rank>100</rank>
            </item>
            <item id="purchase_date">
              <rank>110</rank>
            </item>
            <item id="end_of_warranty">
              <rank>120</rank>
            </item>
          </items>
        </search>
        <list>
          <items>
            <item id="org_id">
              <rank>10</rank>
            </item>
            <item id="status">
              <rank>20</rank>
            </item>
            <item id="business_criticity">
              <rank>30</rank>
            </item>
            <item id="location_id">
              <rank>40</rank>
            </item>
            <item id="brand_id">
              <rank>50</rank>
            </item>
            <item id="model_id">
              <rank>60</rank>
            </item>
            <item id="serialnumber">
              <rank>70</rank>
            </item>
          </items>
        </list>
      </presentation>

You should now have the following XML file:

datamodel.sample-add-class.xml
 
<?xml version="1.0" encoding="UTF-8"?>
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
  <classes>
    <class id="Monitor" _delta="define">
      <parent>PhysicalDevice</parent>
      <properties>
        <category>bizmodel,searchable</category>
        <abstract>false</abstract>
        <key_type>autoincrement</key_type>
        <db_table>monitor</db_table>
        <db_key_field>id</db_key_field>
        <db_final_class_field/>
        <naming>
          <format>%1$s</format>
          <attributes>
            <attribute id="name"/>
          </attributes>
        </naming>
        <display_template/>
        <icon>images/monitor.png</icon>
        <reconciliation>
          <attributes>
            <attribute id="name"/>
            <attribute id="org_id"/>
            <attribute id="organization_name"/>
          </attributes>
        </reconciliation>
      </properties>
      <fields>
        <field id="technology" xsi:type="AttributeEnum">
          <values>
            <value>crt</value>
            <value>lcd</value>
          </values>
          <sql>technology</sql>
          <default_value/>
          <is_null_allowed>true</is_null_allowed>
          <display_style>radio_horizontal</display_style>
        </field>
      </fields>
      <methods/>
      <presentation>
        <details>
          <items>
            <item id="name">
              <rank>10</rank>
            </item>
            <item id="org_id">
              <rank>20</rank>
            </item>
            <item id="status">
              <rank>30</rank>
            </item>
            <item id="business_criticity">
              <rank>40</rank>
            </item>
            <item id="location_id">
              <rank>50</rank>
            </item>
            <item id="brand_id">
              <rank>60</rank>
            </item>
            <item id="model_id">
              <rank>70</rank>
            </item>
            <item id="technology">
              <rank>75</rank>
            </item>
            <item id="serialnumber">
              <rank>80</rank>
            </item>
            <item id="asset_number">
              <rank>90</rank>
            </item>
            <item id="move2production">
              <rank>100</rank>
            </item>
            <item id="purchase_date">
              <rank>110</rank>
            </item>
            <item id="end_of_warranty">
              <rank>120</rank>
            </item>
            <item id="description">
              <rank>130</rank>
            </item>
            <item id="contacts_list">
              <rank>140</rank>
            </item>
            <item id="documents_list">
              <rank>150</rank>
            </item>
            <item id="tickets_list">
              <rank>160</rank>
            </item>
            <item id="providercontracts_list">
              <rank>170</rank>
            </item>
            <item id="services_list">
              <rank>180</rank>
            </item>
          </items>
        </details>
        <search>
          <items>
            <item id="name">
              <rank>10</rank>
            </item>
            <item id="org_id">
              <rank>20</rank>
            </item>
            <item id="status">
              <rank>30</rank>
            </item>
            <item id="business_criticity">
              <rank>40</rank>
            </item>
            <item id="location_id">
              <rank>50</rank>
            </item>
            <item id="brand_id">
              <rank>60</rank>
            </item>
            <item id="model_id">
              <rank>70</rank>
            </item>
            <item id="technology">
              <rank>75</rank>
            </item>
            <item id="serialnumber">
              <rank>80</rank>
            </item>
            <item id="asset_number">
              <rank>90</rank>
            </item>
            <item id="move2production">
              <rank>100</rank>
            </item>
            <item id="purchase_date">
              <rank>110</rank>
            </item>
            <item id="end_of_warranty">
              <rank>120</rank>
            </item>
          </items>
        </search>
        <list>
          <items>
            <item id="org_id">
              <rank>10</rank>
            </item>
            <item id="status">
              <rank>20</rank>
            </item>
            <item id="business_criticity">
              <rank>30</rank>
            </item>
            <item id="location_id">
              <rank>40</rank>
            </item>
            <item id="brand_id">
              <rank>50</rank>
            </item>
            <item id="model_id">
              <rank>60</rank>
            </item>
            <item id="serialnumber">
              <rank>70</rank>
            </item>
          </items>
        </list>
      </presentation>
    </class>
  </classes>
<menus>
</menus>
</itop_design>

Check your modification by running the toolkit. Point your browser to http://your_itop/toolkit.

Checking the modifications with the toolkit

If any error is reported at this stage, fix it by editing the XML file and check again your modifications by clicking on the “Refresh” button in the toolkit page.

Once all the errors have been fixed, you can apply the modifications to iTop by using the second tab of the toolkit:

Updating the database schema with the toolkit

Click on the button Update iTop Code and Database! to:

  1. Compile the XML data model to PHP classes

  2. Update the database schema (creation of the monitor table).

At this point, if you navigate in iTop and click on the “Configuration Management / New CI” menu, you can see that “Monitor” is available in the drop-down list:

New Monitor menu

The following form gets displayed:

Monitor creation form, not yet complete

As you can see the new “Monitor” class seems to work fine already. However there are some missing pieces:

  • The class has no icon associated with it,

  • The label of the “technology” field (and its values) are in lowercase,

  • Model can't be assigned to the Monitor type

Add an Icon for the class

In the datamodel.sample-add-class.xml the class icon is defined as:

        <icon>images/monitor.png</icon>

This means that itop expects a file named monitor.png in the images subfolder of the module.

To provide the icon, create the images folder inside the extensions/sample-add-class folder and copy a nice monitor icon - as monitor.png - inside it.

Icon files can be in any format that is commonly supported by web browsers (JPEG, GIF, PNG…), but PNG-24 is the only format that supports smooth transparency. The recommended size for class icons is 48×48 pixels.

A good source of nice icons is http://www.iconfinder.com/ (pay attention to the licences)

Fix the labels

In order to have the new technology field display properly, you need to edit the dictionary.

Using you text editor, open the file en.dict.sample-add-class.php.

Insert the lines:

  'Class:Monitor' => 'Monitor',
        'Class:Monitor+' => 'A computer display',
        'Class:Monitor/Attribute:technology' => 'Technology',
        'Class:Monitor/Attribute:technology+' => 'Technology used for the display',
        'Class:Monitor/Attribute:technology/Value:crt' => 'CRT',
        'Class:Monitor/Attribute:technology/Value:lcd' => 'LCD',

Just below the comment:

  // Dictionary entries go here

The first two lines are the label for the class and a short explanation about the meaning of the class. The other lines provides the translated label for the new field and its values.

You should obtain the following file:

en.dict.sample-add-class.php
 
<?php
/**
 * Localized data
 *
 * @copyright   Copyright (C) 2013 XXXXX
 * @license     http://opensource.org/licenses/AGPL-3.0
 */
 
Dict::Add('EN US', 'English', 'English', (
        // Dictionary entries go here
        'Class:Monitor' => 'Monitor',
        'Class:Monitor+' => 'A computer display',
        'Class:Monitor/Attribute:technology' => 'Technology',
        'Class:Monitor/Attribute:technology+' => 'Technology used for the display',
        'Class:Monitor/Attribute:technology/Value:crt' => 'CRT',
        'Class:Monitor/Attribute:technology/Value:lcd' => 'LCD',
));
?>

One more time, check your modification by running the toolkit.

Checking the modifications with the toolkit

If errors are reported at this stage, fix them by editing the PHP file and check again your modifications by clicking on the “Refresh” button in the toolkit page.

Once all the errors have been fixed, you can apply the modifications to iTop by using “Update iTop Code” button on the second tab of the toolkit:

Applying the modifications to iTop

If you navigate to the details of a Server in iTop, you should now see the following:

The new Monitor class

Add Monitor class in Model.type

The Model type is defined in the “type” attribute of the class. This attribute is a AttributeEnum, so we need to add Monitor as one of the possible values. To do so, copy/paste this in the classes node of the XML :

    <class id="Model" _delta="must_exist">
      <fields>
        <field id="type" xsi:type="AttributeEnum">
          <values>
            <value id="Monitor" _delta="define">Monitor</value>
          </values>
        </field>
      </fields>
    </class>

Add a dashboard item

At this stage, the only way to access the Monitors in iTop is either by searching for any CI, or through the “New CI” menu.

Let's add the Monitor object to the “Configuration Management / Overview” dashboard, in the “End User Devices” section.

In order to provide the expected result, our customization module will have to alter the definition of this dashboard. This can be achieved by replacing the empty <menus></menus> tags by the following XML definition in the file datamodel.sample-add-class.xml:

<menus>
  <menu id="ConfigManagementOverview" xsi:type="DashboardMenuNode" _delta="must_exist">
    <definition>
      <cells>
        <cell id="2" _delta="must_exist">
          <dashlets>
            <dashlet id="99" xsi:type="DashletBadge" _delta="define">
              <rank>8</rank>
              <class>Monitor</class>
            </dashlet>
          </dashlets>
        </cell>
      </cells>
    </definition>
  </menu>
</menus>

The Overview dashboard is defined in several parts in the iTop data model. The 'End User Devices“ section of the dashboard is defined by the “itop-enduser-devices” module. In order to be able to alter this definition, our customization module must be declared as depending on “itop-enduser-devices”, so that it will be loaded after this module.

One more time, check your modification by running the toolkit.

Checking the modifications with the toolkit

If errors are reported at this stage, fix them by editing the PHP file and check again your modifications by clicking on the “Refresh” button in the toolkit page.

Once all the errors have been fixed, you can apply the modifications to iTop by using “Update iTop Code” button on the second tab of the toolkit:

Applying the modifications to iTop

If you navigate to the “Configuration Management / Overview” menu in iTop, you should now see the following:

Modified Overview dashboard

Final Customization Module

You can download the complete customization module by clicking on the link below:

sample-add-class.zip

Next Steps

To deploy your customization to another iTop server, simply copy the folder “sample-add-class” to the extensions folder of iTop and run the setup again.

标签:
由 superadmin 在 2020/08/27, 17:15 创建
    

需要帮助?

如果您需要有关XWiki的帮助,可以联系:

深圳市艾拓先锋企业管理咨询有限公司