From 4e4aa7eb198963720b377cd568825309616dce8a Mon Sep 17 00:00:00 2001 From: artem Date: Mon, 16 Jul 2007 10:01:08 +0000 Subject: - 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 --- frontends/php/charts.php | 248 +++++++++++++++++++++++++++-------------------- 1 file changed, 145 insertions(+), 103 deletions(-) (limited to 'frontends/php/charts.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 @@ **/ ?> 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'; ?> 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; } ?> 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']); ?> 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"; 0) - { - $row = "\n".''."\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".''."\n"; + } + else{ + $row = "\n".''."\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"; ?> -- cgit