diff options
author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-11-29 09:17:03 +0000 |
---|---|---|
committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-11-29 09:17:03 +0000 |
commit | 25fe20d517ee1553fd569fba2f6c33ee5a9a446a (patch) | |
tree | 74c7002f7eb1c9bd518128352a2711d1723dfa2c /frontends | |
parent | 4df0316c5b609a2a609d9c6a6cd539ded33351d6 (diff) | |
download | zabbix-25fe20d517ee1553fd569fba2f6c33ee5a9a446a.tar.gz zabbix-25fe20d517ee1553fd569fba2f6c33ee5a9a446a.tar.xz zabbix-25fe20d517ee1553fd569fba2f6c33ee5a9a446a.zip |
- [DEV-55] Screen elements('graph','simple graph','plain text') are extended, added new field in DB,table 'screens_items' 'dynamic' (Artem)
git-svn-id: svn://svn.zabbix.com/trunk@5116 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends')
-rw-r--r-- | frontends/php/chart.php | 2 | ||||
-rw-r--r-- | frontends/php/charts.php | 1 | ||||
-rw-r--r-- | frontends/php/include/config.inc.php | 55 | ||||
-rw-r--r-- | frontends/php/include/defines.inc.php | 3 | ||||
-rw-r--r-- | frontends/php/include/forms.inc.php | 32 | ||||
-rw-r--r-- | frontends/php/include/graphs.inc.php | 238 | ||||
-rw-r--r-- | frontends/php/include/hosts.inc.php | 2 | ||||
-rw-r--r-- | frontends/php/include/html.inc.php | 6 | ||||
-rw-r--r-- | frontends/php/include/items.inc.php | 46 | ||||
-rw-r--r-- | frontends/php/include/locales/en_gb.inc.php | 2 | ||||
-rw-r--r-- | frontends/php/include/screens.inc.php | 210 | ||||
-rw-r--r-- | frontends/php/screenedit.php | 38 | ||||
-rw-r--r-- | frontends/php/screens.php | 133 |
13 files changed, 525 insertions, 243 deletions
diff --git a/frontends/php/chart.php b/frontends/php/chart.php index 7806f83f..e8ccabbe 100644 --- a/frontends/php/chart.php +++ b/frontends/php/chart.php @@ -47,7 +47,7 @@ include_once "include/page_header.php"; if(! (DBfetch(DBselect('select itemid from items where itemid='.$_REQUEST['itemid']))) ) { show_error_message(S_NO_ITEM_DEFINED); - +// show_message(S_NO_ITEM_DEFINED); } if(! ($db_data = DBfetch(DBselect("select i.itemid from items i ". diff --git a/frontends/php/charts.php b/frontends/php/charts.php index 47e0c246..bcd5bece 100644 --- a/frontends/php/charts.php +++ b/frontends/php/charts.php @@ -104,7 +104,6 @@ include_once 'include/page_header.php'; $h1 = array(S_GRAPHS_BIG.SPACE."/".SPACE); $availiable_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_LIST, null, null, get_current_nodeid()); -// $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, PERM_MODE_LT); $availiable_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_LIST, null, null, get_current_nodeid()); if($_REQUEST['graphid'] > 0 && DBfetch(DBselect('select distinct graphid from graphs where graphid='.$_REQUEST['graphid']))) diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php index 52d69e90..5840f8c3 100644 --- a/frontends/php/include/config.inc.php +++ b/frontends/php/include/config.inc.php @@ -922,61 +922,6 @@ function TODO($msg) { echo "TODO: ".$msg.BR; } // DEBUG INFO!!! else return validate_float($str); } - # Show screen cell containing plain text values - function& get_screen_plaintext($itemid,$elements) - { - global $DB_TYPE; - - $item=get_item_by_itemid($itemid); - switch($item["value_type"]) - { - case ITEM_VALUE_TYPE_FLOAT: $history_table = "history"; break; - case ITEM_VALUE_TYPE_UINT64: $history_table = "history_uint"; break; - case ITEM_VALUE_TYPE_TEXT: $history_table = "history_text"; break; - default: $history_table = "history_str"; break; - } - - $sql="select h.clock,h.value,i.valuemapid from ".$history_table." h, items i where". - " h.itemid=i.itemid and i.itemid=$itemid order by clock desc"; - - $result=DBselect($sql,$elements); - - $table = new CTableInfo(); - $table->SetHeader(array(S_TIMESTAMP,item_description($item["description"],$item["key_"]))); - while($row=DBfetch($result)) - { - switch($item["value_type"]) - { - case ITEM_VALUE_TYPE_TEXT: - if($DB_TYPE == "ORACLE") - { - if(isset($row["value"])) - { - $row["value"] = $row["value"]->load(); - } - else - { - $row["value"] = ""; - } - } - /* do not use break */ - case ITEM_VALUE_TYPE_STR: - $value = nl2br(nbsp(htmlspecialchars($row["value"]))); - break; - - default: - $value = $row["value"]; - break; - } - - if($row["valuemapid"] > 0) - $value = replace_value_by_map($value, $row["valuemapid"]); - - $table->AddRow(array(date(S_DATE_FORMAT_YMDHMS,$row["clock"]), $value)); - } - return $table; - } - # Add event function get_event_by_eventid($eventid) diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php index a773d373..67dd6531 100644 --- a/frontends/php/include/defines.inc.php +++ b/frontends/php/include/defines.inc.php @@ -266,6 +266,9 @@ define('LOGFILE_SEVERITY_AUDIT_SUCCESS',6); define('LOGFILE_SEVERITY_AUDIT_FAILURE',7); + define('SCREEN_SIMPLE_ITEM',0); + define('SCREEN_DYNAMIC_ITEM',1); + define('SCREEN_RESOURCE_GRAPH', 0); define('SCREEN_RESOURCE_SIMPLE_GRAPH', 1); define('SCREEN_RESOURCE_MAP', 2); diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index 484fad75..08de9df0 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -3576,27 +3576,28 @@ include_once 'include/discovery.inc.php'; $frmScr->Show(); } - function& get_screen_item_form(){ + function get_screen_item_form(){ global $USER_DETAILS; $form = new CFormTable(S_SCREEN_CELL_CONFIGURATION,'screenedit.php#form'); $form->SetHelp('web.screenedit.cell.php'); - if(isset($_REQUEST["screenitemid"])) - { - $iresult=DBSelect("select * FROM screens_items". - " WHERE screenid=".$_REQUEST["screenid"]. - " AND screenitemid=".$_REQUEST["screenitemid"]); + if(isset($_REQUEST["screenitemid"])){ + $iresult=DBSelect('SELECT * FROM screens_items'. + ' WHERE screenid='.$_REQUEST['screenid']. + ' AND screenitemid='.$_REQUEST['screenitemid'] + ); $form->AddVar("screenitemid",$_REQUEST["screenitemid"]); - } else { + } + else{ $form->AddVar("x",$_REQUEST["x"]); $form->AddVar("y",$_REQUEST["y"]); } - if(isset($_REQUEST["screenitemid"]) && !isset($_REQUEST["form_refresh"])) - { + if(isset($_REQUEST["screenitemid"]) && !isset($_REQUEST["form_refresh"])){ + $irow = DBfetch($iresult); $resourcetype = $irow["resourcetype"]; $resourceid = $irow["resourceid"]; @@ -3609,9 +3610,9 @@ include_once 'include/discovery.inc.php'; $halign = $irow["halign"]; $style = $irow["style"]; $url = $irow["url"]; + $dynamic = $irow['dynamic']; } - else - { + else{ $resourcetype = get_request("resourcetype", 0); $resourceid = get_request("resourceid", 0); $width = get_request("width", 500); @@ -3623,6 +3624,7 @@ include_once 'include/discovery.inc.php'; $halign = get_request("halign", HALIGN_DEFAULT); $style = get_request("style", 0); $url = get_request("url", ""); + $dynamic = get_request("dynamic", SCREEN_SIMPLE_ITEM); } $form->AddVar("screenid",$_REQUEST["screenid"]); @@ -3958,9 +3960,13 @@ include_once 'include/discovery.inc.php'; $form->AddRow(S_COLUMN_SPAN, new CNumericBox("colspan",$colspan,2)); $form->AddRow(S_ROW_SPAN, new CNumericBox("rowspan",$rowspan,2)); +// dynamic AddOn + if(in_array($resourcetype,array(SCREEN_RESOURCE_GRAPH,SCREEN_RESOURCE_SIMPLE_GRAPH,SCREEN_RESOURCE_PLAIN_TEXT))){ + $form->AddRow(S_DYNAMIC_ITEM, new CCheckBox("dynamic",$dynamic,null,1)); + } + $form->AddItemToBottomRow(new CButton("save",S_SAVE)); - if(isset($_REQUEST["screenitemid"])) - { + if(isset($_REQUEST["screenitemid"])){ $form->AddItemToBottomRow(SPACE); $form->AddItemToBottomRow(new CButtonDelete(null, url_param("form").url_param("screenid").url_param("screenitemid"))); diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php index df1e621e..b4d1bde0 100644 --- a/frontends/php/include/graphs.inc.php +++ b/frontends/php/include/graphs.inc.php @@ -19,16 +19,16 @@ **/ ?> <?php - /* - * Function: graph_item_type2str - * - * Description: - * Represent integer value of graph item type into the string - * - * Author: - * Eugene Grigorjev - * - */ +/* + * Function: graph_item_type2str + * + * Description: + * Represent integer value of graph item type into the string + * + * Author: + * Eugene Grigorjev + * + */ function graph_item_type2str($type,$count=null) { switch($type){ @@ -46,16 +46,16 @@ return $type; } - /* - * Function: graph_item_drawtypes - * - * Description: - * Return available drawing types for graph item - * - * Author: - * Eugene Grigorjev - * - */ +/* + * Function: graph_item_drawtypes + * + * Description: + * Return available drawing types for graph item + * + * Author: + * Eugene Grigorjev + * + */ function graph_item_drawtypes() { return array( @@ -67,42 +67,42 @@ ); } - /* - * Function: graph_item_drawtype2str - * - * Description: - * Represent integer value of graph item drawing type into the string - * - * Author: - * Eugene Grigorjev - * - */ - function graph_item_drawtype2str($drawtype,$type=null) - { - if($type == GRAPH_ITEM_AGGREGATED) return '-'; +/* + * Function: graph_item_drawtype2str + * + * Description: + * Represent integer value of graph item drawing type into the string + * + * Author: + * Eugene Grigorjev + * + */ + function graph_item_drawtype2str($drawtype,$type=null) + { + if($type == GRAPH_ITEM_AGGREGATED) return '-'; - switch($drawtype) - { - case GRAPH_ITEM_DRAWTYPE_LINE: $drawtype = "Line"; break; - case GRAPH_ITEM_DRAWTYPE_FILLED_REGION: $drawtype = "Filled region"; break; - case GRAPH_ITEM_DRAWTYPE_BOLD_LINE: $drawtype = "Bold line"; break; - case GRAPH_ITEM_DRAWTYPE_DOT: $drawtype = "Dot"; break; - case GRAPH_ITEM_DRAWTYPE_DASHED_LINE: $drawtype = "Dashed line"; break; - default: $drawtype = S_UNKNOWN; break; - } - return $drawtype; - } + switch($drawtype) + { + case GRAPH_ITEM_DRAWTYPE_LINE: $drawtype = "Line"; break; + case GRAPH_ITEM_DRAWTYPE_FILLED_REGION: $drawtype = "Filled region"; break; + case GRAPH_ITEM_DRAWTYPE_BOLD_LINE: $drawtype = "Bold line"; break; + case GRAPH_ITEM_DRAWTYPE_DOT: $drawtype = "Dot"; break; + case GRAPH_ITEM_DRAWTYPE_DASHED_LINE: $drawtype = "Dashed line"; break; + default: $drawtype = S_UNKNOWN; break; + } + return $drawtype; + } - /* - * Function: graph_item_calc_fnc2str - * - * Description: - * Represent integer value of calculation function into the string - * - * Author: - * Eugene Grigorjev - * - */ +/* + * Function: graph_item_calc_fnc2str + * + * Description: + * Represent integer value of calculation function into the string + * + * Author: + * Eugene Grigorjev + * + */ function graph_item_calc_fnc2str($calc_fnc, $type=null) { if($type == GRAPH_ITEM_AGGREGATED) return '-'; @@ -161,7 +161,7 @@ * Return the time of the 1st apearance of items included in graph in trends * * Author: - * Artem Suharev + * Aly * */ function get_min_itemclock_by_graphid($graphid){ @@ -182,7 +182,7 @@ * Return the time of the 1st apearance of item in trends * * Author: - * Artem Suharev + * Aly * */ function get_min_itemclock_by_itemid($itemid){ @@ -236,36 +236,44 @@ return DBselect("SELECT * FROM graphs WHERE templateid=$templateid"); } - /* - * Function: get_same_graphitems_for_host - * - * Description: - * Replace items for specified host - * - * Author: - * Eugene Grigorjev - * - * Comments: !!! Don't forget sync code with C !!! - * - */ - function get_same_graphitems_for_host($gitems, $dest_hostid) +/* + * Function: get_same_graphitems_for_host + * + * Description: + * Replace items for specified host + * + * Author: + * Eugene Grigorjev + * + * Comments: !!! Don't forget sync code with C !!! + * Only PHP: + * $error= true : rise Error if item doesn't exists(error generated), false: special processing (NO error generated) + */ + function get_same_graphitems_for_host($gitems, $dest_hostid, $error=true) { $result = array(); foreach($gitems as $gitem) { - if ( !($db_item = DBfetch(DBselect('select src.itemid from items src, items dest '. - ' where dest.itemid='.$gitem['itemid']. - ' and src.key_=dest.key_ and src.hostid='.$dest_hostid))) ) - { - + $sql = 'SELECT src.itemid '. + ' FROM items src, items dest '. + ' WHERE dest.itemid='.zbx_dbstr($gitem['itemid']). + ' AND src.key_=dest.key_ '. + ' AND src.hostid='.$dest_hostid; + $db_item = DBfetch(DBselect($sql)); + if (!$db_item && $error){ $item = get_item_by_itemid($gitem['itemid']); $host = get_host_by_hostid($dest_hostid); error('Missed key "'.$item['key_'].'" for host "'.$host['host'].'"'); return false; } - - $gitem['itemid'] = $db_item['itemid']; + else if(!$db_item){ + continue; +// $gitem['itemid'] = 0; + } + else{ + $gitem['itemid'] = $db_item['itemid']; + } $result[] = $gitem; } @@ -922,4 +930,82 @@ return; } + + /* + * Function: + * make_array_from_gitems + * + * Description: + * Creates array with items params for preapare_url function + * + * Author: + * Aly + * + * Comments + * + */ + function make_url_from_gitems($gitems){ + + $gurl=array(); + $ifields = array( + 'itemid' => 1, + 'drawtype' => 1, + 'sortorder' => 1, + 'color' => 1, + 'yaxisside' => 1, + 'calc_fnc' => 1, + 'type' => 1, + 'periods_cnt'=>1 + ); + + foreach($gitems as $gitem){ + foreach($gitem as $name => $value){ + if(isset($ifields[$name])){ + $gurl['items['.$gitem['itemid'].']['.$name.']']=$value; + } + } + } + + return prepare_url($gurl); + } + + /* + * Function: + * make_array_from_graphid + * + * Description: + * Creates array with graph params for preapare_url function + * + * Author: + * Aly + * + * Comments + * $full= false: for screens(WITHOUT width && height), true=all params + */ + function make_url_from_graphid($graphid,$full=false){ + + $gurl=array(); + if($full){ + $gparams = array(); + } + else{ + $gparams = array( + 'height'=> 1, + 'width' => 1 + ); + } + + $graph=get_graph_by_graphid($graphid); + if($graph){ + foreach($graph as $name => $value){ + if(!is_numeric($name) && !isset($gparams[$name])) $gurl[$name]=$value; + } + } + + $url = prepare_url($gurl); + if(!empty($url)){ + $url=((($gurl['graphtype']==GRAPH_TYPE_PIE) || ($gurl['graphtype']==GRAPH_TYPE_EXPLODED))?'chart7.php?':'chart3.php?').trim($url,'&'); + } + return $url; + } ?> diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php index 2b393934..d245d3e1 100644 --- a/frontends/php/include/hosts.inc.php +++ b/frontends/php/include/hosts.inc.php @@ -493,7 +493,7 @@ require_once "include/items.inc.php"; return false; } - function get_host_by_itemid($itemid) + function get_host_by_itemid($itemid) { $sql="select h.* from hosts h, items i where i.hostid=h.hostid and i.itemid=$itemid"; $result=DBselect($sql); diff --git a/frontends/php/include/html.inc.php b/frontends/php/include/html.inc.php index 49204077..7233eb6e 100644 --- a/frontends/php/include/html.inc.php +++ b/frontends/php/include/html.inc.php @@ -65,12 +65,12 @@ if(isset($_REQUEST[$var])&&$_REQUEST[$var]==$value) $selected = "selected"; } - return "<option value=\"$value\" $selected>$label"; + return '<option value="'.$value.'" '.$selected.'>'.$label; } function form_input($name, $value, $size) { - return "<input class=\"biginput\" name=\"$name\" size=$size value=\"$value\">"; + return '<input class="'.biginput.'" name="'.$name.'" size="'.$size.'" value="'.$value.'">'; } function form_textarea($name, $value, $cols, $rows) @@ -92,7 +92,7 @@ } } - function prepare_url(&$var, $varname) + function prepare_url(&$var, $varname=null) { $result = ""; diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php index d0d0dd96..e2c4365b 100644 --- a/frontends/php/include/items.inc.php +++ b/frontends/php/include/items.inc.php @@ -724,6 +724,52 @@ error("No item with itemid=[$itemid]"); return FALSE; } + +/* + * Function: get_same_items_for_host + * + * Description: + * Replace items for specified host + * + * Author: + * Aly + * + * Comments: + * $error= true : rise Error if item doesn't exists(error generated), false: special processing (NO error generated) + */ + function get_same_item_for_host($item,$dest_hostid, $error=true){ + + if(!is_array($item)){ + $itemid = $item; + } + else if(isset($item['itemid'])){ + $itemid = $item['itemid']; + } + + if(isset($itemid)){ + $sql = 'SELECT src.itemid '. + ' FROM items src, items dest '. + ' WHERE dest.itemid='.zbx_dbstr($itemid). + ' AND src.key_=dest.key_ '. + ' AND src.hostid='.$dest_hostid; + + $db_item = DBfetch(DBselect($sql)); + if (!$db_item && $error){ + $item = get_item_by_itemid($db_item['itemid']); + $host = get_host_by_hostid($dest_hostid); + error('Missed key "'.$item['key_'].'" for host "'.$host['host'].'"'); + } + else{ + if(is_array($item)){ + return get_item_by_itemid($db_item['itemid']); + } + else{ + return $db_item['itemid']; + } + } + } + return false; + } /****************************************************************************** * * diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php index 145dd274..097e1f9f 100644 --- a/frontends/php/include/locales/en_gb.inc.php +++ b/frontends/php/include/locales/en_gb.inc.php @@ -497,6 +497,7 @@ 'S_ITEM_ADDED'=> 'Item added', 'S_ITEM_UPDATED'=> 'Item updated', 'S_ITEMS_UPDATED'=> 'Items updated', + 'S_ITEM_NOT_EXISTS'=> 'Item not exists', 'S_SORT_ORDER_UPDATED'=> 'Sort order updated', 'S_CANNOT_UPDATE_SORT_ORDER'=> 'Cannot update sort order', 'S_DISPLAYED_PARAMETERS_BIG'=> 'DISPLAYED PARAMETERS', @@ -1018,6 +1019,7 @@ 'S_HEIGHT'=> 'Height', 'S_CREATE_SCREEN'=> 'Create Screen', 'S_EDIT'=> 'Edit', + 'S_DYNAMIC_ITEM'=> 'Dynamic item', 'S_DIMENSION_COLS_ROWS'=> 'Dimension (cols x rows)', 'S_SLIDESHOWS'=> 'Slide shows', diff --git a/frontends/php/include/screens.inc.php b/frontends/php/include/screens.inc.php index 4cbe09bf..115c439a 100644 --- a/frontends/php/include/screens.inc.php +++ b/frontends/php/include/screens.inc.php @@ -106,42 +106,41 @@ return DBexecute($sql); } - function delete_screen($screenid) - { - $result=DBexecute("delete from screens_items where screenid=$screenid"); - if(!$result) return $result; - - $result=DBexecute("delete from screens_items where resourceid=$screenid and resourcetype=".SCREEN_RESOURCE_SCREEN); - if(!$result) return $result; - - $result=DBexecute('delete from slides where screenid='.$screenid); - if(!$result) return $result; + function delete_screen($screenid){ + $result=DBexecute("delete from screens_items where screenid=$screenid"); + if(!$result) return $result; + + $result=DBexecute("delete from screens_items where resourceid=$screenid and resourcetype=".SCREEN_RESOURCE_SCREEN); + if(!$result) return $result; - return DBexecute("delete from screens where screenid=$screenid"); + $result=DBexecute('delete from slides where screenid='.$screenid); + if(!$result) return $result; + + return DBexecute("delete from screens where screenid=$screenid"); } - function add_screen_item($resourcetype,$screenid,$x,$y,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style,$url) - { - $sql="delete from screens_items where screenid=$screenid and x=$x and y=$y"; - DBexecute($sql); - $screenitemid=get_dbid("screens_items","screenitemid"); - $result=DBexecute("insert into screens_items (screenitemid,resourcetype,screenid,x,y,resourceid,width,height,". - " colspan,rowspan,elements,valign,halign,style,url) ". - " values ($screenitemid,$resourcetype,$screenid,$x,$y,$resourceid,". - " $width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style,". - zbx_dbstr($url).")"); - - if(!$result) - return $result; - + function add_screen_item($resourcetype,$screenid,$x,$y,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style,$url,$dynamic){ + $sql="DELETE FROM screens_items WHERE screenid=$screenid and x=$x and y=$y"; + DBexecute($sql); + + $screenitemid=get_dbid("screens_items","screenitemid"); + $result=DBexecute('INSERT INTO screens_items '. + '(screenitemid,resourcetype,screenid,x,y,resourceid,width,height,'. + ' colspan,rowspan,elements,valign,halign,style,url) '. + ' VALUES '. + "($screenitemid,$resourcetype,$screenid,$x,$y,$resourceid,$width,$height,$colspan,". + "$rowspan,$elements,$valign,$halign,$style,".zbx_dbstr($url).",$dynamic)"); + + if(!$result) return $result; return $screenitemid; } - function update_screen_item($screenitemid,$resourcetype,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style,$url) - { - return DBexecute("update screens_items set resourcetype=$resourcetype,resourceid=$resourceid,". - "width=$width,height=$height,colspan=$colspan,rowspan=$rowspan,elements=$elements,valign=$valign,". - "halign=$halign,style=$style,url=".zbx_dbstr($url)." where screenitemid=$screenitemid"); + function update_screen_item($screenitemid,$resourcetype,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style,$url,$dynamic){ + return DBexecute("UPDATE screens_items SET ". + "resourcetype=$resourcetype,"."resourceid=$resourceid,"."width=$width,". + "height=$height,colspan=$colspan,rowspan=$rowspan,elements=$elements,". + "valign=$valign,halign=$halign,style=$style,url=".zbx_dbstr($url).",dynamic=$dynamic". + " WHERE screenitemid=$screenitemid"); } function delete_screen_item($screenitemid) @@ -162,8 +161,7 @@ return FALSE; } - function check_screen_recursion($mother_screenid, $child_screenid) - { + function check_screen_recursion($mother_screenid, $child_screenid){ if($mother_screenid == $child_screenid) return TRUE; $db_scr_items = DBselect("select resourceid from screens_items where". @@ -227,7 +225,7 @@ access_deny(); if(is_null($effectiveperiod)) - $effectiveperiod = 3600; + $effectiveperiod = ZBX_MIN_PERIOD; $result=DBselect('SELECT name,hsize,vsize FROM screens WHERE screenid='.$screenid); $row=DBfetch($result); @@ -289,11 +287,11 @@ $halign = $irow["halign"]; $style = $irow["style"]; $url = $irow["url"]; + $dynamic = $irow['dynamic']; } else { $screenitemid = 0; - $screenitemid = 0; $resourcetype = 0; $resourceid = 0; $width = 0; @@ -305,6 +303,7 @@ $halign = HALIGN_DEFAULT; $style = 0; $url = ""; + $dynamic = 0; } if($editmode == 1 && $screenitemid!=0) @@ -335,7 +334,7 @@ $graphtype = GRAPH_TYPE_NORMAL; $yaxis = 0; -// GRAPH & ZOOM featers +// GRAPH & ZOOM features $sql = 'SELECT MAX(g.graphid) as graphid, MAX(g.graphtype) as graphtype, MIN(gi.yaxisside) as yaxissidel, MAX(gi.yaxisside) as yaxissider'. ' FROM graphs g, graphs_items gi '. ' WHERE g.graphid='.$resourceid. @@ -361,18 +360,40 @@ $shiftXright = 60; } //------------- +// Host feature + if(($dynamic == SCREEN_DYNAMIC_ITEM) && isset($_REQUEST['hostid']) && ($_REQUEST['hostid']>0)){ + $def_items = array(); + $di_res = get_graphitems_by_graphid($resourceid); + while( $gitem = DBfetch($di_res)){ + $def_items[] = $gitem; + }; + + $url=''; + if($new_items = get_same_graphitems_for_host($def_items, $_REQUEST['hostid'], false)){ + $url.= make_url_from_gitems($new_items); + } + + $url= make_url_from_graphid($resourceid,false).$url; + } +//------------- if(($graphtype == GRAPH_TYPE_PIE) || ($graphtype == GRAPH_TYPE_EXPLODED)){ + if(($dynamic==SCREEN_SIMPLE_ITEM) || empty($url)){ + $url="chart6.php?graphid=$resourceid"; + } $item = new CLink( - new CImg("chart6.php?graphid=$resourceid&width=$width&height=$height"."&period=$effectiveperiod".url_param("stime")), + new CImg($url."&width=$width&height=$height"."&period=$effectiveperiod".url_param("stime")), $action ); } else { - + if(($dynamic==SCREEN_SIMPLE_ITEM) || empty($url)){ + $url="chart2.php?graphid=$resourceid"; + } + $dom_graph_id = 'graph_'.$screenitemid.'_'.$resourceid; - $g_img = new CImg("chart2.php?graphid=$resourceid&width=$width&height=$height"."&period=$effectiveperiod".url_param("stime")); + $g_img = new CImg($url."&width=$width&height=$height"."&period=$effectiveperiod".url_param("stime")); $g_img->AddOPtion('id',$dom_graph_id); $item = new CLink($g_img,$action); @@ -399,9 +420,19 @@ $action = "history.php?action=showgraph&itemid=$resourceid". url_param("period").url_param("inc").url_param("dec"); +// Host feature + if(($dynamic == SCREEN_DYNAMIC_ITEM) && isset($_REQUEST['hostid']) && ($_REQUEST['hostid']>0)){ + if($newitemid = get_same_item_for_host($resourceid,$_REQUEST['hostid'],false)){ + $resourceid = $newitemid; + } + else{ + $resourceid=''; + } + } +//------------- + $url = (empty($resourceid))?'chart3.php?':"chart.php?itemid=$resourceid&"; $item = new CLink( - new CImg("chart.php?itemid=$resourceid&width=$width&height=$height". - "&period=$effectiveperiod".url_param("stime")), + new CImg($url."width=$width&height=$height"."&period=$effectiveperiod".url_param("stime")), $action ); } @@ -418,8 +449,17 @@ $item = new CLink($image_map, $action); } } - elseif( ($screenitemid!=0) && ($resourcetype==SCREEN_RESOURCE_PLAIN_TEXT) ) - { + elseif( ($screenitemid!=0) && ($resourcetype==SCREEN_RESOURCE_PLAIN_TEXT) ){ +// Host feature + if(($dynamic == SCREEN_DYNAMIC_ITEM) && isset($_REQUEST['hostid']) && ($_REQUEST['hostid']>0)){ + if($newitemid = get_same_item_for_host($resourceid,$_REQUEST['hostid'],false)){ + $resourceid = $newitemid; + } + else{ + $resourceid=0; + } + } +//------------- $item = array(get_screen_plaintext($resourceid,$elements)); if($editmode == 1) array_push($item,new CLink(S_CHANGE,$action)); } @@ -596,5 +636,91 @@ DBexecute('delete from slides where slideshowid='.$slideshowid) ); } + + + # Show screen cell containing plain text values + function get_screen_plaintext($itemid,$elements){ + + if($itemid == 0){ + $table = new CTableInfo(S_ITEM_NOT_EXISTS); + $table->SetHeader(array(S_TIMESTAMP,S_ITEM)); + return $table; + } + + global $DB_TYPE; + + $item=get_item_by_itemid($itemid); + switch($item["value_type"]) + { + case ITEM_VALUE_TYPE_FLOAT: $history_table = "history"; break; + case ITEM_VALUE_TYPE_UINT64: $history_table = "history_uint"; break; + case ITEM_VALUE_TYPE_TEXT: $history_table = "history_text"; break; + default: $history_table = "history_str"; break; + } + + $sql='SELECT h.clock,h.value,i.valuemapid '. + ' FROM '.$history_table.' h, items i '. + ' WHERE h.itemid=i.itemid '. + ' AND i.itemid='.$itemid. + ' ORDER BY h.clock DESC'; + + $result=DBselect($sql,$elements); + + $host = get_host_by_itemid($itemid); + + $table = new CTableInfo(); + $table->SetHeader(array(S_TIMESTAMP,item_description($host['host'].': '.$item["description"],$item["key_"]))); + + while($row=DBfetch($result)){ + switch($item["value_type"]) + { + case ITEM_VALUE_TYPE_TEXT: + if($DB_TYPE == "ORACLE") + { + if(isset($row["value"])) + { + $row["value"] = $row["value"]->load(); + } + else + { + $row["value"] = ""; + } + } + /* do not use break */ + case ITEM_VALUE_TYPE_STR: + $value = nl2br(nbsp(htmlspecialchars($row["value"]))); + break; + + default: + $value = $row["value"]; + break; + } + + if($row["valuemapid"] > 0) + $value = replace_value_by_map($value, $row["valuemapid"]); + + $table->AddRow(array(date(S_DATE_FORMAT_YMDHMS,$row["clock"]), $value)); + } + return $table; + } +/* +* Function: +* check_dynamic_items +* +* Description: +* Check if in screen are dynamic items, if so return TRUE, esle FALSE +* +* Author: +* Aly +*/ + + function check_dynamic_items($screenid){ + $sql = 'SELECT screenitemid '. + ' FROM screens_items '. + ' WHERE screenid='.$screenid. + ' AND dynamic='.SCREEN_DYNAMIC_ITEM; + if(DBfetch(DBselect($sql,1))) return TRUE; + return FALSE; + } ?> diff --git a/frontends/php/screenedit.php b/frontends/php/screenedit.php index 876cdf5d..791fe08f 100644 --- a/frontends/php/screenedit.php +++ b/frontends/php/screenedit.php @@ -26,6 +26,7 @@ $page["title"] = "S_CONFIGURATION_OF_SCREENS"; $page["file"] = "screenedit.php"; + $page['hist_arg'] = array('screenid'); include_once "include/page_header.php"; @@ -36,24 +37,21 @@ include_once "include/page_header.php"; $fields=array( "screenid"=> array(T_ZBX_INT, O_MAND, P_SYS, DB_ID, null), - "screenitemid"=>array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '(isset({form})&&({form}=="update"))&&(!isset({x})||!isset({y}))'), - "resourcetype"=> array(T_ZBX_INT, O_OPT, null, - BETWEEN(SCREEN_RESOURCE_GRAPH,SCREEN_RESOURCE_EVENTS), 'isset({save})'), + "screenitemid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '(isset({form})&&({form}=="update"))&&(!isset({x})||!isset({y}))'), + "resourcetype"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(SCREEN_RESOURCE_GRAPH,SCREEN_RESOURCE_EVENTS), 'isset({save})'), "resourceid"=> array(T_ZBX_INT, O_OPT, null, DB_ID, 'isset({save})'), - "width"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,65535), null), - "height"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,65535), null), - "colspan"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,100), null), - "rowspan"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,100), 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), + "colspan"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,100), null), + "rowspan"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,100), null), "elements"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(1,65535), null), - "valign"=> array(T_ZBX_INT, O_OPT, null, - BETWEEN(VALIGN_MIDDLE,VALIGN_BOTTOM), null), - "halign"=> array(T_ZBX_INT, O_OPT, null, - BETWEEN(HALIGN_CENTER,HALIGN_RIGHT), null), - "style"=> array(T_ZBX_INT, O_OPT, null, - BETWEEN(STYLE_HORISONTAL,STYLE_VERTICAL), 'isset({save})'), - "url"=> array(T_ZBX_STR, O_OPT, null, null, 'isset({save})'), - "x"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(1,100), 'isset({save})&&(isset({form})&&({form}!="update"))'), - "y"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(1,100), 'isset({save})&&(isset({form})&&({form}!="update"))'), + "valign"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(VALIGN_MIDDLE,VALIGN_BOTTOM), null), + "halign"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(HALIGN_CENTER,HALIGN_RIGHT), null), + "style"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(STYLE_HORISONTAL,STYLE_VERTICAL), 'isset({save})'), + "url"=> array(T_ZBX_STR, O_OPT, null, null, 'isset({save})'), + "dynamic"=> array(T_ZBX_INT, O_OPT, null, null, null), + "x"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(1,100), 'isset({save})&&(isset({form})&&({form}!="update"))'), + "y"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(1,100), 'isset({save})&&(isset({form})&&({form}!="update"))'), "save"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), "delete"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), @@ -63,6 +61,7 @@ include_once "include/page_header.php"; ); check_fields($fields); + $_REQUEST['dynmic'] = get_request('dynamic',SCREEN_SIMPLE_ITEM); ?> <?php show_table_header(S_CONFIGURATION_OF_SCREEN_BIG); @@ -85,7 +84,7 @@ include_once "include/page_header.php"; $_REQUEST["resourcetype"],$_REQUEST["resourceid"],$_REQUEST["width"], $_REQUEST["height"],$_REQUEST["colspan"],$_REQUEST["rowspan"], $_REQUEST["elements"],$_REQUEST["valign"], - $_REQUEST["halign"],$_REQUEST["style"],$_REQUEST["url"]); + $_REQUEST["halign"],$_REQUEST["style"],$_REQUEST["url"],$_REQUEST['dynmic']); show_messages($result, S_ITEM_UPDATED, S_CANNOT_UPDATE_ITEM); } @@ -96,7 +95,7 @@ include_once "include/page_header.php"; $_REQUEST["x"],$_REQUEST["y"],$_REQUEST["resourceid"], $_REQUEST["width"],$_REQUEST["height"],$_REQUEST["colspan"], $_REQUEST["rowspan"],$_REQUEST["elements"],$_REQUEST["valign"], - $_REQUEST["halign"],$_REQUEST["style"],$_REQUEST["url"]); + $_REQUEST["halign"],$_REQUEST["style"],$_REQUEST["url"],$_REQUEST['dynmic']); show_messages($result, S_ITEM_ADDED, S_CANNOT_ADD_ITEM); } @@ -106,7 +105,8 @@ include_once "include/page_header.php"; "[".$_REQUEST["x"].",".$_REQUEST["y"]."]")); unset($_REQUEST["form"]); } - } elseif(isset($_REQUEST["delete"])) { + } + elseif(isset($_REQUEST["delete"])) { $result=delete_screen_item($_REQUEST["screenitemid"]); show_messages($result, S_ITEM_DELETED, S_CANNOT_DELETE_ITEM); unset($_REQUEST["x"]); diff --git a/frontends/php/screens.php b/frontends/php/screens.php index 3a1a8882..bbfc997b 100644 --- a/frontends/php/screens.php +++ b/frontends/php/screens.php @@ -51,7 +51,10 @@ include_once "include/page_header.php"; $fields=array( "config"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("0,1"), null), // 0 - screens, 1 - slides - "elementid"=> array(T_ZBX_INT, O_OPT, P_SYS|P_NZERO, DB_ID,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), + + "elementid"=> array(T_ZBX_INT, O_OPT, P_SYS|P_NZERO, DB_ID,NULL), "step"=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535),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), @@ -62,7 +65,7 @@ include_once "include/page_header.php"; "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("0,1,2"), NULL) + "fullscreen"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("0,1,2"), NULL) ); check_fields($fields); @@ -89,6 +92,7 @@ include_once "include/page_header.php"; ?> <?php + $text = array(S_SCREENS_BIG); $elementid = get_request('elementid', null); @@ -109,15 +113,13 @@ include_once "include/page_header.php"; unset($screen_correct); unset($first_screen); - if( 0 == $config ) - { + if( 0 == $config ){ $result = DBselect('select screenid as elementid,name '. ' from screens '. ' where '.DBin_node('screenid'). ' order by name' ); - while($row=DBfetch($result)) - { + while($row=DBfetch($result)){ if(!screen_accessiable($row["elementid"], PERM_READ_ONLY)) continue; @@ -129,15 +131,13 @@ include_once "include/page_header.php"; if(!isset($first_element)) $first_element = $row["elementid"]; } } - else - { + else{ $result = DBselect('select slideshowid as elementid,name '. ' from slideshows '. ' where '.DBin_node('slideshowid'). ' order by name' ); - while($row=DBfetch($result)) - { + while($row=DBfetch($result)){ if(!slideshow_accessiable($row["elementid"], PERM_READ_ONLY)) continue; @@ -150,58 +150,126 @@ include_once "include/page_header.php"; } } - if(!isset($element_correct) && isset($first_element)) - { + if(!isset($element_correct) && isset($first_element)){ $elementid = $first_element; } - if(isset($elementid)) - { - if( 0 == $config ) - { + if(isset($elementid)){ + if(0 == $config){ if(!screen_accessiable($elementid, PERM_READ_ONLY)) access_deny(); $element = get_screen_by_screenid($elementid); } - else - { + else{ if(!slideshow_accessiable($elementid, PERM_READ_ONLY)) access_deny(); $element = get_slideshow_by_slideshowid($elementid); } - if( $element ) { + if( $element ){ $url = "?elementid=".$elementid; if($_REQUEST["fullscreen"]==0) $url .= "&fullscreen=1"; $text[] = array(nbsp(" / "),new CLink($element["name"], $url)); } - else - { + else{ $elementid = null; update_profile("web.screens.elementid",0); } } - + if($cmbElements->ItemsCount() > 0) $form->AddItem($cmbElements); - if( 2 != $_REQUEST["fullscreen"] ) + if((2 != $_REQUEST["fullscreen"]) && (0 == $config) && (check_dynamic_items($elementid))){ + if(!isset($_REQUEST["hostid"])){ + $_REQUEST["groupid"] = $_REQUEST["hostid"] = 0; + } + + $options = array("allow_all_hosts","monitored_hosts","with_items");//, "always_select_first_host"); + if(!$ZBX_WITH_SUBNODES) array_push($options,"only_current_node"); + + validate_group_with_host(PERM_READ_ONLY,$options); + + $availiable_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_LIST, null, null, get_current_nodeid()); + $availiable_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_LIST, null, null, get_current_nodeid()); + + $r_form = new CForm(); + $r_form->SetMethod('get'); + if(isset($_REQUEST['fullscreen'])) $r_form->AddVar('fullscreen', $_REQUEST['fullscreen']); + if(isset($_REQUEST['period'])) $r_form->AddVar('period', $_REQUEST['period']); + if(isset($_REQUEST['stime'])) $r_form->AddVar('stime', $_REQUEST['stime']); + + $cmbGroup = new CComboBox('groupid',$_REQUEST['groupid'],'submit()'); + $cmbHosts = new CComboBox('hostid',$_REQUEST['hostid'],'submit()'); + + $cmbGroup->AddItem(0,S_ALL_SMALL); + $cmbHosts->AddItem(0,S_DEFAULT); + + + $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 '. + ' ORDER BY g.name'); + while($row=DBfetch($result)){ + $cmbGroup->AddItem( + $row['groupid'], + get_node_name_by_elid($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 IN ('.$availiable_hosts.') '. + ' ORDER BY h.host'; + } + else{ + $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 IN ('.$availiable_hosts.') '. + ' ORDER BY h.host'; + } +//SDI($sql); + $result=DBselect($sql); + while($row=DBfetch($result)) + { + $cmbHosts->AddItem( + $row['hostid'], + get_node_name_by_elid($row['hostid']).$row['host'] + ); + } + + $r_form->AddItem(array(SPACE.S_HOST.SPACE,$cmbHosts)); + show_table_header($text,$form); + show_table_header(null,$r_form); + } + else if(2 != $_REQUEST["fullscreen"]){ show_table_header($text,$form); + } ?> <?php - if(isset($elementid)) - { + if(isset($elementid)){ $effectiveperiod = navigation_bar_calc(); - if( 0 == $config ) - { + if( 0 == $config ){ $element = get_screen($elementid, 0, $effectiveperiod); } - else - { + else{ $element = get_slideshow($elementid, get_request('step', null), $effectiveperiod); zbx_add_post_js('if(isset(parent)) parent.resizeiframe("iframe"); - else resizeiframe("iframe"); - '); + else resizeiframe("iframe");'."\n"); } if($element){ $element->Show(); @@ -211,7 +279,7 @@ include_once "include/page_header.php"; if( 2 != $_REQUEST["fullscreen"] ){ - $stime = time() - (31536000); // 1year + $stime = time() - (31536000); // ~1year $bstime = time()-$effectiveperiod; if(isset($_REQUEST['stime'])){ @@ -225,6 +293,7 @@ include_once "include/page_header.php"; zbx_add_post_js($script); $img = new CImg('images/general/tree/O.gif','space','20','20'); $img->Show(); + echo BR; // navigation_bar("screens.php",array('config','elementid')); } } |