diff options
| author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-07-16 10:01:08 +0000 |
|---|---|---|
| committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-07-16 10:01:08 +0000 |
| commit | 4e4aa7eb198963720b377cd568825309616dce8a (patch) | |
| tree | e1c0bb863be19aeb630bf5ef77fb8c3c8e27731f /frontends/php | |
| parent | bac3a136113548551ad7320cc8a8ed7ecbb2e11a (diff) | |
- added pie graphs (Artem)
- added subclasses chart.inc.php and pie.inc.php, extending graph.inc.php (Artem)
git-svn-id: svn://svn.zabbix.com/trunk@4458 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php')
| -rw-r--r-- | frontends/php/chart.php | 2 | ||||
| -rw-r--r-- | frontends/php/chart2.php | 82 | ||||
| -rw-r--r-- | frontends/php/chart3.php | 4 | ||||
| -rw-r--r-- | frontends/php/chart6.php | 107 | ||||
| -rw-r--r-- | frontends/php/chart7.php | 106 | ||||
| -rw-r--r-- | frontends/php/charts.php | 248 | ||||
| -rw-r--r-- | frontends/php/graphs.php | 131 | ||||
| -rw-r--r-- | frontends/php/include/classes/chart.inc.php | 1104 | ||||
| -rw-r--r-- | frontends/php/include/classes/graph.inc.php | 1599 | ||||
| -rw-r--r-- | frontends/php/include/classes/pie.inc.php | 610 | ||||
| -rw-r--r-- | frontends/php/include/defines.inc.php | 1 | ||||
| -rw-r--r-- | frontends/php/include/forms.inc.php | 221 | ||||
| -rw-r--r-- | frontends/php/include/graphs.inc.php | 147 | ||||
| -rw-r--r-- | frontends/php/include/locales/en_gb.inc.php | 7 | ||||
| -rw-r--r-- | frontends/php/include/screens.inc.php | 27 | ||||
| -rw-r--r-- | frontends/php/js/graphs.js | 14 | ||||
| -rw-r--r-- | frontends/php/popup_gitem.php | 50 |
17 files changed, 2760 insertions, 1700 deletions
diff --git a/frontends/php/chart.php b/frontends/php/chart.php index 502c6c8e..db0d7c4d 100644 --- a/frontends/php/chart.php +++ b/frontends/php/chart.php @@ -20,7 +20,7 @@ ?> <?php require_once "include/config.inc.php"; - require_once "include/classes/graph.inc.php"; + require_once "include/classes/chart.inc.php"; $page["file"] = "chart.php"; $page["title"] = "S_CHART"; diff --git a/frontends/php/chart2.php b/frontends/php/chart2.php index a0dcbe60..a4c2ca7f 100644 --- a/frontends/php/chart2.php +++ b/frontends/php/chart2.php @@ -19,15 +19,15 @@ **/ ?> <?php - require_once "include/config.inc.php"; - require_once "include/graphs.inc.php"; - require_once "include/classes/graph.inc.php"; + require_once 'include/config.inc.php'; + require_once 'include/graphs.inc.php'; + require_once 'include/classes/chart.inc.php'; - $page["file"] = "chart2.php"; - $page["title"] = "S_CHART"; - $page["type"] = PAGE_TYPE_IMAGE; + $page['file'] = 'chart2.php'; + $page['title'] = 'S_CHART'; + $page['type'] = PAGE_TYPE_IMAGE; -include_once "include/page_header.php"; +include_once 'include/page_header.php'; ?> <?php @@ -47,59 +47,63 @@ include_once "include/page_header.php"; <?php $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_MODE_LT); - if( !($db_data = DBfetch(DBselect("select g.*,h.host,h.hostid from graphs g left join graphs_items gi on g.graphid=gi.graphid ". - " left join items i on gi.itemid=i.itemid left join hosts h on i.hostid=h.hostid ". - " where g.graphid=".$_REQUEST["graphid"]. - /* " and ".DBid2nodeid("g.graphid")."=".$ZBX_CURNODEID. */ /* NOTE: the chart can display any accesiable graph! */ - " and ( h.hostid not in (".$denyed_hosts.") OR h.hostid is NULL) ")))) + if( !($db_data = DBfetch(DBselect('SELECT g.*,h.host,h.hostid '. + ' FROM graphs g '. + ' LEFT JOIN graphs_items gi ON g.graphid=gi.graphid '. + ' LEFT JOIN items i ON gi.itemid=i.itemid '. + ' LEFT JOIN hosts h ON i.hostid=h.hostid '. + ' WHERE g.graphid='.$_REQUEST['graphid']. + /* ' and '.DBid2nodeid('g.graphid').'='.$ZBX_CURNODEID. */ /* NOTE: the chart can display any accesiable graph! */ + ' AND ( h.hostid not in ('.$denyed_hosts.') '. + ' OR h.hostid is NULL) ')))) { access_deny(); } + + $graph = new Chart($db_data['graphtype']); - $graph = new Graph($db_data["graphtype"]); - - if(isset($_REQUEST["period"])) $graph->SetPeriod($_REQUEST["period"]); - if(isset($_REQUEST["from"])) $graph->SetFrom($_REQUEST["from"]); - if(isset($_REQUEST["stime"])) $graph->SetSTime($_REQUEST["stime"]); - if(isset($_REQUEST["border"])) $graph->SetBorder(0); + if(isset($_REQUEST['period'])) $graph->SetPeriod($_REQUEST['period']); + if(isset($_REQUEST['from'])) $graph->SetFrom($_REQUEST['from']); + if(isset($_REQUEST['stime'])) $graph->SetSTime($_REQUEST['stime']); + if(isset($_REQUEST['border'])) $graph->SetBorder(0); - $width = get_request("width", 0); + $width = get_request('width', 0); - if($width <= 0) $width = $db_data["width"]; + if($width <= 0) $width = $db_data['width']; - $height = get_request("height", 0); - if($height <= 0) $height = $db_data["height"]; + $height = get_request('height', 0); + if($height <= 0) $height = $db_data['height']; - $graph->ShowWorkPeriod($db_data["show_work_period"]); - $graph->ShowTriggers($db_data["show_triggers"]); + $graph->ShowWorkPeriod($db_data['show_work_period']); + $graph->ShowTriggers($db_data['show_triggers']); $graph->SetWidth($width); $graph->SetHeight($height); - $graph->SetHeader($db_data["host"].":".$db_data['name']); - $graph->SetYAxisType($db_data["yaxistype"]); - $graph->SetYAxisMin($db_data["yaxismin"]); - $graph->SetYAxisMax($db_data["yaxismax"]); + $graph->SetHeader($db_data['host'].':'.$db_data['name']); + $graph->SetYAxisType($db_data['yaxistype']); + $graph->SetYAxisMin($db_data['yaxismin']); + $graph->SetYAxisMax($db_data['yaxismax']); - $result = DBselect("select gi.* from graphs_items gi ". - " where gi.graphid=".$db_data["graphid"]. - " order by gi.sortorder, gi.itemid desc"); + $result = DBselect('SELECT gi.* FROM graphs_items gi '. + ' WHERE gi.graphid='.$db_data['graphid']. + ' order by gi.sortorder, gi.itemid desc'); while($db_data=DBfetch($result)) { $graph->AddItem( - $db_data["itemid"], - $db_data["yaxisside"], - $db_data["calc_fnc"], - $db_data["color"], - $db_data["drawtype"], - $db_data["type"], - $db_data["periods_cnt"] + $db_data['itemid'], + $db_data['yaxisside'], + $db_data['calc_fnc'], + $db_data['color'], + $db_data['drawtype'], + $db_data['type'], + $db_data['periods_cnt'] ); } $graph->Draw(); ?> <?php -include_once "include/page_footer.php"; +include_once 'include/page_footer.php'; ?> diff --git a/frontends/php/chart3.php b/frontends/php/chart3.php index c9360b66..311a141e 100644 --- a/frontends/php/chart3.php +++ b/frontends/php/chart3.php @@ -21,7 +21,7 @@ <?php require_once "include/config.inc.php"; require_once "include/graphs.inc.php"; - require_once "include/classes/graph.inc.php"; + require_once "include/classes/chart.inc.php"; $page["file"] = "chart3.php"; $page["title"] = "S_CHART"; @@ -66,7 +66,7 @@ include_once "include/page_header.php"; } } - $graph = new Graph(get_request("graphtype" ,GRAPH_TYPE_NORMAL)); + $graph = new Chart(get_request("graphtype" ,GRAPH_TYPE_NORMAL)); $graph->SetHeader($host["host"].":".get_request("name","")); diff --git a/frontends/php/chart6.php b/frontends/php/chart6.php new file mode 100644 index 00000000..eb866c20 --- /dev/null +++ b/frontends/php/chart6.php @@ -0,0 +1,107 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php + require_once "include/config.inc.php"; + require_once "include/graphs.inc.php"; + require_once "include/classes/pie.inc.php"; + + $page["file"] = "chart2.php"; + $page["title"] = "S_CHART"; + $page["type"] = PAGE_TYPE_IMAGE; + +include_once "include/page_header.php"; + +?> +<?php +// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION + $fields=array( + "graphid"=> array(T_ZBX_INT, O_MAND, P_SYS, DB_ID, null), + "period"=> array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD,ZBX_MAX_PERIOD), null), + "from"=> array(T_ZBX_INT, O_OPT, P_NZERO, null, null), + "stime"=> array(T_ZBX_STR, O_OPT, P_SYS, null, null), + "border"=> array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), + "width"=> array(T_ZBX_INT, O_OPT, P_NZERO, '{}>0', null), + "height"=> array(T_ZBX_INT, O_OPT, P_NZERO, '{}>0', null), + "graph3d"=> array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), + "legend"=> array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null) + ); + + check_fields($fields); +?> +<?php + $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_MODE_LT); + + if( !($db_data = DBfetch(DBselect( + 'SELECT g.*,h.host,h.hostid '. + ' FROM graphs g '. + ' LEFT JOIN graphs_items gi ON g.graphid=gi.graphid '. + ' LEFT JOIN items i ON gi.itemid=i.itemid '. + ' LEFT JOIN hosts h ON i.hostid=h.hostid '. + ' WHERE g.graphid='.$_REQUEST["graphid"]. + /* " AND '.DBid2nodeid("g.graphid").'='.$ZBX_CURNODEID. */ /* NOTE: the chart can display any accesiable graph! */ + ' AND ( h.hostid NOT IN('.$denyed_hosts.') '. + ' OR h.hostid IS NULL) ')))) + { + access_deny(); + } + + $graph = new Pie($db_data["graphtype"]); + + if(isset($_REQUEST["period"])) $graph->SetPeriod($_REQUEST["period"]); + if(isset($_REQUEST["from"])) $graph->SetFrom($_REQUEST["from"]); + if(isset($_REQUEST["stime"])) $graph->SetSTime($_REQUEST["stime"]); + if(isset($_REQUEST["border"])) $graph->SetBorder(0); + + $width = get_request("width", 0); + + if($width <= 0) $width = $db_data["width"]; + + $height = get_request("height", 0); + if($height <= 0) $height = $db_data["height"]; + + $graph->SetWidth($width); + $graph->SetHeight($height); + $graph->SetHeader($db_data["host"].":".$db_data['name']); + + if($db_data['show_3d'] == 1) $graph->SwitchPie3D(); + $graph->SwitchLegend($db_data['show_legend']); + + $result = DBselect("select gi.* from graphs_items gi ". + " where gi.graphid=".$db_data["graphid"]. + " order by gi.sortorder, gi.itemid desc"); + + while($db_data=DBfetch($result)) + { + $graph->AddItem( + $db_data["itemid"], + $db_data["calc_fnc"], + $db_data["color"], + $db_data["type"], + $db_data["periods_cnt"] + ); + } + $graph->draw(); +?> +<?php + +include_once "include/page_footer.php"; + +?> diff --git a/frontends/php/chart7.php b/frontends/php/chart7.php new file mode 100644 index 00000000..84299b28 --- /dev/null +++ b/frontends/php/chart7.php @@ -0,0 +1,106 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php + require_once "include/config.inc.php"; + require_once "include/graphs.inc.php"; + require_once "include/classes/pie.inc.php"; + + $page["file"] = "chart3.php"; + $page["title"] = "S_CHART"; + $page["type"] = PAGE_TYPE_IMAGE; + +include_once "include/page_header.php"; + +?> +<?php +// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION + $fields=array( + "period"=> array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD,ZBX_MAX_PERIOD), null), + "from"=> array(T_ZBX_INT, O_OPT, P_NZERO, null, null), + "stime"=> array(T_ZBX_INT, O_OPT, P_NZERO, null, null), + "border"=> array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), + "name"=> array(T_ZBX_STR, O_OPT, NULL, null, null), + "width"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,65535), null), + "height"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,65535), null), + "graphtype"=> array(T_ZBX_INT, O_OPT, NULL, IN("2,3"), null), + "graph3d"=> array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), + "legend"=> array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), + "items"=> array(T_ZBX_STR, O_OPT, NULL, null, null) + ); + + check_fields($fields); +?> +<?php + $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_MODE_LT, PERM_RES_IDS_ARRAY); + + $items = get_request('items', array()); + + asort_by_key($items, 'sortorder'); + + foreach($items as $gitem) + { + $host = DBfetch(DBselect('select h.* from hosts h,items i where h.hostid=i.hostid and i.itemid='.$gitem['itemid'])); + if(in_array($host['hostid'], $denyed_hosts)) + { + access_deny(); + } + } + + $graph = new Pie(get_request("graphtype" ,GRAPH_TYPE_NORMAL)); + + $graph->SetHeader($host["host"].":".get_request("name","")); + + $graph3d = get_request('graph3d',0); + $legend = get_request('legend',0); + + if($graph3d == 1) $graph->SwitchPie3D(); + $graph->SwitchLegend($legend); + + unset($host, $denyed_hosts); + + if(isset($_REQUEST["period"])) $graph->SetPeriod($_REQUEST["period"]); + if(isset($_REQUEST["from"])) $graph->SetFrom($_REQUEST["from"]); + if(isset($_REQUEST["stime"])) $graph->SetSTime($_REQUEST["stime"]); + if(isset($_REQUEST["border"])) $graph->SetBorder(0); + + $graph->SetWidth(get_request("width", 400)); + $graph->SetHeight(get_request("height", 300)); + + foreach($items as $id => $gitem) + { +// SDI($gitem); + $graph->AddItem( + $gitem["itemid"], + $gitem["calc_fnc"], + $gitem["color"], + $gitem["type"], + $gitem["periods_cnt"] + ); + + unset($items[$id]); + } + $graph->Draw(); +?> +<?php + +include_once "include/page_footer.php"; + +?> diff --git a/frontends/php/charts.php b/frontends/php/charts.php index 483ec332..24af3b94 100644 --- a/frontends/php/charts.php +++ b/frontends/php/charts.php @@ -19,44 +19,44 @@ **/ ?> <?php - require_once "include/config.inc.php"; - require_once "include/hosts.inc.php"; - require_once "include/graphs.inc.php"; + require_once 'include/config.inc.php'; + require_once 'include/hosts.inc.php'; + require_once 'include/graphs.inc.php'; - $page["title"] = "S_CUSTOM_GRAPHS"; - $page["file"] = "charts.php"; + $page['title'] = 'S_CUSTOM_GRAPHS'; + $page['file'] = 'charts.php'; $page['hist_arg'] = array('hostid','grouid','graphid','period','dec','inc','left','right','stime'); ?> <?php - if(isset($_REQUEST["fullscreen"])) + if(isset($_REQUEST['fullscreen'])) { define('ZBX_PAGE_NO_MENU', 1); } - if(isset($_REQUEST["graphid"]) && $_REQUEST["graphid"] > 0 && !isset($_REQUEST["period"]) && !isset($_REQUEST["stime"])) + if(isset($_REQUEST['graphid']) && $_REQUEST['graphid'] > 0 && !isset($_REQUEST['period']) && !isset($_REQUEST['stime'])) { define('ZBX_PAGE_DO_REFRESH', 1); } -include_once "include/page_header.php"; +include_once 'include/page_header.php'; ?> <?php // VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields=array( - "groupid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID,NULL), - "hostid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID,NULL), - "graphid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID,NULL), - "dec"=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535*65535),NULL), - "inc"=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535*65535),NULL), - "left"=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535*65535),NULL), - "right"=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535*65535),NULL), - "from"=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535*65535),NULL), - "period"=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(ZBX_MIN_PERIOD,ZBX_MAX_PERIOD),NULL), - "stime"=> array(T_ZBX_STR, O_OPT, P_SYS, NULL,NULL), - "action"=> array(T_ZBX_STR, O_OPT, P_SYS, IN("'go'"),NULL), - "reset"=> array(T_ZBX_STR, O_OPT, P_SYS, IN("'reset'"),NULL), - "fullscreen"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("1"), NULL) + 'groupid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID,NULL), + 'hostid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID,NULL), + 'graphid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID,NULL), + 'dec'=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535*65535),NULL), + 'inc'=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535*65535),NULL), + 'left'=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535*65535),NULL), + 'right'=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535*65535),NULL), + 'from'=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535*65535),NULL), + 'period'=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(ZBX_MIN_PERIOD,ZBX_MAX_PERIOD),NULL), + 'stime'=> array(T_ZBX_STR, O_OPT, P_SYS, NULL,NULL), + 'action'=> array(T_ZBX_STR, O_OPT, P_SYS, IN("'go'"),NULL), + 'reset'=> array(T_ZBX_STR, O_OPT, P_SYS, IN("'reset'"),NULL), + 'fullscreen'=> array(T_ZBX_INT, O_OPT, P_SYS, IN("1"), NULL) ); check_fields($fields); @@ -76,22 +76,25 @@ include_once "include/page_header.php"; validate_group_with_host(PERM_READ_ONLY,array("allow_all_hosts","monitored_hosts","with_items", "always_select_first_host")); - if($_REQUEST["graphid"] > 0 && $_REQUEST["hostid"] > 0) + if($_REQUEST['graphid'] > 0 && $_REQUEST['hostid'] > 0) { - $result=DBselect("select g.graphid from graphs g, graphs_items gi, items i". - " where i.hostid=".$_REQUEST["hostid"]." and gi.itemid = i.itemid". - " and gi.graphid = g.graphid and g.graphid=".$_REQUEST["graphid"]); - if(!DBfetch($result)) - $_REQUEST["graphid"] = 0; + $result=DBselect('SELECT g.graphid '. + ' FROM graphs g, graphs_items gi, items i'. + ' WHERE i.hostid='.$_REQUEST['hostid']. + ' AND gi.itemid = i.itemid'. + ' AND gi.graphid = g.graphid '. + ' AND g.graphid='.$_REQUEST['graphid']); + + if(!DBfetch($result)) $_REQUEST['graphid'] = 0; } ?> <?php - if($_REQUEST["graphid"] > 0 && $_REQUEST["period"] >= ZBX_MIN_PERIOD) + if($_REQUEST['graphid'] > 0 && $_REQUEST['period'] >= ZBX_MIN_PERIOD) { - update_profile("web.graph[".$_REQUEST["graphid"]."].period",$_REQUEST["period"]); + update_profile('web.graph['.$_REQUEST['graphid'].'].period',$_REQUEST['period']); } - update_profile("web.charts.graphid",$_REQUEST["graphid"]); + update_profile('web.charts.graphid',$_REQUEST['graphid']); ?> <?php $h1 = array(S_GRAPHS_BIG.SPACE."/".SPACE); @@ -99,21 +102,24 @@ include_once "include/page_header.php"; $availiable_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_LIST, null, null, $ZBX_CURNODEID); $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, PERM_MODE_LT); - if($_REQUEST["graphid"] > 0) + if($_REQUEST['graphid'] > 0) { - if(! ($row = DBfetch(DBselect(" select distinct h.host, g.name from hosts h, items i, graphs_items gi, graphs g ". - " where h.status=".HOST_STATUS_MONITORED. - " and h.hostid=i.hostid and g.graphid=".$_REQUEST["graphid"]. - " and i.itemid=gi.itemid and gi.graphid=g.graphid". - " and h.hostid not in (".$denyed_hosts.") ". - " and ".DBid2nodeid("g.graphid")."=".$ZBX_CURNODEID. - " order by h.host, g.name" + if(! ($row = DBfetch(DBselect(' SELECT distinct h.host, g.name '. + ' FROM hosts h, items i, graphs_items gi, graphs g '. + ' WHERE h.status='.HOST_STATUS_MONITORED. + ' AND h.hostid=i.hostid '. + ' AND g.graphid='.$_REQUEST['graphid']. + ' AND i.itemid=gi.itemid '. + ' AND gi.graphid=g.graphid'. + ' AND h.hostid NOT IN ('.$denyed_hosts.') '. + ' AND '.DBid2nodeid('g.graphid').'='.$ZBX_CURNODEID. + ' ORDER BY h.host, g.name' )))) { - update_profile("web.charts.graphid",0); + update_profile('web.charts.graphid',0); access_deny(); } - array_push($h1, new CLink($row["name"], "?graphid=".$_REQUEST["graphid"].(isset($_REQUEST["fullscreen"]) ? "&fullscreen=1" : ""))); + array_push($h1, new CLink($row['name'], '?graphid='.$_REQUEST['graphid'].(isset($_REQUEST['fullscreen']) ? '&fullscreen=1' : ''))); } else { @@ -125,80 +131,96 @@ include_once "include/page_header.php"; if(isset($_REQUEST['fullscreen'])) $r_form->AddVar('fullscreen', 1); - $cmbGroup = new CComboBox("groupid",$_REQUEST["groupid"],"submit()"); - $cmbHosts = new CComboBox("hostid",$_REQUEST["hostid"],"submit()"); - $cmbGraph = new CComboBox("graphid",$_REQUEST["graphid"],"submit()"); + $cmbGroup = new CComboBox('groupid',$_REQUEST['groupid'],'submit()'); + $cmbHosts = new CComboBox('hostid',$_REQUEST['hostid'],'submit()'); + $cmbGraph = new CComboBox('graphid',$_REQUEST['graphid'],'submit()'); $cmbGroup->AddItem(0,S_ALL_SMALL); - $result=DBselect("select distinct g.groupid,g.name from groups g, hosts_groups hg, hosts h, items i, graphs_items gi ". - " where g.groupid in (".$availiable_groups.") ". - " and hg.groupid=g.groupid and h.status=".HOST_STATUS_MONITORED. - " and h.hostid=i.hostid and hg.hostid=h.hostid and i.itemid=gi.itemid ". - " order by g.name"); - while($row=DBfetch($result)) - { - $cmbGroup->AddItem($row["groupid"],$row["name"]); + $result=DBselect('SELECT distinct g.groupid,g.name '. + ' FROM groups g, hosts_groups hg, hosts h, items i, graphs_items gi '. + ' WHERE g.groupid in ('.$availiable_groups.') '. + ' AND hg.groupid=g.groupid '. + ' AND h.status='.HOST_STATUS_MONITORED. + ' AND h.hostid=i.hostid '. + ' AND hg.hostid=h.hostid '. + ' AND i.itemid=gi.itemid '. + ' ORDER BY g.name'); + while($row=DBfetch($result)){ + $cmbGroup->AddItem($row['groupid'],$row['name']); } $r_form->AddItem(array(S_GROUP.SPACE,$cmbGroup)); - if($_REQUEST["groupid"] > 0) - { - $sql = " select distinct h.hostid,h.host from hosts h,items i,hosts_groups hg, graphs_items gi ". - " where h.status=".HOST_STATUS_MONITORED. - " and h.hostid=i.hostid and hg.groupid=".$_REQUEST["groupid"]." and hg.hostid=h.hostid ". - " and h.hostid not in (".$denyed_hosts.") and i.itemid=gi.itemid". - " order by h.host"; + if($_REQUEST['groupid'] > 0){ + $sql = ' SELECT distinct h.hostid,h.host '. + ' FROM hosts h,items i,hosts_groups hg, graphs_items gi '. + ' WHERE h.status='.HOST_STATUS_MONITORED. + ' AND h.hostid=i.hostid '. + ' AND hg.groupid='.$_REQUEST['groupid']. + ' AND hg.hostid=h.hostid '. + ' AND h.hostid NOT IN ('.$denyed_hosts.') '. + ' AND i.itemid=gi.itemid'. + ' ORDER BY h.host'; } - else - { + else{ $cmbHosts->AddItem(0,S_ALL_SMALL); - $sql = "select distinct h.hostid,h.host from hosts h,items i, graphs_items gi where h.status=".HOST_STATUS_MONITORED. - " and i.status=".ITEM_STATUS_ACTIVE." and h.hostid=i.hostid". - " and h.hostid not in (".$denyed_hosts.") and i.itemid=gi.itemid". - " order by h.host"; + $sql = 'SELECT distinct h.hostid,h.host '. + ' FROM hosts h,items i, graphs_items gi '. + ' WHERE h.status='.HOST_STATUS_MONITORED. + ' AND i.status='.ITEM_STATUS_ACTIVE. + ' AND h.hostid=i.hostid'. + ' AND h.hostid NOT IN ('.$denyed_hosts.') '. + ' AND i.itemid=gi.itemid'. + ' ORDER BY h.host'; } $result=DBselect($sql); - while($row=DBfetch($result)) - { - $cmbHosts->AddItem($row["hostid"],$row["host"]); + while($row=DBfetch($result)){ + $cmbHosts->AddItem($row['hostid'],$row['host']); } $r_form->AddItem(array(SPACE.S_HOST.SPACE,$cmbHosts)); $cmbGraph->AddItem(0,S_SELECT_GRAPH_DOT_DOT_DOT); - if($_REQUEST["hostid"] > 0) - { - $sql = "select distinct g.graphid,g.name from graphs g,graphs_items gi,items i". - " where i.itemid=gi.itemid and g.graphid=gi.graphid and i.hostid=".$_REQUEST["hostid"]. - " and ".DBid2nodeid("g.graphid")."=".$ZBX_CURNODEID. - " and i.hostid not in (".$denyed_hosts.") ". - " order by g.name"; + if($_REQUEST['hostid'] > 0){ + $sql = 'SELECT distinct g.graphid,g.name '. + ' FROM graphs g,graphs_items gi,items i'. + ' WHERE i.itemid=gi.itemid '. + ' AND g.graphid=gi.graphid '. + ' AND i.hostid='.$_REQUEST['hostid']. + ' AND '.DBid2nodeid('g.graphid').'='.$ZBX_CURNODEID. + ' AND i.hostid NOT IN ('.$denyed_hosts.') '. + ' ORDER BY g.name'; } - elseif ($_REQUEST["groupid"] > 0) - { - $sql = "select distinct g.graphid,g.name from graphs g,graphs_items gi,items i,hosts_groups hg,hosts h". - " where i.itemid=gi.itemid and g.graphid=gi.graphid and i.hostid=hg.hostid and hg.groupid=".$_REQUEST["groupid"]. - " and i.hostid=h.hostid and h.status=".HOST_STATUS_MONITORED. - " and ".DBid2nodeid("g.graphid")."=".$ZBX_CURNODEID. - " and h.hostid not in (".$denyed_hosts.") ". - " order by g.name"; + elseif ($_REQUEST['groupid'] > 0){ + $sql = 'SELECT distinct g.graphid,g.name '. + ' FROM graphs g,graphs_items gi,items i,hosts_groups hg,hosts h'. + ' WHERE i.itemid=gi.itemid '. + ' AND g.graphid=gi.graphid '. + ' AND i.hostid=hg.hostid '. + ' AND hg.groupid='.$_REQUEST['groupid']. + ' AND i.hostid=h.hostid '. + ' AND h.status='.HOST_STATUS_MONITORED. + ' AND '.DBid2nodeid('g.graphid').'='.$ZBX_CURNODEID. + ' AND h.hostid NOT IN ('.$denyed_hosts.') '. + ' ORDER BY g.name'; } - else - { - $sql = "select distinct g.graphid,g.name from graphs g,graphs_items gi,items i,hosts h". - " where i.itemid=gi.itemid and g.graphid=gi.graphid ". - " and i.hostid=h.hostid and h.status=".HOST_STATUS_MONITORED. - " and ".DBid2nodeid("g.graphid")."=".$ZBX_CURNODEID. - " and h.hostid not in (".$denyed_hosts.") ". - " order by g.name"; + else{ + $sql = 'SELECT DISTINCT g.graphid,g.name '. + ' FROM graphs g,graphs_items gi,items i,hosts h'. + ' WHERE i.itemid=gi.itemid '. + ' AND g.graphid=gi.graphid '. + ' AND i.hostid=h.hostid '. + ' AND h.status='.HOST_STATUS_MONITORED. + ' AND '.DBid2nodeid('g.graphid').'='.$ZBX_CURNODEID. + ' AND h.hostid NOT IN ('.$denyed_hosts.') '. + ' ORDER BY g.name'; } $result = DBselect($sql); while($row=DBfetch($result)) { - $cmbGraph->AddItem($row["graphid"],$row["name"]); + $cmbGraph->AddItem($row['graphid'],$row['name']); } $r_form->AddItem(array(SPACE.S_GRAPH.SPACE,$cmbGraph)); @@ -208,22 +230,42 @@ include_once "include/page_header.php"; <?php $table = new CTableInfo('...','chart'); - if($_REQUEST["graphid"] > 0) - { - $row = "\n".'<script language="javascript" type="text/javascript"> - <!-- - if(window.innerWidth) width=window.innerWidth; - else width=document.body.clientWidth; - document.write(\'<img src="chart2.php?graphid='.$_REQUEST['graphid'].url_param('stime').url_param('from'). - '&period='.$effectiveperiod.'&width=\'+(width-108)+\'" />\'); - --> - </script>'."\n"; + if($_REQUEST['graphid'] > 0){ + $graphtype = GRAPH_TYPE_NORMAL; + + $sql = 'SELECT DISTINCT `graphtype` FROM `graphs` WHERE `graphid`='.$_REQUEST['graphid']; + $res = DBselect($sql); + + while($rows = DBfetch($res)){ + $graphtype = $rows['graphtype']; + } + + if(($graphtype == GRAPH_TYPE_PIE) || ($graphtype == GRAPH_TYPE_EXPLODED)){ + $row = "\n".'<script language="javascript" type="text/javascript"> + <!-- + if(window.innerWidth) width=window.innerWidth; + else width=document.body.clientWidth; + document.write(\'<img src="chart6.php?graphid='.$_REQUEST['graphid'].url_param('stime').url_param('from'). + '&period='.$effectiveperiod.'" />\'); + --> + </script>'."\n"; + } + else{ + $row = "\n".'<script language="javascript" type="text/javascript"> + <!-- + if(window.innerWidth) width=window.innerWidth; + else width=document.body.clientWidth; + document.write(\'<img src="chart2.php?graphid='.$_REQUEST['graphid'].url_param('stime').url_param('from'). + '&period='.$effectiveperiod.'&width=\'+(width-108)+\'" />\'); + --> + </script>'."\n"; + } $table->AddRow($row); } $table->Show(); - if($_REQUEST["graphid"] > 0) + if($_REQUEST['graphid'] > 0) { navigation_bar('charts.php',array('groupid','hostid','graphid')); } @@ -231,6 +273,6 @@ include_once "include/page_header.php"; ?> <?php -include_once "include/page_footer.php"; +include_once 'include/page_footer.php'; ?> diff --git a/frontends/php/graphs.php b/frontends/php/graphs.php index f1628b8a..0cf15e2f 100644 --- a/frontends/php/graphs.php +++ b/frontends/php/graphs.php @@ -23,10 +23,14 @@ require_once "include/hosts.inc.php"; require_once "include/graphs.inc.php"; require_once "include/forms.inc.php"; + require_once "include/classes/chart.inc.php"; + require_once "include/classes/pie.inc.php"; + $page["title"] = "S_CONFIGURATION_OF_GRAPHS"; $page["file"] = "graphs.php"; $page['hist_arg'] = array(); + $page['scripts'] = array('graphs.js'); include_once "include/page_header.php"; @@ -44,10 +48,13 @@ include_once "include/page_header.php"; "name"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({save})'), "width"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,65535), 'isset({save})'), "height"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,65535), 'isset({save})'), - "yaxistype"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1"), 'isset({save})'), - "graphtype"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1"), 'isset({save})'), - "yaxismin"=> array(T_ZBX_DBL, O_OPT, NULL, null, 'isset({save})'), - "yaxismax"=> array(T_ZBX_DBL, O_OPT, NULL, null, 'isset({save})'), + "yaxistype"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1"), 'isset({save})&&(({graphtype} == 0) || ({graphtype} == 1))'), + "graphtype"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1,2,3"), 'isset({save})'), + + "yaxismin"=> array(T_ZBX_DBL, O_OPT, NULL, null, 'isset({save})&&(({graphtype} == 0) || ({graphtype} == 1))'), + "yaxismax"=> array(T_ZBX_DBL, O_OPT, NULL, null, 'isset({save})&&(({graphtype} == 0) || ({graphtype} == 1))'), + "graph3d"=> array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), + "legend"=> array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), "items"=> array(T_ZBX_STR, O_OPT, NULL, null, null), "new_graph_item"=> array(T_ZBX_STR, O_OPT, NULL, null, null), @@ -82,12 +89,16 @@ include_once "include/page_header.php"; 'web.last.conf.groupid', 'web.last.conf.hostid'); ?> <?php + $_REQUEST['items'] = get_request('items', array()); $_REQUEST['group_gid'] = get_request('group_gid', array()); + $_REQUEST['graph3d'] = get_request('graph3d', 0); + $_REQUEST['legend'] = get_request('legend', 0); $availiable_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, $ZBX_CURNODEID); $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, PERM_MODE_LT); +// ---- <ACTIONS> ---- if(isset($_REQUEST["clone"]) && isset($_REQUEST["graphid"])) { unset($_REQUEST["graphid"]); @@ -98,7 +109,7 @@ include_once "include/page_header.php"; $items = get_request('items', array()); foreach($items as $gitem) { - $host = DBfetch(DBselect('select h.* from hosts h,items i where h.hostid=i.hostid and i.itemid='.$gitem['itemid'])); + $host = DBfetch(DBselect('SELECT h.* FROM hosts h,items i WHERE h.hostid=i.hostid AND i.itemid='.$gitem['itemid'])); if(in_array($host['hostid'], explode(',',$denyed_hosts))) { access_deny(); @@ -110,15 +121,21 @@ include_once "include/page_header.php"; } else { + isset($_REQUEST["yaxistype"])?(''):($_REQUEST["yaxistype"]=0); + isset($_REQUEST["yaxismin"])?(''):($_REQUEST["yaxismin"]=0); + isset($_REQUEST["yaxismax"])?(''):($_REQUEST["yaxismax"]=0); + $showworkperiod = isset($_REQUEST["showworkperiod"]) ? 1 : 0; $showtriggers = isset($_REQUEST["showtriggers"]) ? 1 : 0; if(isset($_REQUEST["graphid"])) { + $result = update_graph_with_items($_REQUEST["graphid"], $_REQUEST["name"],$_REQUEST["width"],$_REQUEST["height"], $_REQUEST["yaxistype"],$_REQUEST["yaxismin"],$_REQUEST["yaxismax"], - $showworkperiod,$showtriggers,$_REQUEST["graphtype"],$items); + $showworkperiod,$showtriggers,$_REQUEST["graphtype"], + $_REQUEST["legend"],$_REQUEST["graph3d"],$items); if($result) { @@ -130,9 +147,11 @@ include_once "include/page_header.php"; } else { + $result = add_graph_with_items($_REQUEST["name"],$_REQUEST["width"],$_REQUEST["height"], $_REQUEST["yaxistype"],$_REQUEST["yaxismin"],$_REQUEST["yaxismax"], - $showworkperiod,$showtriggers,$_REQUEST["graphtype"],$items); + $showworkperiod,$showtriggers,$_REQUEST["graphtype"], + $_REQUEST["legend"],$_REQUEST["graph3d"],$items); if($result) { @@ -183,9 +202,9 @@ include_once "include/page_header.php"; else { /* groups */ $hosts_ids = array(); - $db_hosts = DBselect('select distinct h.hostid from hosts h, hosts_groups hg'. - ' where h.hostid=hg.hostid and hg.groupid in ('.implode(',',$_REQUEST['copy_targetid']).')'. - ' and h.hostid in ('.$availiable_hosts.")" + $db_hosts = DBselect('SELECT distinct h.hostid FROM hosts h, hosts_groups hg'. + ' WHERE h.hostid=hg.hostid AND hg.groupid in ('.implode(',',$_REQUEST['copy_targetid']).')'. + ' AND h.hostid in ('.$availiable_hosts.")" ); while($db_host = DBfetch($db_hosts)) { @@ -247,6 +266,7 @@ include_once "include/page_header.php"; if($_REQUEST['items'][$_REQUEST['move_down']]['sortorder'] < 1000) $_REQUEST['items'][$_REQUEST['move_down']]['sortorder']++; } +// ----</ACTIONS>---- ?> <?php $form = new CForm(); @@ -264,11 +284,18 @@ include_once "include/page_header.php"; insert_graph_form(); echo BR; $table = new CTable(NULL,"graph"); - $table->AddRow(new CImg('chart3.php?period=3600&from=0'.url_param('items'). - url_param('name').url_param('width').url_param('height').url_param('yaxistype'). - url_param('yaxismin').url_param('yaxismax').url_param('show_work_period'). - url_param('show_triggers').url_param('graphtype'))); - $table->Show(); + if(($_REQUEST['graphtype'] == GRAPH_TYPE_PIE) || ($_REQUEST['graphtype'] == GRAPH_TYPE_EXPLODED)){ + $table->AddRow(new CImg('chart7.php?period=3600&from=0'.url_param('items'). + url_param('name').url_param('legend').url_param('graph3d').url_param('width').url_param('height').url_param('graphtype'))); + $table->Show(); + } + else { + $table->AddRow(new CImg('chart3.php?period=3600&from=0'.url_param('items'). + url_param('name').url_param('width').url_param('height').url_param('yaxistype'). + url_param('yaxismin').url_param('yaxismax').url_param('show_work_period'). + url_param('show_triggers').url_param('graphtype'))); + $table->Show(); + } } else { /* Table HEADER */ if(isset($_REQUEST["graphid"])&&($_REQUEST["graphid"]==0)) @@ -283,31 +310,37 @@ include_once "include/page_header.php"; $cmbGroup->AddItem(0,S_ALL_SMALL); - $result=DBselect("select distinct g.groupid,g.name from groups g, hosts_groups hg, hosts h, items i ". - " where h.hostid in (".$availiable_hosts.") ". - " and hg.groupid=g.groupid ". - " and h.hostid=i.hostid and hg.hostid=h.hostid ". - " order by g.name"); - while($row=DBfetch($result)) - { + $result=DBselect('SELECT distinct g.groupid,g.name '. + ' FROM groups g, hosts_groups hg, hosts h, items i '. + ' WHERE h.hostid IN ('.$availiable_hosts.') '. + ' AND hg.groupid=g.groupid '. + ' AND h.hostid=i.hostid AND hg.hostid=h.hostid '. + ' ORDER BY g.name'); + + while($row=DBfetch($result)){ $cmbGroup->AddItem($row["groupid"],$row["name"]); } $r_form->AddItem(array(S_GROUP.SPACE,$cmbGroup)); if($_REQUEST["groupid"] > 0) { - $sql="select h.hostid,h.host from hosts h,items i,hosts_groups hg where ". - " h.hostid=i.hostid and hg.groupid=".$_REQUEST["groupid"]." and hg.hostid=h.hostid". - " and h.hostid in (".$availiable_hosts.") ". - " group by h.hostid,h.host order by h.host"; + $sql='SELECT h.hostid,h.host FROM hosts h,items i,hosts_groups hg '. + 'WHERE h.hostid=i.hostid '. + ' AND hg.groupid='.$_REQUEST["groupid"]. + ' AND hg.hostid=h.hostid '. + ' AND h.hostid in ('.$availiable_hosts.') '. + ' GROUP BY h.hostid,h.host '. + ' ORDER BY h.host'; } else { $cmbHosts->AddItem(0,S_ALL_SMALL); - $sql="select h.hostid,h.host from hosts h,items i where ". - " h.hostid=i.hostid". - " and h.hostid in (".$availiable_hosts.") ". - " group by h.hostid,h.host order by h.host"; + $sql='SELECT h.hostid,h.host '. + ' FROM hosts h,items i '. + ' WHERE h.hostid=i.hostid'. + ' AND h.hostid IN ('.$availiable_hosts.') '. + ' GROUP BY h.hostid,h.host '. + ' ORDER BY h.host'; } $result=DBselect($sql); while($row=DBfetch($result)) @@ -334,21 +367,21 @@ include_once "include/page_header.php"; if($_REQUEST["hostid"] > 0) { - $result = DBselect("select distinct g.* from graphs g left join graphs_items gi on g.graphid=gi.graphid ". + $result = DBselect("SELECT distinct g.* FROM graphs g left join graphs_items gi on g.graphid=gi.graphid ". " left join items i on gi.itemid=i.itemid ". - " where i.hostid=".$_REQUEST["hostid"]. - " and i.hostid not in (".$denyed_hosts.") ". - " and ".DBid2nodeid("g.graphid")."=".$ZBX_CURNODEID. - " and i.hostid is not NULL ". - " order by g.name"); + " WHERE i.hostid=".$_REQUEST["hostid"]. + " AND i.hostid not in (".$denyed_hosts.") ". + " AND ".DBid2nodeid("g.graphid")."=".$ZBX_CURNODEID. + " AND i.hostid is not NULL ". + " ORDER BY g.name"); } else { - $result = DBselect("select distinct g.* from graphs g left join graphs_items gi on g.graphid=gi.graphid ". + $result = DBselect("SELECT distinct g.* FROM graphs g left join graphs_items gi on g.graphid=gi.graphid ". " left join items i on gi.itemid=i.itemid ". - " where ".DBid2nodeid("g.graphid")."=".$ZBX_CURNODEID. - " and ( i.hostid not in (".$denyed_hosts.") OR i.hostid is NULL )". - " order by g.name"); + " WHERE ".DBid2nodeid("g.graphid")."=".$ZBX_CURNODEID. + " AND ( i.hostid not in (".$denyed_hosts.") OR i.hostid is NULL )". + " ORDER BY g.name"); } while($row=DBfetch($result)) { @@ -398,10 +431,20 @@ include_once "include/page_header.php"; $chkBox = new CCheckBox("group_graphid[]",NULL,NULL,$row["graphid"]); if($row["templateid"] > 0) $chkBox->SetEnabled(false); - if($row["graphtype"] == GRAPH_TYPE_STACKED) - $graphtype = S_STACKED; - else - $graphtype = S_NORMAL; + switch($row["graphtype"]){ + case GRAPH_TYPE_STACKED: + $graphtype = S_STACKED; + break; + case GRAPH_TYPE_PIE: + $graphtype = S_PIE; + break; + case GRAPH_TYPE_EXPLODED: + $graphtype = S_EXPLODED; + break; + default: + $graphtype = S_NORMAL; + break; + } $table->AddRow(array( $host_list, diff --git a/frontends/php/include/classes/chart.inc.php b/frontends/php/include/classes/chart.inc.php new file mode 100644 index 00000000..64c30a1d --- /dev/null +++ b/frontends/php/include/classes/chart.inc.php @@ -0,0 +1,1104 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2007 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php +require_once "include/classes/graph.inc.php"; + +class Chart extends Graph{ + + function Chart($type = GRAPH_TYPE_NORMAL){ + parent::Graph($type); + + $this->yaxismin = null; + $this->yaxismax = null; + + $this->triggers = array(); + + $this->yaxistype=GRAPH_YAXIS_TYPE_CALCULATED; + $this->yaxisright=0; + $this->yaxisleft=0; + + $this->m_showWorkPeriod = 1; + $this->m_showTriggers = 1; + + $this->zero = array(); + $this->graphorientation = ''; + } + + function updateShifts() + { + if( ($this->yaxisleft == 1) && ($this->yaxisright == 1)) + { + $this->shiftXleft = 60; + $this->shiftXright = 60; + } + else if($this->yaxisleft == 1) + { + $this->shiftXleft = 60; + $this->shiftXright = 20; + } + else if($this->yaxisright == 1) + { + $this->shiftXleft = 10; + $this->shiftXright = 60; + } +// $this->sizeX = $this->sizeX - $this->shiftXleft-$this->shiftXright; + } + + function ShowWorkPeriod($value) + { + $this->m_showWorkPeriod = $value == 1 ? 1 : 0; + } + + function ShowTriggers($value) + { + $this->m_showTriggers = $value == 1 ? 1 : 0; + } + + function AddItem($itemid, $axis=GRAPH_YAXIS_SIDE_RIGHT, $calc_fnc=CALC_FNC_AVG, + $color=null, $drawtype=null, $type=null, $periods_cnt=null) + { + if($this->type == GRAPH_TYPE_STACKED /* stacked graph */) + $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION; + + $this->items[$this->num] = get_item_by_itemid($itemid); + $this->items[$this->num]["description"]=item_description($this->items[$this->num]["description"],$this->items[$this->num]["key_"]); + $host=get_host_by_hostid($this->items[$this->num]["hostid"]); + + $this->items[$this->num]["host"] = $host["host"]; + $this->items[$this->num]["color"] = is_null($color) ? "Dark Green" : $color; + $this->items[$this->num]["drawtype"] = is_null($drawtype) ? GRAPH_ITEM_DRAWTYPE_LINE : $drawtype; + $this->items[$this->num]["axisside"] = is_null($axis) ? GRAPH_YAXIS_SIDE_RIGHT : $axis; + $this->items[$this->num]["calc_fnc"] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc; + $this->items[$this->num]["calc_type"] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type; + $this->items[$this->num]["periods_cnt"] = is_null($periods_cnt) ? 0 : $periods_cnt; + + if($this->items[$this->num]["axisside"] == GRAPH_YAXIS_SIDE_LEFT) + $this->yaxisleft=1; + + if($this->items[$this->num]["axisside"] == GRAPH_YAXIS_SIDE_RIGHT) + $this->yaxisright=1; +// SDI($this->items); + + $this->num++; + } + + function CheckGraphOrientation($value){ + + if(!empty($this->graphorientation)){ + if(($this->graphorientation == '+') && ($value<0)){ +// Error(); + } + elseif(($this->graphorientation == '-') && ($value>0)){ +// Error(); + } + } + else { + if($value < 0){ + $this->graphorientation = '-'; + } + elseif($value > 0){ + $this->graphorientation = '+'; + } + } + } + + function setYAxisMin($yaxismin) + { + $this->yaxismin=$yaxismin; + } + + function setYAxisMax($yaxismax) + { + $this->yaxismax=$yaxismax; + } + + function setYAxisType($yaxistype) + { + $this->yaxistype=$yaxistype; + } + + function drawGrid() + { + $this->drawSmallRectangle(); + for($i=1;$i<=5;$i++) + { + DashedLine($this->im,$this->shiftXleft,$i*($this->sizeY/6)+$this->shiftY,$this->sizeX+$this->shiftXleft,$i*($this->sizeY/6)+$this->shiftY,$this->GetColor("Gray")); + } + + for($i=1;$i<=23;$i++) + { + DashedLine($this->im,$i*($this->sizeX/24)+$this->shiftXleft,$this->shiftY,$i*($this->sizeX/24)+$this->shiftXleft,$this->sizeY+$this->shiftY,$this->GetColor("Gray")); + } + + $old_day=-1; + for($i=0;$i<=24;$i++) + { + ImageStringUp($this->im, 1,$i*($this->sizeX/24)+$this->shiftXleft-3, $this->sizeY+$this->shiftY+57, date(" H:i",$this->from_time+$i*($this->period/24)) , $this->GetColor("Black No Alpha")); + + $new_day=date("d",$this->from_time+$i*($this->period/24)); + if( ($old_day != $new_day) ||($i==24)) + { + $old_day=$new_day; + ImageStringUp($this->im, 1,$i*($this->sizeX/24)+$this->shiftXleft-3, $this->sizeY+$this->shiftY+57, date("m.d H:i",$this->from_time+$i*($this->period/24)) , $this->GetColor("Dark Red No Alpha")); + + } + } + } + + function drawWorkPeriod() + { + if($this->m_showWorkPeriod != 1) return; + if($this->period > 2678400) return; // > 31*24*3600 (month) + + $db_work_period = DBselect("select work_period from config"); + $work_period = DBfetch($db_work_period); + if(!$work_period) + return; + + $periods = parse_period($work_period['work_period']); + if(!$periods) + return; + + ImageFilledRectangle($this->im, + $this->shiftXleft+1, + $this->shiftY, + $this->sizeX+$this->shiftXleft, + $this->sizeY+$this->shiftY, + $this->GetColor("Not Work Period")); + + $now = time(); + if(isset($this->stime)) + { + $this->from_time=$this->stime; + $this->to_time=$this->stime+$this->period; + } + else + { + $this->to_time=$now-3600*$this->from; + $this->from_time=$this->to_time-$this->period; + } + $from = $this->from_time; + $max_time = $this->to_time; + + $start = find_period_start($periods,$from); + $end = -1; + while($start < $max_time && $start > 0) + { + $end = find_period_end($periods,$start,$max_time); + + $x1 = round((($start-$from)*$this->sizeX)/$this->period) + $this->shiftXleft; + $x2 = round((($end-$from)*$this->sizeX)/$this->period) + $this->shiftXleft; + + //draw rectangle + ImageFilledRectangle( + $this->im, + $x1, + $this->shiftY, + $x2, + $this->sizeY+$this->shiftY, + $this->GetColor("White")); + + $start = find_period_start($periods,$end); + } + } + + function calcTriggers() + { + $this->triggers = array(); + if($this->m_showTriggers != 1) return; + if($this->num != 1) return; // skip multiple graphs + + $max = 3; + $cnt = 0; + + $db_triggers = DBselect("select distinct tr.triggerid,tr.expression,tr.priority from triggers tr,functions f,items i". + " where tr.triggerid=f.triggerid and f.function in ('last','min','max') and". + " tr.status=".TRIGGER_STATUS_ENABLED." and i.itemid=f.itemid and f.itemid=".$this->items[0]["itemid"]." order by tr.priority"); + + while(($trigger = DBfetch($db_triggers)) && ($cnt < $max)) + { + $db_fnc_cnt = DBselect('select count(*) as cnt from functions f where f.triggerid='.$trigger['triggerid']); + $fnc_cnt = DBfetch($db_fnc_cnt); + if($fnc_cnt['cnt'] != 1) continue; + + if(!eregi('\{([0-9]{1,})\}([\<\>\=]{1})([0-9\.]{1,})([K|M|G]{0,1})',$trigger['expression'],$arr)) + continue; + + $val = $arr[3]; + if(strcasecmp($arr[4],'K') == 0) $val *= 1024; + else if(strcasecmp($arr[4],'M') == 0) $val *= 1048576; //1024*1024; + else if(strcasecmp($arr[4],'G') == 0) $val *= 1073741824; //1024*1024*1024; + + $minY = $this->m_minY[$this->items[0]["axisside"]]; + $maxY = $this->m_maxY[$this->items[0]["axisside"]]; + + if($val <= $minY || $val >= $maxY) continue; + + if($trigger['priority'] == 5) $color = "Priority Disaster"; + elseif($trigger['priority'] == 4) $color = "Priority Hight"; + elseif($trigger['priority'] == 3) $color = "Priority Average"; + else $color = "Priority"; + + array_push($this->triggers,array( + 'y' => $this->sizeY - (($val-$minY) / ($maxY-$minY)) * $this->sizeY + $this->shiftY, + 'color' => $color, + 'description' => 'trigger: '.expand_trigger_description($trigger['triggerid']).' ['.$arr[2].' '.$arr[3].$arr[4].']' + )); + ++$cnt; + } + + } + function drawTriggers() + { + if($this->m_showTriggers != 1) return; + if($this->num != 1) return; // skip multiple graphs + + foreach($this->triggers as $trigger) + { + DashedLine( + $this->im, + $this->shiftXleft, + $trigger['y'], + $this->sizeX+$this->shiftXleft, + $trigger['y'], + $this->GetColor($trigger['color'])); + } + + } + + + function drawLegend() + { + $max_host_len=0; + $max_desc_len=0; + for($i=0;$i<$this->num;$i++) + { + if(strlen($this->items[$i]["host"])>$max_host_len) $max_host_len=strlen($this->items[$i]["host"]); + if(strlen($this->items[$i]["description"])>$max_desc_len) $max_desc_len=strlen($this->items[$i]["description"]); + } + + for($i=0;$i<$this->num;$i++) + { + if($this->items[$i]["calc_type"] == GRAPH_ITEM_AGGREGATED) + { + $fnc_name = "agr(".$this->items[$i]["periods_cnt"].")"; + $color = $this->GetColor("HistoryMinMax"); + } + else + { + $color = $this->GetColor($this->items[$i]["color"]); + switch($this->items[$i]["calc_fnc"]) + { + case CALC_FNC_MIN: $fnc_name = "min"; break; + case CALC_FNC_MAX: $fnc_name = "max"; break; + case CALC_FNC_ALL: $fnc_name = "all"; break; + case CALC_FNC_AVG: + default: $fnc_name = "avg"; + } + } + + $data = &$this->data[$this->items[$i]["itemid"]][$this->items[$i]["calc_type"]]; + if(isset($data)&&isset($data->min)) + { + $str=sprintf("%s: %s [%s] [min:%s max:%s last:%s]", + str_pad($this->items[$i]["host"],$max_host_len," "), + str_pad($this->items[$i]["description"],$max_desc_len," "), + $fnc_name, + convert_units(min($data->min),$this->items[$i]["units"]), + convert_units(max($data->max),$this->items[$i]["units"]), + convert_units($this->getLastValue($i),$this->items[$i]["units"])); + } + else + { + $str=sprintf("%s: %s [ no data ]", + str_pad($this->items[$i]["host"],$max_host_len," "), + str_pad($this->items[$i]["description"],$max_desc_len," ")); + } + + ImageFilledRectangle($this->im,$this->shiftXleft,$this->sizeY+$this->shiftY+62+12*$i,$this->shiftXleft+5,$this->sizeY+$this->shiftY+5+62+12*$i,$color); + ImageRectangle($this->im,$this->shiftXleft,$this->sizeY+$this->shiftY+62+12*$i,$this->shiftXleft+5,$this->sizeY+$this->shiftY+5+62+12*$i,$this->GetColor("Black No Alpha")); + + ImageString($this->im, 2, + $this->shiftXleft+9, + $this->sizeY+$this->shiftY+(62-5)+12*$i, + $str, + $this->GetColor("Black No Alpha")); + } + + if($this->sizeY < 120) return; + + foreach($this->triggers as $trigger) + { + ImageFilledEllipse($this->im, + $this->shiftXleft + 2, + $this->sizeY+$this->shiftY+2+62+12*$i, + 6, + 6, + $this->GetColor($trigger["color"])); + + ImageEllipse($this->im, + $this->shiftXleft + 2, + $this->sizeY+$this->shiftY+2+62+12*$i, + 6, + 6, + $this->GetColor("Black No Alpha")); + + ImageString( + $this->im, + 2, + $this->shiftXleft+9, + $this->sizeY+$this->shiftY+(62-5)+12*$i, + $trigger['description'], + $this->GetColor("Black No Alpha")); + ++$i; + } + } + + function drawElement( + &$data, $from, $to, + $minX, $maxX, $minY, $maxY, + $drawtype, $max_color, $avg_color, $min_color, $minmax_color, + $calc_fnc, + $axisside + ) + { + if(!isset($data->max[$from]) || !isset($data->max[$to])) return; + + $oxy = $this->oxy[$axisside]; + $zero = $this->zero[$axisside]; + $unit2px = $this->unit2px[$axisside]; + + $shift_min_from = $shift_min_to = 0; + $shift_max_from = $shift_max_to = 0; + $shift_avg_from = $shift_avg_to = 0; + + if(isset($data->shift_min[$from])) $shift_min_from = $data->shift_min[$from]; + if(isset($data->shift_min[$to])) $shift_min_to = $data->shift_min[$to]; + + if(isset($data->shift_max[$from])) $shift_max_from = $data->shift_max[$from]; + if(isset($data->shift_max[$to])) $shift_max_to = $data->shift_max[$to]; + + if(isset($data->shift_avg[$from])) $shift_avg_from = $data->shift_avg[$from]; + if(isset($data->shift_avg[$to])) $shift_avg_to = $data->shift_avg[$to]; +/**/ + $min_from = $data->min[$from] + $shift_min_from; + $min_to = $data->min[$to] + $shift_min_to; + + $max_from = $data->max[$from] + $shift_max_from; + $max_to = $data->max[$to] + $shift_max_to; + + $avg_from = $data->avg[$from] + $shift_avg_from; + $avg_to = $data->avg[$to] + $shift_avg_to; + + $x1 = $from + $this->shiftXleft - 1; + $x2 = $to + $this->shiftXleft; + + + $y1min = $zero - ($min_from-$oxy)/$unit2px; + $y2min = $zero - ($min_to-$oxy)/$unit2px; + + $y1max = $zero - ($max_from-$oxy)/$unit2px; + $y2max = $zero - ($max_to-$oxy)/$unit2px; + + $y1avg = $zero - ($avg_from-$oxy)/$unit2px; + $y2avg = $zero - ($avg_to-$oxy)/$unit2px; //*/ + + switch($calc_fnc){ + case CALC_FNC_MAX: + $y1 = $y1max; + $y2 = $y2max; + $shift_from = $shift_max_from; + $shift_to = $shift_max_to; + break; + case CALC_FNC_MIN: + $y1 = $y1min; + $y2 = $y2min; + $shift_from = $shift_min_from; + $shift_to = $shift_min_to; + break; + case CALC_FNC_ALL: + $a[0] = $x1; $a[1] = $y1max; + $a[2] = $x1; $a[3] = $y1min; + $a[4] = $x2; $a[5] = $y2min; + $a[6] = $x2; $a[7] = $y2max; + + ImageFilledPolygon($this->im,$a,4,$minmax_color); + ImageLine($this->im,$x1,$y1max,$x2,$y2max,$max_color); + ImageLine($this->im,$x1,$y1min,$x2,$y2min,$min_color); + + /* don't use break, avg must be drawed in this statement */ + // break; + case CALC_FNC_AVG: + /* don't use break, avg must be drawed in this statement */ + // break; + default: + $y1 = $y1avg; + $y2 = $y2avg; + $shift_from = $shift_avg_from ; + $shift_to = $shift_avg_to; + } + + $shift_from -= ($shift_from != 0)?($oxy):(0); + $shift_to -= ($shift_to != 0)?($oxy):(0); + + $y1_shift = $zero - $shift_from/$unit2px; + $y2_shift = $zero - $shift_to/$unit2px;//*/ + + /* draw main line */ + switch($drawtype) + { + case GRAPH_ITEM_DRAWTYPE_BOLD_LINE: + ImageLine($this->im,$x1,$y1+1,$x2,$y2+1,$avg_color); + // break; /* don't use break, must be drawed line also */ + case GRAPH_ITEM_DRAWTYPE_LINE: + ImageLine($this->im,$x1,$y1,$x2,$y2,$avg_color); + break; + case GRAPH_ITEM_DRAWTYPE_FILLED_REGION: + $a[0] = $x1; $a[1] = $y1; + $a[2] = $x1; $a[3] = $y1_shift; + $a[4] = $x2; $a[5] = $y2_shift; + $a[6] = $x2; $a[7] = $y2; + +// SDI($a); + + ImageFilledPolygon($this->im,$a,4,$avg_color); + break; + case GRAPH_ITEM_DRAWTYPE_DOT: + ImageFilledRectangle($this->im,$x1-1,$y1-1,$x1+1,$y1+1,$avg_color); + ImageFilledRectangle($this->im,$x2-1,$y2-1,$x2+1,$y2+1,$avg_color); + break; + case GRAPH_ITEM_DRAWTYPE_DASHED_LINE: + if( function_exists('imagesetstyle') ){ + + /* Use ImageSetStyle+ImageLIne instead of bugged ImageDashedLine */ + $style = array($avg_color, $avg_color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); + ImageSetStyle($this->im, $style); + ImageLine($this->im,$x1,$y1,$x2,$y2,IMG_COLOR_STYLED); + } + else{ + ImageDashedLine($this->im,$x1,$y1,$x2,$y2,$avg_color); + } + break; + } + } + +// Calculation of minimum Y axis + function calculateMinY($side){ + if($this->yaxistype==GRAPH_YAXIS_TYPE_FIXED){ + return $this->yaxismin; + } + else{ + unset($minY); + for($i=0;$i<$this->num;$i++){ + + if($this->items[$i]["axisside"] != $side) + continue; + + foreach(array(GRAPH_ITEM_SIMPLE, GRAPH_ITEM_AGGREGATED) as $type){ + + if(!isset($this->data[$this->items[$i]["itemid"]][$type])) + continue; + + $data = &$this->data[$this->items[$i]["itemid"]][$type]; + + if(!isset($data)) continue; + + if($type == GRAPH_ITEM_AGGREGATED) + $calc_fnc = CALC_FNC_ALL; + else + $calc_fnc = $this->items[$i]["calc_fnc"]; + + switch($calc_fnc){ + case CALC_FNC_ALL: /* use min */ + case CALC_FNC_MIN: $val = $data->min; $shift_val = $data->shift_min; break; + case CALC_FNC_MAX: $val = $data->max; $shift_val = $data->shift_max; break; + case CALC_FNC_AVG: + default: $val = $data->avg; $shift_val = $data->shift_avg; + } + + if(!isset($val)) continue; + + if($this->type == GRAPH_TYPE_STACKED){ + $min_val_shift = min(count($val), count($shift_val)); + for($ci=0; $ci < $min_val_shift; $ci++){ + if($shift_val[$ci] < 0){ + $val[$ci] += $shift_val[$ci]; + } + } + + } + + if(!isset($minY)){ + if(isset($val) && count($val) > 0){ + $minY = min($val); + } + } + else{ + $minY = min($minY, min($val)); + } + } + } + + if(isset($minY)&&($minY>0)){ + $minY = $minY - ($minY * 0.2) - 0.05; + } + elseif(isset($minY)&&($minY<0)){ + $minY = $minY + ($minY * 0.2) - 0.05; + } + else { + $minY=0; + } + + $minY = round($minY,1); + return $minY; + } + } + +// Calculation of maximum Y of a side (left/right) + function calculateMaxY($side) + { + if($this->yaxistype==GRAPH_YAXIS_TYPE_FIXED) + { + return $this->yaxismax; + } + else + { + + unset($maxY); + for($i=0;$i<$this->num;$i++) + { + if($this->items[$i]["axisside"] != $side) + continue; + + foreach(array(GRAPH_ITEM_SIMPLE, GRAPH_ITEM_AGGREGATED) as $type) + { + if(!isset($this->data[$this->items[$i]["itemid"]][$type])) + continue; + + $data = &$this->data[$this->items[$i]["itemid"]][$type]; + + if(!isset($data)) continue; + + if($type == GRAPH_ITEM_AGGREGATED) + $calc_fnc = CALC_FNC_ALL; + else + $calc_fnc = $this->items[$i]["calc_fnc"]; + + switch($calc_fnc) + { + case CALC_FNC_ALL: /* use max */ + case CALC_FNC_MAX: $val = $data->max; $shift_val = $data->shift_max; break; + case CALC_FNC_MIN: $val = $data->min; $shift_val = $data->shift_min; break; + case CALC_FNC_AVG: + default: $val = $data->avg; $shift_val = $data->shift_avg; + } + + if(!isset($val)) continue; + + for($ci=0; $ci < min(count($val),count($shift_val)); $ci++) $val[$ci] += $shift_val[$ci]; + + if(!isset($maxY)) + { + if(isset($val) && count($val) > 0) + { + $maxY = max($val); + } + } + else + { + $maxY = max($maxY, max($val)); + } + + } + } + + if(isset($maxY)&&($maxY>0)){ + +/* $exp = round(log10($maxY)); + $mant = $maxY/pow(10,$exp); + + $mant=((round(($mant*11)/6)-1)*6)/10; + $maxY = $mant*pow(10,$exp);//*/ + + $maxY = round($maxY,1) + round($maxY,1)*0.2 + 0.05; + } + elseif(isset($maxY)&&($maxY<0)){ + $maxY = round($maxY,1) - round($maxY,1)*0.2 + 0.05; + } + else { + $maxY=0.3; + } + return $maxY; + } + } + + function selectData(){ + global $DB_TYPE; + + $this->data = array(); + + $now = time(NULL); + + if(isset($this->stime)){ + $this->from_time = $this->stime; + $this->to_time = $this->stime + $this->period; + } + else{ + $this->to_time = $now - 3600 * $this->from; + $this->from_time = $this->to_time - $this->period; + } + + $p = $this->to_time - $this->from_time; // graph size in time + $z = $p - $this->from_time % $p; //<strong></strong> + $x = $this->sizeX; // graph size in px + + for($i=0; $i < $this->num; $i++){ + + $type = $this->items[$i]["calc_type"]; + + if($type == GRAPH_ITEM_AGGREGATED) { + /* skip current period */ + $from_time = $this->from_time - $this->period * $this->items[$i]["periods_cnt"]; + $to_time = $this->from_time; + } else { + $from_time = $this->from_time; + $to_time = $this->to_time; + } + + $calc_field = 'round('.$x.'*(mod(clock+'.$z.','.$p.'))/('.$p.'),0)'; /* required for 'group by' support of Oracle */ + $sql_arr = array(); + + if(($this->period / $this->sizeX) <= (ZBX_MAX_TREND_DIFF / ZBX_GRAPH_MAX_SKIP_CELL)){ + array_push($sql_arr, + 'select itemid,'.$calc_field.' as i,'. + ' count(*) as count,avg(value) as avg,min(value) as min,'. + ' max(value) as max,max(clock) as clock'. + ' from history where itemid='.$this->items[$i]['itemid'].' and clock>='.$from_time. + ' and clock<='.$to_time.' group by itemid,'.$calc_field + , + + 'select itemid,'.$calc_field.' as i,'. + ' count(*) as count,avg(value) as avg,min(value) as min,'. + ' max(value) as max,max(clock) as clock'. + ' from history_uint where itemid='.$this->items[$i]['itemid'].' and clock>='.$from_time. + ' and clock<='.$to_time.' group by itemid,'.$calc_field + ); + } + else{ + array_push($sql_arr, + 'select itemid,'.$calc_field.' as i,'. + ' sum(num) as count,avg(value_avg) as avg,min(value_min) as min,'. + ' max(value_max) as max,max(clock) as clock'. + ' from trends where itemid='.$this->items[$i]['itemid'].' and clock>='.$from_time. + ' and clock<='.$to_time.' group by itemid,'.$calc_field + ); + } + + $curr_data = &$this->data[$this->items[$i]["itemid"]][$type]; + $curr_data->count = NULL; + $curr_data->min = NULL; + $curr_data->max = NULL; + $curr_data->avg = NULL; + $curr_data->clock = NULL; + + foreach($sql_arr as $sql){ + $result=DBselect($sql); + + while($row=DBfetch($result)){ + $idx=$row["i"]-1; + if($idx<0) continue; + /* -------------------------------------------------- + We are taking graph on 1px more than we need, + and here we are skiping first px, because of MOD (in SELECT), + it combined prelast point (it would be last point if not that 1px in begining) + and first point, but we still losing prelast point :( + but now we've got the first point. + --------------------------------------------------*/ + + $curr_data->count[$idx] = $row["count"]; + $curr_data->min[$idx] = $row["min"]; + $curr_data->max[$idx] = $row["max"]; + $curr_data->avg[$idx] = $row["avg"]; + $curr_data->clock[$idx] = $row["clock"]; + $curr_data->shift_min[$idx] = 0; + $curr_data->shift_max[$idx] = 0; + $curr_data->shift_avg[$idx] = 0; + + if($this->type == GRAPH_TYPE_STACKED){ + $this->CheckGraphOrientation($curr_data->min[$idx]); + } + } + unset($row); + } + /* calculate missed points */ + $first_idx = 0; + /* + first_idx - last existed point + ci - current index + cj - count of missed in onetime + dx - offset to first value (count to last existed point) + //*/ + + for($ci = 0, $cj=0; $ci < $this->sizeX; $ci++) + { + if(!isset($curr_data->count[$ci]) || $curr_data->count[$ci] == 0) + { + $curr_data->count[$ci] = 0; + $curr_data->shift_min[$ci] = 0; + $curr_data->shift_max[$ci] = 0; + $curr_data->shift_avg[$ci] = 0; + $cj++; + } + else if($cj > 0) + { + $dx = $cj + 1; + + $first_idx = $ci - $dx; + + if($first_idx < 0) $first_idx = $ci; // if no data from start of graph get current data as first data + + for(;$cj > 0; $cj--){ + +/* if(($first_idx == $ci) && ($dx < ($this->sizeX)) && ($this->type == GRAPH_TYPE_STACKED)){ + $curr_data->count[$ci - ($dx - $cj)] = 1; + } + else //*/ + if(($dx < ($this->sizeX/20)) && ($this->type == GRAPH_TYPE_STACKED)){ + $curr_data->count[$ci - ($dx - $cj)] = 1; + }//*/ + + foreach(array('clock','min','max','avg') as $var_name){ + $var = &$curr_data->$var_name; + + if($first_idx == $ci && $var_name == 'clock'){ + $var[$ci - ($dx - $cj)] = $var[$first_idx] - (($p / $this->sizeX) * ($dx - $cj)); + continue; + } + + $dy = $var[$ci] - $var[$first_idx]; + $var[$ci - ($dx - $cj)] = $var[$first_idx] + ($cj * $dy) / $dx; + } + } + } + } + + if($cj > 0 && $ci > $cj){ + $dx = $cj + 1; + + $first_idx = $ci - $dx; + + for(;$cj > 0; $cj--){ + +// if($dx < ($this->sizeX/20)) //($this->type == GRAPH_TYPE_STACKED) +// $curr_data->count[$first_idx + ($dx - $cj)] = 1; + + foreach(array('clock','min','max','avg') as $var_name){ + $var = &$curr_data->$var_name; + + if( $var_name == 'clock') + { + $var[$first_idx + ($dx - $cj)] = $var[$first_idx] + (($p / $this->sizeX) * ($dx - $cj)); + continue; + } + $var[$first_idx + ($dx - $cj)] = $var[$first_idx]; + } + } + } + /* end of missed points calculation */ + } + + /* calculte shift for stacked graphs */ + + if($this->type == GRAPH_TYPE_STACKED) + { + for($i=1; $i<$this->num; $i++) + { + $curr_data = &$this->data[$this->items[$i]["itemid"]][$this->items[$i]["calc_type"]]; + + if(!isset($curr_data)) continue; + + for($j = $i-1; $j >= 0; $j--) + { + if($this->items[$j]["axisside"] != $this->items[$i]["axisside"]) continue; + + $prev_data = &$this->data[$this->items[$j]["itemid"]][$this->items[$j]["calc_type"]]; + + if(!isset($prev_data)) continue; + + for($ci = 0; $ci < $this->sizeX; $ci++) + { + foreach(array('min','max','avg') as $var_name) + { + $shift_var_name = 'shift_'.$var_name; + $curr_shift = &$curr_data->$shift_var_name; + $curr_var = &$curr_data->$var_name; + $prev_shift = &$prev_data->$shift_var_name; + $prev_var = &$prev_data->$var_name; + $curr_shift[$ci] = $prev_var[$ci] + $prev_shift[$ci]; + } + } + break; + } + } + } + /* end calculation of stacked graphs */ + } + + function DrawLeftSide() + { + if($this->yaxisleft == 1) + { + $minY = $this->m_minY[GRAPH_YAXIS_SIDE_LEFT]; + $maxY = $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT]; + + for($item=0;$item<$this->num;$item++) + { + if($this->items[$item]["axisside"] == GRAPH_YAXIS_SIDE_LEFT) + { + $units=$this->items[$item]["units"]; + break; + } + } + for($i=0;$i<=6;$i++) + { + $str = str_pad(convert_units($this->sizeY*$i/6*($maxY-$minY)/$this->sizeY+$minY,$units),10," ", STR_PAD_LEFT); + ImageString($this->im, 1, 5, $this->sizeY-$this->sizeY*$i/6-4+$this->shiftY, $str, $this->GetColor("Dark Red No Alpha")); + } + if(($this->zero[GRAPH_YAXIS_SIDE_LEFT] != $this->sizeY+$this->shiftY) && + ($this->zero[GRAPH_YAXIS_SIDE_LEFT] != $this->shiftY)){ + imageline($this->im, + $this->shiftXleft, + $this->zero[GRAPH_YAXIS_SIDE_LEFT], + $this->shiftXleft+$this->sizeX, + $this->zero[GRAPH_YAXIS_SIDE_LEFT], + $this->GetColor(GRAPH_ZERO_LINE_COLOR_LEFT) + ); //*/ + } + } + } + + function DrawRightSide() + { + if($this->yaxisright == 1) + { + $minY = $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT]; + $maxY = $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT]; + + for($item=0;$item<$this->num;$item++){ + if($this->items[$item]["axisside"] == GRAPH_YAXIS_SIDE_RIGHT){ + $units=$this->items[$item]["units"]; + break; + } + } + for($i=0;$i<=6;$i++){ + $str = str_pad(convert_units($this->sizeY*$i/6*($maxY-$minY)/$this->sizeY+$minY,$units),10," "); + ImageString($this->im, 1, $this->sizeX+$this->shiftXleft+2, $this->sizeY-$this->sizeY*$i/6-4+$this->shiftY, $str, $this->GetColor("Dark Red No Alpha")); + } + + if(($this->zero[GRAPH_YAXIS_SIDE_RIGHT] != $this->sizeY+$this->shiftY) && + ($this->zero[GRAPH_YAXIS_SIDE_RIGHT] != $this->shiftY)){ + imageline($this->im, + $this->shiftXleft, + $this->zero[GRAPH_YAXIS_SIDE_RIGHT], + $this->shiftXleft+$this->sizeX, + $this->zero[GRAPH_YAXIS_SIDE_RIGHT], + $this->GetColor(GRAPH_ZERO_LINE_COLOR_RIGHT) + ); //*/ + } + } + } + + function CalcZero(){ + $left = GRAPH_YAXIS_SIDE_LEFT; + $right = GRAPH_YAXIS_SIDE_RIGHT; + + $this->unit2px[$right] = ($this->m_maxY[$right] - $this->m_minY[$right])/$this->sizeY; + $this->unit2px[$left] = ($this->m_maxY[$left] - $this->m_minY[$left])/$this->sizeY; + + if($this->m_minY[$right]>0){ + $this->zero[$right] = $this->sizeY+$this->shiftY; + $this->oxy[$right] = min(abs($this->m_minY[$right]),abs($this->m_maxY[$right])); + } + elseif($this->m_maxY[$right]<0) { + $this->zero[$right] = $this->shiftY; + $this->oxy[$right] = min(abs($this->m_minY[$right]),abs($this->m_maxY[$right])); + } + else{ + $this->zero[$right] = $this->sizeY+$this->shiftY - (int)abs($this->m_minY[$right]/$this->unit2px[$right]); + $this->oxy[$right] = 0; + } + + if($this->m_minY[$left]>0){ + $this->zero[$left] = $this->sizeY+$this->shiftY; + $this->oxy[$left] = min(abs($this->m_minY[$left]),abs($this->m_maxY[$left])); + } + elseif($this->m_maxY[$left]<0){ + $this->zero[$left] = $this->shiftY; + $this->oxy[$left] = min(abs($this->m_minY[$left]),abs($this->m_maxY[$left])); + } + else{ + $this->zero[$left] = $this->sizeY+$this->shiftY - (int)abs($this->m_minY[$left]/$this->unit2px[$left]); + $this->oxy[$left] = 0; + } + } + + function Draw() + { + $start_time=getmicrotime(); + + set_image_header(); + + check_authorisation(); + + $this->selectData(); + + $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = $this->calculateMinY(GRAPH_YAXIS_SIDE_LEFT); + $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = $this->calculateMinY(GRAPH_YAXIS_SIDE_RIGHT); + $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT] = $this->calculateMaxY(GRAPH_YAXIS_SIDE_LEFT); + $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT] = $this->calculateMaxY(GRAPH_YAXIS_SIDE_RIGHT); + + $this->updateShifts(); + $this->calcTriggers(); + $this->CalcZero(); + + $this->fullSizeX = $this->sizeX+$this->shiftXleft+$this->shiftXright+1; + $this->fullSizeY = $this->sizeY+$this->shiftY+62+12*($this->num+ (($this->sizeY < 120) ? 0 : count($this->triggers)))+8; + + if(function_exists("ImageColorExactAlpha")&&function_exists("ImageCreateTrueColor")&&@imagecreatetruecolor(1,1)) + $this->im = imagecreatetruecolor($this->fullSizeX,$this->fullSizeY); + else + $this->im = imagecreate($this->fullSizeX,$this->fullSizeY); + + + $this->initColors(); + $this->drawRectangle(); + $this->drawHeader(); + + if($this->num==0) + { +// $this->noDataFound(); + } + + $this->drawWorkPeriod(); + $this->drawGrid(); + + $maxX = $this->sizeX; + + // For each metric + for($item = 0; $item < $this->num; $item++) + { + $minY = $this->m_minY[$this->items[$item]["axisside"]]; + $maxY = $this->m_maxY[$this->items[$item]["axisside"]]; + + $data = &$this->data[$this->items[$item]["itemid"]][$this->items[$item]["calc_type"]]; + + if(!isset($data)) continue; + + if($this->items[$item]["calc_type"] == GRAPH_ITEM_AGGREGATED){ + $drawtype = GRAPH_ITEM_DRAWTYPE_LINE; + + $max_color = $this->GetColor("HistoryMax"); + $avg_color = $this->GetColor("HistoryAvg"); + $min_color = $this->GetColor("HistoryMin"); + $minmax_color = $this->GetColor("HistoryMinMax"); + + $calc_fnc = CALC_FNC_ALL; + } + elseif($this->type == GRAPH_TYPE_STACKED){ + $drawtype = $this->items[$item]["drawtype"]; + + $max_color = $this->GetColor("ValueMax",GRAPH_STACKED_ALFA); + $avg_color = $this->GetColor($this->items[$item]["color"],GRAPH_STACKED_ALFA); + $min_color = $this->GetColor("ValueMin",GRAPH_STACKED_ALFA); + $minmax_color = $this->GetColor("ValueMinMax",GRAPH_STACKED_ALFA); + + $calc_fnc = $this->items[$item]["calc_fnc"]; + } + else{ + $drawtype = $this->items[$item]["drawtype"]; + + $max_color = $this->GetColor("ValueMax"); + $avg_color = $this->GetColor($this->items[$item]["color"]); + $min_color = $this->GetColor("ValueMin"); + $minmax_color = $this->GetColor("ValueMinMax"); + + $calc_fnc = $this->items[$item]["calc_fnc"]; + } + // For each X + for($i = 1, $j = 0; $i < $maxX; $i++) // new point + { + if(($data->count[$i] == 0) && ($i != ($maxX-1))) continue; + + $diff = abs($data->clock[$i] - $data->clock[$j]); + $cell = ($this->to_time - $this->from_time)/$this->sizeX; + $delay = $this->items[$item]["delay"]; + + if($cell > $delay) + $draw = (boolean) ($diff < ZBX_GRAPH_MAX_SKIP_CELL * $cell); + else + $draw = (boolean) ($diff < ZBX_GRAPH_MAX_SKIP_DELAY * $delay); + + if($draw == false && $this->items[$item]["calc_type"] == GRAPH_ITEM_AGGREGATED) + $draw = $i - $j < 5; + + if($this->items[$item]["type"] == ITEM_TYPE_TRAPPER) + $draw = true; +// SDI($draw); + if($draw){ + + $this->drawElement( + $data, + $i, $j, + 0, $this->sizeX, + $minY, $maxY, + $drawtype, + $max_color, + $avg_color, + $min_color, + $minmax_color, + $calc_fnc, + $this->items[$item]['axisside'] + ); + } +// echo "\nDraw II \n"; printf("%0.4f",(getmicrotime()-$start_time)); + + $j = $i; + } + } + + $this->DrawLeftSide(); + $this->DrawRightSide(); + $this->drawTriggers(); + + $this->drawLogo(); + + $this->drawLegend(); + + $end_time=getmicrotime(); + $str=sprintf("%0.2f",(getmicrotime()-$start_time)); + ImageString($this->im, 0,$this->fullSizeX-120,$this->fullSizeY-12,"Generated in $str sec", $this->GetColor("Gray")); + + unset($this->items, $this->data); + + ImageOut($this->im); + } +} +?>
\ No newline at end of file diff --git a/frontends/php/include/classes/graph.inc.php b/frontends/php/include/classes/graph.inc.php index fd97fd7c..c6b6f2d0 100644 --- a/frontends/php/include/classes/graph.inc.php +++ b/frontends/php/include/classes/graph.inc.php @@ -19,1431 +19,346 @@ **/ ?> <?php - require_once "include/items.inc.php"; - require_once "include/hosts.inc.php"; +require_once "include/items.inc.php"; +require_once "include/hosts.inc.php"; - define("GRAPH_YAXIS_TYPE_CALCULATED",0); - define("GRAPH_YAXIS_TYPE_FIXED",1); +define("GRAPH_YAXIS_TYPE_CALCULATED",0); +define("GRAPH_YAXIS_TYPE_FIXED",1); - define("GRAPH_YAXIS_SIDE_LEFT",0); - define("GRAPH_YAXIS_SIDE_RIGHT",1); +define("GRAPH_YAXIS_SIDE_LEFT",0); +define("GRAPH_YAXIS_SIDE_RIGHT",1); - define("GRAPH_ITEM_SIMPLE" , 0); - define("GRAPH_ITEM_AGGREGATED", 1); +define("GRAPH_ITEM_SIMPLE" , 0); +define("GRAPH_ITEM_AGGREGATED", 1); +define("GRAPH_ITEM_SUM", 2); - define("GRAPH_TYPE_NORMAL", 0); - define("GRAPH_TYPE_STACKED", 1); - define("GRAPH_STACKED_ALFA", 15); //0..100 - - define("GRAPH_ZERO_LINE_COLOR_LEFT", 'AAAAAA'); - define("GRAPH_ZERO_LINE_COLOR_RIGHT", '888888'); - - define('ZBX_MAX_TREND_DIFF', 3600); - - define('ZBX_GRAPH_MAX_SKIP_CELL', 16); - define('ZBX_GRAPH_MAX_SKIP_DELAY', 4); - - class Graph - { - /* - //var $period; - //var $from; - var $stime; - //var $sizeX; - //var $sizeY; - //var $shiftXleft; - //var $shiftXright; - //var $shiftY; - //var $border; - - var $fullSizeX; - var $fullSizeY; - - //var $m_showWorkPeriod; - //var $m_showTriggers; +define("GRAPH_TYPE_NORMAL", 0); +define("GRAPH_TYPE_STACKED", 1); - //var $type; // 0 - simple graph; 1 - stacked graph; +define("GRAPH_TYPE_PIE", 2); +define("GRAPH_TYPE_EXPLODED", 3); +define("GRAPH_TYPE_3D", 4); +define("GRAPH_TYPE_3D_EXPLODED", 5); - //var $yaxistype; - var $yaxismin; - var $yaxismax; - //var $yaxisleft; - //var $yaxisright; - var $m_minY; - var $m_maxY; +define("GRAPH_3D_ANGLE", 70); - var $data = array(); +define("GRAPH_STACKED_ALFA", 15); //0..100 transperancy - // items[num].data.min[max|avg] - var $items; - // $idnum[$num] is itemid - var $min; - var $max; - var $avg; - var $clock; - var $count; - // Number of items - //var $num; - - var $header; - - var $from_time; - var $to_time; - - var $colors; - var $im; - - var $triggers = array();*/ - - function Graph($type = GRAPH_TYPE_NORMAL) - { - $this->stime = null; - $this->fullSizeX = null; - $this->fullSizeY = null; +define("GRAPH_ZERO_LINE_COLOR_LEFT", 'AAAAAA'); +define("GRAPH_ZERO_LINE_COLOR_RIGHT", '888888'); - $this->yaxismin = null; - $this->yaxismax = null; +define('ZBX_MAX_TREND_DIFF', 3600); - $this->m_minY = null; - $this->m_maxY = null; +define('ZBX_GRAPH_MAX_SKIP_CELL', 16); +define('ZBX_GRAPH_MAX_SKIP_DELAY', 4); - $this->data = array(); +class Graph{ - $this->items = null; - - $this->min = null; - $this->max = null; - $this->avg = null; - $this->clock = null; - $this->count = null; - - $this->header = null; - - $this->from_time = null; - $this->to_time = null; + function Graph($type = GRAPH_TYPE_NORMAL){ + + $this->stime = null; + $this->fullSizeX = null; + $this->fullSizeY = null; - $this->colors = null; - $this->im = null; + $this->m_minY = null; + $this->m_maxY = null; - $this->triggers = array(); - - $this->period=3600; - $this->from=0; - $this->sizeX=900; - $this->sizeY=200; - $this->shiftXleft=10; - $this->shiftXright=60; - $this->shiftY=17; - $this->border=1; - $this->num=0; - $this->type = $type; - $this->yaxistype=GRAPH_YAXIS_TYPE_CALCULATED; - $this->yaxisright=0; - $this->yaxisleft=0; - - $this->m_showWorkPeriod = 1; - $this->m_showTriggers = 1; - - $this->zero = array(); - $this->graphorientation = ''; -/* if($this->period<=3600) - { - $this->date_format="H:i"; - } - else - { - $this->date_format="m.d H:i"; - }*/ + $this->data = array(); - } + $this->items = null; - function updateShifts() - { - if( ($this->yaxisleft == 1) && ($this->yaxisright == 1)) - { - $this->shiftXleft = 60; - $this->shiftXright = 60; - } - else if($this->yaxisleft == 1) - { - $this->shiftXleft = 60; - $this->shiftXright = 20; - } - else if($this->yaxisright == 1) - { - $this->shiftXleft = 10; - $this->shiftXright = 60; - } -# $this->sizeX = $this->sizeX - $this->shiftXleft-$this->shiftXright; - } + $this->min = null; + $this->max = null; + $this->avg = null; + $this->clock = null; + $this->count = null; - function initColors() - { + $this->header = null; - $colors = array( /* Red, Green, Blue, Alpha */ - "Red" => array(255,0,0,50), - "Dark Red" => array(150,0,0,50), - "Green" => array(0,255,0,50), - "Dark Green" => array(0,150,0,50), - "Blue" => array(0,0,255,50), - "Dark Blue" => array(0,0,150,50), - "Yellow" => array(255,255,0,50), - "Dark Yellow" => array(150,150,0,50), - "Cyan" => array(0,255,255,50), - "Black" => array(0,0,0,50), - "Gray" => array(150,150,150,50), - "White" => array(255,255,255), - "Dark Red No Alpha" => array(150,0,0), - "Black No Alpha" => array(0,0,0), + $this->from_time = null; + $this->to_time = null; - "HistoryMinMax" => array(90,150,185,50), - "HistoryMax" => array(255,100,100,50), - "HistoryMin" => array(50,255,50,50), - "HistoryAvg" => array(50,50,50,50), + $this->colors = null; + $this->colorsrgb = null; + $this->im = null; + + $this->period=3600; + $this->from=0; + $this->sizeX=900; + $this->sizeY=200; + $this->shiftXleft=10; + $this->shiftXright=60; + $this->shiftY=17; + $this->border=1; + $this->num=0; + $this->type = $type; - "ValueMinMax" => array(255,255,150,50), - "ValueMax" => array(255,180,180,50), - "ValueMin" => array(100,255,100,50), + } - "Priority Disaster" => array(255,0,0), - "Priority Hight" => array(255,100,100), - "Priority Average" => array(221,120,120), - "Priority" => array(100,100,100), - "Not Work Period" => array(230,230,230), - "UnknownData" => array(130,130,130, 50) - ); + function initColors() + { + $colors = array( /* Red, Green, Blue, Alpha */ + "Red" => array(255,0,0,50), + "Dark Red" => array(150,0,0,50), + "Green" => array(0,255,0,50), + "Dark Green" => array(0,150,0,50), + "Blue" => array(0,0,255,50), + "Dark Blue" => array(0,0,150,50), + "Yellow" => array(255,255,0,50), + "Dark Yellow" => array(150,150,0,50), + "Cyan" => array(0,255,255,50), + "Dark Cyan" => array(0,150,150,50), + "Black" => array(0,0,0,50), + "Gray" => array(150,150,150,50), + "White" => array(255,255,255), + "Dark Red No Alpha" => array(150,0,0), + "Black No Alpha" => array(0,0,0), + + "HistoryMinMax" => array(90,150,185,50), + "HistoryMax" => array(255,100,100,50), + "HistoryMin" => array(50,255,50,50), + "HistoryAvg" => array(50,50,50,50), + + "ValueMinMax" => array(255,255,150,50), + "ValueMax" => array(255,180,180,50), + "ValueMin" => array(100,255,100,50), + + "Priority Disaster" => array(255,0,0), + "Priority Hight" => array(255,100,100), + "Priority Average" => array(221,120,120), + "Priority" => array(100,100,100), + "Not Work Period" => array(230,230,230), + + "UnknownData" => array(130,130,130, 50) + ); + + $this->colorsrgb = $colors; + // I should rename No Alpha to Alpha at some point to get rid of some confusion - foreach($colors as $name => $RGBA) + foreach($colors as $name => $RGBA) + { + if(isset($RGBA[3]) && + function_exists("ImageColorExactAlpha") && + function_exists("ImageCreateTrueColor") && + @ImageCreateTrueColor(1,1) + ) { - if(isset($RGBA[3]) && - function_exists("ImageColorExactAlpha") && - function_exists("ImageCreateTrueColor") && - @ImageCreateTrueColor(1,1) - ) - { - $this->colors[$name] = ImageColorExactAlpha($this->im,$RGBA[0],$RGBA[1],$RGBA[2],$RGBA[3]); - } - else - { - $this->colors[$name] = ImageColorAllocate($this->im,$RGBA[0],$RGBA[1],$RGBA[2]); - } + $this->colors[$name] = ImageColorExactAlpha($this->im,$RGBA[0],$RGBA[1],$RGBA[2],$RGBA[3]); } - } - - function ShowWorkPeriod($value) - { - $this->m_showWorkPeriod = $value == 1 ? 1 : 0; - } - - function ShowTriggers($value) - { - $this->m_showTriggers = $value == 1 ? 1 : 0; - } - - function AddItem($itemid, $axis=GRAPH_YAXIS_SIDE_RIGHT, $calc_fnc=CALC_FNC_AVG, - $color=null, $drawtype=null, $type=null, $periods_cnt=null) - { - if($this->type == GRAPH_TYPE_STACKED /* stacked graph */) - $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION; - - $this->items[$this->num] = get_item_by_itemid($itemid); - $this->items[$this->num]["description"]=item_description($this->items[$this->num]["description"],$this->items[$this->num]["key_"]); - $host=get_host_by_hostid($this->items[$this->num]["hostid"]); - - $this->items[$this->num]["host"] = $host["host"]; - $this->items[$this->num]["color"] = is_null($color) ? "Dark Green" : $color; - $this->items[$this->num]["drawtype"] = is_null($drawtype) ? GRAPH_ITEM_DRAWTYPE_LINE : $drawtype; - $this->items[$this->num]["axisside"] = is_null($axis) ? GRAPH_YAXIS_SIDE_RIGHT : $axis; - $this->items[$this->num]["calc_fnc"] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc; - $this->items[$this->num]["calc_type"] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type; - $this->items[$this->num]["periods_cnt"] = is_null($periods_cnt) ? 0 : $periods_cnt; - - if($this->items[$this->num]["axisside"] == GRAPH_YAXIS_SIDE_LEFT) - $this->yaxisleft=1; - - if($this->items[$this->num]["axisside"] == GRAPH_YAXIS_SIDE_RIGHT) - $this->yaxisright=1; -// SDI($this->items); - - $this->num++; - } - - function CheckGraphOrientation($value){ - - if(!empty($this->graphorientation)){ - if(($this->graphorientation == '+') && ($value<0)){ -// Error(); - } - elseif(($this->graphorientation == '-') && ($value>0)){ -// Error(); - } - } - else { - if($value < 0){ - $this->graphorientation = '-'; - } - elseif($value > 0){ - $this->graphorientation = '+'; - } + else{ + $this->colors[$name] = ImageColorAllocate($this->im,$RGBA[0],$RGBA[1],$RGBA[2]); } } + } - function setPeriod($period) - { - $this->period=$period; - } - function setYAxisMin($yaxismin) - { - $this->yaxismin=$yaxismin; - } - function setYAxisMax($yaxismax) - { - $this->yaxismax=$yaxismax; - } + function setPeriod($period) + { + $this->period=$period; + } - function setYAxisType($yaxistype) - { - $this->yaxistype=$yaxistype; - } - function SetSTime($stime) + function SetSTime($stime) + { + if($stime>200000000000 && $stime<220000000000) { - if($stime>200000000000 && $stime<220000000000) - { - $this->stime=mktime(substr($stime,8,2),substr($stime,10,2),0,substr($stime,4,2),substr($stime,6,2),substr($stime,0,4)); - } + $this->stime=mktime(substr($stime,8,2),substr($stime,10,2),0,substr($stime,4,2),substr($stime,6,2),substr($stime,0,4)); } + } - function setFrom($from) - { - $this->from=$from; - } + function setFrom($from) + { + $this->from=$from; + } - function setWidth($value = NULL) - { + function setWidth($value = NULL) + { // Avoid sizeX==0, to prevent division by zero later - if($value == 0) $value = NULL; - if($value > 1300) $value = 1300; - if(is_null($value)) $value = 900; + if($value == 0) $value = NULL; + if($value > 1300) $value = 1300; + if(is_null($value)) $value = 900; - $this->sizeX = $value; - } + $this->sizeX = $value; + } - function setHeight($value = NULL) - { - if($value == 0) $value = NULL; - if(is_null($value)) $value = 900; + function setHeight($value = NULL) + { + if($value == 0) $value = NULL; + if(is_null($value)) $value = 900; - $this->sizeY = $value; - } + $this->sizeY = $value; + } - function setBorder($border) - { - $this->border=$border; - } + function setBorder($border) + { + $this->border=$border; + } - function getLastValue($num) + function getLastValue($num) + { + $data = &$this->data[$this->items[$num]["itemid"]][$this->items[$num]["calc_type"]]; + if(isset($data)) for($i=$this->sizeX-1;$i>=0;$i--) { - $data = &$this->data[$this->items[$num]["itemid"]][$this->items[$num]["calc_type"]]; - if(isset($data)) for($i=$this->sizeX-1;$i>=0;$i--) + if(isset($data->count[$i]) && ($data->count[$i] > 0)) { - if(isset($data->count[$i]) && ($data->count[$i] > 0)) + switch($this->items[$num]["calc_fnc"]) { - switch($this->items[$num]["calc_fnc"]) - { - case CALC_FNC_MIN: return $data->min[$i]; - case CALC_FNC_MAX: return $data->max[$i]; - case CALC_FNC_ALL: /* use avg */ - case CALC_FNC_AVG: - default: return $data->avg[$i]; - } + case CALC_FNC_MIN: return $data->min[$i]; + case CALC_FNC_MAX: return $data->max[$i]; + case CALC_FNC_ALL: /* use avg */ + case CALC_FNC_AVG: + default: return $data->avg[$i]; } } - return 0; - } - - function drawSmallRectangle() - { - DashedRectangle($this->im, - $this->shiftXleft-1, - $this->shiftY-1, - $this->sizeX+$this->shiftXleft-1, - $this->sizeY+$this->shiftY+1, - $this->GetColor("Black No Alpha") - ); } + return 0; + } - function drawRectangle() - { - ImageFilledRectangle($this->im,0,0, - $this->fullSizeX,$this->fullSizeY, - $this->GetColor("White")); - - - if($this->border==1) - { - ImageRectangle($this->im,0,0,$this->fullSizeX-1,$this->fullSizeY-1,$this->GetColor("Black No Alpha")); - } - } - - function period2str($period) - { - $second = 1; $minute=$second * 60; $hour=$minute*60; $day=$hour*24; - $str = " ( "; - - $days=floor($this->period/$day); - $hours=floor(($this->period%$day)/$hour); - $minutes=floor((($this->period%$day)%$hour)/$minute); - $seconds=floor(((($this->period%$day)%$hour)%$minute)/$second); - - $str.=($days>0 ? $days."d" : "").($hours>0 ? $hours."h" : "").($minutes>0 ? $minutes."m" : "").($seconds>0 ? $seconds."s" : ""); - $str.=" history "; - - $hour=1; $day=$hour*24; - $days=floor($this->from/$day); - $hours=floor(($this->from%$day)/$hour); - $minutes=floor((($this->from%$day)%$hour)/$minute); - $seconds=floor(((($this->from%$day)%$hour)%$minute)/$second); - - $str.=($days>0 ? $days."d" : "").($hours>0 ? $hours."h" : "").($minutes>0 ? $minutes."m" : "").($seconds>0 ? $seconds."s" : ""); - $str.=($days+$hours+$minutes+$seconds>0 ? " in past " : ""); + function drawSmallRectangle() + { + DashedRectangle($this->im, + $this->shiftXleft-1, + $this->shiftY-1, + $this->sizeX+$this->shiftXleft-1, + $this->sizeY+$this->shiftY+1, + $this->GetColor("Black No Alpha") + ); + } - $str.=")"; + function drawRectangle() + { + ImageFilledRectangle($this->im,0,0, + $this->fullSizeX,$this->fullSizeY, + $this->GetColor("White")); - return $str; - } - function drawHeader() + if($this->border==1) { - if(!isset($this->header)) - { - $str=$this->items[0]["host"].":".$this->items[0]["description"]; - } - else - { - $str=$this->header; - } - - $str=$str.$this->period2str($this->period); - - if($this->sizeX < 500) - { - $fontnum = 2; - } - else - { - $fontnum = 4; - } - $x=$this->fullSizeX/2-ImageFontWidth($fontnum)*strlen($str)/2; - ImageString($this->im, $fontnum,$x,1, $str , $this->GetColor("Dark Red No Alpha")); + ImageRectangle($this->im,0,0,$this->fullSizeX-1,$this->fullSizeY-1,$this->GetColor("Black No Alpha")); } + } - function setHeader($header) - { - $this->header=$header; - } + function period2str($period) + { + $second = 1; $minute=$second * 60; $hour=$minute*60; $day=$hour*24; + $str = " ( "; - function drawGrid() - { - $this->drawSmallRectangle(); - for($i=1;$i<=5;$i++) - { - DashedLine($this->im,$this->shiftXleft,$i*($this->sizeY/6)+$this->shiftY,$this->sizeX+$this->shiftXleft,$i*($this->sizeY/6)+$this->shiftY,$this->GetColor("Gray")); - } + $days=floor($this->period/$day); + $hours=floor(($this->period%$day)/$hour); + $minutes=floor((($this->period%$day)%$hour)/$minute); + $seconds=floor(((($this->period%$day)%$hour)%$minute)/$second); - for($i=1;$i<=23;$i++) - { - DashedLine($this->im,$i*($this->sizeX/24)+$this->shiftXleft,$this->shiftY,$i*($this->sizeX/24)+$this->shiftXleft,$this->sizeY+$this->shiftY,$this->GetColor("Gray")); - } - - $old_day=-1; - for($i=0;$i<=24;$i++) - { - ImageStringUp($this->im, 1,$i*($this->sizeX/24)+$this->shiftXleft-3, $this->sizeY+$this->shiftY+57, date(" H:i",$this->from_time+$i*($this->period/24)) , $this->GetColor("Black No Alpha")); - - $new_day=date("d",$this->from_time+$i*($this->period/24)); - if( ($old_day != $new_day) ||($i==24)) - { - $old_day=$new_day; - ImageStringUp($this->im, 1,$i*($this->sizeX/24)+$this->shiftXleft-3, $this->sizeY+$this->shiftY+57, date("m.d H:i",$this->from_time+$i*($this->period/24)) , $this->GetColor("Dark Red No Alpha")); - - } - } - } - - function drawWorkPeriod() - { - if($this->m_showWorkPeriod != 1) return; - if($this->period > 2678400) return; // > 31*24*3600 (month) - - $db_work_period = DBselect("select work_period from config"); - $work_period = DBfetch($db_work_period); - if(!$work_period) - return; - - $periods = parse_period($work_period['work_period']); - if(!$periods) - return; - - ImageFilledRectangle($this->im, - $this->shiftXleft+1, - $this->shiftY, - $this->sizeX+$this->shiftXleft, - $this->sizeY+$this->shiftY, - $this->GetColor("Not Work Period")); - - $now = time(); - if(isset($this->stime)) - { - $this->from_time=$this->stime; - $this->to_time=$this->stime+$this->period; - } - else - { - $this->to_time=$now-3600*$this->from; - $this->from_time=$this->to_time-$this->period; - } - $from = $this->from_time; - $max_time = $this->to_time; - - $start = find_period_start($periods,$from); - $end = -1; - while($start < $max_time && $start > 0) - { - $end = find_period_end($periods,$start,$max_time); - - $x1 = round((($start-$from)*$this->sizeX)/$this->period) + $this->shiftXleft; - $x2 = round((($end-$from)*$this->sizeX)/$this->period) + $this->shiftXleft; - - //draw rectangle - ImageFilledRectangle( - $this->im, - $x1, - $this->shiftY, - $x2, - $this->sizeY+$this->shiftY, - $this->GetColor("White")); - - $start = find_period_start($periods,$end); - } - } + $str.=($days>0 ? $days."d" : "").($hours>0 ? $hours."h" : "").($minutes>0 ? $minutes."m" : "").($seconds>0 ? $seconds."s" : ""); + $str.=" history "; + + $hour=1; $day=$hour*24; + $days=floor($this->from/$day); + $hours=floor(($this->from%$day)/$hour); + $minutes=floor((($this->from%$day)%$hour)/$minute); + $seconds=floor(((($this->from%$day)%$hour)%$minute)/$second); - function calcTriggers() - { - $this->triggers = array(); - if($this->m_showTriggers != 1) return; - if($this->num != 1) return; // skip multiple graphs - - $max = 3; - $cnt = 0; - - $db_triggers = DBselect("select distinct tr.triggerid,tr.expression,tr.priority from triggers tr,functions f,items i". - " where tr.triggerid=f.triggerid and f.function in ('last','min','max') and". - " tr.status=".TRIGGER_STATUS_ENABLED." and i.itemid=f.itemid and f.itemid=".$this->items[0]["itemid"]." order by tr.priority"); - - while(($trigger = DBfetch($db_triggers)) && ($cnt < $max)) - { - $db_fnc_cnt = DBselect('select count(*) as cnt from functions f where f.triggerid='.$trigger['triggerid']); - $fnc_cnt = DBfetch($db_fnc_cnt); - if($fnc_cnt['cnt'] != 1) continue; - - if(!eregi('\{([0-9]{1,})\}([\<\>\=]{1})([0-9\.]{1,})([K|M|G]{0,1})',$trigger['expression'],$arr)) - continue; - - $val = $arr[3]; - if(strcasecmp($arr[4],'K') == 0) $val *= 1024; - else if(strcasecmp($arr[4],'M') == 0) $val *= 1048576; //1024*1024; - else if(strcasecmp($arr[4],'G') == 0) $val *= 1073741824; //1024*1024*1024; + $str.=($days>0 ? $days."d" : "").($hours>0 ? $hours."h" : "").($minutes>0 ? $minutes."m" : "").($seconds>0 ? $seconds."s" : ""); + $str.=($days+$hours+$minutes+$seconds>0 ? " in past " : ""); - $minY = $this->m_minY[$this->items[0]["axisside"]]; - $maxY = $this->m_maxY[$this->items[0]["axisside"]]; + $str.=")"; - if($val <= $minY || $val >= $maxY) continue; - - if($trigger['priority'] == 5) $color = "Priority Disaster"; - elseif($trigger['priority'] == 4) $color = "Priority Hight"; - elseif($trigger['priority'] == 3) $color = "Priority Average"; - else $color = "Priority"; + return $str; + } - array_push($this->triggers,array( - 'y' => $this->sizeY - (($val-$minY) / ($maxY-$minY)) * $this->sizeY + $this->shiftY, - 'color' => $color, - 'description' => 'trigger: '.expand_trigger_description($trigger['triggerid']).' ['.$arr[2].' '.$arr[3].$arr[4].']' - )); - ++$cnt; - } - - } - function drawTriggers() + function drawHeader() + { + if(!isset($this->header)) { - if($this->m_showTriggers != 1) return; - if($this->num != 1) return; // skip multiple graphs - - foreach($this->triggers as $trigger) - { - DashedLine( - $this->im, - $this->shiftXleft, - $trigger['y'], - $this->sizeX+$this->shiftXleft, - $trigger['y'], - $this->GetColor($trigger['color'])); - } - + $str=$this->items[0]["host"].":".$this->items[0]["description"]; } - - function drawLogo() + else { - ImageStringUp($this->im,0,$this->fullSizeX-10,$this->fullSizeY-50, "http://www.zabbix.com", $this->GetColor("Gray")); + $str=$this->header; } - function GetColor($color,$alfa=50) + $str=$str.$this->period2str($this->period); + + if($this->sizeX < 500) { - if(isset($this->colors[$color])) - return $this->colors[$color]; - - $RGB = array( - hexdec('0x'.substr($color, 0,2)), - hexdec('0x'.substr($color, 2,2)), - hexdec('0x'.substr($color, 4,2)) - ); - - if(isset($alfa) && - function_exists("ImageColorExactAlpha") && - function_exists("ImageCreateTrueColor") && - @ImageCreateTrueColor(1,1) - ) - { - return ImageColorExactAlpha($this->im,$RGB[0],$RGB[1],$RGB[2],$alfa); - } - - return ImageColorAllocate($this->im,$RGB[0],$RGB[1],$RGB[2]); + $fontnum = 2; } - - function drawLegend() + else { - $max_host_len=0; - $max_desc_len=0; - for($i=0;$i<$this->num;$i++) - { - if(strlen($this->items[$i]["host"])>$max_host_len) $max_host_len=strlen($this->items[$i]["host"]); - if(strlen($this->items[$i]["description"])>$max_desc_len) $max_desc_len=strlen($this->items[$i]["description"]); - } - - for($i=0;$i<$this->num;$i++) - { - if($this->items[$i]["calc_type"] == GRAPH_ITEM_AGGREGATED) - { - $fnc_name = "agr(".$this->items[$i]["periods_cnt"].")"; - $color = $this->GetColor("HistoryMinMax"); - } - else - { - $color = $this->GetColor($this->items[$i]["color"]); - switch($this->items[$i]["calc_fnc"]) - { - case CALC_FNC_MIN: $fnc_name = "min"; break; - case CALC_FNC_MAX: $fnc_name = "max"; break; - case CALC_FNC_ALL: $fnc_name = "all"; break; - case CALC_FNC_AVG: - default: $fnc_name = "avg"; - } - } - - $data = &$this->data[$this->items[$i]["itemid"]][$this->items[$i]["calc_type"]]; - if(isset($data)&&isset($data->min)) - { - $str=sprintf("%s: %s [%s] [min:%s max:%s last:%s]", - str_pad($this->items[$i]["host"],$max_host_len," "), - str_pad($this->items[$i]["description"],$max_desc_len," "), - $fnc_name, - convert_units(min($data->min),$this->items[$i]["units"]), - convert_units(max($data->max),$this->items[$i]["units"]), - convert_units($this->getLastValue($i),$this->items[$i]["units"])); - } - else - { - $str=sprintf("%s: %s [ no data ]", - str_pad($this->items[$i]["host"],$max_host_len," "), - str_pad($this->items[$i]["description"],$max_desc_len," ")); - } - - ImageFilledRectangle($this->im,$this->shiftXleft,$this->sizeY+$this->shiftY+62+12*$i,$this->shiftXleft+5,$this->sizeY+$this->shiftY+5+62+12*$i,$color); - ImageRectangle($this->im,$this->shiftXleft,$this->sizeY+$this->shiftY+62+12*$i,$this->shiftXleft+5,$this->sizeY+$this->shiftY+5+62+12*$i,$this->GetColor("Black No Alpha")); - - ImageString($this->im, 2, - $this->shiftXleft+9, - $this->sizeY+$this->shiftY+(62-5)+12*$i, - $str, - $this->GetColor("Black No Alpha")); - } - - if($this->sizeY < 120) return; - - foreach($this->triggers as $trigger) - { - ImageFilledEllipse($this->im, - $this->shiftXleft + 2, - $this->sizeY+$this->shiftY+2+62+12*$i, - 6, - 6, - $this->GetColor($trigger["color"])); - - ImageEllipse($this->im, - $this->shiftXleft + 2, - $this->sizeY+$this->shiftY+2+62+12*$i, - 6, - 6, - $this->GetColor("Black No Alpha")); - - ImageString( - $this->im, - 2, - $this->shiftXleft+9, - $this->sizeY+$this->shiftY+(62-5)+12*$i, - $trigger['description'], - $this->GetColor("Black No Alpha")); - ++$i; - } - } - - function drawElement( - &$data, $from, $to, - $minX, $maxX, $minY, $maxY, - $drawtype, $max_color, $avg_color, $min_color, $minmax_color, - $calc_fnc, - $axisside - ) - { - if(!isset($data->max[$from]) || !isset($data->max[$to])) return; - - $oxy = $this->oxy[$axisside]; - $zero = $this->zero[$axisside]; - $unit2px = $this->unit2px[$axisside]; - - $shift_min_from = $shift_min_to = 0; - $shift_max_from = $shift_max_to = 0; - $shift_avg_from = $shift_avg_to = 0; - - if(isset($data->shift_min[$from])) $shift_min_from = $data->shift_min[$from]; - if(isset($data->shift_min[$to])) $shift_min_to = $data->shift_min[$to]; - - if(isset($data->shift_max[$from])) $shift_max_from = $data->shift_max[$from]; - if(isset($data->shift_max[$to])) $shift_max_to = $data->shift_max[$to]; - - if(isset($data->shift_avg[$from])) $shift_avg_from = $data->shift_avg[$from]; - if(isset($data->shift_avg[$to])) $shift_avg_to = $data->shift_avg[$to]; -/**/ - $min_from = $data->min[$from] + $shift_min_from; - $min_to = $data->min[$to] + $shift_min_to; - - $max_from = $data->max[$from] + $shift_max_from; - $max_to = $data->max[$to] + $shift_max_to; - - $avg_from = $data->avg[$from] + $shift_avg_from; - $avg_to = $data->avg[$to] + $shift_avg_to; - - $x1 = $from + $this->shiftXleft - 1; - $x2 = $to + $this->shiftXleft; - -// SDI($max_from." : ".$max_to." : ".$oxy); - - $y1min = $zero - ($min_from-$oxy)/$unit2px; - $y2min = $zero - ($min_to-$oxy)/$unit2px; - - $y1max = $zero - ($max_from-$oxy)/$unit2px; - $y2max = $zero - ($max_to-$oxy)/$unit2px; - - $y1avg = $zero - ($avg_from-$oxy)/$unit2px; - $y2avg = $zero - ($avg_to-$oxy)/$unit2px; //*/ - - switch($calc_fnc){ - case CALC_FNC_MAX: - $y1 = $y1max; - $y2 = $y2max; - $shift_from = $shift_max_from; - $shift_to = $shift_max_to; - break; - case CALC_FNC_MIN: - $y1 = $y1min; - $y2 = $y2min; - $shift_from = $shift_min_from; - $shift_to = $shift_min_to; - break; - case CALC_FNC_ALL: - $a[0] = $x1; $a[1] = $y1max; - $a[2] = $x1; $a[3] = $y1min; - $a[4] = $x2; $a[5] = $y2min; - $a[6] = $x2; $a[7] = $y2max; - - ImageFilledPolygon($this->im,$a,4,$minmax_color); - ImageLine($this->im,$x1,$y1max,$x2,$y2max,$max_color); - ImageLine($this->im,$x1,$y1min,$x2,$y2min,$min_color); - - /* don't use break, avg must be drawed in this statement */ - // break; - case CALC_FNC_AVG: - /* don't use break, avg must be drawed in this statement */ - // break; - default: - $y1 = $y1avg; - $y2 = $y2avg; - $shift_from = $shift_avg_from ; - $shift_to = $shift_avg_to; - } - - $shift_from -= ($shift_from != 0)?($oxy):(0); - $shift_to -= ($shift_to != 0)?($oxy):(0); - - $y1_shift = $zero - $shift_from/$unit2px; - $y2_shift = $zero - $shift_to/$unit2px;//*/ - - /* draw main line */ - switch($drawtype) - { - case GRAPH_ITEM_DRAWTYPE_BOLD_LINE: - ImageLine($this->im,$x1,$y1+1,$x2,$y2+1,$avg_color); - // break; /* don't use break, must be drawed line also */ - case GRAPH_ITEM_DRAWTYPE_LINE: - ImageLine($this->im,$x1,$y1,$x2,$y2,$avg_color); - break; - case GRAPH_ITEM_DRAWTYPE_FILLED_REGION: - $a[0] = $x1; $a[1] = $y1; - $a[2] = $x1; $a[3] = $y1_shift; - $a[4] = $x2; $a[5] = $y2_shift; - $a[6] = $x2; $a[7] = $y2; - -// SDI($a); - - ImageFilledPolygon($this->im,$a,4,$avg_color); - break; - case GRAPH_ITEM_DRAWTYPE_DOT: - ImageFilledRectangle($this->im,$x1-1,$y1-1,$x1+1,$y1+1,$avg_color); - ImageFilledRectangle($this->im,$x2-1,$y2-1,$x2+1,$y2+1,$avg_color); - break; - case GRAPH_ITEM_DRAWTYPE_DASHED_LINE: - if( function_exists('imagesetstyle') ){ - - /* Use ImageSetStyle+ImageLIne instead of bugged ImageDashedLine */ - $style = array($avg_color, $avg_color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); - ImageSetStyle($this->im, $style); - ImageLine($this->im,$x1,$y1,$x2,$y2,IMG_COLOR_STYLED); - } - else{ - ImageDashedLine($this->im,$x1,$y1,$x2,$y2,$avg_color); - } - break; - } - } - -// Calculation of minimum Y axis - function calculateMinY($side){ - if($this->yaxistype==GRAPH_YAXIS_TYPE_FIXED){ - return $this->yaxismin; - } - else{ - unset($minY); - for($i=0;$i<$this->num;$i++){ - - if($this->items[$i]["axisside"] != $side) - continue; - - foreach(array(GRAPH_ITEM_SIMPLE, GRAPH_ITEM_AGGREGATED) as $type){ - - if(!isset($this->data[$this->items[$i]["itemid"]][$type])) - continue; - - $data = &$this->data[$this->items[$i]["itemid"]][$type]; - - if(!isset($data)) continue; - - if($type == GRAPH_ITEM_AGGREGATED) - $calc_fnc = CALC_FNC_ALL; - else - $calc_fnc = $this->items[$i]["calc_fnc"]; - - switch($calc_fnc){ - case CALC_FNC_ALL: /* use min */ - case CALC_FNC_MIN: $val = $data->min; $shift_val = $data->shift_min; break; - case CALC_FNC_MAX: $val = $data->max; $shift_val = $data->shift_max; break; - case CALC_FNC_AVG: - default: $val = $data->avg; $shift_val = $data->shift_avg; - } - - if(!isset($val)) continue; - - if($this->type == GRAPH_TYPE_STACKED){ - $min_val_shift = min(count($val), count($shift_val)); - for($ci=0; $ci < $min_val_shift; $ci++){ - if($shift_val[$ci] < 0){ - $val[$ci] += $shift_val[$ci]; - } - } - - } - - if(!isset($minY)){ - if(isset($val) && count($val) > 0){ - $minY = min($val); - } - } - else{ - $minY = min($minY, min($val)); - } - } - } - - if(isset($minY)&&($minY>0)){ - $minY = $minY - ($minY * 0.2) - 0.05; - } - elseif(isset($minY)&&($minY<0)){ - $minY = $minY + ($minY * 0.2) - 0.05; - } - else { - $minY=0; - } - - $minY = round($minY,1); - return $minY; - } + $fontnum = 4; } + $x=$this->fullSizeX/2-ImageFontWidth($fontnum)*strlen($str)/2; + ImageString($this->im, $fontnum,$x,1, $str , $this->GetColor("Dark Red No Alpha")); + } -// Calculation of maximum Y of a side (left/right) - function calculateMaxY($side) - { - if($this->yaxistype==GRAPH_YAXIS_TYPE_FIXED) - { - return $this->yaxismax; - } - else - { - - unset($maxY); - for($i=0;$i<$this->num;$i++) - { - if($this->items[$i]["axisside"] != $side) - continue; - - foreach(array(GRAPH_ITEM_SIMPLE, GRAPH_ITEM_AGGREGATED) as $type) - { - if(!isset($this->data[$this->items[$i]["itemid"]][$type])) - continue; - - $data = &$this->data[$this->items[$i]["itemid"]][$type]; - - if(!isset($data)) continue; - - if($type == GRAPH_ITEM_AGGREGATED) - $calc_fnc = CALC_FNC_ALL; - else - $calc_fnc = $this->items[$i]["calc_fnc"]; + function setHeader($header) + { + $this->header=$header; + } - switch($calc_fnc) - { - case CALC_FNC_ALL: /* use max */ - case CALC_FNC_MAX: $val = $data->max; $shift_val = $data->shift_max; break; - case CALC_FNC_MIN: $val = $data->min; $shift_val = $data->shift_min; break; - case CALC_FNC_AVG: - default: $val = $data->avg; $shift_val = $data->shift_avg; - } - - if(!isset($val)) continue; - for($ci=0; $ci < min(count($val),count($shift_val)); $ci++) $val[$ci] += $shift_val[$ci]; + function drawLogo() + { + ImageStringUp($this->im,0,$this->fullSizeX-10,$this->fullSizeY-50, "http://www.zabbix.com", $this->GetColor("Gray")); + } - if(!isset($maxY)) - { - if(isset($val) && count($val) > 0) - { - $maxY = max($val); - } - } - else - { - $maxY = max($maxY, max($val)); - } - - } - } + function GetColor($color,$alfa=50){ - if(isset($maxY)&&($maxY>0)){ - -/* $exp = round(log10($maxY)); - $mant = $maxY/pow(10,$exp); - - $mant=((round(($mant*11)/6)-1)*6)/10; - $maxY = $mant*pow(10,$exp);//*/ - - $maxY = round($maxY,1) + round($maxY,1)*0.2 + 0.05; - } - elseif(isset($maxY)&&($maxY<0)){ - $maxY = round($maxY,1) - round($maxY,1)*0.2 + 0.05; - } - else { - $maxY=0.3; - } - return $maxY; - } - } - - function selectData() - { - global $DB_TYPE; - - $this->data = array(); - - $now = time(NULL); - - if(isset($this->stime)) - { - $this->from_time = $this->stime; - $this->to_time = $this->stime + $this->period; - } - else - { - $this->to_time = $now - 3600 * $this->from; - $this->from_time = $this->to_time - $this->period; - } - - $p = $this->to_time - $this->from_time; // graph size in time - $z = $p - $this->from_time % $p; //<strong></strong> - $x = $this->sizeX; // graph size in px - - for($i=0; $i < $this->num; $i++) - { - $type = $this->items[$i]["calc_type"]; - - if($type == GRAPH_ITEM_AGGREGATED) { - /* skip current period */ - $from_time = $this->from_time - $this->period * $this->items[$i]["periods_cnt"]; - $to_time = $this->from_time; - } else { - $from_time = $this->from_time; - $to_time = $this->to_time; - } - - $calc_field = 'round('.$x.'*(mod(clock+'.$z.','.$p.'))/('.$p.'),0)'; /* required for 'group by' support of Oracle */ - $sql_arr = array(); - if(($this->period / $this->sizeX) <= (ZBX_MAX_TREND_DIFF / ZBX_GRAPH_MAX_SKIP_CELL)) - { - array_push($sql_arr, - 'select itemid,'.$calc_field.' as i,'. - ' count(*) as count,avg(value) as avg,min(value) as min,'. - ' max(value) as max,max(clock) as clock'. - ' from history where itemid='.$this->items[$i]['itemid'].' and clock>='.$from_time. - ' and clock<='.$to_time.' group by itemid,'.$calc_field - , - - 'select itemid,'.$calc_field.' as i,'. - ' count(*) as count,avg(value) as avg,min(value) as min,'. - ' max(value) as max,max(clock) as clock'. - ' from history_uint where itemid='.$this->items[$i]['itemid'].' and clock>='.$from_time. - ' and clock<='.$to_time.' group by itemid,'.$calc_field - ); - } - else - { - array_push($sql_arr, - 'select itemid,'.$calc_field.' as i,'. - ' sum(num) as count,avg(value_avg) as avg,min(value_min) as min,'. - ' max(value_max) as max,max(clock) as clock'. - ' from trends where itemid='.$this->items[$i]['itemid'].' and clock>='.$from_time. - ' and clock<='.$to_time.' group by itemid,'.$calc_field - ); - } - - $curr_data = &$this->data[$this->items[$i]["itemid"]][$type]; - $curr_data->count = NULL; - $curr_data->min = NULL; - $curr_data->max = NULL; - $curr_data->avg = NULL; - $curr_data->clock = NULL; - - foreach($sql_arr as $sql) - { - $result=DBselect($sql); - while($row=DBfetch($result)) - { - $idx=$row["i"]-1; - if($idx<0) continue; - /* -------------------------------------------------- - We are taking graph on 1px more than we need, - and here we are skiping first px, because of MOD (in SELECT), - it combines prelast point (it would be last point if not that 1px in begining) - and first point, but we still losing prelast point :( - --------------------------------------------------*/ - - $curr_data->count[$idx] = $row["count"]; - $curr_data->min[$idx] = $row["min"]; - $curr_data->max[$idx] = $row["max"]; - $curr_data->avg[$idx] = $row["avg"]; - $curr_data->clock[$idx] = $row["clock"]; - $curr_data->shift_min[$idx] = 0; - $curr_data->shift_max[$idx] = 0; - $curr_data->shift_avg[$idx] = 0; -// SDI($idx.' : '.$row['clock'].' : '.$row['count'].' : '.round($x * (($row['clock']+$z) % $p) / $p, 0)); - - if($this->type == GRAPH_TYPE_STACKED){ - $this->CheckGraphOrientation($curr_data->min[$idx]); - } - } - unset($row); - } - /* calculate missed points */ - $first_idx = 0; - /* - first_idx - last existed point - ci - current index - cj - count of missed in onetime - dx - offset to first value (count to last existed point) - //*/ - - for($ci = 0, $cj=0; $ci < $this->sizeX; $ci++) - { - if(!isset($curr_data->count[$ci]) || $curr_data->count[$ci] == 0) - { - $curr_data->count[$ci] = 0; - $curr_data->shift_min[$ci] = 0; - $curr_data->shift_max[$ci] = 0; - $curr_data->shift_avg[$ci] = 0; - $cj++; - } - else if($cj > 0) - { - $dx = $cj + 1; - - $first_idx = $ci - $dx; - - if($first_idx < 0) $first_idx = $ci; // if no data from start of graph get current data as first data - - for(;$cj > 0; $cj--){ - -/* if(($first_idx == $ci) && ($dx < ($this->sizeX)) && ($this->type == GRAPH_TYPE_STACKED)){ - $curr_data->count[$ci - ($dx - $cj)] = 1; - } - else //*/ - if(($dx < ($this->sizeX/20)) && ($this->type == GRAPH_TYPE_STACKED)){ - $curr_data->count[$ci - ($dx - $cj)] = 1; - }//*/ - - foreach(array('clock','min','max','avg') as $var_name){ - $var = &$curr_data->$var_name; - - if($first_idx == $ci && $var_name == 'clock'){ - $var[$ci - ($dx - $cj)] = $var[$first_idx] - (($p / $this->sizeX) * ($dx - $cj)); - continue; - } - - $dy = $var[$ci] - $var[$first_idx]; - $var[$ci - ($dx - $cj)] = $var[$first_idx] + ($cj * $dy) / $dx; - } - } - } - } - - if($cj > 0 && $ci > $cj){ - $dx = $cj + 1; - - $first_idx = $ci - $dx; - - for(;$cj > 0; $cj--){ - -// if($dx < ($this->sizeX/20)) //($this->type == GRAPH_TYPE_STACKED) -// $curr_data->count[$first_idx + ($dx - $cj)] = 1; - - foreach(array('clock','min','max','avg') as $var_name){ - $var = &$curr_data->$var_name; - - if( $var_name == 'clock') - { - $var[$first_idx + ($dx - $cj)] = $var[$first_idx] + (($p / $this->sizeX) * ($dx - $cj)); - continue; - } - $var[$first_idx + ($dx - $cj)] = $var[$first_idx]; - } - } - } - /* end of missed points calculation */ - } - - /* calculte shift for stacked graphs */ + if(isset($this->colors[$color])) + return $this->colors[$color]; - if($this->type == GRAPH_TYPE_STACKED) - { - for($i=1; $i<$this->num; $i++) - { - $curr_data = &$this->data[$this->items[$i]["itemid"]][$this->items[$i]["calc_type"]]; - - if(!isset($curr_data)) continue; - - for($j = $i-1; $j >= 0; $j--) - { - if($this->items[$j]["axisside"] != $this->items[$i]["axisside"]) continue; - - $prev_data = &$this->data[$this->items[$j]["itemid"]][$this->items[$j]["calc_type"]]; - - if(!isset($prev_data)) continue; - - for($ci = 0; $ci < $this->sizeX; $ci++) - { - foreach(array('min','max','avg') as $var_name) - { - $shift_var_name = 'shift_'.$var_name; - $curr_shift = &$curr_data->$shift_var_name; - $curr_var = &$curr_data->$var_name; - $prev_shift = &$prev_data->$shift_var_name; - $prev_var = &$prev_data->$var_name; - $curr_shift[$ci] = $prev_var[$ci] + $prev_shift[$ci]; - } - } - break; - } - } - } - /* end calculation of stacked graphs */ - } - - function DrawLeftSide() + $RGB = array( + hexdec('0x'.substr($color, 0,2)), + hexdec('0x'.substr($color, 2,2)), + hexdec('0x'.substr($color, 4,2)) + ); + + if(isset($alfa) && + function_exists("ImageColorExactAlpha") && + function_exists("ImageCreateTrueColor") && + @ImageCreateTrueColor(1,1) + ) { - if($this->yaxisleft == 1) - { - $minY = $this->m_minY[GRAPH_YAXIS_SIDE_LEFT]; - $maxY = $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT]; - - for($item=0;$item<$this->num;$item++) - { - if($this->items[$item]["axisside"] == GRAPH_YAXIS_SIDE_LEFT) - { - $units=$this->items[$item]["units"]; - break; - } - } - for($i=0;$i<=6;$i++) - { - $str = str_pad(convert_units($this->sizeY*$i/6*($maxY-$minY)/$this->sizeY+$minY,$units),10," ", STR_PAD_LEFT); - ImageString($this->im, 1, 5, $this->sizeY-$this->sizeY*$i/6-4+$this->shiftY, $str, $this->GetColor("Dark Red No Alpha")); - } - if(($this->zero[GRAPH_YAXIS_SIDE_LEFT] != $this->sizeY+$this->shiftY) && - ($this->zero[GRAPH_YAXIS_SIDE_LEFT] != $this->shiftY)){ - imageline($this->im, - $this->shiftXleft, - $this->zero[GRAPH_YAXIS_SIDE_LEFT], - $this->shiftXleft+$this->sizeX, - $this->zero[GRAPH_YAXIS_SIDE_LEFT], - $this->GetColor(GRAPH_ZERO_LINE_COLOR_LEFT) - ); //*/ - } - } + return ImageColorExactAlpha($this->im,$RGB[0],$RGB[1],$RGB[2],$alfa); } - - function DrawRightSide() - { - if($this->yaxisright == 1) - { - $minY = $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT]; - $maxY = $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT]; - - for($item=0;$item<$this->num;$item++){ - if($this->items[$item]["axisside"] == GRAPH_YAXIS_SIDE_RIGHT){ - $units=$this->items[$item]["units"]; - break; - } - } - for($i=0;$i<=6;$i++){ - $str = str_pad(convert_units($this->sizeY*$i/6*($maxY-$minY)/$this->sizeY+$minY,$units),10," "); - ImageString($this->im, 1, $this->sizeX+$this->shiftXleft+2, $this->sizeY-$this->sizeY*$i/6-4+$this->shiftY, $str, $this->GetColor("Dark Red No Alpha")); - } - - if(($this->zero[GRAPH_YAXIS_SIDE_RIGHT] != $this->sizeY+$this->shiftY) && - ($this->zero[GRAPH_YAXIS_SIDE_RIGHT] != $this->shiftY)){ - imageline($this->im, - $this->shiftXleft, - $this->zero[GRAPH_YAXIS_SIDE_RIGHT], - $this->shiftXleft+$this->sizeX, - $this->zero[GRAPH_YAXIS_SIDE_RIGHT], - $this->GetColor(GRAPH_ZERO_LINE_COLOR_RIGHT) - ); //*/ - } - } + + return ImageColorAllocate($this->im,$RGB[0],$RGB[1],$RGB[2]); + } + + function GetShadow($color,$alfa=0){ + + if(isset($this->colorsrgb[$color])){ + $red = $this->colorsrgb[$color][0]; + $green = $this->colorsrgb[$color][1]; + $blue = $this->colorsrgb[$color][2]; + } + else{ + $red = hexdec(substr($color, 0,2)); + $green = hexdec(substr($color, 2,2)); + $blue = hexdec(substr($color, 4,2)); } - function CalcZero(){ - $left = GRAPH_YAXIS_SIDE_LEFT; - $right = GRAPH_YAXIS_SIDE_RIGHT; - - $this->unit2px[$right] = ($this->m_maxY[$right] - $this->m_minY[$right])/$this->sizeY; - $this->unit2px[$left] = ($this->m_maxY[$left] - $this->m_minY[$left])/$this->sizeY; - - if($this->m_minY[$right]>0){ - $this->zero[$right] = $this->sizeY+$this->shiftY; - $this->oxy[$right] = min(abs($this->m_minY[$right]),abs($this->m_maxY[$right])); - } - elseif($this->m_maxY[$right]<0) { - $this->zero[$right] = $this->shiftY; - $this->oxy[$right] = min(abs($this->m_minY[$right]),abs($this->m_maxY[$right])); - } - else{ - $this->zero[$right] = $this->sizeY+$this->shiftY - (int)abs($this->m_minY[$right]/$this->unit2px[$right]); - $this->oxy[$right] = 0; - } - - if($this->m_minY[$left]>0){ - $this->zero[$left] = $this->sizeY+$this->shiftY; - $this->oxy[$left] = min(abs($this->m_minY[$left]),abs($this->m_maxY[$left])); - } - elseif($this->m_maxY[$left]<0){ - $this->zero[$left] = $this->shiftY; - $this->oxy[$left] = min(abs($this->m_minY[$left]),abs($this->m_maxY[$left])); - } - else{ - $this->zero[$left] = $this->sizeY+$this->shiftY - (int)abs($this->m_minY[$left]/$this->unit2px[$left]); - $this->oxy[$left] = 0; - } + if($this->sum > 0){ + $red = (int)($red * 0.6); + $green = (int)($green * 0.6); + $blue = (int)($blue * 0.6); } - - function Draw() + + $RGB = array($red,$green,$blue); + + if(isset($alfa) && + function_exists("ImageColorExactAlpha") && + function_exists("ImageCreateTrueColor") && + @ImageCreateTrueColor(1,1) + ) { - $start_time=getmicrotime(); - - set_image_header(); - - check_authorisation(); - - $this->selectData(); - - $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = $this->calculateMinY(GRAPH_YAXIS_SIDE_LEFT); - $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = $this->calculateMinY(GRAPH_YAXIS_SIDE_RIGHT); - $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT] = $this->calculateMaxY(GRAPH_YAXIS_SIDE_LEFT); - $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT] = $this->calculateMaxY(GRAPH_YAXIS_SIDE_RIGHT); - - $this->updateShifts(); - $this->calcTriggers(); - $this->CalcZero(); - - $this->fullSizeX = $this->sizeX+$this->shiftXleft+$this->shiftXright+1; - $this->fullSizeY = $this->sizeY+$this->shiftY+62+12*($this->num+ (($this->sizeY < 120) ? 0 : count($this->triggers)))+8; - - if(function_exists("ImageColorExactAlpha")&&function_exists("ImageCreateTrueColor")&&@imagecreatetruecolor(1,1)) - $this->im = imagecreatetruecolor($this->fullSizeX,$this->fullSizeY); - else - $this->im = imagecreate($this->fullSizeX,$this->fullSizeY); - - - $this->initColors(); - $this->drawRectangle(); - $this->drawHeader(); - - if($this->num==0) - { -// $this->noDataFound(); - } - - $this->drawWorkPeriod(); - $this->drawGrid(); - - $maxX = $this->sizeX; - - // For each metric - for($item = 0; $item < $this->num; $item++) - { - $minY = $this->m_minY[$this->items[$item]["axisside"]]; - $maxY = $this->m_maxY[$this->items[$item]["axisside"]]; - - $data = &$this->data[$this->items[$item]["itemid"]][$this->items[$item]["calc_type"]]; - - if(!isset($data)) continue; - - if($this->items[$item]["calc_type"] == GRAPH_ITEM_AGGREGATED){ - $drawtype = GRAPH_ITEM_DRAWTYPE_LINE; - - $max_color = $this->GetColor("HistoryMax"); - $avg_color = $this->GetColor("HistoryAvg"); - $min_color = $this->GetColor("HistoryMin"); - $minmax_color = $this->GetColor("HistoryMinMax"); - - $calc_fnc = CALC_FNC_ALL; - } - elseif($this->type == GRAPH_TYPE_STACKED){ - $drawtype = $this->items[$item]["drawtype"]; - - $max_color = $this->GetColor("ValueMax",GRAPH_STACKED_ALFA); - $avg_color = $this->GetColor($this->items[$item]["color"],GRAPH_STACKED_ALFA); - $min_color = $this->GetColor("ValueMin",GRAPH_STACKED_ALFA); - $minmax_color = $this->GetColor("ValueMinMax",GRAPH_STACKED_ALFA); - - $calc_fnc = $this->items[$item]["calc_fnc"]; - } - else{ - $drawtype = $this->items[$item]["drawtype"]; - - $max_color = $this->GetColor("ValueMax"); - $avg_color = $this->GetColor($this->items[$item]["color"]); - $min_color = $this->GetColor("ValueMin"); - $minmax_color = $this->GetColor("ValueMinMax"); - - $calc_fnc = $this->items[$item]["calc_fnc"]; - } - // For each X - for($i = 1, $j = 0; $i < $maxX; $i++) // new point - { - if(($data->count[$i] == 0) && ($i != ($maxX-1))) continue; - - $diff = abs($data->clock[$i] - $data->clock[$j]); - $cell = ($this->to_time - $this->from_time)/$this->sizeX; - $delay = $this->items[$item]["delay"]; - - if($cell > $delay) - $draw = (boolean) ($diff < ZBX_GRAPH_MAX_SKIP_CELL * $cell); - else - $draw = (boolean) ($diff < ZBX_GRAPH_MAX_SKIP_DELAY * $delay); - - if($draw == false && $this->items[$item]["calc_type"] == GRAPH_ITEM_AGGREGATED) - $draw = $i - $j < 5; - - if($this->items[$item]["type"] == ITEM_TYPE_TRAPPER) - $draw = true; -// SDI($draw); - if($draw){ - - $this->drawElement( - $data, - $i, $j, - 0, $this->sizeX, - $minY, $maxY, - $drawtype, - $max_color, - $avg_color, - $min_color, - $minmax_color, - $calc_fnc, - $this->items[$item]['axisside'] - ); - } -// echo "\nDraw II \n"; printf("%0.4f",(getmicrotime()-$start_time)); - - $j = $i; - } - } - - $this->DrawLeftSide(); - $this->DrawRightSide(); - $this->drawTriggers(); - - $this->drawLogo(); - - $this->drawLegend(); - - $end_time=getmicrotime(); - $str=sprintf("%0.2f",(getmicrotime()-$start_time)); - ImageString($this->im, 0,$this->fullSizeX-120,$this->fullSizeY-12,"Generated in $str sec", $this->GetColor("Gray")); - - unset($this->items, $this->data); - - ImageOut($this->im); + return ImageColorExactAlpha($this->im,$RGB[0],$RGB[1],$RGB[2],$alfa); } + + return ImageColorAllocate($this->im,$RGB[0],$RGB[1],$RGB[2]); } + +} ?> diff --git a/frontends/php/include/classes/pie.inc.php b/frontends/php/include/classes/pie.inc.php new file mode 100644 index 00000000..dd14bb41 --- /dev/null +++ b/frontends/php/include/classes/pie.inc.php @@ -0,0 +1,610 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2007 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php +require_once "include/classes/graph.inc.php"; + +class Pie extends Graph{ + +function Pie($type = GRAPH_TYPE_PIE){ + parent::Graph($type); + + $this->background = false; + $this->sum = false; + $this->exploderad = 1; + $this->exploderad3d = 3; + $this->graphheight3d = 12; + $this->shiftlegendright = 17*7 + 7 + 10; // count of static chars * px/char + for color rectangle + space + $this->drawlegendallow = 1; +} + +function switchlegend($type=false){ + if($type && is_numeric($type)){ + $this->drawlegendallow = $type; + return $this->drawlegendallow; + } elseif($this->drawlegendallow == 0){ + $this->drawlegendallow = 1; + } else { + $this->drawlegendallow = 0; + } +return $this->drawlegendallow; +} + +function AddItem($itemid, $calc_fnc=CALC_FNC_AVG,$color=null, $type=null, $periods_cnt=null) +{ + if($this->type == GRAPH_TYPE_STACKED /* stacked graph */) + $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION; + + $this->items[$this->num] = get_item_by_itemid($itemid); + $this->items[$this->num]['description']=item_description($this->items[$this->num]['description'],$this->items[$this->num]['key_']); + $host=get_host_by_hostid($this->items[$this->num]['hostid']); + + $this->items[$this->num]['host'] = $host['host']; + $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color; + $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc; + $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type; + $this->items[$this->num]['periods_cnt'] = is_null($periods_cnt) ? 0 : $periods_cnt; + + $this->num++; +} + + +function selectData(){ + global $DB_TYPE; + + $this->data = array(); + + $now = time(NULL); + + if(isset($this->stime)){ + $this->from_time = $this->stime; + $this->to_time = $this->stime + $this->period; + } + else{ + $this->to_time = $now - 3600 * $this->from; + $this->from_time = $this->to_time - $this->period; + } + + $p = $this->to_time - $this->from_time; // graph size in time + $z = $p - $this->from_time % $p; //<strong></strong> + $x = $this->sizeX; // graph size in px + $strvaluelength = 0; // we need to know how long in px will be our legend + + for($i=0; $i < $this->num; $i++){ + + $type = $this->items[$i]['calc_type']; + + $from_time = $this->from_time; + $to_time = $this->to_time; + +// $calc_field = 'round('.$x.'*(mod(clock+'.$z.','.$p.'))/('.$p.'),0)'; /* required for 'group by' support of Oracle */ + $sql_arr = array(); + + if(($this->period / $this->sizeX) <= (ZBX_MAX_TREND_DIFF / ZBX_GRAPH_MAX_SKIP_CELL)){ + array_push($sql_arr, + 'SELECT h.itemid, i.lastvalue as lst, '. + ' avg(h.value) AS avg,min(h.value) AS min, '. + ' max(h.value) AS max,max(h.clock) AS clock '. + ' FROM history AS h LEFT JOIN items AS i ON h.itemid = i.itemid'. + ' WHERE h.itemid='.$this->items[$i]['itemid']. + ' AND h.clock>='.$from_time. + ' AND h.clock<='.$to_time. + ' GROUP BY h.itemid' + , + + 'SELECT hu.itemid, i.lastvalue as lst, '. + ' avg(hu.value) AS avg,min(hu.value) AS min,'. + ' max(hu.value) AS max,max(hu.clock) AS clock'. + ' FROM history_uint AS hu LEFT JOIN items AS i ON hu.itemid = i.itemid'. + ' WHERE hu.itemid='.$this->items[$i]['itemid']. + ' AND hu.clock>='.$from_time. + ' AND hu.clock<='.$to_time. + ' GROUP BY hu.itemid' + ); + } + else{ + array_push($sql_arr, + 'SELECT t.itemid, i.lastvalue as lst, '. + ' avg(t.value_avg) AS avg,min(t.value_min) AS min,'. + ' max(t.value_max) AS max,max(t.clock) AS clock'. + ' FROM trends AS t LEFT JOIN items AS i ON t.itemid = i.itemid'. + ' WHERE t.itemid='.$this->items[$i]['itemid']. + ' AND t.clock>='.$from_time. + ' AND t.clock<='.$to_time. + ' GROUP BY t.itemid' + ); + } + + $curr_data = &$this->data[$this->items[$i]['itemid']][$type]; + $curr_data->min = NULL; + $curr_data->max = NULL; + $curr_data->avg = NULL; + $curr_data->clock = NULL; + + foreach($sql_arr as $sql){ + $result=DBselect($sql); + + while($row=DBfetch($result)){ + $curr_data->min = $row['min']; + $curr_data->max = $row['max']; + $curr_data->avg = $row['avg']; + $curr_data->lst = $row['lst']; + $curr_data->clock = $row['clock']; + $curr_data->shift_min = 0; + $curr_data->shift_max = 0; + $curr_data->shift_avg = 0; + } + unset($row); + } + + switch($this->items[$i]['calc_fnc']){ + case CALC_FNC_MIN: + $item_value = abs($curr_data->min); + + break; + case CALC_FNC_MAX: + $item_value = abs($curr_data->max); + break; + case CALC_FNC_LST: + $item_value = abs($curr_data->lst); + break; + case CALC_FNC_AVG: + default: + $item_value = abs($curr_data->avg); + } + + if($type == GRAPH_ITEM_SUM){ + $this->background = $i; + $graph_sum = $item_value; + } + + $this->sum += $item_value; + $strvaluelenght = max($strvaluelenght,strlen($item_value)); + } + + if(isset($graph_sum)) $this->sum = $graph_sum; + $this->shiftlegendright += $strvaluelenght * 6; +} + + +/*function set3DAngle($angle = 70){ + if(is_numeric($angle) && ($angle < 85) && ($angle > 10)){ + $this->angle3d = (int) $angle; + } + else { + $this->angle3d = 70; + } +}//*/ + +function SwitchPie3D($type = false){ + if($type){ + $this->type = $type; + } + else{ + switch($this->type){ + case GRAPH_TYPE_EXPLODED: + $this->type = GRAPH_TYPE_3D_EXPLODED; + break; + case GRAPH_TYPE_3D_EXPLODED: + $this->type = GRAPH_TYPE_EXPLODED; + break; + case GRAPH_TYPE_3D: + $this->type = GRAPH_TYPE_PIE; + break; + case GRAPH_TYPE_PIE: + $this->type = GRAPH_TYPE_3D; + break; + default: + $this->type = GRAPH_TYPE_PIE; + } + } +return $this->type; +} + +function SwitchPieExploded($type){ + if($type){ + $this->type = $type; + } + else{ + switch($this->type){ + case GRAPH_TYPE_EXPLODED: + $this->type = GRAPH_TYPE_PIE; + break; + case GRAPH_TYPE_3D_EXPLODED: + $this->type = GRAPH_TYPE_3D; + break; + case GRAPH_TYPE_3D: + $this->type = GRAPH_TYPE_3D_EXPLODED; + break; + case GRAPH_TYPE_PIE: + $this->type = GRAPH_TYPE_EXPLODED; + break; + default: + $this->type = GRAPH_TYPE_PIE; + } + } +return $this->type; +} + +function calc3dhight($height){ + $this->graphheight3d = (int) ($height/20); +} + +function calcExplodedCenter($anglestart,$angleend,$x,$y,$count){ + $count *= $this->exploderad; + $anglemid = (int) (($anglestart + $angleend) / 2 ); + + $y+= round($count * sin(deg2rad($anglemid))); + $x+= round($count * cos(deg2rad($anglemid))); +// SDI($x.' xy '.$y); + +return array($x,$y); +} + +function calcExplodedRadius($sizeX,$sizeY,$count){ + $count *= $this->exploderad*2; + $sizeX -= $count; + $sizeY -= $count; +return array($sizeX,$sizeY); +} + +function calc3DAngle($sizeX,$sizeY){ + $sizeY *= (GRAPH_3D_ANGLE / 90); +return array($sizeX,round($sizeY)); +} + +function drawLegend(){ + + $shiftY = $this->shiftY + $this->shiftYLegend; + + $max_host_len=0; + $max_desc_len=0; + + for($i=0;$i<$this->num;$i++){ + if(strlen($this->items[$i]['host'])>$max_host_len) $max_host_len=strlen($this->items[$i]['host']); + if(strlen($this->items[$i]['description'])>$max_desc_len) $max_desc_len=strlen($this->items[$i]['description']); + } + + for($i=0;$i<$this->num;$i++){ + + $color = $this->GetColor($this->items[$i]['color']); + $data = &$this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']]; + + switch($this->items[$i]['calc_fnc']){ + case CALC_FNC_MIN: + $fnc_name = 'min'; + $datavalue = $data->min; + break; + case CALC_FNC_MAX: + $fnc_name = 'max'; + $datavalue = $data->max; + break; + case CALC_FNC_LST: + $fnc_name = 'last'; + $datavalue = $data->lst; + break; + case CALC_FNC_AVG: + default: + $fnc_name = 'avg'; + $datavalue = $data->avg; + } + + $proc = ($datavalue * 100)/ $this->sum; + + if(isset($data) && isset($datavalue)){ + $strvalue = sprintf("Value: %0.4f (%0.2f%s)",$datavalue,$proc,'%'); + $str = sprintf("%s: %s [%s] ", + str_pad($this->items[$i]['host'],$max_host_len,' '), + str_pad($this->items[$i]['description'],$max_desc_len,' '), + $fnc_name); + } + else{ + $strvalue = sprintf("Value: no data"); + $str=sprintf("%s: %s [ no data ]", + str_pad($this->items[$i]['host'],$max_host_len,' '), + str_pad($this->items[$i]['description'],$max_desc_len,' ')); + } + + ImageFilledRectangle($this->im,$this->shiftXleft,$this->sizeY+$shiftY+12*$i,$this->shiftXleft+5,$this->sizeY+$shiftY+5+12*$i,$color); + ImageRectangle($this->im,$this->shiftXleft,$this->sizeY+$shiftY+12*$i,$this->shiftXleft+5,$this->sizeY+$shiftY+5+12*$i,$this->GetColor('Black No Alpha')); + + ImageString($this->im, 2, + $this->shiftXleft+9, + $this->sizeY+$shiftY-5+12*$i, + $str, + $this->GetColor('Black No Alpha')); + + $shiftX = $this->fullSizeX - $this->shiftlegendright - $this->shiftXright + 10; +// SDI($shiftX.','.$this->sizeX); + + ImageFilledRectangle($this->im,$shiftX,$this->shiftY+10+5+12*$i,$shiftX+5,$this->shiftY+10+10+12*$i,$color); + ImageRectangle($this->im,$shiftX,$this->shiftY+10+5+12*$i,$shiftX+5,$this->shiftY+10+10+12*$i,$this->GetColor('Black No Alpha')); + + ImageString($this->im, 2, + $shiftX+9, + $this->shiftY+10+12*$i, + $strvalue, + $this->GetColor('Black No Alpha')); + } + + if($this->sizeY < 120) return; +} + + +function drawElementPie($values){ + + $sum = $this->sum; + + if($this->background !== false){ + $least = 0; + foreach($values as $item => $value){ +// SDI($item.' : '.$value.' , '.$this->background); + if($item != $this->background){ + $least += $value; + } + } + $values[$this->background] -= $least; + } + + if($sum <= 0){ + $this->items[0]['color'] = 'FFFFFF'; + $values = array(0 => 1); + $sum = 1; + } +// asort($values); + + $sizeX = $this->sizeX; + $sizeY = $this->sizeY; + + if($this->type == GRAPH_TYPE_EXPLODED){ + list($sizeX,$sizeY) = $this->calcExplodedRadius($sizeX,$sizeY,count($values)); + } else { + $sizeX =(int) $sizeX * 0.95; + $sizeY =(int) $sizeY * 0.95; + } + + $xc = $x = (int) $this->sizeX/2 + ($this->shiftXleft); + $yc = $y = (int) $this->sizeY/2 + $this->shiftY; + + $anglestart = 0; + $angleend = 0; + foreach($values as $item => $value){ + $angleend += (int)(360 * $value/$sum)+1; + $angleend = ($angleend > 360)?(360):($angleend); + if(($angleend - $anglestart) < 1) continue; + + if($this->type == GRAPH_TYPE_EXPLODED){ + list($x,$y) = $this->calcExplodedCenter($anglestart,$angleend,$xc,$yc,count($values)); + } + + imagefilledarc($this->im, $x, $y, $sizeX, $sizeY, $anglestart, $angleend, $this->GetColor($this->items[$item]['color'],0), IMG_ARC_PIE); + imagefilledarc($this->im, $x, $y, $sizeX, $sizeY, $anglestart, $angleend, $this->GetColor('Black'), IMG_ARC_PIE|IMG_ARC_EDGED|IMG_ARC_NOFILL); + $anglestart = $angleend; + } +// imageline($this->im, $xc, $yc, $xc, $yc, $this->GetColor('Black')); +} + +function drawElementPie3D($values){ + + $sum = $this->sum; + + if($this->background !== false){ + $least = 0; + foreach($values as $item => $value){ + if($item != $this->background){ + $least += $value; + } + } + $values[$this->background] -= $least; + } + + if($sum <= 0){ + $this->items[0]['color'] = 'FFFFFF'; + $values = array(0 => 1); + $sum = 1; + } +// asort($values); + + $sizeX = $this->sizeX; + $sizeY = $this->sizeY; + + $this->exploderad = $this->exploderad3d; + + if($this->type == GRAPH_TYPE_3D_EXPLODED){ + list($sizeX,$sizeY) = $this->calcExplodedRadius($sizeX,$sizeY,count($values)); + } + + list($sizeX,$sizeY) = $this->calc3DAngle($sizeX,$sizeY); + + $xc = $x = (int) $this->sizeX/2 + ($this->shiftXleft); + $yc = $y = (int) $this->sizeY/2 + $this->shiftY; + +// ----- bottom angle line ---- + $anglestart = 0; + $angleend = 0; + foreach($values as $item => $value){ + + $angleend += (int)(360 * $value/$sum) +1; + $angleend = ($angleend > 360)?(360):($angleend); + if(($angleend - $anglestart) < 1) continue; + + if($this->type == GRAPH_TYPE_3D_EXPLODED){ + list($x,$y) = $this->calcExplodedCenter($anglestart,$angleend,$xc,$yc,count($values)); + } + imagefilledarc($this->im, $x, $y+$this->graphheight3d+1, $sizeX, $sizeY, $anglestart, $angleend, $this->GetShadow($this->items[$item]['color'],0), IMG_ARC_PIE); + imagefilledarc($this->im, $x, $y+$this->graphheight3d+1, $sizeX, $sizeY, $anglestart, $angleend, $this->GetColor('Black'), IMG_ARC_PIE|IMG_ARC_EDGED|IMG_ARC_NOFILL); + $anglestart = $angleend; + }//*/ + +// ------ 3d effect ------ + for ($i = $this->graphheight3d; $i > 0; $i--) { + $anglestart = 0; + $angleend = 0; + foreach($values as $item => $value){ + $angleend += (int)(360 * $value/$sum) +1; + $angleend = ($angleend > 360)?(360):($angleend); + + if(($angleend - $anglestart) < 1) continue; + elseif($this->sum == 0) continue; + + if($this->type == GRAPH_TYPE_3D_EXPLODED){ + list($x,$y) = $this->calcExplodedCenter($anglestart,$angleend,$xc,$yc,count($values)); + } + + imagefilledarc($this->im, $x, $y+$i, $sizeX, $sizeY, $anglestart, $angleend, $this->GetShadow($this->items[$item]['color'],0), IMG_ARC_PIE); + $anglestart = $angleend; + } + } + + $anglestart = 0; + $angleend = 0; + foreach($values as $item => $value){ + + $angleend += (int)(360 * $value/$sum) +1; + $angleend = ($angleend > 360)?(360):($angleend); + if(($angleend - $anglestart) < 1) continue; + + if($this->type == GRAPH_TYPE_3D_EXPLODED){ + list($x,$y) = $this->calcExplodedCenter($anglestart,$angleend,$xc,$yc,count($values)); + } + + imagefilledarc($this->im, $x, $y, $sizeX, $sizeY, $anglestart, $angleend, $this->GetColor($this->items[$item]['color'],0), IMG_ARC_PIE); + imagefilledarc($this->im, $x, $y, $sizeX, $sizeY, $anglestart, $angleend, $this->GetColor('Black'), IMG_ARC_PIE|IMG_ARC_EDGED|IMG_ARC_NOFILL); + $anglestart = $angleend; + }//*/ +} + +function Draw(){ + $start_time=getmicrotime(); + set_image_header(); + check_authorisation(); + + $this->selectData(); + + $this->shiftY = 20; + $this->shiftYLegend = 20; + $this->shiftXleft = 10; + $this->shiftXright = 0; + + $this->fullSizeX = $this->sizeX; + $this->fullSizeY = $this->sizeY; + + if(($this->sizeX < 300) || ($this->sizeY < 200)) $this->switchlegend(0); + + if($this->drawlegendallow == 1){ + $this->sizeX -= ($this->shiftXleft+$this->shiftXright+$this->shiftlegendright); + $this->sizeY -= ($this->shiftY+$this->shiftYLegend+12*$this->num+8); + } + else { + $this->sizeX -= ($this->shiftXleft*2); + $this->sizeY -= ($this->shiftY*2); + } + +// SDI($this->sizeX.','.$this->sizeY); + + $this->sizeX = min($this->sizeX,$this->sizeY); + $this->sizeY = min($this->sizeX,$this->sizeY); + +// SDI($this->graphheight3d); + $this->calc3dhight($this->sizeY); +// SDI($this->graphheight3d); + + $this->exploderad = (int) $this->sizeX / 100; + $this->exploderad3d = (int) $this->sizeX / 60; + + if(function_exists('ImageColorExactAlpha')&&function_exists('ImageCreateTrueColor')&&@imagecreatetruecolor(1,1)) + $this->im = imagecreatetruecolor($this->fullSizeX,$this->fullSizeY); + else + $this->im = imagecreate($this->fullSizeX,$this->fullSizeY); + + + $this->initColors(); + $this->drawRectangle(); + $this->drawHeader(); + + $maxX = $this->sizeX; + + // For each metric + for($item = 0; $item < $this->num; $item++){ + $minY = $this->m_minY[$this->items[$item]['axisside']]; + $maxY = $this->m_maxY[$this->items[$item]['axisside']]; + + $data = &$this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']]; + + if(!isset($data)) continue; + + $drawtype = $this->items[$item]['drawtype']; + + $max_color = $this->GetColor('ValueMax'); + $avg_color = $this->GetColor($this->items[$item]['color']); + $min_color = $this->GetColor('ValueMin'); + $minmax_color = $this->GetColor('ValueMinMax'); + + $calc_fnc = $this->items[$item]['calc_fnc']; + + switch($calc_fnc){ + case CALC_FNC_MAX: + $values[$item] = abs($data->max); + break; + case CALC_FNC_MIN: + $values[$item] = abs($data->min); + break; + case CALC_FNC_AVG: + $values[$item] = abs($data->avg); + break; + case CALC_FNC_LST: + $values[$item] = abs($data->lst); + break; + } +// $this->sum += $values[$item]; + } +// $this->SwitchPie3D(); +// $this->SwitchPieExploded(); + + switch($this->type){ + case GRAPH_TYPE_EXPLODED: + $this->drawElementPie($values); + break; + case GRAPH_TYPE_3D: + $this->drawElementPie3D($values); + break; + case GRAPH_TYPE_3D_EXPLODED: + $this->drawElementPie3D($values); + break; + default: + $this->drawElementPie($values); + break; + } + + $this->drawLogo(); + + if($this->drawlegendallow == 1) $this->drawLegend(); + + $end_time=getmicrotime(); + $str=sprintf("%0.2f",(getmicrotime()-$start_time)); + ImageString($this->im, 0,$this->fullSizeX-120,$this->fullSizeY-12,"Generated in $str sec", $this->GetColor('Gray')); + + unset($this->items, $this->data); + + ImageOut($this->im); +} + +} +?>
\ No newline at end of file diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php index 37ed61ab..a4fa6abe 100644 --- a/frontends/php/include/defines.inc.php +++ b/frontends/php/include/defines.inc.php @@ -298,6 +298,7 @@ define('CALC_FNC_AVG', 2); define('CALC_FNC_MAX', 4); define('CALC_FNC_ALL', 7); + define('CALC_FNC_LST', 9); define('SERVICE_TIME_TYPE_UPTIME', 0); diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index 517dd0e1..34506e2d 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -2359,6 +2359,7 @@ $frmGraph = new CFormTable(S_GRAPH); $frmGraph->SetName('frm_graph'); $frmGraph->SetHelp("web.graphs.graph.php"); + $frmGraph->SetMethod('post'); $items = get_request('items', array()); @@ -2366,24 +2367,26 @@ { $frmGraph->AddVar("graphid",$_REQUEST["graphid"]); - $result=DBselect("select * from graphs where graphid=".$_REQUEST["graphid"]); + $result=DBselect("SELECT * FROM graphs WHERE graphid=".$_REQUEST["graphid"]); $row=DBfetch($result); $frmGraph->SetTitle(S_GRAPH." \"".$row["name"]."\""); } - if(isset($_REQUEST["graphid"]) && !isset($_REQUEST["form_refresh"])) + if(isset($_REQUEST['graphid']) && !isset($_REQUEST['form_refresh'])) { - $name =$row["name"]; - $width =$row["width"]; - $height =$row["height"]; - $yaxistype =$row["yaxistype"]; - $yaxismin =$row["yaxismin"]; - $yaxismax =$row["yaxismax"]; - $showworkperiod = $row["show_work_period"]; - $showtriggers = $row["show_triggers"]; - $graphtype = $row["graphtype"]; + $name =$row['name']; + $width =$row['width']; + $height =$row['height']; + $yaxistype =$row['yaxistype']; + $yaxismin =$row['yaxismin']; + $yaxismax =$row['yaxismax']; + $showworkperiod = $row['show_work_period']; + $showtriggers = $row['show_triggers']; + $graphtype = $row['graphtype']; + $legend = $row['show_legend']; + $graph3d = $row['show_3d']; - $db_items = DBselect('select * from graphs_items where graphid='.$_REQUEST["graphid"]); + $db_items = DBselect('SELECT * FROM graphs_items WHERE graphid='.$_REQUEST['graphid']); while($item = DBfetch($db_items)) { array_push($items, @@ -2399,15 +2402,25 @@ )); } } else { - $name = get_request("name" ,""); - $width = get_request("width" ,900); - $height = get_request("height" ,200); + $name = get_request('name' ,''); + $graphtype = get_request("graphtype" ,GRAPH_TYPE_NORMAL); + + if(($graphtype == GRAPH_TYPE_PIE) || ($graphtype == GRAPH_TYPE_EXPLODED)){ + $width = get_request("width" ,400); + $height = get_request("height" ,300); + } + else { + $width = get_request("width" ,900); + $height = get_request("height" ,200); + } + $yaxistype = get_request("yaxistype" ,GRAPH_YAXIS_TYPE_CALCULATED); $yaxismin = get_request("yaxismin" ,0.00); $yaxismax = get_request("yaxismax" ,100.00); $showworkperiod = get_request("showworkperiod" ,1); $showtriggers = get_request("showtriggers" ,1); - $graphtype = get_request("graphtype" ,GRAPH_TYPE_NORMAL); + $legend = get_request("legend" ,0); + $graph3d = get_request("graph3d" ,0); } /* reinit $_REQUEST */ @@ -2421,9 +2434,11 @@ $_REQUEST['showworkperiod'] = $showworkperiod; $_REQUEST['showtriggers'] = $showtriggers; $_REQUEST['graphtype'] = $graphtype; + $_REQUEST['legend'] = $legend; + $_REQUEST['graph3d'] = $graph3d; /********************/ - if($graphtype == GRAPH_TYPE_STACKED) + if($graphtype != GRAPH_TYPE_NORMAL) { foreach($items as $gid => $gitem) { @@ -2440,35 +2455,43 @@ $frmGraph->AddRow(S_WIDTH,new CNumericBox("width",$width,5)); $frmGraph->AddRow(S_HEIGHT,new CNumericBox("height",$height,5)); - $cmbGType = new CComboBox("graphtype",$graphtype,'submit()'); + $cmbGType = new CComboBox("graphtype",$graphtype,'graphs.submit(this)'); $cmbGType->AddItem(GRAPH_TYPE_NORMAL,S_NORMAL); $cmbGType->AddItem(GRAPH_TYPE_STACKED,S_STACKED); + $cmbGType->AddItem(GRAPH_TYPE_PIE,S_PIE); + $cmbGType->AddItem(GRAPH_TYPE_EXPLODED,S_EXPLODED); + + zbx_add_post_js('graphs.graphtype = '.$graphtype.";\n"); + $frmGraph->AddRow(S_GRAPH_TYPE,$cmbGType); - $frmGraph->AddRow(S_SHOW_WORKING_TIME,new CCheckBox("showworkperiod",$showworkperiod,null,1)); - $frmGraph->AddRow(S_SHOW_TRIGGERS,new CCheckBox("showtriggers",$showtriggers,null,1)); + if(($graphtype == GRAPH_TYPE_NORMAL) || ($graphtype == GRAPH_TYPE_STACKED)){ + $frmGraph->AddRow(S_SHOW_WORKING_TIME,new CCheckBox("showworkperiod",$showworkperiod,null,1)); + $frmGraph->AddRow(S_SHOW_TRIGGERS,new CCheckBox("showtriggers",$showtriggers,null,1)); + - $cmbYType = new CComboBox("yaxistype",$yaxistype,"submit()"); - $cmbYType->AddItem(GRAPH_YAXIS_TYPE_CALCULATED,S_CALCULATED); - $cmbYType->AddItem(GRAPH_YAXIS_TYPE_FIXED,S_FIXED); - $frmGraph->AddRow(S_YAXIS_TYPE,$cmbYType); + $cmbYType = new CComboBox("yaxistype",$yaxistype,"graphs.submit(this)"); + $cmbYType->AddItem(GRAPH_YAXIS_TYPE_CALCULATED,S_CALCULATED); + $cmbYType->AddItem(GRAPH_YAXIS_TYPE_FIXED,S_FIXED); + $frmGraph->AddRow(S_YAXIS_TYPE,$cmbYType); - if($yaxistype == GRAPH_YAXIS_TYPE_FIXED) - { - $frmGraph->AddRow(S_YAXIS_MIN_VALUE,new CTextBox("yaxismin",$yaxismin,9)); - $frmGraph->AddRow(S_YAXIS_MAX_VALUE,new CTextBox("yaxismax",$yaxismax,9)); - } - else - { - $frmGraph->AddVar("yaxismin",$yaxismin); - $frmGraph->AddVar("yaxismax",$yaxismax); + if($yaxistype == GRAPH_YAXIS_TYPE_FIXED){ + $frmGraph->AddRow(S_YAXIS_MIN_VALUE,new CTextBox("yaxismin",$yaxismin,9)); + $frmGraph->AddRow(S_YAXIS_MAX_VALUE,new CTextBox("yaxismax",$yaxismax,9)); + } + else{ + $frmGraph->AddVar("yaxismin",$yaxismin); + $frmGraph->AddVar("yaxismax",$yaxismax); + } + } else { + $frmGraph->AddRow(S_3D_VIEW,new CCheckBox("graph3d",$graph3d,'javascript: graphs.submit(this);',1)); + $frmGraph->AddRow(S_LEGEND,new CCheckBox("legend",$legend,'javascript: graphs.submit(this);',1)); } $only_hostid = null; $monitored_hosts = null; - if(count($items)) - { + if(count($items)){ $frmGraph->AddVar('items', $items); $items_table = new CTableInfo(); @@ -2501,18 +2524,32 @@ url_param($graphtype, false, 'graphtype'). url_param($gitem, false). url_param($gid,false,'gid'). + url_param($_REQUEST['graphid'],false,'graphid'). '",550,400,"graph_item_form");'); - - $items_table->AddRow(array( - new CCheckBox('group_gid['.$gid.']',isset($group_gid[$gid])), - $gitem['sortorder'], - $description, - graph_item_calc_fnc2str($gitem["calc_fnc"],$gitem["type"]), - graph_item_type2str($gitem['type'],$gitem["periods_cnt"]), - graph_item_drawtype2str($gitem["drawtype"],$gitem["type"]), - $color, - array( $do_up, SPACE."|".SPACE, $do_down ) - )); + + if(($graphtype == GRAPH_TYPE_PIE) || ($graphtype == GRAPH_TYPE_EXPLODED)){ + $items_table->AddRow(array( + new CCheckBox('group_gid['.$gid.']',isset($group_gid[$gid])), + $gitem['sortorder'], + $description, + graph_item_calc_fnc2str($gitem["calc_fnc"],$gitem["type"]), + graph_item_type2str($gitem['type'],$gitem["periods_cnt"]), + $color, + array( $do_up, SPACE."|".SPACE, $do_down ) + )); + } + else{ + $items_table->AddRow(array( + new CCheckBox('group_gid['.$gid.']',isset($group_gid[$gid])), + $gitem['sortorder'], + $description, + graph_item_calc_fnc2str($gitem["calc_fnc"],$gitem["type"]), + graph_item_type2str($gitem['type'],$gitem["periods_cnt"]), + graph_item_drawtype2str($gitem["drawtype"],$gitem["type"]), + $color, + array( $do_up, SPACE."|".SPACE, $do_down ) + )); + } } $dedlete_button = new CButton('delete_item', S_DELETE_SELECTED); } @@ -2556,6 +2593,7 @@ $frmGItem->AddVar('dstfrm',$_REQUEST['dstfrm']); + $graphid = get_request("graphid", null); $graphtype = get_request("graphtype", GRAPH_TYPE_NORMAL); $gid = get_request("gid", null); $list_name = get_request("list_name", null); @@ -2577,6 +2615,7 @@ $description = item_description($description['description'],$description['key_']); } + $frmGItem->AddVar('graphid',$graphid); $frmGItem->AddVar('gid',$gid); $frmGItem->AddVar('list_name',$list_name); $frmGItem->AddVar('itemid',$itemid); @@ -2603,63 +2642,81 @@ $frmGItem->AddRow(S_PARAMETER ,array($txtCondVal,$btnSelect)); - if($graphtype == GRAPH_TYPE_NORMAL) - { + if($graphtype == GRAPH_TYPE_NORMAL){ $cmbType = new CComboBox("type",$type,"submit()"); $cmbType->AddItem(GRAPH_ITEM_SIMPLE, S_SIMPLE); $cmbType->AddItem(GRAPH_ITEM_AGGREGATED, S_AGGREGATED); $frmGItem->AddRow(S_TYPE, $cmbType); } - else - { + else if(($graphtype == GRAPH_TYPE_PIE) || ($graphtype == GRAPH_TYPE_EXPLODED)){ + $cmbType = new CComboBox("type",$type,"submit()"); + $cmbType->AddItem(GRAPH_ITEM_SIMPLE, S_SIMPLE); + $cmbType->AddItem(GRAPH_ITEM_SUM, S_GRAPH_SUM); + $frmGItem->AddRow(S_TYPE, $cmbType); + } + else{ $frmGItem->AddVar("type",GRAPH_ITEM_SIMPLE); } - if($type == GRAPH_ITEM_AGGREGATED) - { + if($type == GRAPH_ITEM_AGGREGATED){ $frmGItem->AddRow(S_AGGREGATED_PERIODS_COUNT, new CTextBox("periods_cnt",$periods_cnt,15)); $frmGItem->AddVar("calc_fnc",$calc_fnc); $frmGItem->AddVar("drawtype",$drawtype); $frmGItem->AddVar("color",$color); } - else - { - $frmGItem->AddVar("periods_cnt",$periods_cnt); - - $cmbFnc = new CComboBox("calc_fnc",$calc_fnc,'submit();'); - - if($graphtype == GRAPH_TYPE_NORMAL) - $cmbFnc->AddItem(CALC_FNC_ALL, S_ALL_SMALL); - - $cmbFnc->AddItem(CALC_FNC_MIN, S_MIN_SMALL); - $cmbFnc->AddItem(CALC_FNC_AVG, S_AVG_SMALL); - $cmbFnc->AddItem(CALC_FNC_MAX, S_MAX_SMALL); - $frmGItem->AddRow(S_FUNCTION, $cmbFnc); - - if($graphtype == GRAPH_TYPE_NORMAL) - { - $cmbType = new CComboBox("drawtype",$drawtype); - for($i=0; $i < 5; ++$i) + else { + if(($graphtype == GRAPH_TYPE_PIE) || ($graphtype == GRAPH_TYPE_EXPLODED)){ + $frmGItem->AddVar("periods_cnt",$periods_cnt); + + $cmbFnc = new CComboBox("calc_fnc",$calc_fnc,'submit();'); + + $cmbFnc->AddItem(CALC_FNC_MIN, S_MIN_SMALL); + $cmbFnc->AddItem(CALC_FNC_AVG, S_AVG_SMALL); + $cmbFnc->AddItem(CALC_FNC_MAX, S_MAX_SMALL); + $cmbFnc->AddItem(CALC_FNC_LST, S_LST_SMALL); + $frmGItem->AddRow(S_FUNCTION, $cmbFnc); + } + else{ + $frmGItem->AddVar("periods_cnt",$periods_cnt); + + $cmbFnc = new CComboBox("calc_fnc",$calc_fnc,'submit();'); + + if($graphtype == GRAPH_TYPE_NORMAL) + $cmbFnc->AddItem(CALC_FNC_ALL, S_ALL_SMALL); + + $cmbFnc->AddItem(CALC_FNC_MIN, S_MIN_SMALL); + $cmbFnc->AddItem(CALC_FNC_AVG, S_AVG_SMALL); + $cmbFnc->AddItem(CALC_FNC_MAX, S_MAX_SMALL); + $frmGItem->AddRow(S_FUNCTION, $cmbFnc); + + if($graphtype == GRAPH_TYPE_NORMAL) { - $cmbType->AddItem($i,graph_item_drawtype2str($i)); + $cmbType = new CComboBox("drawtype",$drawtype); + for($i=0; $i < 5; ++$i) + { + $cmbType->AddItem($i,graph_item_drawtype2str($i)); + } + $frmGItem->AddRow(S_DRAW_STYLE, $cmbType); + } + else + { + $frmGItem->AddVar("drawtype", 1); } - $frmGItem->AddRow(S_DRAW_STYLE, $cmbType); - } - else - { - $frmGItem->AddVar("drawtype", 1); } $frmGItem->AddRow(S_COLOR, new CColor('color',$color)); } + if(($graphtype == GRAPH_TYPE_NORMAL) || ($graphtype == GRAPH_TYPE_STACKED)){ + $cmbYax = new CComboBox("yaxisside",$yaxisside); + $cmbYax->AddItem(GRAPH_YAXIS_SIDE_RIGHT, S_RIGHT); + $cmbYax->AddItem(GRAPH_YAXIS_SIDE_LEFT, S_LEFT); + $frmGItem->AddRow(S_YAXIS_SIDE, $cmbYax); + } - $cmbYax = new CComboBox("yaxisside",$yaxisside); - $cmbYax->AddItem(GRAPH_YAXIS_SIDE_RIGHT, S_RIGHT); - $cmbYax->AddItem(GRAPH_YAXIS_SIDE_LEFT, S_LEFT); - $frmGItem->AddRow(S_YAXIS_SIDE, $cmbYax); - - $frmGItem->AddRow(S_SORT_ORDER_1_100, new CTextBox("sortorder",$sortorder,3)); + if($type != GRAPH_ITEM_SUM){ + $frmGItem->AddRow(S_SORT_ORDER_1_100, new CTextBox("sortorder",$sortorder,3)); + } $frmGItem->AddItemToBottomRow(new CButton("save", isset($gid) ? S_SAVE : S_ADD)); diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php index 85e9ac8e..8e561cd1 100644 --- a/frontends/php/include/graphs.inc.php +++ b/frontends/php/include/graphs.inc.php @@ -21,11 +21,17 @@ <?php function graph_item_type2str($type,$count=null) { - switch($type) - { - case GRAPH_ITEM_AGGREGATED: $type = S_AGGREGATED.(isset($count) ? '('.$count.')' : ''); break; + switch($type){ + case GRAPH_ITEM_SUM: + $type = S_GRAPH_SUM; + break; + case GRAPH_ITEM_AGGREGATED: + $type = S_AGGREGATED.(isset($count) ? '('.$count.')' : ''); + break; case GRAPH_ITEM_SIMPLE: - default: $type = S_SIMPLE; break; + default: + $type = S_SIMPLE; + break; } return $type; } @@ -66,6 +72,7 @@ case CALC_FNC_ALL: $calc_fnc = S_ALL_SMALL; break; case CALC_FNC_MIN: $calc_fnc = S_MIN_SMALL; break; case CALC_FNC_MAX: $calc_fnc = S_MAX_SMALL; break; + case CALC_FNC_LST: $calc_fnc = S_LST_SMALL; break; case CALC_FNC_AVG: default: $calc_fnc = S_AVG_SMALL; break; } @@ -74,19 +81,19 @@ function get_graph_by_gitemid($gitemid) { - $db_graphs = DBselect("select distinct g.* from graphs g, graphs_items gi". - " where g.graphid=gi.graphid and gi.gitemid=$gitemid"); + $db_graphs = DBselect("SELECT distinct g.* FROM graphs g, graphs_items gi". + " WHERE g.graphid=gi.graphid and gi.gitemid=$gitemid"); return DBfetch($db_graphs); } - function &get_graphs_by_hostid($hostid) + function get_graphs_by_hostid($hostid) { - return DBselect("select distinct g.* from graphs g, graphs_items gi, items i". - " where g.graphid=gi.graphid and gi.itemid=i.itemid and i.hostid=$hostid"); + return DBselect("SELECT distinct g.* FROM graphs g, graphs_items gi, items i". + " WHERE g.graphid=gi.graphid and gi.itemid=i.itemid and i.hostid=$hostid"); } - function &get_realhosts_by_graphid($graphid) + function get_realhosts_by_graphid($graphid) { $graph = get_graph_by_graphid($graphid); if($graph["templateid"] != 0) @@ -95,21 +102,21 @@ return get_hosts_by_graphid($graphid); } - function &get_hosts_by_graphid($graphid) + function get_hosts_by_graphid($graphid) { - return DBselect("select distinct h.* from graphs_items gi, items i, hosts h". - " where h.hostid=i.hostid and gi.itemid=i.itemid and gi.graphid=$graphid"); + return DBselect("SELECT distinct h.* FROM graphs_items gi, items i, hosts h". + " WHERE h.hostid=i.hostid and gi.itemid=i.itemid and gi.graphid=$graphid"); } - function &get_graphitems_by_graphid($graphid) + function get_graphitems_by_graphid($graphid) { - return DBselect("select * from graphs_items where graphid=$graphid". + return DBselect("SELECT * FROM graphs_items WHERE graphid=$graphid". " order by itemid,drawtype,sortorder,color,yaxisside"); } function get_graphitem_by_gitemid($gitemid) { - $result=DBselect("select * from graphs_items where gitemid=$gitemid"); + $result=DBselect("SELECT * FROM graphs_items WHERE gitemid=$gitemid"); $row=DBfetch($result); if($row) { @@ -121,7 +128,7 @@ function get_graphitem_by_itemid($itemid) { - $result = DBfetch(DBselect('select * from graphs_items where itemid='.$itemid)); + $result = DBfetch(DBselect('SELECT * FROM graphs_items WHERE itemid='.$itemid)); $row=DBfetch($result); if($row) { @@ -133,7 +140,7 @@ function get_graph_by_graphid($graphid) { - $result=DBselect("select * from graphs where graphid=$graphid"); + $result=DBselect("SELECT * FROM graphs WHERE graphid=$graphid"); $row=DBfetch($result); if($row) { @@ -143,9 +150,9 @@ return false; } - function &get_graphs_by_templateid($templateid) + function get_graphs_by_templateid($templateid) { - return DBselect("select * from graphs where templateid=$templateid"); + return DBselect("SELECT * FROM graphs WHERE templateid=$templateid"); } /****************************************************************************** @@ -153,14 +160,14 @@ * Comments: !!! Don't forget sync code with C !!! * * * ******************************************************************************/ - function add_graph($name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype=GRAPH_TYPE_NORMAL,$templateid=0) + function add_graph($name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype,$legend,$graph3d,$templateid=0) { $graphid = get_dbid("graphs","graphid"); $result=DBexecute("insert into graphs". - " (graphid,name,width,height,yaxistype,yaxismin,yaxismax,templateid,show_work_period,show_triggers,graphtype)". + " (graphid,name,width,height,yaxistype,yaxismin,yaxismax,templateid,show_work_period,show_triggers,graphtype,show_legend,show_3d)". " values ($graphid,".zbx_dbstr($name).",$width,$height,$yaxistype,$yaxismin,". - " $yaxismax,$templateid,$showworkperiod,$showtriggers,$graphtype)"); + " $yaxismax,$templateid,$showworkperiod,$showtriggers,$graphtype,$legend,$graph3d)"); if($result) { info("Graph '$name' added"); @@ -169,9 +176,9 @@ return $result; } - function add_graph_with_items($name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype=GRAPH_TYPE_NORMAL,$items=array(),$templateid=0) + function add_graph_with_items($name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype,$legend,$graph3d,$items=array(),$templateid) { - if($result = add_graph($name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype,$templateid)) + if($result = add_graph($name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype,$legend,$graph3d,$templateid)) { foreach($items as $gitem) { @@ -197,29 +204,29 @@ # Update Graph - function update_graph($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype=GRAPH_TYPE_NORMAL,$templateid=0) + function update_graph($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype,$legend,$graph3d,$templateid=0) { $g_graph = get_graph_by_graphid($graphid); $graphs = get_graphs_by_templateid($graphid); - while($graph = DBfetch($graphs)) - { - $result = update_graph($graph["graphid"],$name,$width, - $height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype,$graphid); + while($graph = DBfetch($graphs)){ + $result = update_graph($graph["graphid"],$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype,$legend,$graph3d,$graphid); if(!$result) return $result; } - $result = DBexecute("update graphs set name=".zbx_dbstr($name).",width=$width,height=$height,". - "yaxistype=$yaxistype,yaxismin=$yaxismin,yaxismax=$yaxismax,templateid=$templateid,". - "show_work_period=$showworkperiod,show_triggers=$showtriggers,graphtype=$graphtype ". - "where graphid=$graphid"); - if($result) - { - if($g_graph['graphtype'] != $graphtype && $graphtype == GRAPH_TYPE_STACKED) - { - $result = DBexecute('update graphs_items set calc_fnc='.CALC_FNC_AVG.',drawtype=1,type='.GRAPH_ITEM_SIMPLE. - ' where graphid='.$graphid); + $result = DBexecute( + 'UPDATE graphs '. + 'SET name='.zbx_dbstr($name).',width='.$width.',height='.$height. + ',yaxistype='.$yaxistype.',yaxismin='.$yaxismin.',yaxismax='.$yaxismax.',templateid='.$templateid. + ',show_work_period='.$showworkperiod.',show_triggers='.$showtriggers.',graphtype='.$graphtype. + ',show_legend='.$legend.',show_3d='.$graph3d. + ' WHERE graphid='.$graphid); + + if($result){ + if($g_graph['graphtype'] != $graphtype && $graphtype == GRAPH_TYPE_STACKED){ + $result = DBexecute('UPDATE graphs_items SET calc_fnc='.CALC_FNC_AVG.',drawtype=1,type='.GRAPH_ITEM_SIMPLE. + ' WHERE graphid='.$graphid); } info("Graph '".$g_graph["name"]."' updated"); @@ -227,21 +234,19 @@ return $result; } - function update_graph_with_items($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype=GRAPH_TYPE_NORMAL,$items=array(),$templateid=0) + function update_graph_with_items($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype,$legend,$graph3d,$items=array(),$templateid=0) { $result = update_graph($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod, - $showtriggers,$graphtype,$templateid); + $showtriggers,$graphtype,$legend,$graph3d,$templateid); - if($result) - { - $db_graphs_items = DBselect('select gitemid from graphs_items where graphid='.$graphid); - while($gitem_data = DBfetch($db_graphs_items)) - { + if($result){ + $db_graphs_items = DBselect('SELECT gitemid FROM graphs_items WHERE graphid='.$graphid); + + while($gitem_data = DBfetch($db_graphs_items)){ delete_graph_item($gitem_data['gitemid']); } - foreach($items as $gitem) - { + foreach($items as $gitem){ if(!add_item_to_graph( $graphid, $gitem['itemid'], @@ -261,6 +266,7 @@ return $result; } + /****************************************************************************** * * * Comments: !!! Don't forget sync code with C !!! * @@ -279,11 +285,11 @@ } // delete graph - $result=DBexecute("delete from graphs_items where graphid=$graphid"); + $result=DBexecute("delete FROM graphs_items WHERE graphid=$graphid"); if(!$result) return $result; - $result = DBexecute("delete from graphs where graphid=$graphid"); + $result = DBexecute("delete FROM graphs WHERE graphid=$graphid"); if($result) { info("Graph '".$graph["name"]."' deleted"); @@ -325,7 +331,7 @@ if($gitemid && $host["status"]==HOST_STATUS_TEMPLATE) {// add to child graphs $item_num = DBfetch(DBselect( - 'select count(*) as num from graphs_items where graphid='.$graphid + 'SELECT count(*) as num FROM graphs_items WHERE graphid='.$graphid )); if($item_num['num'] == 1) @@ -342,8 +348,8 @@ $result = $new_graphid; break; } - $db_items = DBselect("select itemid from items". - " where key_=".zbx_dbstr($item["key_"]). + $db_items = DBselect("SELECT itemid FROM items". + " WHERE key_=".zbx_dbstr($item["key_"]). " and hostid=".$chd_host["hostid"]); $db_item = DBfetch($db_items); if(!$db_item) @@ -367,8 +373,8 @@ { ! $chd_hosts = get_hosts_by_graphid($child["graphid"]); $chd_host = DBfetch($chd_hosts); - $db_items = DBselect("select itemid from items". - " where key_=".zbx_dbstr($item["key_"]). + $db_items = DBselect("SELECT itemid FROM items". + " WHERE key_=".zbx_dbstr($item["key_"]). " and hostid=".$chd_host["hostid"]); $db_item = DBfetch($db_items); if(!$db_item) @@ -426,11 +432,11 @@ } } - $result = DBexecute("delete from graphs_items where gitemid=$gitemid"); + $result = DBexecute("delete FROM graphs_items WHERE gitemid=$gitemid"); if($result) { $item = get_item_by_itemid($gitem["itemid"]); - info("Item '".$item["description"]."' deleted from graph '".$graph["name"]."'"); + info("Item '".$item["description"]."' deleted FROM graph '".$graph["name"]."'"); $graph_items = get_graphitems_by_graphid($graph["graphid"]); if($graph["templateid"]>0 && !DBfetch($graph_items)) @@ -446,7 +452,7 @@ * Comments: !!! Don't forget sync code with C !!! * * * ******************************************************************************/ - function delete_template_graphs($hostid, $templateid = null, $unlink_mode = false) + function delete_template_graphs($hostid, $templateid = null /* array format 'arr[id]=name' */, $unlink_mode = false) { $db_graphs = get_graphs_by_hostid($hostid); while($db_graph = DBfetch($db_graphs)) @@ -454,19 +460,22 @@ if($db_graph["templateid"] == 0) continue; - if( !is_null($templateid) ) + if($templateid != null) { - if( !is_array($templateid) ) $templateid=array($templateid); - - $tmp_host = DBfetch(get_hosts_by_graphid($db_graph["templateid"])); - - if( !in_array($tmp_host["hostid"], $templateid)) + $hosts = get_hosts_by_graphid($db_graph["templateid"]); + $tmp_host = DBfetch($hosts); + if(is_array($templateid)) + { + if(!isset($templateid[$tmp_host["hostid"]])) + continue; + } + elseif($tmp_host["hostid"] != $templateid) continue; } if($unlink_mode) { - if(DBexecute("update graphs set templateid=0 where graphid=".$db_graph["graphid"])) + if(DBexecute("update graphs set templateid=0 WHERE graphid=".$db_graph["graphid"])) { info("Graph '".$db_graph["name"]."' unlinked"); } @@ -483,16 +492,16 @@ * Comments: !!! Don't forget sync code with C !!! * * * ******************************************************************************/ - function copy_template_graphs($hostid, $templateid = null, $copy_mode = false) + function copy_template_graphs($hostid, $templateid = null /* array format 'arr[id]=name' */, $copy_mode = false) { if($templateid == null) { - $templateid = array_keys(get_templates_by_hostid($hostid)); + $templateid = get_templates_by_hostid($hostid); } if(is_array($templateid)) { - foreach($templateid as $id) + foreach($templateid as $id => $name) copy_template_graphs($hostid, $id, $copy_mode); // attention recursion return; } diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php index d2bae0f1..b63daaec 100644 --- a/frontends/php/include/locales/en_gb.inc.php +++ b/frontends/php/include/locales/en_gb.inc.php @@ -498,11 +498,14 @@ 'S_MIN_SMALL'=> 'min', 'S_AVG_SMALL'=> 'avg', 'S_MAX_SMALL'=> 'max', + 'S_LST_SMALL'=> 'last', 'S_DRAW_STYLE'=> 'Draw style', 'S_SIMPLE'=> 'Simple', 'S_GRAPH_TYPE'=> 'Graph type', 'S_STACKED'=> 'Stacked', 'S_NORMAL'=> 'Normal', + 'S_PIE'=> 'Pie', + 'S_EXPLODED'=> 'Exploded', 'S_AGGREGATED'=> 'Aggregated', 'S_AGGREGATED_PERIODS_COUNT'=> 'Aggregated periods count', @@ -515,6 +518,7 @@ 'S_GRAPH_DELETED'=> 'Graph deleted', 'S_CANNOT_DELETE_GRAPH'=> 'Cannot delete graph', 'S_CANNOT_ADD_GRAPH'=> 'Cannot add graph', + 'S_ANOTHER_ITEM_SUM'=> 'Cannot add onemore item with type "Graph sum"', 'S_ID'=> 'Id', 'S_NO_GRAPHS_DEFINED'=> 'No graphs defined', 'S_DELETE_GRAPH_Q'=> 'Delete graph?', @@ -526,6 +530,9 @@ 'S_CREATE_GRAPH'=> 'Create Graph', 'S_SHOW_WORKING_TIME'=> 'Show working time', 'S_SHOW_TRIGGERS'=> 'Show triggers', + 'S_3D_VIEW'=> '3D view', + 'S_LEGEND'=> 'Legend', + 'S_GRAPH_SUM'=> 'Graph sum', 'S_GRAPH_ITEM'=> 'Graph item', 'S_REQUIRED_ITEMS_FOR_GRAPH'=> 'Required items for graph', diff --git a/frontends/php/include/screens.inc.php b/frontends/php/include/screens.inc.php index 7194dd25..664815ba 100644 --- a/frontends/php/include/screens.inc.php +++ b/frontends/php/include/screens.inc.php @@ -329,11 +329,28 @@ $action = "charts.php?graphid=$resourceid".url_param("period"). url_param("inc").url_param("dec"); - $item = new CLink( - new CImg("chart2.php?graphid=$resourceid&width=$width&height=$height". - "&period=$effectiveperiod".url_param("stime").url_param("from")), - $action - ); + $graphtype = GRAPH_TYPE_NORMAL; + + $sql = 'SELECT DISTINCT `graphtype` FROM `graphs` WHERE `graphid`='.$resourceid; + $res = DBselect($sql); + + while($rows = DBfetch($res)){ + $graphtype = $rows['graphtype']; + } + + if(($graphtype == GRAPH_TYPE_PIE) || ($graphtype == GRAPH_TYPE_EXPLODED)){ + $item = new CLink( + new CImg("chart6.php?graphid=$resourceid&width=$width&height=$height"."&period=$effectiveperiod".url_param("stime").url_param("from")), + $action + ); + } + else { + $item = new CLink( + new CImg("chart2.php?graphid=$resourceid&width=$width&height=$height"."&period=$effectiveperiod".url_param("stime").url_param("from")), + $action + ); + + } } elseif( ($screenitemid!=0) && ($resourcetype==SCREEN_RESOURCE_SIMPLE_GRAPH) ) { diff --git a/frontends/php/js/graphs.js b/frontends/php/js/graphs.js new file mode 100644 index 00000000..b55137c3 --- /dev/null +++ b/frontends/php/js/graphs.js @@ -0,0 +1,14 @@ +// JavaScript Document +var graphs = { +graphtype : 0, + +submit : function(obj){ + if(obj.name == 'graphtype'){ + if(((obj.selectedIndex > 1) && (this.graphtype < 2)) || ((obj.selectedIndex < 2) && (this.graphtype > 1))){ + var refr = document.getElementsByName('form_refresh'); + refr[0].value = 0; + } + } + document.getElementsByName('frm_graph')[0].submit(); +} +}
\ No newline at end of file diff --git a/frontends/php/popup_gitem.php b/frontends/php/popup_gitem.php index 4c2f4196..bdc36419 100644 --- a/frontends/php/popup_gitem.php +++ b/frontends/php/popup_gitem.php @@ -38,25 +38,26 @@ include_once "include/page_header.php"; $fields=array( "dstfrm"=> array(T_ZBX_STR, O_MAND,P_SYS, NOT_EMPTY, null), - "gid"=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535), null), - "list_name"=> array(T_ZBX_STR, O_OPT, P_SYS, NOT_EMPTY, 'isset({save})&&isset({gid})'), - "itemid"=> array(T_ZBX_INT, O_OPT, null, DB_ID.'({}!=0)', 'isset({save})'), - "color"=> array(T_ZBX_CLR, O_OPT, null, null, 'isset({save})'), - "drawtype"=> array(T_ZBX_INT, O_OPT, null, IN(graph_item_drawtypes()),'isset({save})'), - "sortorder"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,65535), 'isset({save})'), - "yaxisside"=> array(T_ZBX_INT, O_OPT, null, IN("0,1"), 'isset({save})'), - "calc_fnc"=> array(T_ZBX_INT, O_OPT, null, IN("1,2,4,7"), 'isset({save})'), - "type"=> array(T_ZBX_INT, O_OPT, null, IN("0,1"), 'isset({save})'), + "graphid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), + "gid"=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535), null), + "graphtype"=> array(T_ZBX_INT, O_OPT, null, IN("0,1,2,3"), 'isset({save})'), + "list_name"=> array(T_ZBX_STR, O_OPT, P_SYS, NOT_EMPTY, 'isset({save})&&isset({gid})'), + "itemid"=> array(T_ZBX_INT, O_OPT, null, DB_ID.'({}!=0)', 'isset({save})'), + "color"=> array(T_ZBX_CLR, O_OPT, null, null, 'isset({save})'), + "drawtype"=> array(T_ZBX_INT, O_OPT, null, IN(graph_item_drawtypes()),'isset({save})&&(({graphtype} == 0) || ({graphtype} == 1))'), + "sortorder"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,65535), 'isset({save})&&(({graphtype} == 0) || ({graphtype} == 1))'), + "yaxisside"=> array(T_ZBX_INT, O_OPT, null, IN("0,1"), 'isset({save})&&(({graphtype} == 0) || ({graphtype} == 1))'), + "calc_fnc"=> array(T_ZBX_INT, O_OPT, null, IN("1,2,4,7,9"), 'isset({save})'), + "type"=> array(T_ZBX_INT, O_OPT, null, IN("0,1,2"), 'isset({save})'), "periods_cnt"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,360), 'isset({save})'), - "graphtype"=> array(T_ZBX_INT, O_OPT, null, IN("0,1"), 'isset({save})'), "only_hostid"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null), "monitored_hosts"=>array(T_ZBX_INT, O_OPT, null, IN("0,1"), null), /* actions */ - "add"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), - "save"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), + "add"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), + "save"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), /* other */ - "form"=> array(T_ZBX_STR, O_OPT, P_SYS, null, null), + "form"=> array(T_ZBX_STR, O_OPT, P_SYS, null, null), "form_refresh"=>array(T_ZBX_STR, O_OPT, null, null, null) ); @@ -125,12 +126,34 @@ function update_graph_item(formname,list_name,gid,itemid,color,drawtype,sortorde --> </script> <?php + $_REQUEST['drawtype'] = get_request('drawtype',0); + $_REQUEST['yaxisside'] = get_request('yaxisside',0); + $_REQUEST['sortorder'] = get_request('sortorder',0); + $graphid = get_request('graphid',false); + + if(($_REQUEST['type'] == GRAPH_ITEM_SUM) && ($graphid !== false)){ + $sql = 'SELECT COUNT(itemid) as items'. + ' FROM graphs_items '. + ' WHERE type='.GRAPH_ITEM_SUM. + ' AND graphid='.$graphid. + ' AND itemid<>'.$_REQUEST['itemid']; + $res = DBselect($sql); + while($rows = DBfetch($res)){ + if(isset($rows['items']) && ($rows['items'] > 0)){ + show_messages(false, null, S_ANOTHER_ITEM_SUM); + if(isset($_REQUEST['save'])) unset($_REQUEST['save']); + $_REQUEST['type'] = GRAPH_ITEM_SIMPLE; + } + } + } + if(isset($_REQUEST['save']) && !isset($_REQUEST['gid'])) { ?> <script language="JavaScript" type="text/javascript"> <!-- <?php + echo "add_graph_item('". $_REQUEST['dstfrm']."','". $_REQUEST['itemid']."','". @@ -152,6 +175,7 @@ function update_graph_item(formname,list_name,gid,itemid,color,drawtype,sortorde <script language="JavaScript" type="text/javascript"> <!-- <?php + echo "update_graph_item('". $_REQUEST['dstfrm']."','". $_REQUEST['list_name']."','". |
