zabbix版本2.4.6,此欄目下的分享都是在2.4.6版本基礎下
在進行zabbix二次開發前需要考慮的事情:
- zabbix應用了jquery.js和prototype.js,因爲2個js包之間的衝突導致網上的jquery插件都無法使用。
- 使用了jquery-ui,樣式扁平化比較困難
目錄結構:
audio-聲音文件夾
conf-配置文件夾
fonts-字體文件夾
images-圖片文件夾
include-包文件
-classes包文件
-view一些視圖文件
js-js文件夾
locale-語言文件夾
styles-樣式文件夾
地址分析:
例http://ol-zabbix.chinacloudapp.cn/zabbix/dashboard.php
都是很簡單的結構,按照目錄找文件即可
文件結構分析:
例:dashboard.php
require_once dirname(__FILE__).’/include/config.inc.php’;
require_once dirname(__FILE__).’/include/blocks.inc.php’;
$page[‘title’] = _(‘Dashboard’);
$page[‘file’] = ‘dashboard.php’;
$page[‘hist_arg’] = array();
$page[‘scripts’] = array(‘class.pmaster.js’);
$page[‘type’] = detect_page_type(PAGE_TYPE_HTML);
require_once dirname(__FILE__).’/include/page_header.php’;
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields = array(
‘groupid’ => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null),
‘view_style’ => array(T_ZBX_INT, O_OPT, P_SYS, IN(‘0,1’), null),
‘type’ => array(T_ZBX_INT, O_OPT, P_SYS, IN(‘0,1’), null),
‘output’ => array(T_ZBX_STR, O_OPT, P_SYS, null, null),
‘jsscriptid’ => array(T_ZBX_STR, O_OPT, P_SYS, null, null),
‘fullscreen’ => array(T_ZBX_INT, O_OPT, P_SYS, IN(‘0,1’), null),
// ajax
‘widgetName’ => array(T_ZBX_STR, O_OPT, P_ACT, null, null),
‘widgetRefresh’ => array(T_ZBX_STR, O_OPT, null, null, null),
‘widgetRefreshRate’ => array(T_ZBX_STR, O_OPT, P_ACT, null, null),
‘widgetSort’ => array(T_ZBX_STR, O_OPT, P_ACT, null, null),
‘widgetState’ => array(T_ZBX_STR, O_OPT, P_ACT, null, null),
‘favobj’ => array(T_ZBX_STR, O_OPT, P_ACT, null, null),
‘favaction’ => array(T_ZBX_STR, O_OPT, P_ACT, IN(‘”add”,”remove”‘), null),
‘favid’ => array(T_ZBX_STR, O_OPT, P_ACT, null, null)
);
check_fields($fields);
check_fields爲檢測傳入參數的方法,例如:想新增一個post到此頁面的參數,必須在$fields中增加該參數,否則無法接受該參數。
在需要引入view頁時你都能在文件尾部找到
/*
** Display
*/
$data = array(
‘pageFilter’ => $pageFilter,
‘graphid’ => $pageFilter->graphid,
‘hostid’ => $pageFilter->hostid,
‘fullscreen’ => $_REQUEST[‘fullscreen’]
);
$chartsView = new CView(‘monitoring.charts’, $data);
$chartsView->render();
$chartsView->show();
類似的代碼,’monitoring.charts’即爲view文件的文件名。可以在/include/view裏找到該文件。
或者你能在尾部找到$dashboardWidget->show();類似代碼,表示展示$dashboardWidget。
主要數據庫關係說明:
graphs圖形表
graphs_items圖形關聯items表
groups主機羣組表
hosts主機表
hosts_groups主機與圖形關聯表
items監控項表
history每分鐘一條的監控數據表(大於零的數值)
-value具體數值
-clock時間
history_uint每分鐘一條的監控數據表(小於零的數值,主要用作百分比)
trends每小時一條的最大值、最小值、平均值表(大於零的數值)
trends_uint(小於零的數值,主要用作百分比)
好了知道這些表你就可以用懂zabbix的監控數據了