manifest.json

任何模块都需要manifest.json file. file 必须位于模块的主目录中(例如,zabbix/ui/modules/module_name/manifest.json).

manifest.json至少需要指定以下字段:

{
           "manifest_version": 2.0,
           "id": "my_ip_address",
           "name": "My IP Address",
           "namespace": "MyIPAddress",
           "version": "1.0"
       }

manifest.json支持的参数(点击参数名称查看详细描述):

参数 描述 必填
manifest_version 模块的清单version.
id 模块的唯一ID.
name 在管理部分显示的模块名称.
namespace 模块类的PHP命名空间.
version 模块version.
type 模块类型. 对于小部件必须设置为widget 小部件必填,其他情况非必填
widget 小部件配置. 仅用于小部件.
actions 注册到模块的操作.
assets 要包含的CSS样式和JavaScript文件.
author 模块作者.
config 自定义模块选项的默认值.
description 模块描述.
url 模块描述的链接.

manifest_version

模块的清单version. 当前支持的version版本为2.0.

类型: 双精度浮点

示例:

"manifest_version": 2.0

id

模块ID。必须唯一。为避免未来命名冲突,建议为模块使用前缀(作者或公司名称,或其他任何名称)。 例如,如果一个模块是课程示例且模块名称为"My module",则ID将为"example_my_module"。

类型: string

示例:

"id": "example_my_module"

名称

将在管理部分显示的模块名称。

类型: string

示例:

"name": "My module"

命名空间

模块类的PHP命名空间.

类型: string

示例:

"namespace": "ClockWidget"

版本

模块 version. version 将显示在管理部分.

类型: string

示例:

"version": "1.0"

类型

模块类型。对于小部件是必需的,必须等于"widget"。

类型: string

默认值: "module"

示例:

"type": "widget"

动作

模块注册所需的操作。 必须为每个操作定义class object键,其他操作键为可选。

类型: object

typemodule时支持的object键:

  • write.your.action.name (object) - 操作名称,应使用小写字母[a-z]书写,单词间用点号分隔。

    Supports the keys:

    • class (string; required) - action class name.
    • layout (string) - action layout. Supported values: layout.json, layout.htmlpage (default), null.
    • view (string) - action view.

示例:

"actions": {
           "module.example.list": {
               "class": "ExampleList",
               "view": "example.list",
               "layout": "layout.htmlpage"
               }
           }

typewidget时支持的object键:

  • widget.{id}.view (object) - 小部件视图的file和类名。将{id}替换为小部件的id值(例如widget.example_clock.view)。 支持以下键:

    • class (string; 必需) - 用于扩展默认CControllerDashboardWidgetView类的小部件视图模式操作类名。 类源file必须位于actions目录中。
    • view (string) - 小部件视图。必须位于views目录中。 如果视图file是默认预期的widget.view.php,则可以省略此参数。 如果使用不同名称,请在此处指定。
  • widget.{id}.edit (object) - 小部件配置视图的file名称。将{id}替换为小部件的id值(例如widget.example_clock.edit)。

    Supports the keys:

    • class (string; required) - action class name for widget configuration view mode. The class source file must be located in the actions directory.
    • view (string) - widget configuration view. Must be located in the views directory. If the view file is widget.edit.php, which is expected by default, this parameter maybe omitted. If using a different name, specify it here.

示例:

"actions": {
           "widget.tophosts.view": {
               "class": "WidgetView"
           },
           "widget.tophosts.column.edit": {
               "class": "ColumnEdit",
               "view": "column.edit",
               "layout": "layout.json"
           }
       }

资产

需包含的CSS样式和JavaScript文件.

类型: object

支持的object键值:

  • css (array) - 需包含的CSS文件. 文件必须位于assets/css目录下.
  • js (array) - 需包含的JavaScript文件. 文件必须位于assets/js目录下.

示例:

"assets": {
           "css": ["widget.css"],
           "js": ["class.widget.js"]
       }

作者

模块作者。该作者名称将显示在管理界面中。

类型: string

示例:

"author": "John Smith"

配置

模块选项的默认值。object可以包含任何自定义键。 如果指定,这些值将在模块注册期间写入数据库。 稍后添加的新变量将在第一次调用时写入。 之后,变量值只能直接在数据库中更改。

类型: object

示例:

"config": {
           "username": "Admin",
           "password": "",
           "auth_url": "https://example.com/auth"
       }

描述

模块描述.

类型: string

示例:

"description": "This is a clock widget."

小组件

小部件配置。当type设置为widget时使用。

类型: object

支持的object键值:

  • name (string) - 用于小部件列表和默认标题。如果为空,将使用模块中的"name"参数。

  • size (object) - 默认小部件尺寸。支持以下键值:

    • width (integer) - default widget width.
    • height (integer) - default widget height.
  • form_class (string) - 包含小部件字段表单的类。必须位于includes目录中。

    If the class is WidgetForm.php, which is expected by default, this parameter maybe omitted. If using a different name, specify it here.

  • js_class (string) - 用于小部件视图模式的JavaScript类名,用于扩展默认的CWidget类。

    The class will be loaded with the dashboard. The class source file must be located in the assets/js directory. See also: assets.

  • use_time_selector (boolean) - 确定小部件是否需要仪表板时间选择器。

    Supported values: true, false (default).

  • refresh_rate (integer) - 小部件刷新频率(单位:秒,默认值:60)。

示例:

"widget": {
           "name": "",
           "size": {
               "width": 12,
               "height": 5
           },
           "form_class": "WidgetForm",
           "js_class": "CWidget",
           "use_time_selector": false,
           "refresh_rate": 60
       }

url

指向模块描述的链接。对于小部件,点击帮助图标添加部件小部件窗口时,将打开此链接。 如果未指定url,点击帮助图标将打开通用的 Dashboard widgets页面。

类型: string

示例:

"url": "http://example.com"