创建你自己的主题

概述

默认情况下,Zabbix 提供了多个预定义的前端主题。 要创建自定义主题,请按照此处提供的分步流程进行操作。

第 1 步:创建您的主题

要创建您自己的主题:

  1. 从头创建一个 CSS 文件,或者从 assets/styles/ 目录中复制一个现有主题(例如 blue-theme.css、dark-theme.css 或其他主题)并进行修改。
  2. 将您的主题(例如 custom-theme.css)保存到 assets/styles/ 目录中。
步骤 2:在主题列表中启用主题

要使自定义主题在前端中可用,必须将其添加到 APP::getThemes() 方法返回的主题列表中。 具体方法是在 APP 类中重写 ZBase::getThemes() 方法,如下所示:

  1. 打开 include/classes/core/APP.php 文件并找到 APP 类:
class APP extends ZBase {

}
  1. 在类中,在最后一个右花括号 } 之前添加以下方法:
public static function getThemes() {
          return array_merge(parent::getThemes(), [
              'custom-theme' => _('Custom theme')
          ]);
}

其中:

  • custom-theme - 主题的内部标识符,必须与 CSS 文件名(不含 .css 扩展名)一致;
  • Custom theme - 在前端中显示的名称。

要添加多个主题,请将它们列在数组中,并使用逗号分隔每个条目。 最后一个条目后的逗号可选。

例如:

      public static function getThemes() {
          return array_merge(parent::getThemes(), [
              'custom-theme' => _('Custom theme'),
              'anothertheme' => _('Another theme'),
              'onemoretheme' => _('One more theme')
          ]);
      }
步骤 3:更改图形颜色

要更改图形颜色,必须在数据库表 graph_theme 中为新主题添加一条记录。

向 MySQL/MariaDB 数据库添加记录的示例:

    mysql -u zabbix -p
    # Enter password:
mysql> USE zabbix;
mysql> INSERT INTO graph_theme (
    graphthemeid,
    theme,
    backgroundcolor,
    graphcolor,
    gridcolor,
    maingridcolor,
    gridbordercolor,
    textcolor,
    highlightcolor,
    leftpercentilecolor,
    rightpercentilecolor,
    nonworktimecolor,
    colorpalette
)
SELECT
    MAX(graphthemeid) + 1,
    'custom-theme',
    'FFFFFF',
    'FFFFFF',
    'CCD5D9',
    'ACBBC2',
    'ACBBC2',
    '1F2C33',
    'CC745E',
    '5ECCAB',
    'CC745E',
    'EBEBEB',
    '329F7E,C2583D,346D91,B26E44,CC6C91,7A6DC2,C4AA56,7C2731,BF75B8,73A350,B04833,633A60,879CCC,7FAD6C,324978,3F5C3D,795C94,D66B58,732230,809C5D,C79DD1'
FROM graph_theme;
步骤 4:使用新主题

在 Zabbix 前端中,您可以将此主题设置为默认主题,也可以在用户配置文件中选择该主题。