[ZBXNEXT-734] PATCH: dynamic URL screen items Created: 2008 Jan 11  Updated: 2014 May 23  Due: 2014 Apr 30  Resolved: 2014 May 21

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: Frontend (F)
Affects Version/s: None
Fix Version/s: 2.3.0

Type: Change Request Priority: Major
Reporter: Sebastian Raible Assignee: Ivo Kurzemnieks
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

trunk@5238, ZBX-251 applied


Attachments: File frontend_make-screenitem-URL-dynamic.patch    
Issue Links:
Duplicate
is duplicated by ZBXNEXT-1702 URL as a dynamic screen item. Closed

 Description   

http://www.zabbix.com/forum/showthread.php?p=29729

I wanted to be able to call a custom script to display additional information for a host in a screen as a URL item, so I wrote this patch that makes SCREEN_RESOURCE_URL dynamic.

If a URL item is marked as dynamic, the URL will be extended with hostid=[selected host's hostid]. (Probably it shouldn't be "hostid" but "zbx_hostid" or something to avoid messing other stuff up, but I think if one knows how to write a custom script, they can change that themselves..)

The URL itself may contain query strings (i.e. foo.php?bar=true&waz=false will work as well as foo.php, they will be extended with &hostid=[ID] or ?hostid=[ID] respectively).

This patch applies to trunk@5238 with ZBX-251 applied. (I'll add the file as an attachment.)

Greetings
Sebastian



 Comments   
Comment by Sebastian Raible [ 2008 Jan 11 ]

patch file

Comment by Alexander Vladishev [ 2014 Apr 25 ]

Added specification: https://www.zabbix.org/wiki/Docs/specs/ZBXNEXT-734

Comment by Ivo Kurzemnieks [ 2014 May 13 ]

RESOLVED in svn://svn.zabbix.com/branches/dev/ZBXNEXT-734

Comment by Alexander Vladishev [ 2014 May 15 ]

(1) frontends/php/include/classes/screens/CScreenUrl.php

In this place $this->hostid variable can be null.

$url = CMacrosResolverHelper::resolveScreenElementURL(array(
    $this->hostid => array(
        'url' => $this->screenitem['url']
    )
));

iivs To avoid this problem, I made so $this->hostid is 0 by default.
RESOLVED in r45595

sasha CLOSED

Comment by Alexander Vladishev [ 2014 May 16 ]

(2) SQL errors when screen doesn't have dynamic elements

  • Monitoring -> Screens:
    pg_query(): Query failed: ERROR:  invalid input syntax for integer: ""
    LINE 1: SELECT h.hostid,h.name,h.host FROM hosts h WHERE h.hostid=''
                                                                      ^ [screens.php:176 → CView->render() → include() → CScreenBuilder->show() → CScreenUrl->get() → CMacrosResolverHelper::resolveScreenElementURL() → CMacrosResolver->resolve() → CMacrosResolver->resolveTexts() → DBselect() → pg_query() in include/db.inc.php:384]
    Error in query [SELECT h.hostid,h.name,h.host FROM hosts h WHERE h.hostid=''] [ERROR:  invalid input syntax for integer: ""
    LINE 1: SELECT h.hostid,h.name,h.host FROM hosts h WHERE h.hostid=''
                                                                      ^]
    pg_query(): Query failed: ERROR:  invalid input syntax for integer: ""
    LINE 1: ...type FROM interface i WHERE i.main=1 AND i.hostid='' AND i.t...
                                                                 ^ [screens.php:176 → CView->render() → include() → CScreenBuilder->show() → CScreenUrl->get() → CMacrosResolverHelper::resolveScreenElementURL() → CMacrosResolver->resolve() → CMacrosResolver->resolveTexts() → DBselect() → pg_query() in include/db.inc.php:384]
    Error in query [SELECT i.hostid,i.ip,i.dns,i.useip,i.type FROM interface i WHERE i.main=1 AND i.hostid='' AND i.type IN ('1','2','3','4')] [ERROR:  invalid input syntax for integer: ""
    LINE 1: ...type FROM interface i WHERE i.main=1 AND i.hostid='' AND i.t...
                                                                 ^]
    pg_query(): Query failed: ERROR:  invalid input syntax for integer: ""
    LINE 1: ... FROM hosts h WHERE h.flags IN (0,4) AND h.hostid='' AND h.s...
                                                                 ^ [screens.php:176 → CView->render() → include() → CScreenBuilder->show() → CScreenUrl->get() → CMacrosResolverHelper::resolveScreenElementURL() → CMacrosResolver->resolve() → CMacrosResolver->resolveTexts() → CMacrosResolverGeneral->getUserMacros() → CFrontendApiWrapper->get() → CApiWrapper->__call() → CFrontendApiWrapper->callMethod() → CApiWrapper->callMethod() → CFrontendApiWrapper->callClientMethod() → CLocalApiClient->callMethod() → call_user_func_array() → CHost->get() → DBselect() → pg_query() in include/db.inc.php:384]
    Error in query [SELECT   h.hostid FROM hosts h WHERE h.flags IN (0,4) AND h.hostid='' AND h.status IN (0,1,3)] [ERROR:  invalid input syntax for integer: ""
    LINE 1: ... FROM hosts h WHERE h.flags IN (0,4) AND h.hostid='' AND h.s...
                                                                 ^]
    
  • Monitoring -> Screens (Slide shows):
    pg_query(): Query failed: ERROR:  invalid input syntax for integer: ""
    LINE 1: SELECT h.hostid,h.name,h.host FROM hosts h WHERE h.hostid=''
                                                                      ^ [slides.php:110 → CScreenBuilder->show() → CScreenUrl->get() → CMacrosResolverHelper::resolveScreenElementURL() → CMacrosResolver->resolve() → CMacrosResolver->resolveTexts() → DBselect() → pg_query() in include/db.inc.php:384]
    Error in query [SELECT h.hostid,h.name,h.host FROM hosts h WHERE h.hostid=''] [ERROR:  invalid input syntax for integer: ""
    LINE 1: SELECT h.hostid,h.name,h.host FROM hosts h WHERE h.hostid=''
                                                                      ^]
    pg_query(): Query failed: ERROR:  invalid input syntax for integer: ""
    LINE 1: ...type FROM interface i WHERE i.main=1 AND i.hostid='' AND i.t...
                                                                 ^ [slides.php:110 → CScreenBuilder->show() → CScreenUrl->get() → CMacrosResolverHelper::resolveScreenElementURL() → CMacrosResolver->resolve() → CMacrosResolver->resolveTexts() → DBselect() → pg_query() in include/db.inc.php:384]
    Error in query [SELECT i.hostid,i.ip,i.dns,i.useip,i.type FROM interface i WHERE i.main=1 AND i.hostid='' AND i.type IN ('1','2','3','4')] [ERROR:  invalid input syntax for integer: ""
    LINE 1: ...type FROM interface i WHERE i.main=1 AND i.hostid='' AND i.t...
                                                                 ^]
    pg_query(): Query failed: ERROR:  invalid input syntax for integer: ""
    LINE 1: ... FROM hosts h WHERE h.flags IN (0,4) AND h.hostid='' AND h.s...
                                                                 ^ [slides.php:110 → CScreenBuilder->show() → CScreenUrl->get() → CMacrosResolverHelper::resolveScreenElementURL() → CMacrosResolver->resolve() → CMacrosResolver->resolveTexts() → CMacrosResolverGeneral->getUserMacros() → CFrontendApiWrapper->get() → CApiWrapper->__call() → CFrontendApiWrapper->callMethod() → CApiWrapper->callMethod() → CFrontendApiWrapper->callClientMethod() → CLocalApiClient->callMethod() → call_user_func_array() → CHost->get() → DBselect() → pg_query() in include/db.inc.php:384]
    Error in query [SELECT   h.hostid FROM hosts h WHERE h.flags IN (0,4) AND h.hostid='' AND h.status IN (0,1,3)] [ERROR:  invalid input syntax for integer: ""
    LINE 1: ... FROM hosts h WHERE h.flags IN (0,4) AND h.hostid='' AND h.s...
                                                                 ^]
    

iivs MySQL was working, but I observed this on PostgreSQL and it's related to (1) when $this->hostid is null.
RESOLVED in r45595

sasha CLOSED

Comment by Alexander Vladishev [ 2014 May 16 ]

(3) If "Dynamic item" was not selected, only global macros should be expanded.

iivs RESOLVED in r45595

sasha CLOSED

Comment by Alexander Vladishev [ 2014 May 16 ]

(4) Invalid pattern: '

{(HOST.ID)}

'. The dot should be escaped.

iivs RESOLVED in r45595

sasha CLOSED

Comment by Ivo Kurzemnieks [ 2014 May 19 ]

Implemented in pre-2.3.0 (trunk) r45640

Comment by Ivo Kurzemnieks [ 2014 May 19 ]

(5) Documentation needs to be updated.

martins-v Updated:

RESOLVED.

iivs REVIEWED.
Thanks!
CLOSED.

Comment by Alexander Vladishev [ 2014 May 21 ]

(6) "Undefined index" on history screen:

Undefined index: screenid [ in /home/sasha/zabbix-svn/trunk/frontends/php/jsrpc.php:208]
array_flip(): Can only flip STRING and INTEGER values! [jsrpc.php:210 → CFrontendApiWrapper->get() → CApiWrapper->__call() → CFrontendApiWrapper->callMethod() → CApiWrapper->callMethod() → CFrontendApiWrapper->callClientMethod() → CLocalApiClient->callMethod() → call_user_func_array() → CTemplateScreen->get() → dbConditionInt() → array_flip() in /home/sasha/zabbix-svn/trunk/frontends/php/include/db.inc.php:850]
pg_query(): Query failed: ERROR:  syntax error at end of input
LINE 1: ...emplateid FROM screens s WHERE s.templateid IS NOT NULL AND 
                                                                       ^ [jsrpc.php:210 → CFrontendApiWrapper->get() → CApiWrapper->__call() → CFrontendApiWrapper->callMethod() → CApiWrapper->callMethod() → CFrontendApiWrapper->callClientMethod() → CLocalApiClient->callMethod() → call_user_func_array() → CTemplateScreen->get() → DBselect() → pg_query() in /home/sasha/zabbix-svn/trunk/frontends/php/include/db.inc.php:384]
Error in query [SELECT   s.screenid,s.templateid FROM screens s WHERE s.templateid IS NOT NULL AND ] [ERROR:  syntax error at end of input
LINE 1: ...emplateid FROM screens s WHERE s.templateid IS NOT NULL AND 
                                                                       ^]

iivs RESOLVED in svn://svn.zabbix.com/branches/dev/ZBXNEXT-734 r45700

sasha CLOSED

Comment by Ivo Kurzemnieks [ 2014 May 22 ]

(7) As discussed, I moved templated screen request for URL elements from jsrpc to screenBuilder::getScreen()

see r45773

sasha CLOSED

Comment by Ivo Kurzemnieks [ 2014 May 23 ]

Fixed undefined indexes, SQL errors and moved screen.get out of jsrpc.

Fixed in pre-2.3.0 (trunk) r45801

Generated at Tue Apr 08 22:13:51 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.