PDA

View Full Version : PATCH: 1.4.1: Allow screens to be defined on templates


cpicton
30-06-2007, 07:56
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


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_RE AD_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
{

starstream
02-07-2007, 13:41
Hi!
This is a feature i would like to se implemented!

What are the issues thats left?

/m

cpicton
02-07-2007, 13:53
Issues are cosmetic

When first browsing to the page, I get PHP var not defined errors. It should be an easy fix, but it is not bugging me yet

starstream
02-07-2007, 14:28
Nothing more serious that that...
I thought that my zabbix server would go up in smoke ...

I will try the patch during the week and let you know.

Cheers!

Saftnase
26-07-2007, 09:15
YES PLEASE IMPLEMENT THIS !!!!!
This would save me hours of work with the monitoring project i am setting up

kloczek
22-10-2007, 23:09
Issues are cosmetic

When first browsing to the page, I get PHP var not defined errors. It should be an easy fix, but it is not bugging me yet

BTW discuss about zabbix improvements.
Any progress on merge templates for screens to official svn tree ?
Alexei ?
And/or what is missing in this patch before merge this in official tree ?

freak
23-10-2007, 11:03
YES PLEASE IMPLEMENT THIS !!!!!
I second that :)

cpicton
24-10-2007, 09:20
I have picked up on one error which I will be fixing soon - If the host inherits the screen from a 'grandparent' template - ie, host is a member of TemplateA, which itself is a member of TemplateB, then the graphs don't display, if the screen was defined on TemplateB

Will let you know when fixed.

jonnjonzzn
07-11-2007, 21:59
Yes, this is probably the most important functionality missing for us.

Patch does not apply cleanly to 1.4.2 code base? Will look into when able but if someone is really bored, please, by all means take a look!

I think this would just be a terrific piece for Zabbix I hope this functionality can be implemented for 1.4.3 (1.6).

noxis
08-11-2007, 10:19
Any chance of a 1.4.2 patch for this?

Alexei
10-11-2007, 14:05
Screen based templates will be implemented in 1.6. The functionality will be ready within 2-3 weeks in the latest code.

sebelk
05-12-2007, 18:06
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


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_RE AD_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
{



Does this patch work in zabbix 1.4.2?

cpicton
10-01-2008, 06:43
I have been running on 1.4.1 for a while now - I am about to update to 1.4.4, as I have been experiencing zabbix server and agent hangs.

I will update the screen template patch for 1.4.4

Chris