Hi all
This is a preliminary patch, which allows screens to be defined on templates. This allows one to define a screen, viewable for multiple hosts, without having to define a screen per host, with the same set of graphs in each screen.
There are still some issues, but it works for me.
Please give me any comments or suggestions.
Chris
This is a preliminary patch, which allows screens to be defined on templates. This allows one to define a screen, viewable for multiple hosts, without having to define a screen per host, with the same set of graphs in each screen.
There are still some issues, but it works for me.
Please give me any comments or suggestions.
Chris
Code:
diff -uNr zabbix-1.4.1.orig/frontends/php/include/graphs.inc.php zabbix-1.4.1/frontends/php/include/graphs.inc.php
--- zabbix-1.4.1.orig/frontends/php/include/graphs.inc.php 2007-06-29 22:50:28.000000000 +0200
+++ zabbix-1.4.1/frontends/php/include/graphs.inc.php 2007-07-01 12:30:44.000000000 +0200
@@ -605,7 +605,7 @@
function navigation_bar($url,$ext_saved_request=NULL)
{
- $saved_request = array("screenid","itemid","action","from","fullscreen");
+ $saved_request = array("screenid","itemid","action","from","fullscreen","hostid");
if(is_array($ext_saved_request))
$saved_request = array_merge($saved_request, $ext_saved_request);
diff -uNr zabbix-1.4.1.orig/frontends/php/include/screens.inc.php zabbix-1.4.1/frontends/php/include/screens.inc.php
--- zabbix-1.4.1.orig/frontends/php/include/screens.inc.php 2007-06-29 22:50:28.000000000 +0200
+++ zabbix-1.4.1/frontends/php/include/screens.inc.php 2007-07-01 12:28:35.000000000 +0200
@@ -219,7 +219,7 @@
}
// editmode: 0 - view with actions, 1 - edit mode, 2 - view without any actions
- function get_screen($screenid, $editmode, $effectiveperiod=NULL)
+ function get_screen($screenid, $editmode, $effectiveperiod=NULL, $hostid=NULL)
{
if(!screen_accessiable($screenid, $editmode ? PERM_READ_WRITE : PERM_READ_ONLY))
access_deny();
@@ -325,6 +325,10 @@
}
elseif( ($screenitemid!=0) && ($resourcetype==SCREEN_RESOURCE_GRAPH) )
{
+ if ($hostid != NULL)
+ {
+ $resourceid = graphid_for_hostid($resourceid, $hostid);
+ }
if($editmode == 0)
$action = "charts.php?graphid=$resourceid".url_param("period").
url_param("inc").url_param("dec");
@@ -444,6 +448,21 @@
return $table;
}
+ function graphid_for_hostid($graphid, $hostid)
+ {
+ $result = DBselect("SELECT distinct g.graphid, g.name, h.host ".
+ "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 h.hostid=i.hostid ".
+ "WHERE g.templateid=$graphid and h.hostid=$hostid"
+ );
+ $newid = DBfetch($result);
+ if (isset($newid["graphid"])) {
+ return $newid["graphid"];
+ }
+ return $graphid;
+ }
+
function slideshow_accessiable($slideshowid, $perm)
{
global $USER_DETAILS;
diff -uNr zabbix-1.4.1.orig/frontends/php/screens.php zabbix-1.4.1/frontends/php/screens.php
--- zabbix-1.4.1.orig/frontends/php/screens.php 2007-06-29 22:50:30.000000000 +0200
+++ zabbix-1.4.1/frontends/php/screens.php 2007-07-01 12:32:36.000000000 +0200
@@ -49,6 +49,7 @@
"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),
+ "hostid"=> array(T_ZBX_INT, O_OPT, P_SYS, 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),
@@ -104,6 +105,23 @@
unset($screen_correct);
unset($first_screen);
+ $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, PERM_MODE_LT);
+ $cmbHosts = new CComboBox("hostid",$_REQUEST["hostid"],"submit()");
+
+ $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";
+
+ $result=DBselect($sql);
+ while($row=DBfetch($result))
+ {
+ $cmbHosts->AddItem($row["hostid"],$row["host"]);
+ }
+ $form->AddItem(array(SPACE.S_HOST.SPACE,$cmbHosts));
+
+
if( 0 == $config )
{
$result = DBselect("select screenid as elementid,name from screens where ".DBid2nodeid("screenid")."=".$ZBX_CURNODEID." order by name");
@@ -175,7 +193,7 @@
$effectiveperiod = navigation_bar_calc();
if( 0 == $config )
{
- $element = get_screen($elementid, 0, $effectiveperiod);
+ $element = get_screen($elementid, 0, $effectiveperiod, $_REQUEST['hostid']);
}
else
{
Comment