diff options
author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-08-05 08:29:22 +0000 |
---|---|---|
committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-08-05 08:29:22 +0000 |
commit | b1a528879c1e7e7d7886a273cf954741d057e038 (patch) | |
tree | 85821a6560cbd493c921c26fd0d0855df47e9be2 /frontends | |
parent | 456d33cecd93804e8dcd9f3884ad21fb4eb71ab4 (diff) | |
download | zabbix-b1a528879c1e7e7d7886a273cf954741d057e038.tar.gz zabbix-b1a528879c1e7e7d7886a273cf954741d057e038.tar.xz zabbix-b1a528879c1e7e7d7886a273cf954741d057e038.zip |
- [DEV-137] small fixes & performance enchantments (Artem)
git-svn-id: svn://svn.zabbix.com/trunk@5869 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends')
-rw-r--r-- | frontends/php/include/blocks.inc.php | 27 | ||||
-rw-r--r-- | frontends/php/include/classes/chostsinfo.mod.php | 21 | ||||
-rw-r--r-- | frontends/php/include/config.inc.php | 210 | ||||
-rw-r--r-- | frontends/php/include/graphs.inc.php | 16 | ||||
-rw-r--r-- | frontends/php/include/maps.inc.php | 136 | ||||
-rw-r--r-- | frontends/php/include/page_header.php | 6 | ||||
-rw-r--r-- | frontends/php/include/perm.inc.php | 6 | ||||
-rw-r--r-- | frontends/php/include/screens.inc.php | 2 | ||||
-rw-r--r-- | frontends/php/maps.php | 10 |
9 files changed, 218 insertions, 216 deletions
diff --git a/frontends/php/include/blocks.inc.php b/frontends/php/include/blocks.inc.php index 88a04f1f..fcd127d5 100644 --- a/frontends/php/include/blocks.inc.php +++ b/frontends/php/include/blocks.inc.php @@ -176,7 +176,7 @@ function make_system_summary(){ $config=select_config(); $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_RES_IDS_ARRAY); - $available_triggers = get_accessible_triggers(PERM_READ_LIST,PERM_RES_IDS_ARRAY); + $available_triggers = get_accessible_triggers(PERM_READ_ONLY,PERM_RES_IDS_ARRAY); $table = new CTableInfo(); $table->SetHeader(array( @@ -190,18 +190,19 @@ function make_system_summary(){ S_NOT_CLASSIFIED )); - $gr_result=DBselect('SELECT DISTINCT g.groupid,g.name '. - ' FROM groups g, hosts_groups hg, hosts h, items i, functions f, triggers t '. - ' WHERE '.DBcondition('h.hostid',$available_hosts). - ' AND hg.groupid=g.groupid '. - ' AND h.status='.HOST_STATUS_MONITORED. - ' AND h.hostid=i.hostid '. - ' AND hg.hostid=h.hostid '. - ' AND i.status='.ITEM_STATUS_ACTIVE. - ' AND i.itemid=f.itemid '. - ' AND t.triggerid=f.triggerid '. - ' AND t.status='.TRIGGER_STATUS_ENABLED. - ' ORDER BY g.name'); + $sql = 'SELECT DISTINCT g.groupid,g.name '. + ' FROM groups g, hosts_groups hg, hosts h, items i, functions f, triggers t '. + ' WHERE '.DBcondition('h.hostid',$available_hosts). + ' AND hg.groupid=g.groupid '. + ' AND h.status='.HOST_STATUS_MONITORED. + ' AND h.hostid=i.hostid '. + ' AND hg.hostid=h.hostid '. + ' AND i.status='.ITEM_STATUS_ACTIVE. + ' AND i.itemid=f.itemid '. + ' AND t.triggerid=f.triggerid '. + ' AND t.status='.TRIGGER_STATUS_ENABLED. + ' ORDER BY g.name'; + $gr_result=DBselect($sql); while($group = DBFetch($gr_result)){ $group_row = new CRow(); diff --git a/frontends/php/include/classes/chostsinfo.mod.php b/frontends/php/include/classes/chostsinfo.mod.php index bb582c04..c9e07fc0 100644 --- a/frontends/php/include/classes/chostsinfo.mod.php +++ b/frontends/php/include/classes/chostsinfo.mod.php @@ -20,11 +20,9 @@ ?> <?php - class CHostsInfo extends CTable - { + class CHostsInfo extends CTable{ //var $style; - function CHostsInfo($groupid=0, $style = STYLE_HORISONTAL) - { + function CHostsInfo($groupid=0, $style = STYLE_HORISONTAL){ $this->nodeid = id2nodeid($groupid); $this->groupid = $groupid; $this->style = null; @@ -33,16 +31,14 @@ $this->SetOrientation($style); } - function SetOrientation($value) - { + function SetOrientation($value){ if($value != STYLE_HORISONTAL && $value != STYLE_VERTICAL) return $this->error("Incorrect value for SetOrientation [$value]"); $this->style = $value; } - function BodyToString() - { + function BodyToString(){ global $USER_DETAILS; $this->CleanItems(); @@ -53,6 +49,7 @@ $db_host_cnt = DBselect('SELECT COUNT(*) as cnt '. ' FROM hosts h, hosts_groups hg'. ' WHERE h.available='.HOST_AVAILABLE_TRUE. +// ' AND h.status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.') '. ' AND hg.groupid IN ('.$accessible_groups.') '.$cond); $host_cnt = DBfetch($db_host_cnt); @@ -61,6 +58,7 @@ $db_host_cnt = DBselect('SELECT COUNT(*) as cnt '. ' FROM hosts h, hosts_groups hg'. ' WHERE h.available='.HOST_AVAILABLE_FALSE. +// ' AND h.status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.') '. ' AND hg.groupid IN ('.$accessible_groups.') '.$cond); $host_cnt = DBfetch($db_host_cnt); @@ -69,6 +67,7 @@ $db_host_cnt = DBselect('SELECT COUNT(*) as cnt '. ' FROM hosts h, hosts_groups hg'. ' WHERE h.available='.HOST_AVAILABLE_UNKNOWN. +// ' AND h.status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.') '. ' AND hg.groupid IN ('.$accessible_groups.') '.$cond); @@ -97,12 +96,10 @@ $notav = new CCol($notav." ".S_NOT_AVAILABLE, "notav"); $uncn = new CCol($uncn." ".S_UNKNOWN, "uncn"); - if($this->style == STYLE_HORISONTAL) - { + if($this->style == STYLE_HORISONTAL){ $this->AddRow(array($avail, $notav, $uncn)); } - else - { + else{ $this->AddRow($avail); $this->AddRow($notav); $this->AddRow($uncn); diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php index 0b0f5d5a..c866bb93 100644 --- a/frontends/php/include/config.inc.php +++ b/frontends/php/include/config.inc.php @@ -131,7 +131,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! global $ZBX_LOCALNODEID, $ZBX_LOCMASTERID; /* Init LOCAL NODE ID */ - if($local_node_data = DBfetch(DBselect('select * from nodes where nodetype=1 order by nodeid'))){ + if($local_node_data = DBfetch(DBselect('SELECT * FROM nodes WHERE nodetype=1 order by nodeid'))){ $ZBX_LOCALNODEID = $local_node_data['nodeid']; $ZBX_LOCMASTERID = $local_node_data['masterid']; @@ -221,7 +221,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! if(!defined('ZBX_PAGE_NO_AUTHERIZATION') && ZBX_DISTRIBUTED){ //SDI($_REQUEST); $ZBX_CURRENT_NODEID = get_cookie('zbx_current_nodeid', $ZBX_LOCALNODEID); // Selected node - $ZBX_WITH_SUBNODES = get_cookie('zbx_with_subnodes', false); // Show elements from subnodes + $ZBX_WITH_SUBNODES = get_cookie('zbx_with_subnodes', false); // Show elements FROM subnodes if(isset($_REQUEST['switch_node'])){ if($node_data = DBfetch(DBselect('SELECT * FROM nodes WHERE nodeid='.$_REQUEST['switch_node']))){ @@ -528,8 +528,8 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! $priority = array(0=>0, 1=>0, 2=>0, 3=>0, 4=>0, 5=>0); $triggerids=""; - $result=DBselect('select t.triggerid,t.priority from triggers t,hosts h,items i,functions f'. - ' where t.value=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and i.status=0'); + $result=DBselect('SELECT t.triggerid,t.priority from triggers t,hosts h,items i,functions f'. + ' WHERE t.value=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and i.status=0'); while($row=DBfetch($result)){ $ack = get_last_event_by_triggerid($row["triggerid"]); @@ -711,10 +711,10 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! * * ******************************************************************************/ function reset_items_nextcheck($triggerid){ - $sql="select itemid from functions where triggerid=$triggerid"; + $sql="SELECT itemid from functions WHERE triggerid=$triggerid"; $result=DBselect($sql); while($row=DBfetch($result)){ - $sql="update items set nextcheck=0 where itemid=".$row["itemid"]; + $sql="update items set nextcheck=0 WHERE itemid=".$row["itemid"]; DBexecute($sql); } } @@ -731,38 +731,39 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! } // history & trends /* if ($DB['DB_TYPE'] == "MYSQL"){ - $row=DBfetch(DBselect("show table status like 'history'")); + $row=DBfetch(DBselect('show table status like "history"')); $status["history_count"] = $row["Rows"]; - $row=DBfetch(DBselect("show table status like 'history_log'")); + $row=DBfetch(DBselect('show table status like "history_log"')); $status["history_count"] += $row["Rows"]; - $row=DBfetch(DBselect("show table status like 'history_str'")); + $row=DBfetch(DBselect('show table status like "history_str"')); $status["history_count"] += $row["Rows"]; - $row=DBfetch(DBselect("show table status like 'history_uint'")); + $row=DBfetch(DBselect('show table status like "history_uint"')); $status["history_count"] += $row["Rows"]; - $row=DBfetch(DBselect("show table status like 'trends'")); + $row=DBfetch(DBselect('show table status like "trends"')); $status["trends_count"] = $row["Rows"]; } else{ - $row=DBfetch(DBselect("select count(itemid) as cnt from history")); + $row=DBfetch(DBselect('SELECT COUNT(itemid) as cnt from history')); $status["history_count"] = $row["cnt"]; - $row=DBfetch(DBselect("select count(itemid) as cnt from history_log")); + $row=DBfetch(DBselect('SELECT COUNT(itemid) as cnt from history_log')); $status["history_count"] += $row["cnt"]; - $row=DBfetch(DBselect("select count(itemid) as cnt from history_str")); + $row=DBfetch(DBselect('SELECT COUNT(itemid) as cnt from history_str')); $status["history_count"] += $row["cnt"]; - $row=DBfetch(DBselect("select count(itemid) as cnt from history_uint")); + $row=DBfetch(DBselect('SELECT COUNT(itemid) as cnt from history_uint')); $status["history_count"] += $row["cnt"]; - $result=DBselect("select count(itemid) as cnt from trends"); + $result=DBselect('SELECT COUNT(itemid) as cnt from trends'); $row=DBfetch($result); $status["trends_count"]=$row["cnt"]; }*/ // events -/* $row=DBfetch(DBselect("select count(eventid) as cnt from events")); +/* $row=DBfetch(DBselect('SELECT COUNT(eventid) as cnt from events')); $status["events_count"]=$row["cnt"];*/ // alerts -/* $row=DBfetch(DBselect("select count(alertid) as cnt from alerts")); +/* $row=DBfetch(DBselect('SELECT COUNT(alertid) as cnt from alerts")); $status["alerts_count"]=$row["cnt"];*/ + // triggers $sql = 'SELECT COUNT(DISTINCT t.triggerid) as cnt '. ' FROM triggers t, functions f, items i, hosts h'. @@ -773,22 +774,23 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! ' AND h.status='.HOST_STATUS_MONITORED; $row=DBfetch(DBselect($sql)); - $status["triggers_count"]=$row["cnt"]; + $status['triggers_count']=$row['cnt']; - $row=DBfetch(DBselect($sql." and t.status=0")); - $status["triggers_count_enabled"]=$row["cnt"]; + $row=DBfetch(DBselect($sql.' and t.status=0')); + $status['triggers_count_enabled']=$row['cnt']; - $row=DBfetch(DBselect($sql." and t.status=1")); - $status["triggers_count_disabled"]=$row["cnt"]; + $row=DBfetch(DBselect($sql.' and t.status=1')); + $status['triggers_count_disabled']=$row['cnt']; - $row=DBfetch(DBselect($sql." and t.status=0 and t.value=0")); - $status["triggers_count_off"]=$row["cnt"]; + $row=DBfetch(DBselect($sql.' and t.status=0 and t.value=0')); + $status['triggers_count_off']=$row['cnt']; - $row=DBfetch(DBselect($sql." and t.status=0 and t.value=1")); - $status["triggers_count_on"]=$row["cnt"]; + $row=DBfetch(DBselect($sql.' and t.status=0 and t.value=1')); + $status['triggers_count_on']=$row['cnt']; - $row=DBfetch(DBselect($sql." and t.status=0 and t.value=2")); - $status["triggers_count_unknown"]=$row["cnt"]; + $row=DBfetch(DBselect($sql.' and t.status=0 and t.value=2')); + $status['triggers_count_unknown']=$row['cnt']; + // items $sql = 'SELECT COUNT(DISTINCT i.itemid) as cnt '. ' FROM items i, hosts h '. @@ -796,127 +798,147 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! ' AND h.status='.HOST_STATUS_MONITORED; $row=DBfetch(DBselect($sql)); - $status["items_count"]=$row["cnt"]; + $status['items_count']=$row['cnt']; - $row=DBfetch(DBselect($sql." and i.status=0")); - $status["items_count_monitored"]=$row["cnt"]; + $row=DBfetch(DBselect($sql.' and i.status=0')); + $status['items_count_monitored']=$row['cnt']; - $row=DBfetch(DBselect($sql." and i.status=1")); - $status["items_count_disabled"]=$row["cnt"]; + $row=DBfetch(DBselect($sql.' and i.status=1')); + $status['items_count_disabled']=$row['cnt']; - $row=DBfetch(DBselect($sql." and i.status=3")); - $status["items_count_not_supported"]=$row["cnt"]; + $row=DBfetch(DBselect($sql.' and i.status=3')); + $status['items_count_not_supported']=$row['cnt']; - $row=DBfetch(DBselect($sql." and i.type=2")); - $status["items_count_trapper"]=$row["cnt"]; + $row=DBfetch(DBselect($sql.' and i.type=2')); + $status['items_count_trapper']=$row['cnt']; + // hosts - $row=DBfetch(DBselect("select count(hostid) as cnt from hosts")); - $status["hosts_count"]=$row["cnt"]; + $sql = 'SELECT COUNT(hostid) as cnt '. + ' FROM hosts '. + ' WHERE status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.','.HOST_STATUS_TEMPLATE.','.HOST_STATUS_DELETED.' )'; + $row=DBfetch(DBselect($sql)); + $status['hosts_count']=$row['cnt']; - $row=DBfetch(DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_MONITORED)); - $status["hosts_count_monitored"]=$row["cnt"]; + $row=DBfetch(DBselect('SELECT COUNT(hostid) as cnt FROM hosts WHERE status='.HOST_STATUS_MONITORED)); + $status['hosts_count_monitored']=$row['cnt']; - $row=DBfetch(DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_NOT_MONITORED)); - $status["hosts_count_not_monitored"]=$row["cnt"]; + $row=DBfetch(DBselect('SELECT COUNT(hostid) as cnt FROM hosts WHERE status='.HOST_STATUS_NOT_MONITORED)); + $status['hosts_count_not_monitored']=$row['cnt']; - $row=DBfetch(DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_TEMPLATE)); - $status["hosts_count_template"]=$row["cnt"]; + $row=DBfetch(DBselect('SELECT COUNT(hostid) as cnt FROM hosts WHERE status='.HOST_STATUS_TEMPLATE)); + $status['hosts_count_template']=$row['cnt']; - $row=DBfetch(DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_DELETED)); - $status["hosts_count_deleted"]=$row["cnt"]; + $row=DBfetch(DBselect('SELECT COUNT(hostid) as cnt FROM hosts WHERE status='.HOST_STATUS_DELETED)); + $status['hosts_count_deleted']=$row['cnt']; + // users - $row=DBfetch(DBselect("select count(userid) as cnt from users")); - $status["users_count"]=$row["cnt"]; + $row=DBfetch(DBselect('SELECT COUNT(userid) as cnt FROM users')); + $status['users_count']=$row['cnt']; - $status["users_online"]=0; - $result=DBselect("select distinct s.userid from sessions s, users u where u.userid=s.userid and u.autologout>0 and (s.lastaccess+u.autologout)>".time()); - while(DBfetch($result)) $status["users_online"]++; - $result=DBselect("select distinct s.userid from sessions s, users u where u.userid=s.userid and u.autologout=0"); - while(DBfetch($result)) $status["users_online"]++; - - $result=DBselect("select i.type, i.delay, count(*),count(*)/i.delay as qps from items i,hosts h where i.status=".ITEM_STATUS_ACTIVE." and i.hostid=h.hostid and h.status=".HOST_STATUS_MONITORED." group by i.type,i.delay order by i.type, i.delay"); - - $status["qps_total"]=0; + $status['users_online']=0; + $sql = 'SELECT DISTINCT s.userid '. + ' FROM sessions s, users u '. + ' WHERE u.userid=s.userid '. + ' AND u.autologout>0 '. + ' AND (s.lastaccess+u.autologout)>'.time(); + $result=DBselect($sql); + while(DBfetch($result)) $status['users_online']++; + + $result=DBselect('SELECT DISTINCT s.userid '. + ' FROM sessions s, users u '. + ' WHERE u.userid=s.userid '. + ' AND u.autologout=0'); + while(DBfetch($result)) $status['users_online']++; + + $result=DBselect('SELECT i.type, i.delay, count(*),count(*)/i.delay as qps '. + ' FROM items i,hosts h '. + ' WHERE i.status='.ITEM_STATUS_ACTIVE. + ' AND i.hostid=h.hostid '. + ' AND h.status='.HOST_STATUS_MONITORED. + ' GROUP BY i.type,i.delay '. + ' ORDER BY i.type, i.delay'); + + $status['qps_total']=0; while($row=DBfetch($result)){ - $status["qps_total"]+=$row["qps"]; + $status['qps_total']+=$row['qps']; } - return $status; + return $status; } function get_resource_name($permission,$id){ - $res="-"; - if($permission=="Graph"){ + $res='-'; + if($permission=='Graph'){ if(isset($id)&&($id!=0)){ if($graph=get_graph_by_graphid($id)) - $res=$graph["name"]; + $res=$graph['name']; } else if(!isset($id) || $id == 0){ - $res="All graphs"; + $res='All graphs'; } } - else if($permission=="Host"){ + else if($permission=='Host'){ if(isset($id)&&($id!=0)){ if($host=get_host_by_hostid($id)) - $res=$host["host"]; + $res=$host['host']; } else if(!isset($id) || $id == 0){ - $res="All hosts"; + $res='All hosts'; } } - else if($permission=="Screen"){ + else if($permission=='Screen'){ if(isset($id)&&($id!=0)){ if($screen=get_screen_by_screenid($id)) - $res=$screen["name"]; + $res=$screen['name']; } else if(!isset($id) || $id == 0){ - $res="All screens"; + $res='All screens'; } } - else if($permission=="Item"){ + else if($permission=='Item'){ if(isset($id)&&($id!=0)){ if($item=get_item_by_itemid($id)) - if($host=get_host_by_hostid($item["hostid"])) - $res=$host["host"].":".$item["description"]; + if($host=get_host_by_hostid($item['hostid'])) + $res=$host['host'].':'.$item['description']; } else if(!isset($id) || $id == 0){ - $res="All items"; + $res='All items'; } } - else if($permission=="User"){ + else if($permission=='User'){ if(isset($id)&&($id!=0)){ if($user=get_user_by_userid($id)) - $res=$user["alias"]; + $res=$user['alias']; } else if(!isset($id) || $id == 0){ - $res="All users"; + $res='All users'; } } - else if($permission=="Network map"){ + else if($permission=='Network map'){ if(isset($id)&&($id!=0)){ if($user=get_sysmap_by_sysmapid($id)) - $res=$user["name"]; + $res=$user['name']; } else if(!isset($id) || $id == 0){ - $res="All maps"; + $res='All maps'; } } - else if($permission=="Application"){ + else if($permission=='Application'){ if(isset($id)&&($id > 0)){ if($app = get_application_by_applicationid($id)) - $res = $app["name"]; + $res = $app['name']; } else if(!isset($id) || $id == 0){ - $res="All applications"; + $res='All applications'; } } - else if($permission=="Service"){ + else if($permission=='Service'){ if(isset($id)&&($id > 0)){ if($service = get_service_by_serviceid($id)) - $res = $service["name"]; + $res = $service['name']; } else if(!isset($id) || $id == 0){ - $res="All services"; + $res='All services'; } } @@ -927,7 +949,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! } /* Use ImageSetStyle+ImageLIne instead of bugged ImageDashedLine */ - if(function_exists("imagesetstyle")){ + if(function_exists('imagesetstyle')){ function DashedLine($image,$x1,$y1,$x2,$y2,$color){ // Style for dashed lines // $style = array($color, $color, $color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); @@ -988,7 +1010,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! /*************** VALUE MAPPING ******************/ function add_mapping_to_valuemap($valuemapid, $mappings){ - DBexecute("delete from mappings where valuemapid=$valuemapid"); + DBexecute("delete FROM mappings WHERE valuemapid=$valuemapid"); foreach($mappings as $map){ $mappingid = get_dbid("mappings","mappingid"); @@ -1026,7 +1048,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! if(!is_array($mappings)) return FALSE; $result = DBexecute("update valuemaps set name=".zbx_dbstr($name). - " where valuemapid=$valuemapid"); + " WHERE valuemapid=$valuemapid"); if(!$result) return $result; @@ -1039,16 +1061,16 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! } function delete_valuemap($valuemapid){ - DBexecute("delete from mappings where valuemapid=$valuemapid"); - DBexecute("delete from valuemaps where valuemapid=$valuemapid"); + DBexecute("delete FROM mappings WHERE valuemapid=$valuemapid"); + DBexecute("delete FROM valuemaps WHERE valuemapid=$valuemapid"); return TRUE; } function replace_value_by_map($value, $valuemapid){ if($valuemapid < 1) return $value; - $result = DBselect("select newvalue from mappings". - " where valuemapid=".zbx_dbstr($valuemapid)." and value=".zbx_dbstr($value)); + $result = DBselect("SELECT newvalue FROM mappings". + " WHERE valuemapid=".zbx_dbstr($valuemapid)." and value=".zbx_dbstr($value)); $row = DBfetch($result); if($row){ return $row["newvalue"]." "."($value)"; diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php index e20342b9..0ab259f4 100644 --- a/frontends/php/include/graphs.inc.php +++ b/frontends/php/include/graphs.inc.php @@ -191,11 +191,17 @@ * Aly * */ - function get_accessible_graphs($perm,$perm_res=null,$nodeid=null,$hostid=null){ + function get_accessible_graphs($perm,$perm_res=null,$nodeid=null,$hostid=null,$cache=1){ global $USER_DETAILS; - - if(is_null($perm_res)) - $perm_res = PERM_RES_STRING_LINE; + static $available_graphs; + + if(is_null($perm_res)) $perm_res = PERM_RES_STRING_LINE; + $nodeid_str =(is_array($nodeid))?implode('',$nodeid):strval($nodeid); + $hostid_str =(is_array($hostid))?implode('',$hostid):strval($hostid); + + if($cache && isset($available_graphs[$perm][$perm_res][$nodeid_str][$hostid_str])){ + return $available_triggers[$perm][$perm_res][$nodeid_str][$hostid_str]; + } $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, PERM_RES_IDS_ARRAY, $nodeid); @@ -233,6 +239,8 @@ else $result = implode(',',$result); } + + $available_graphs[$perm][$perm_res][$nodeid_str][$hostid_str] = $result; return $result; } diff --git a/frontends/php/include/maps.inc.php b/frontends/php/include/maps.inc.php index f194169b..b80c26db 100644 --- a/frontends/php/include/maps.inc.php +++ b/frontends/php/include/maps.inc.php @@ -19,23 +19,22 @@ **/ ?> <?php - require_once "include/images.inc.php"; - require_once "include/hosts.inc.php"; - require_once "include/triggers.inc.php"; - require_once "include/scripts.inc.php"; + require_once('include/images.inc.php'); + require_once('include/hosts.inc.php'); + require_once('include/triggers.inc.php'); + require_once('include/scripts.inc.php'); - /* - * Function: map_link_drawtypes - * - * Description: - * Return available drawing types for links - * - * Author: - * Eugene Grigorjev - * - */ - function map_link_drawtypes() - { +/* + * Function: map_link_drawtypes + * + * Description: + * Return available drawing types for links + * + * Author: + * Eugene Grigorjev + * + */ + function map_link_drawtypes(){ return array( MAP_LINK_DRAWTYPE_LINE, MAP_LINK_DRAWTYPE_BOLD_LINE, @@ -44,17 +43,17 @@ ); } - /* - * Function: map_link_drawtype2str - * - * Description: - * Represent integer value of links drawing type into the string - * - * Author: - * Eugene Grigorjev - * - */ - function map_link_drawtype2str($drawtype){ +/* + * Function: map_link_drawtype2str + * + * Description: + * Represent integer value of links drawing type into the string + * + * Author: + * Eugene Grigorjev + * + */ + function map_link_drawtype2str($drawtype){ switch($drawtype){ case MAP_LINK_DRAWTYPE_LINE: $drawtype = S_LINE; break; case MAP_LINK_DRAWTYPE_BOLD_LINE: $drawtype = S_BOLD_LINE; break; @@ -65,18 +64,15 @@ return $drawtype; } - /* - * Function: sysmap_accessible - * - * Description: - * Check permission for map - * - * Return: true on success - - * Author: - * Eugene Grigorjev - * - */ +/* + * Function: sysmap_accessible + * + * Description: Check permission for map + * + * Return: true on success + * + * Author: Aly + */ function sysmap_accessible($sysmapid,$perm){ global $USER_DETAILS; @@ -88,7 +84,7 @@ ' AND '.DBin_node('sysmapid', get_current_nodeid($perm)))) { $result = true; - $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_RES_IDS_ARRAY); + $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,$perm,PERM_RES_IDS_ARRAY); while(($se_data = DBfetch($db_result)) && $result){ switch($se_data['elementtype']){ @@ -98,29 +94,17 @@ } break; case SYSMAP_ELEMENT_TYPE_MAP: - $result &= sysmap_accessible($se_data['elementid'], PERM_READ_ONLY); + $result = sysmap_accessible($se_data['elementid'], PERM_READ_ONLY); break; case SYSMAP_ELEMENT_TYPE_TRIGGER: - $available_triggers = get_accessible_triggers(PERM_READ_ONLY, PERM_RES_IDS_ARRAY); - - $sql = 'SELECT t.triggerid '. - ' FROM triggers t'. - ' WHERE t.triggerid='.$se_data['elementid']. - ' AND '.DBcondition('t.triggerid',$available_triggers,true); - if(DBfetch(DBselect($sql,1))){ - $result = false; + $available_triggers = get_accessible_triggers($perm, PERM_RES_IDS_ARRAY); + if(!uint_in_array($se_data['elementid'],$available_triggers)){ + $result = false; } - break; case SYSMAP_ELEMENT_TYPE_HOST_GROUP: - $available_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY); - - $sql = 'SELECT g.groupid '. - ' FROM groups g '. - ' WHERE g.groupid='.$se_data['elementid']. - ' AND g.groupid NOT IN('.$available_groups.') '; - - if(DBfetch(DBselect($sql,1))){ + $available_groups = get_accessible_groups_by_user($USER_DETAILS,$perm); + if(!uint_in_array($se_data['elementid'],$available_groups)){ $result = false; } break; @@ -132,7 +116,7 @@ ' AND '.DBin_node('sysmapid', get_current_nodeid($perm)))) $result = true; } - return $result; + return $result; } function get_sysmap_by_sysmapid($sysmapid){ @@ -159,8 +143,7 @@ // Add System Map - function add_sysmap($name,$width,$height,$backgroundid,$label_type,$label_location) - { + function add_sysmap($name,$width,$height,$backgroundid,$label_type,$label_location){ $sysmapid=get_dbid("sysmaps","sysmapid"); $result=DBexecute("insert into sysmaps (sysmapid,name,width,height,backgroundid,label_type,label_location)". @@ -170,13 +153,12 @@ if(!$result) return $result; - return $sysmapid; + return $sysmapid; } // Update System Map - function update_sysmap($sysmapid,$name,$width,$height,$backgroundid,$label_type,$label_location) - { + function update_sysmap($sysmapid,$name,$width,$height,$backgroundid,$label_type,$label_location){ return DBexecute("update sysmaps set name=".zbx_dbstr($name).",width=$width,height=$height,". "backgroundid=".$backgroundid.",label_type=$label_type,". "label_location=$label_location WHERE sysmapid=$sysmapid"); @@ -567,8 +549,7 @@ } } - if(isset($tr_info[TRIGGER_VALUE_TRUE])) - { + if(isset($tr_info[TRIGGER_VALUE_TRUE])){ $inf =& $tr_info[TRIGGER_VALUE_TRUE]; $out['type'] = TRIGGER_VALUE_TRUE; @@ -586,8 +567,7 @@ $out['iconid'] = $db_element['iconid_on']; } - elseif(isset($tr_info[TRIGGER_VALUE_UNKNOWN]) && !isset($tr_info[TRIGGER_VALUE_FALSE])) - { + else if(isset($tr_info[TRIGGER_VALUE_UNKNOWN]) && !isset($tr_info[TRIGGER_VALUE_FALSE])){ $inf =& $tr_info[TRIGGER_VALUE_UNKNOWN]; $out['type'] = TRIGGER_VALUE_UNKNOWN; @@ -604,8 +584,7 @@ else $out['iconid'] = $db_element['iconid_unknown']; } - else - { + else{ $inf =& $tr_info[TRIGGER_VALUE_FALSE]; $out['type'] = TRIGGER_VALUE_FALSE; @@ -622,7 +601,7 @@ $out['priority'] = $inf['priority']; $out['name'] = $el_name; - return $out; + return $out; } /* @@ -635,19 +614,16 @@ * Eugene Grigorjev * */ - function get_action_map_by_sysmapid($sysmapid) - { + function get_action_map_by_sysmapid($sysmapid){ $action_map = new CMap("links$sysmapid"); $db_elements=DBselect('SELECT * FROM sysmaps_elements WHERE sysmapid='.$sysmapid); - while($db_element = DBfetch($db_elements)) - { + while($db_element = DBfetch($db_elements)){ $url = $db_element["url"]; $alt = "Label: ".$db_element["label"]; $scripts_by_hosts = null; - if($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST) - { + if($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST){ $host = get_host_by_hostid($db_element["elementid"]); if($host["status"] != HOST_STATUS_MONITORED) continue; @@ -657,8 +633,7 @@ $alt = "Host: ".$host["host"]." ".$alt; } - elseif($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_MAP) - { + else if($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_MAP){ $map = get_sysmap_by_sysmapid($db_element["elementid"]); if(empty($url)) @@ -671,8 +646,7 @@ if(empty($url) && $db_element["elementid"]!=0) $url="events.php?triggerid=".$db_element["elementid"]; } - elseif($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST_GROUP) - { + else if($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST_GROUP){ if(empty($url) && $db_element["elementid"]!=0) $url="events.php?hostid=0&groupid=".$db_element["elementid"]; } diff --git a/frontends/php/include/page_header.php b/frontends/php/include/page_header.php index bd04e0f9..c8c25a16 100644 --- a/frontends/php/include/page_header.php +++ b/frontends/php/include/page_header.php @@ -52,15 +52,15 @@ COpt::profiling_start("page"); case PAGE_TYPE_XML: header('Content-Type: text/xml'); header('Content-Disposition: attachment; filename="'.$page['file'].'"'); - define('ZBX_PAGE_NO_MENU', 1); + if(!defined('ZBX_PAGE_NO_MENU')) define('ZBX_PAGE_NO_MENU', 1); break; case PAGE_TYPE_JS: header('Content-Type: application/javascript; charset=UTF-8'); - define('ZBX_PAGE_NO_MENU', 1); + if(!defined('ZBX_PAGE_NO_MENU')) define('ZBX_PAGE_NO_MENU', 1); break; case PAGE_TYPE_HTML_BLOCK: header('Content-Type: text/plain; charset=UTF-8'); - define('ZBX_PAGE_NO_MENU', 1); + if(!defined('ZBX_PAGE_NO_MENU')) define('ZBX_PAGE_NO_MENU', 1); break; case PAGE_TYPE_HTML: default: diff --git a/frontends/php/include/perm.inc.php b/frontends/php/include/perm.inc.php index 9d74caa4..a9f2ba93 100644 --- a/frontends/php/include/perm.inc.php +++ b/frontends/php/include/perm.inc.php @@ -19,8 +19,7 @@ **/ ?> <?php -function permission2str($group_permission) -{ +function permission2str($group_permission){ $str_perm[PERM_READ_WRITE] = S_READ_WRITE; $str_perm[PERM_READ_ONLY] = S_READ_ONLY; $str_perm[PERM_DENY] = S_DENY; @@ -282,9 +281,10 @@ function get_accessible_hosts_by_user(&$user_data,$perm,$perm_res=null,$nodeid=n $nodeid_str =(is_array($nodeid))?md5(implode('',$nodeid)):strval($nodeid); if($cache && isset($available_hosts[$userid][$perm][$perm_res][$nodeid_str])){ +//SDI('Cache!!! '."[$userid][$perm][$perm_res]"); return $available_hosts[$userid][$perm][$perm_res][$nodeid_str]; } - +//SDI('NOOOO Cache!!!'."[$userid][$perm][$perm_res]"); COpt::counter_up('perm_host['.$userid.','.$perm.','.$perm_res.','.$nodeid.']'); COpt::counter_up('perm'); diff --git a/frontends/php/include/screens.inc.php b/frontends/php/include/screens.inc.php index 4871e0bf..2fb7b9ce 100644 --- a/frontends/php/include/screens.inc.php +++ b/frontends/php/include/screens.inc.php @@ -54,7 +54,7 @@ if(DBfetch(DBselect('SELECT itemid '. ' FROM items '. - ' WHERE itemid IN ('.implode(',',$itemid).') '. + ' WHERE '.DBcondition('itemid',$itemid). ' AND '.DBcondition('hostid',$available_hosts,true)))) { $result = false; diff --git a/frontends/php/maps.php b/frontends/php/maps.php index ea2710b8..34a1f6c3 100644 --- a/frontends/php/maps.php +++ b/frontends/php/maps.php @@ -19,10 +19,10 @@ **/ ?> <?php - require_once "include/config.inc.php"; + require_once('include/config.inc.php'); - $page["title"] = "S_NETWORK_MAPS"; - $page["file"] = "maps.php"; + $page['title'] = "S_NETWORK_MAPS"; + $page['file'] = 'maps.php'; $page['hist_arg'] = array('sysmapid'); $page['scripts'] = array('prototype.js','url.js'); @@ -32,7 +32,7 @@ define('ZBX_PAGE_DO_REFRESH', 1); } -include_once "include/page_header.php"; +include_once('include/page_header.php'); ?> <?php @@ -192,4 +192,4 @@ include_once "include/page_header.php"; include_once "include/page_footer.php"; -?> +?>
\ No newline at end of file |