summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorartem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-08-12 14:36:28 +0000
committerartem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-08-12 14:36:28 +0000
commit43e14ba71f408eb30acd4c46a22e7f7ecb65c997 (patch)
treeedba7b8708f53de25f0b2b22f2c7fe0a56545e50
parent9b414f6bc817fb041b960df504933d4694e4bd61 (diff)
downloadzabbix-43e14ba71f408eb30acd4c46a22e7f7ecb65c997.tar.gz
zabbix-43e14ba71f408eb30acd4c46a22e7f7ecb65c997.tar.xz
zabbix-43e14ba71f408eb30acd4c46a22e7f7ecb65c997.zip
- [DEV-201] improved performance on disabling/enabling, deleting hosts (Artem)
- [DEV-137] selections *all and groups *all are not saved to profiles (Artem) - [DEV-199] some fixes (Artem) git-svn-id: svn://svn.zabbix.com/trunk@5899 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--create/schema/schema.sql1
-rw-r--r--frontends/php/hosts.php68
-rw-r--r--frontends/php/include/audit.inc.php8
-rw-r--r--frontends/php/include/classes/chostsinfo.mod.php73
-rw-r--r--frontends/php/include/config.inc.php2
-rw-r--r--frontends/php/include/db.inc.php36
-rw-r--r--frontends/php/include/forms.inc.php1
-rw-r--r--frontends/php/include/func.inc.php8
-rw-r--r--frontends/php/include/graphs.inc.php124
-rw-r--r--frontends/php/include/hosts.inc.php231
-rw-r--r--frontends/php/include/httptest.inc.php88
-rw-r--r--frontends/php/include/import.inc.php1
-rw-r--r--frontends/php/include/items.inc.php184
-rw-r--r--frontends/php/include/locales/en_gb.inc.php5
-rw-r--r--frontends/php/include/maps.inc.php118
-rw-r--r--frontends/php/include/page_footer.php2
-rw-r--r--frontends/php/include/triggers.inc.php300
-rw-r--r--frontends/php/items.php10
-rw-r--r--src/libs/zbxdbhigh/db.c3
-rw-r--r--src/libs/zbxdbhigh/host.c3
20 files changed, 742 insertions, 524 deletions
diff --git a/create/schema/schema.sql b/create/schema/schema.sql
index 2630d1a0..2003c3d0 100644
--- a/create/schema/schema.sql
+++ b/create/schema/schema.sql
@@ -265,7 +265,6 @@ FIELD |value |t_integer |'0' |NOT NULL |0
FIELD |acknowledged |t_integer |'0' |NOT NULL |0
INDEX |1 |object,objectid,eventid
INDEX |2 |clock
-INDEX |3 |object,objectid,clock
TABLE|trends|itemid,clock|ZBX_HISTORY_TRENDS
FIELD |itemid |t_id |'0' |NOT NULL |0
diff --git a/frontends/php/hosts.php b/frontends/php/hosts.php
index ec020b02..02528da4 100644
--- a/frontends/php/hosts.php
+++ b/frontends/php/hosts.php
@@ -486,25 +486,30 @@ include_once 'include/page_header.php';
else {
/* group operations */
$result = true;
- $hosts = get_request("hosts",array());
-
- DBstart();
- $db_hosts=DBselect('select hostid from hosts where '.DBin_node('hostid'));
- while($db_host=DBfetch($db_hosts)){
- $host=get_host_by_hostid($db_host["hostid"]);
+ $hosts = get_request('hosts',array());
+ $del_hosts = array();
+ $sql = 'SELECT host,hostid '.
+ ' FROM hosts '.
+ ' WHERE '.DBin_node('hostid').
+ ' AND '.DBcondition('hostid',$hosts).
+ ' AND '.DBcondition('hostid',$available_hosts);
+ $db_hosts=DBselect($sql);
- if(!uint_in_array($db_host["hostid"],$hosts)) continue;
- $result &= delete_host($db_host["hostid"], $unlink_mode);
-
- if($result)
- add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_HOST,"Host [".$host["host"]."]");
+ DBstart();
+ while($db_host=DBfetch($db_hosts)){
+ $del_hosts[$db_host['hostid']] = $db_host['hostid'];
+ add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_HOST,'Host ['.$db_host['host'].']');
}
+
+ $result = delete_host($del_hosts, $unlink_mode);
$result = DBend($result);
+
show_messages($result, S_HOST_DELETED, S_CANNOT_DELETE_HOST);
+
}
unset($_REQUEST["delete"]);
}
-/* ACTIVATE / DISABLE HOSTS */
+/* ADD / REMOVE HOSTS FROM GROUP*/
else if(($_REQUEST["config"]==0 || $_REQUEST["config"]==3) && (inarr_isset(array('add_to_group','hostid')))){
global $USER_DETAILS;
@@ -531,24 +536,28 @@ include_once 'include/page_header.php';
show_messages($result, S_HOST_UPDATED, S_CANNOT_UPDATE_HOST);
}
+/* ACTIVATE / DISABLE HOSTS */
else if(($_REQUEST["config"]==0 || $_REQUEST["config"]==3) && (isset($_REQUEST["activate"])||isset($_REQUEST["disable"]))){
$result = true;
$status = isset($_REQUEST["activate"]) ? HOST_STATUS_MONITORED : HOST_STATUS_NOT_MONITORED;
- $hosts = get_request("hosts",array());
+
+ $hosts = get_request('hosts',array());
+ $act_hosts = array();
+ $sql = 'SELECT host,hostid,status '.
+ ' FROM hosts '.
+ ' WHERE '.DBin_node('hostid').
+ ' AND '.DBcondition('hostid',$hosts).
+ ' AND '.DBcondition('hostid',$available_hosts);
+ $db_hosts=DBselect($sql);
- $db_hosts=DBselect('select hostid from hosts where '.DBin_node('hostid'));
DBstart();
- while($db_host=DBfetch($db_hosts)){
- if(!uint_in_array($db_host["hostid"],$hosts)) continue;
-
- $host = get_host_by_hostid($db_host["hostid"]);
- $result &= update_host_status($db_host["hostid"],$status);
-
- if($result){
- add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_HOST,"Old status [".$host["status"]."] "."New status [".$status."]");
- }
+ while($db_host=DBfetch($db_hosts)){
+ $act_hosts[$db_host['hostid']] = $db_host['hostid'];
+ add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_HOST,'Host ['.$db_host['host'].']. Old status ['.$db_host['status'].'] '.'New status ['.$status.']');
}
+
+ $result = update_host_status($act_hosts,$status);
$result = DBend($result);
show_messages($result, S_HOST_STATUS_UPDATED, S_CANNOT_UPDATE_HOST);
@@ -564,7 +573,7 @@ include_once 'include/page_header.php';
show_messages($result,S_HOST_STATUS_UPDATED,S_CANNOT_UPDATE_HOST_STATUS);
if($result){
- add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_HOST,"Old status [".$host["status"]."] New status [".$_REQUEST["chstatus"]."]");
+ add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_HOST,'Host ['.$db_host['host'].']. Old status ['.$host["status"].'] New status ['.$_REQUEST["chstatus"].']');
}
unset($_REQUEST["chstatus"]);
unset($_REQUEST["hostid"]);
@@ -1379,9 +1388,8 @@ include_once 'include/page_header.php';
"CheckAll('".$form->GetName()."','all_hosts');"),
SPACE,
make_sorting_link(S_NAME,'g.name')),
- S_LASTSEEN_AGE,
' # ',
- S_MEMBERS));
+ S_MEMBERS,S_LASTSEEN_AGE));
$available_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_WRITE);
@@ -1404,14 +1412,14 @@ include_once 'include/page_header.php';
$style = $db_host["status"]==HOST_STATUS_MONITORED ? NULL: (
$db_host["status"]==HOST_STATUS_TEMPLATE ? "unknown" :
"on");
- array_push($hosts, empty($hosts) ? '' : ', ', new CSpan($db_host["host"], $style));
+ array_push($hosts, empty($hosts) ? '' : ',', new CSpan($db_host["host"], $style));
$count++;
}
if($db_proxy['lastaccess'] != 0)
$lastclock = zbx_date2age($db_proxy['lastaccess']);
else
- $lastclock = '-';
+ $lastclock = new CCol('-', 'center');
$table->AddRow(array(
array(
@@ -1421,9 +1429,9 @@ include_once 'include/page_header.php';
"hosts.php?form=update&hostid=".$db_proxy["hostid"].url_param("config"),
'action')
),
- $lastclock,
$count,
- new CCol((empty($hosts) ? '-' : $hosts), 'wraptext')
+ $hosts,
+ $lastclock
));
}
$table->SetFooter(new CCol(array(
diff --git a/frontends/php/include/audit.inc.php b/frontends/php/include/audit.inc.php
index 662aaf76..662c0ea7 100644
--- a/frontends/php/include/audit.inc.php
+++ b/frontends/php/include/audit.inc.php
@@ -50,16 +50,14 @@
return S_UNKNOWN_RESOURCE;
}
- function add_audit_if($condition,$action,$resourcetype,$details)
- {
+ function add_audit_if($condition,$action,$resourcetype,$details){
if($condition)
return add_audit($action,$resourcetype,$details);
return false;
}
- function add_audit($action,$resourcetype,$details)
- {
+ function add_audit($action,$resourcetype,$details){
global $USER_DETAILS;
if(!isset($USER_DETAILS["userid"])) check_authorisation();
@@ -69,7 +67,7 @@
if(strlen($details) > 128)
$details = substr($details, 0, 125).'...';
- if(($result = DBexecute("insert into auditlog (auditid,userid,clock,action,resourcetype,details) ".
+ if(($result = DBexecute('INSERT INTO auditlog (auditid,userid,clock,action,resourcetype,details) '.
" values ($auditid,".$USER_DETAILS["userid"].",".time().",$action,$resourcetype,".zbx_dbstr($details).")")))
{
$result = $auditid;
diff --git a/frontends/php/include/classes/chostsinfo.mod.php b/frontends/php/include/classes/chostsinfo.mod.php
index c9e07fc0..c5265d37 100644
--- a/frontends/php/include/classes/chostsinfo.mod.php
+++ b/frontends/php/include/classes/chostsinfo.mod.php
@@ -42,69 +42,90 @@
global $USER_DETAILS;
$this->CleanItems();
- $accessible_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY);
+ $total = 0;
- $cond = (remove_nodes_from_id($this->groupid)>0)?(' AND hg.groupid='.zbx_dbstr($this->groupid)):(' AND '.DBin_node('hg.groupid', $this->nodeid));
+ $accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_RES_IDS_ARRAY);
- $db_host_cnt = DBselect('SELECT COUNT(*) as cnt '.
- ' FROM hosts h, hosts_groups hg'.
+ $cond_from = '';
+ if(remove_nodes_from_id($this->groupid)>0){
+ $cond_from = ', hosts_groups hg ';
+ $cond_where = 'AND hg.hostid=h.hostid AND hg.groupid='.$this->groupid;
+ }
+ else{
+ $cond_where = ' AND '.DBin_node('h.hostid', $this->nodeid);
+ }
+
+ $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt '.
+ ' FROM hosts h'.$cond_from.
' WHERE h.available='.HOST_AVAILABLE_TRUE.
-// ' AND h.status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.') '.
- ' AND hg.groupid IN ('.$accessible_groups.') '.$cond);
+ ' AND h.status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.') '.
+ ' AND '.DBcondition('h.hostid',$accessible_hosts).
+ $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$avail = $host_cnt['cnt'];
-
- $db_host_cnt = DBselect('SELECT COUNT(*) as cnt '.
- ' FROM hosts h, hosts_groups hg'.
+ $total += $host_cnt['cnt'];
+
+ $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt '.
+ ' FROM hosts h'.$cond_from.
' WHERE h.available='.HOST_AVAILABLE_FALSE.
-// ' AND h.status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.') '.
- ' AND hg.groupid IN ('.$accessible_groups.') '.$cond);
+ ' AND h.status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.') '.
+ ' AND '.DBcondition('h.hostid',$accessible_hosts).
+ $cond_where);
+
$host_cnt = DBfetch($db_host_cnt);
$notav = $host_cnt['cnt'];
+ $total += $host_cnt['cnt'];
- $db_host_cnt = DBselect('SELECT COUNT(*) as cnt '.
- ' FROM hosts h, hosts_groups hg'.
+ $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt '.
+ ' FROM hosts h'.$cond_from.
' WHERE h.available='.HOST_AVAILABLE_UNKNOWN.
-// ' AND h.status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.') '.
- ' AND hg.groupid IN ('.$accessible_groups.') '.$cond);
+ ' AND h.status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.') '.
+ ' AND '.DBcondition('h.hostid',$accessible_hosts).
+ $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$uncn = $host_cnt['cnt'];
-
+ $total += $host_cnt['cnt'];
+
$node = get_node_by_nodeid($this->nodeid);
$header_str = S_HOSTS_INFO.SPACE;
+ $header_str.= S_FOR_GROUP_SMALL.SPACE.'&quot;';
+ if($node > 0) $header_str.= '('.$node['name'].')'.SPACE;
+
if(remove_nodes_from_id($this->groupid)>0){
$group = get_hostgroup_by_groupid($this->groupid);
- $header_str.= S_FOR_GROUP_SMALL.SPACE.'&quot;('.$node['name'].')'.SPACE.$group['name'].'&quot;';
+ $header_str.= $group['name'].'&quot;';
}
else{
- $header_str.= S_FOR_NODE_SMALL.SPACE.'&quot;('.$node['name'].')&quot;';
- }
-
+ $header_str.= S_ALL.'&quot;';
+ }
$header = new CCol($header_str,"header");
if($this->style == STYLE_HORISONTAL)
- $header->SetColspan(3);
+ $header->SetColspan(4);
$this->AddRow($header);
- $avail = new CCol($avail." ".S_AVAILABLE, "avail");
- $notav = new CCol($notav." ".S_NOT_AVAILABLE, "notav");
- $uncn = new CCol($uncn." ".S_UNKNOWN, "uncn");
+ $avail = new CCol($avail.' '.S_AVAILABLE, 'avail');
+ $notav = new CCol($notav.' '.S_NOT_AVAILABLE, 'notav');
+ $uncn = new CCol($uncn.' '.S_UNKNOWN, 'uncn');
+ $total = new CCol($total.' '.S_TOTAL, 'total');
if($this->style == STYLE_HORISONTAL){
- $this->AddRow(array($avail, $notav, $uncn));
+ $this->AddRow(array($avail, $notav, $uncn, $total));
}
else{
$this->AddRow($avail);
$this->AddRow($notav);
$this->AddRow($uncn);
+ $this->AddRow($total);
}
- return parent::BodyToString();
+
+ return parent::BodyToString();
}
}
?>
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index c866bb93..f1c582c8 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -85,6 +85,8 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
function zbx_err_handler($errno, $errstr, $errfile, $errline){
error($errstr.'['.$errfile.':'.$errline.']');
+// show_messages();
+// die();
}
/********** START INITIALIZATION *********/
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index 15a12348..fdb68ee6 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -20,11 +20,11 @@
?>
<?php
if(!isset($DB)){
- if(isset($DB_TYPE)) $DB['TYPE'] = $DB_TYPE;
- if(isset($DB_SERVER)) $DB['SERVER'] = $DB_SERVER;
- if(isset($DB_PORT)) $DB['PORT'] = $DB_PORT;
+ if(isset($DB_TYPE)) $DB['TYPE'] = $DB_TYPE;
+ if(isset($DB_SERVER)) $DB['SERVER'] = $DB_SERVER;
+ if(isset($DB_PORT)) $DB['PORT'] = $DB_PORT;
if(isset($DB_DATABASE)) $DB['DATABASE'] = $DB_DATABASE;
- if(isset($DB_USER)) $DB['USER'] = $DB_USER;
+ if(isset($DB_USER)) $DB['USER'] = $DB_USER;
if(isset($DB_PASSWORD)) $DB['PASSWORD'] = $DB_PASSWORD;
}
@@ -35,6 +35,10 @@ if(!isset($DB)){
$DB['DB'] = null;
$DB['TRANSACTIONS'] = 0;
+
+//Stats
+ $DB['SELECT_COUNT'] = 0;
+ $DB['EXECUTE_COUNT'] = 0;
//SDI('type: '.$DB['TYPE'].'; server: '.$DB['SERVER'].'; port: '.$DB['PORT'].'; db: '.$DB['DATABASE'].'; usr: '.$DB['USER'].'; pass: '.$DB['PASSWORD']);
@@ -215,9 +219,12 @@ if(!isset($DB)){
return true;
}
- function DBstart(){
+ function DBstart($comments=false){
global $DB;
//SDI('DBStart(): '.$DB['TRANSACTIONS']);
+ $DB['COMMENTS'] = $comments;
+ if($DB['COMMENTS']) info(S_TRANSACTION.': '.S_STARTED_BIG);
+
$DB['TRANSACTIONS']++;
if($DB['TRANSACTIONS']>1){
@@ -280,9 +287,12 @@ if(!isset($DB)){
$DBresult = DBcommit();
}
+ $msg = S_TRANSACTION.': '.S_COMMITED_BIG;
if(!$DBresult){ // FAIL
DBrollback();
+ $msg = S_TRANSACTION.': '.S_ROLLBACKED_BIG;
}
+ if($DB['COMMENTS']) info($msg);
$result = (!is_null($result) && $DBresult)?$result:$DBresult;
@@ -358,7 +368,10 @@ if(!isset($DB)){
global $DB;
//COpt::savesqlrequest($query);
//SDI('SQL: '.$query);
+
+ $DB['SELECT_COUNT']++;
$result = false;
+
if( isset($DB['DB']) && !empty($DB['DB']) )
switch($DB['TYPE']){
case "MYSQL":
@@ -434,6 +447,8 @@ if(!isset($DB)){
global $DB;
//SDI('SQL Exec: '.$query);
//COpt::savesqlrequest($query);
+
+ $DB['EXECUTE_COUNT']++; // WRONG FOR ORACLE!!
$result = false;
if( isset($DB['DB']) && !empty($DB['DB']) )
@@ -693,16 +708,13 @@ else {
DBexecute("update ids set nextid=nextid+1 where nodeid=$nodeid and table_name='$table' and field_name='$field'");
$row = DBfetch(DBselect("select nextid from ids where nodeid=$nodeid and table_name='$table' and field_name='$field'"));
- if(!$row || is_null($row["nextid"]))
- {
+ if(!$row || is_null($row["nextid"])){
/* Should never be here */
continue;
}
- else
- {
+ else{
$ret2 = $row["nextid"];
- if(bccomp(bcadd($ret1,1),$ret2) ==0)
- {
+ if(bccomp(bcadd($ret1,1),$ret2) ==0){
$found = true;
}
}
@@ -731,7 +743,7 @@ else {
global $DB;
$condition = '';
-//if(!is_array($array)) SDI('OPA: '.$fieldname.' : '.$array);
+if(!is_array($array)) SDI('OPA: '.$fieldname.' : '.$array);
$in = $notin?' NOT IN ':' IN ';
$concat = $notin?' AND ':' OR ';
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index 6098b482..3698fd29 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -4413,7 +4413,6 @@
' WHERE hostid='.$_REQUEST['hostid'].
' AND templateid=0 '.
' ORDER BY description';
-
$host_items_res = DBselect($sql);
while($host_item = DBfetch($host_items_res)){
$item_description = item_description($host_item['description'],$host_item['key_']);
diff --git a/frontends/php/include/func.inc.php b/frontends/php/include/func.inc.php
index 0881d5dd..253b731e 100644
--- a/frontends/php/include/func.inc.php
+++ b/frontends/php/include/func.inc.php
@@ -345,6 +345,14 @@ function zbx_nl2br(&$str){
}
return $str_res;
}
+
+function zbx_value2array(&$values){
+ if(!is_array($values) && !is_null($values)){
+ $tmp = array();
+ $tmp[$values] = $values;
+ $values = $tmp;
+ }
+}
/************* END ZBX MISC *************/
?> \ No newline at end of file
diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php
index 0ab259f4..b597b987 100644
--- a/frontends/php/include/graphs.inc.php
+++ b/frontends/php/include/graphs.inc.php
@@ -200,7 +200,7 @@
$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];
+ return $available_graphs[$perm][$perm_res][$nodeid_str][$hostid_str];
}
$available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, PERM_RES_IDS_ARRAY, $nodeid);
@@ -227,7 +227,7 @@
' AND i.itemid=gi.itemid '.
' AND i.status='.ITEM_STATUS_ACTIVE.
(!empty($denied_graphs)?' AND g.graphid NOT IN ('.implode(',',$denied_graphs).')':'');
-
+
$db_graphs = DBselect($sql);
while($graph = DBfetch($db_graphs)){
$result[$graph['graphid']] = $graph['graphid'];
@@ -239,7 +239,7 @@
else
$result = implode(',',$result);
}
-
+
$available_graphs[$perm][$perm_res][$nodeid_str][$hostid_str] = $result;
return $result;
@@ -255,8 +255,7 @@
* Aly
*
*/
- function get_min_itemclock_by_graphid($graphid)
- {
+ function get_min_itemclock_by_graphid($graphid){
$min = 0;
$row = DBfetch(DBselect('SELECT MIN(t.clock) as clock '.
' FROM graphs_items gi, trends t '.
@@ -274,7 +273,7 @@
if(!empty($row) && $row && $row['clock'])
$min = $min == 0 ? $row['clock'] : min($min, $row['clock']);
- return $min;
+ return $min;
}
/*
@@ -287,8 +286,7 @@
* Aly
*
*/
- function get_min_itemclock_by_itemid($itemid)
- {
+ function get_min_itemclock_by_itemid($itemid){
$min = 0;
$row = DBfetch(DBselect('SELECT MIN(t.clock) as clock '.
' FROM trends t '.
@@ -304,7 +302,7 @@
if(!empty($row) && $row && $row['clock'])
$min = $min == 0 ? $row['clock'] : min($min, $row['clock']);
- return $min;
+ return $min;
}
// Show History Graph
@@ -334,7 +332,7 @@
echo SBR;
}
- function get_graphitem_by_gitemid($gitemid){
+ function get_graphitem_by_gitemid($gitemid){
$result=DBselect("SELECT * FROM graphs_items WHERE gitemid=$gitemid");
$row=DBfetch($result);
if($row){
@@ -345,8 +343,7 @@
return $result;
}
- function get_graphitem_by_itemid($itemid)
- {
+ function get_graphitem_by_itemid($itemid){
$result = DBfetch(DBselect('SELECT * FROM graphs_items WHERE itemid='.$itemid));
$row=DBfetch($result);
if($row)
@@ -356,7 +353,7 @@
return $result;
}
- function get_graph_by_graphid($graphid){
+ function get_graph_by_graphid($graphid){
$result=DBselect("SELECT * FROM graphs WHERE graphid=$graphid");
$row=DBfetch($result);
@@ -367,8 +364,9 @@
return false;
}
- function get_graphs_by_templateid($templateid){
- return DBselect("SELECT * FROM graphs WHERE templateid=$templateid");
+ function get_graphs_by_templateid($templateids){
+ zbx_value2array($templateids);
+ return DBselect('SELECT * FROM graphs WHERE '.DBcondition('templateid',$templateids));
}
/*
@@ -677,31 +675,44 @@
* Comments: !!! Don't forget sync code with C !!!
*
*/
- function delete_graph($graphid){
- $graph = get_graph_by_graphid($graphid);
-
- $host_list = array();
- $db_hosts = get_hosts_by_graphid($graphid);
- while($db_host = DBfetch($db_hosts)){
- $host_list[] = '"'.$db_host['host'].'"';
- }
+ function delete_graph($graphids){
+ zbx_value2array($graphids);
$result = true;
- /* firstly remove child graphs */
- $chd_graphs = get_graphs_by_templateid($graphid);
+
+ $graphs = array();
+ $host_lists = array();
+ foreach($graphids as $id => $graphid){
+ $graphs[] = get_graph_by_graphid($graphid);
+
+ $host_list[$graphid] = array();
+ $db_hosts = get_hosts_by_graphid($graphid);
+ while($db_host = DBfetch($db_hosts)){
+ $host_list[$graphid] = '"'.$db_host['host'].'"';
+ }
+ }
+// firstly remove child graphs
+ $del_chd_graphs = array();
+ $chd_graphs = get_graphs_by_templateid($graphids);
while($chd_graph = DBfetch($chd_graphs)){ /* recursion */
- $result &= delete_graph($chd_graph['graphid']);
+ $del_chd_graphs[$chd_graph['graphid']] = $chd_graph['graphid'];
}
-
- $result &= DBexecute('DELETE FROM screens_items WHERE resourceid='.$graphid.' AND resourcetype='.SCREEN_RESOURCE_GRAPH);
+ if(!empty($del_chd_graphs)){
+ $result &= delete_graph($del_chd_graphs);
+ }
+
+ $result &= DBexecute('DELETE FROM screens_items WHERE '.DBcondition('resourceid',$graphids).' AND resourcetype='.SCREEN_RESOURCE_GRAPH);
/* delete graph */
- $result &= DBexecute('DELETE FROM graphs_items WHERE graphid='.$graphid);
- $result &= DBexecute('DELETE FROM graphs WHERE graphid='.$graphid);
- $result &= DBexecute("DELETE FROM profiles WHERE idx='web.favorite.graphids' AND source='graphid' AND value_id=$graphid");
+ $result &= DBexecute('DELETE FROM graphs_items WHERE '.DBcondition('graphid',$graphids));
+ $result &= DBexecute('DELETE FROM graphs WHERE '.DBcondition('graphid',$graphids));
+ $result &= DBexecute("DELETE FROM profiles WHERE idx='web.favorite.graphids' AND source='graphid' AND ".DBcondition('value_id',$graphids));
if($result){
- info('Graph "'.$graph['name'].'" deleted from hosts '.implode(',',$host_list));
+ foreach($graphs as $graphid => $graph){
+ if(isset($host_list[$graphid]))
+ info('Graph "'.$graph['name'].'" deleted from hosts '.implode(',',$host_list[$graphid]));
+ }
}
return $result;
@@ -758,46 +769,39 @@
return ( $result ? $gitemid : $result );
}
- /*
- * Function: delete_template_graphs
- *
- * Description:
- * Delete template graph from specified host
- *
- * Author:
- * Eugene Grigorjev
- *
- * Comments: !!! Don't forget sync code with C !!!
- *
- */
- function delete_template_graphs($hostid, $templateid = null /* array format 'arr[id]=name' */, $unlink_mode = false)
- {
+/*
+ * Function: delete_template_graphs
+ *
+ * Description:
+ * Delete template graph from specified host
+ *
+ * Author:
+ * Eugene Grigorjev
+ *
+ * Comments: !!! Don't forget sync code with C !!!
+ *
+ */
+ function delete_template_graphs($hostid, $templateids = null /* array format 'arr[id]=name' */, $unlink_mode = false){
+ zbx_value2array($templateids);
+
$db_graphs = get_graphs_by_hostid($hostid);
- while($db_graph = DBfetch($db_graphs))
- {
+ while($db_graph = DBfetch($db_graphs)){
if($db_graph['templateid'] == 0)
continue;
- if($templateid != null)
- {
- if( !is_array($templateid) ) $templateid=array($templateid);
-
+ if(!is_null($templateids)){
$tmp_hhosts = get_hosts_by_graphid($db_graph['templateid']);
$tmp_host = DBfetch($tmp_hhosts);
- if( !uint_in_array($tmp_host['hostid'], $templateid))
- continue;
+ if( !uint_in_array($tmp_host['hostid'], $templateids)) continue;
}
- if($unlink_mode)
- {
- if(DBexecute('update graphs set templateid=0 WHERE graphid='.$db_graph['graphid']))
- {
+ if($unlink_mode){
+ if(DBexecute('UPDATE graphs SET templateid=0 WHERE graphid='.$db_graph['graphid'])){
info('Graph "'.$db_graph['name'].'" unlinked');
}
}
- else
- {
+ else{
delete_graph($db_graph['graphid']);
}
}
diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php
index c9bf4b8a..d283dd53 100644
--- a/frontends/php/include/hosts.inc.php
+++ b/frontends/php/include/hosts.inc.php
@@ -312,12 +312,11 @@ require_once "include/httptest.inc.php";
* Comments: !!! Don't forget sync code with C !!!
*
*/
- function unlink_template($hostid, $templateid, $unlink_mode = true){
- if(!is_numeric($templateid))
- fatal_error('Not supported type for [templateid] in [unlink_template] - ['.$templateid.']');
-
- $result = delete_template_elements($hostid, $templateid, $unlink_mode);
- $result&= DBexecute("delete from hosts_templates where hostid=".$hostid.' and templateid='.$templateid);
+ function unlink_template($hostid, $templateids, $unlink_mode = true){
+ zbx_value2array($templateids);
+
+ $result = delete_template_elements($hostid, $templateids, $unlink_mode);
+ $result&= DBexecute('DELETE FROM hosts_templates WHERE hostid='.$hostid.' AND '.DBcondition('templateid',$templateids));
return $result;
}
@@ -333,11 +332,13 @@ require_once "include/httptest.inc.php";
* Comments: !!! Don't forget sync code with C !!!
*
*/
- function delete_template_elements($hostid, $templateid = null, $unlink_mode = false){
- delete_template_graphs($hostid, $templateid, $unlink_mode);
- delete_template_triggers($hostid, $templateid, $unlink_mode);
- delete_template_items($hostid, $templateid, $unlink_mode);
- delete_template_applications($hostid, $templateid, $unlink_mode);
+ function delete_template_elements($hostid, $templateids = null, $unlink_mode = false){
+ zbx_value2array($templateids);
+
+ delete_template_graphs($hostid, $templateids, $unlink_mode);
+ delete_template_triggers($hostid, $templateids, $unlink_mode);
+ delete_template_items($hostid, $templateids, $unlink_mode);
+ delete_template_applications($hostid, $templateids, $unlink_mode);
return true;
}
@@ -380,79 +381,93 @@ require_once "include/httptest.inc.php";
function delete_groups_by_hostid($hostid){
$sql="select groupid from hosts_groups where hostid=$hostid";
$result=DBselect($sql);
- while($row=DBfetch($result))
- {
+ while($row=DBfetch($result)){
+
$sql="delete from hosts_groups where hostid=$hostid and groupid=".$row["groupid"];
DBexecute($sql);
+
$sql="select count(*) as count from hosts_groups where groupid=".$row["groupid"];
$result2=DBselect($sql);
$row2=DBfetch($result2);
- if($row2["count"]==0)
- {
+ if($row2["count"]==0){
delete_host_group($row["groupid"]);
}
}
}
- /*
- * Function: delete_host
- *
- * Description:
- * Delete host with all elements and relations
- *
- * Author:
- * Eugene Grigorjev (eugene.grigorjev@zabbix.com)
- *
- * Comments: !!! Don't forget sync code with C !!!
- *
- */
- function delete_host($hostid, $unlink_mode = false){
- $ret = false;
-
- // unlink child hosts
- $db_childs = get_hosts_by_templateid($hostid);
- while($db_child = DBfetch($db_childs))
- {
- unlink_template($db_child["hostid"], $hostid, $unlink_mode);
+/*
+ * Function: delete_host
+ *
+ * Description:
+ * Delete host with all elements and relations
+ *
+ * Author:
+ * Eugene Grigorjev (eugene.grigorjev@zabbix.com)
+ *
+ * Comments: !!! Don't forget sync code with C !!!
+ *
+ */
+ function delete_host($hostids, $unlink_mode = false){
+ zbx_value2array($hostids);
+
+ $ret = false;
+// unlink child hosts
+ $db_childs = get_hosts_by_templateid($hostids);
+ while($db_child = DBfetch($db_childs)){
+ unlink_template($db_child['hostid'], $hostids, $unlink_mode);
}
- // delete items -> triggers -> graphs
- $db_items = get_items_by_hostid($hostid);
+// delete items -> triggers -> graphs
+ $del_items = array();
+ $db_items = get_items_by_hostid($hostids);
while($db_item = DBfetch($db_items)){
- delete_item($db_item["itemid"]);
+ $del_items[$db_item['itemid']] = $db_item['itemid'];
+ }
+ if(!empty($del_items)){
+ delete_item($del_items);
}
- // delete host from maps
- delete_sysmaps_elements_with_hostid($hostid);
+// delete host from maps
+ delete_sysmaps_elements_with_hostid($hostids);
- // delete host from group
- DBexecute("delete from hosts_groups where hostid=$hostid");
-
- // delete host from template linkages
- DBexecute("delete from hosts_templates where hostid=$hostid");
-
- // disable actions
- $db_actions = DBselect("select distinct actionid from conditions ".
- " where conditiontype=".CONDITION_TYPE_HOST." and value=".zbx_dbstr($hostid));
- while($db_action = DBfetch($db_actions))
- {
- DBexecute("update actions set status=".ACTION_STATUS_DISABLED.
- " where actionid=".$db_action["actionid"]);
+// delete host from group
+ DBexecute('DELETE FROM hosts_groups WHERE '.DBcondition('hostid',$hostids));
+
+// delete host from template linkages
+ DBexecute('DELETE FROM hosts_templates WHERE '.DBcondition('hostid',$hostids));
+
+// disable actions
+ $db_actions = DBselect('SELECT DISTINCT actionid '.
+ ' FROM conditions '.
+ ' WHERE conditiontype='.CONDITION_TYPE_HOST.
+ ' AND '.DBcondition('value',$hostids)); // POSIBLE value type violation!!! Warning !!! Warning !!! Warning !!!
+
+ while($db_action = DBfetch($db_actions)){
+ DBexecute('UPDATE actions '.
+ ' SET status='.ACTION_STATUS_DISABLED.
+ ' WHERE actionid='.$db_action['actionid']);
}
- // delete action conditions
- DBexecute('delete from conditions where conditiontype='.CONDITION_TYPE_HOST.' and value='.zbx_dbstr($hostid));
+
+// delete action conditions
+ DBexecute('DELETE FROM conditions '.
+ ' WHERE conditiontype='.CONDITION_TYPE_HOST.
+ ' AND '.DBcondition('value',$hostids)); // POSIBLE value type violation!!! Warning !!! Warning !!! Warning !!! );
- // delete host profile
- delete_host_profile($hostid);
+// delete host profile
+ delete_host_profile($hostids);
- // delete web tests
- $db_httptests = get_httptests_by_hostid($hostid);
+// delete web tests
+ $del_httptests = array();
+ $db_httptests = get_httptests_by_hostid($hostids);
while($db_httptest = DBfetch($db_httptests)){
- delete_httptest($db_httptest['httptestid']);
+ $del_httptests[$db_httptest['httptestid']] = $db_httptest['httptestid'];
+ }
+ if(!empty($del_httptests)){
+ delete_httptest($del_httptests);
}
- // delete host
- return DBexecute("delete from hosts where hostid=$hostid");
+// delete host
+ return DBexecute('DELETE FROM hosts WHERE '.DBcondition('hostid',$hostids));
}
function delete_host_group($groupid){
@@ -521,11 +536,12 @@ require_once "include/httptest.inc.php";
return DBexecute('update hosts set host='.zbx_dbstr($name).' where hostid='.$proxyid);
}
- function delete_proxy($proxyid){
- if(!DBexecute("update hosts set proxy_hostid=0 where proxy_hostid=$proxyid"))
+ function delete_proxy($proxyids){
+ zbx_value2array($proxyids);
+ if(!DBexecute('UPDATE hosts SET proxy_hostid=0 WHERE '.DBcondition('proxy_hostid',$proxyids)))
return false;
- return DBexecute("delete from hosts where hostid=$proxyid");
+ return DBexecute('DELETE FROM hosts WHERE '.DBcondition('hostid',$proxyids));
}
function update_hosts_by_proxyid($proxyid,$hosts=array()){
@@ -556,15 +572,30 @@ require_once "include/httptest.inc.php";
return $result;
}
- 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);
- $row=DBfetch($result);
- if($row){
- return $row;
+ function get_host_by_itemid($itemids){
+ zbx_value2array($itemids);
+
+ $result = false;
+ $hosts = array();
+
+ $sql = 'SELECT i.itemid, h.* FROM hosts h, items i WHERE i.hostid=h.hostid AND '.DBcondition('i.itemid',$itemids);
+ $res=DBselect($sql);
+ while($row=DBfetch($res)){
+ $result = true;
+ $hosts[$row['itemid']] = $row;
}
- error("No host with itemid=[$itemid]");
- return false;
+
+ if(count($hosts) == 1){
+ foreach($hosts as $itemid => $host){
+ $result = $host;
+ }
+ }
+ else if($result){
+ $result = $hosts;
+ unset($hosts);
+ }
+
+ return $result;
}
function get_host_by_hostid($hostid,$no_error_message=0){
@@ -581,26 +612,35 @@ require_once "include/httptest.inc.php";
return false;
}
- function get_hosts_by_templateid($templateid){
+ function get_hosts_by_templateid($templateids){
+ zbx_value2array($templateids);
return DBselect('SELECT h.* '.
' FROM hosts h, hosts_templates ht '.
' WHERE h.hostid=ht.hostid '.
- ' AND ht.templateid='.$templateid);
+ ' AND '.DBcondition('ht.templateid',$templateids));
}
# Update Host status
- function update_host_status($hostid,$status){
-
- $row=DBfetch(DBselect("select status,host from hosts where hostid=$hostid"));
- $old_status=$row["status"];
+ function update_host_status($hostids,$status){
+ zbx_value2array($hostids);
- if($status != $old_status){
- update_trigger_value_to_unknown_by_hostid($hostid);
- info("Updated status of host ".$row["host"]);
- return DBexecute('update hosts set status='.$status.' where hostid='.$hostid.
- ' and status in ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.')'
- );
+ $hosts = array();
+ $result = DBselect('SELECT host, hostid, status FROM hosts WHERE '.DBcondition('hostid',$hostids));
+ while($host=DBfetch($result)){
+ if($status != $host['status']){
+ $hosts[$host['hostid']] = $host['hostid'];
+ info('Updated status of host '.$host['host']);
+ }
+ }
+
+ if(!empty($hosts)){
+ update_trigger_value_to_unknown_by_hostid($hosts);
+
+ return DBexecute('UPDATE hosts SET status='.$status.
+ ' WHERE '.DBcondition('hostid',$hosts).
+ ' AND status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.')'
+ );
}
else{
return 1;
@@ -879,8 +919,8 @@ require_once "include/httptest.inc.php";
$_REQUEST['groupid'] = $result['groupid'];
$_REQUEST['hostid'] = $result['hostid'];
- update_profile($host_var,$_REQUEST['hostid'], PROFILE_TYPE_ID);
- update_profile($group_var,$_REQUEST['groupid'], PROFILE_TYPE_ID);
+ if($_REQUEST['hostid'] > 0) update_profile($host_var,$_REQUEST['hostid'], PROFILE_TYPE_ID);
+ if($_REQUEST['groupid'] > 0) update_profile($group_var,$_REQUEST['groupid'], PROFILE_TYPE_ID);
}
/*
@@ -907,7 +947,7 @@ require_once "include/httptest.inc.php";
$result = get_correct_group_and_host($_REQUEST['groupid'],null,$perm,$options);
$_REQUEST['groupid'] = $result['groupid'];
- update_profile($group_var, $_REQUEST['groupid'], PROFILE_TYPE_ID);
+ if($_REQUEST['groupid'] > 0) update_profile($group_var, $_REQUEST['groupid'], PROFILE_TYPE_ID);
}
/* APPLICATIONS */
@@ -1137,19 +1177,19 @@ require_once "include/httptest.inc.php";
* $templateid can be numeric or numeric array
*
*/
- function delete_template_applications($hostid, $templateid = null, $unlink_mode = false){
+ function delete_template_applications($hostid, $templateids = null, $unlink_mode = false){
+ zbx_value2array($templateids);
+
$db_apps = get_applications_by_hostid($hostid);
while($db_app = DBfetch($db_apps)){
if($db_app["templateid"] == 0)
continue;
- if($templateid != null){
- if(!is_array($templateid))
- $templateid = array($templateid);
+ if(!is_null($templateids)){
unset($skip);
if($tmp_app_data = get_application_by_applicationid($db_app["templateid"])){
- if(!uint_in_array($tmp_app_data["hostid"], $templateid)){
+ if(!uint_in_array($tmp_app_data["hostid"], $templateids)){
$skip = true;
break;
}
@@ -1288,8 +1328,9 @@ require_once "include/httptest.inc.php";
// Delete Host Profile
- function delete_host_profile($hostid){
- $result=DBexecute("delete from hosts_profiles where hostid=$hostid");
+ function delete_host_profile($hostids){
+ zbx_value2array($hostids);
+ $result=DBexecute('DELETE FROM hosts_profiles WHERE '.DBcondition('hostid',$hostids));
return $result;
}
diff --git a/frontends/php/include/httptest.inc.php b/frontends/php/include/httptest.inc.php
index 57855b65..46ae4923 100644
--- a/frontends/php/include/httptest.inc.php
+++ b/frontends/php/include/httptest.inc.php
@@ -330,82 +330,86 @@
return $result;
}
- function delete_httpstep($httpstepid)
- {
- $db_httpstepitems = DBselect('select distinct * from httpstepitem where httpstepid='.$httpstepid);
- while($httpstepitem_data = DBfetch($db_httpstepitems))
- {
- if(!DBexecute('delete from httpstepitem where httpstepitemid='.$httpstepitem_data['httpstepitemid'])) return false;
+ function delete_httpstep($httpstepids){
+ zbx_value2array($httpstepids);
+
+ $db_httpstepitems = DBselect('SELECT DISTINCT * FROM httpstepitem WHERE '.DBcondition('httpstepid',$httpstepids));
+ while($httpstepitem_data = DBfetch($db_httpstepitems)){
+ if(!DBexecute('DELETE FROM httpstepitem WHERE httpstepitemid='.$httpstepitem_data['httpstepitemid'])) return false;
if(!delete_item($httpstepitem_data['itemid'])) return false;
}
- return DBexecute('delete from httpstep where httpstepid='.$httpstepid);
+ return DBexecute('DELETE FROM httpstep WHERE '.DBcondition('httpstepid',$httpstepids));
}
- function delete_httptest($httptestid)
- {
- if (!($httptest = DBfetch(DBselect('select * from httptest where httptestid='.$httptestid)))) return false;
-
- $db_httpstep = DBselect('select distinct s.httpstepid from httpstep s '.
- ' where s.httptestid='.$httptestid);
- while($httpstep_data = DBfetch($db_httpstep))
- {
- delete_httpstep($httpstep_data['httpstepid']);
+ function delete_httptest($httptestids){
+ zbx_value2array($httptestids);
+
+ $httptests = array();
+ foreach($httptestids as $id => $httptestid){
+ $httptests[$httptestid] = DBfetch(DBselect('SELECT * FROM httptest WHERE httptestid='.$httptestid));
}
- if(!DBexecute('delete from httptest where httptestid='.$httptestid)) return false;
+ $db_httpstep = DBselect('SELECT DISTINCT s.httpstepid '.
+ ' FROM httpstep s '.
+ ' WHERE '.DBcondition('s.httptestid',$httptestids));
+ $del_httpsteps = array();
+ while($httpstep_data = DBfetch($db_httpstep)){
+ $del_httpsteps[$httpstep_data['httpstepid']] = $httpstep_data['httpstepid'];
+ }
+ delete_httpstep($del_httpsteps);
- info("Sceanrio '".$httptest["name"]."' deleted");
+ if(!DBexecute('DELETE FROM httptest WHERE '.DBcondition('httptestid',$httptestids))) return false;
- return true;
+ foreach($httptests as $id => $httptest){
+ info("Sceanrio '".$httptest["name"]."' deleted");
+ }
+
+ return true;
}
- function activate_httptest($httptestid)
- {
- return DBexecute('update httptest set status='.HTTPTEST_STATUS_ACTIVE.' where httptestid='.$httptestid);
+ function activate_httptest($httptestid){
+ return DBexecute('UPDATE httptest SET status='.HTTPTEST_STATUS_ACTIVE.' WHERE httptestid='.$httptestid);
}
- function disable_httptest($httptestid)
- {
- return DBexecute('update httptest set status='.HTTPTEST_STATUS_DISABLED.' where httptestid='.$httptestid);
+ function disable_httptest($httptestid){
+ return DBexecute('UPDATE httptest SET status='.HTTPTEST_STATUS_DISABLED.' WHERE httptestid='.$httptestid);
}
- function delete_history_by_httptestid($httptestid)
- {
- $db_items = DBselect('select distinct i.itemid from items i, httpstepitem si, httpstep s '.
- ' where s.httptestid='.$httptestid.' and si.httpstepid=s.httpstepid and i.itemid=si.itemid');
- while($item_data = DBfetch($db_items))
- {
+ function delete_history_by_httptestid($httptestid){
+ $db_items = DBselect('SELECT DISTINCT i.itemid '.
+ ' FROM items i, httpstepitem si, httpstep s '.
+ ' WHERE s.httptestid='.$httptestid.
+ ' AND si.httpstepid=s.httpstepid '.
+ ' AND i.itemid=si.itemid');
+ while($item_data = DBfetch($db_items)){
if(!delete_history_by_itemid($item_data['itemid'], 0 /* use housekeeper */)) return false;
}
return true;
}
- function get_httptest_by_httptestid($httptestid)
- {
+ function get_httptest_by_httptestid($httptestid){
return DBfetch(DBselect('select * from httptest where httptestid='.$httptestid));
}
- function get_httpsteps_by_httptestid($httptestid)
- {
+ function get_httpsteps_by_httptestid($httptestid){
return DBselect('select * from httpstep where httptestid='.$httptestid);
}
- function get_httpstep_by_httpstepid($httpstepid)
- {
+ function get_httpstep_by_httpstepid($httpstepid){
return DBfetch(DBselect('select * from httpstep where httpstepid='.$httpstepid));
}
- function get_httpstep_by_no($httptestid, $no)
- {
+ function get_httpstep_by_no($httptestid, $no){
return DBfetch(DBselect('select * from httpstep where httptestid='.$httptestid.' and no='.$no));
}
- function get_httptests_by_hostid($hostid){
+ function get_httptests_by_hostid($hostids){
+ zbx_value2array($hostids);
$sql = 'SELECT DISTINCT ht.* '.
' FROM httptest ht, applications ap '.
- ' WHERE ap.hostid='.$hostid.
+ ' WHERE '.DBcondition('ap.hostid',$hostids).
' AND ht.applicationid=ap.applicationid';
- return DBselect($sql);
+ return DBselect($sql);
}
?>
diff --git a/frontends/php/include/import.inc.php b/frontends/php/include/import.inc.php
index 6df83045..f906b67f 100644
--- a/frontends/php/include/import.inc.php
+++ b/frontends/php/include/import.inc.php
@@ -94,6 +94,7 @@
$data['hostid'] = $host_data['hostid'];
$data['templates'] = get_templates_by_hostid($host_data['hostid']);
+ $data['groups'] = get_groupids_by_host($host_data['hostid']);
}
else{ /* missed */
if($this->host['missed']==1){ /* skip */
diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php
index 8a022791..3e6769e1 100644
--- a/frontends/php/include/items.inc.php
+++ b/frontends/php/include/items.inc.php
@@ -511,22 +511,22 @@
* Comments: !!! Don't forget sync code with C !!!
*
*/
- function delete_template_items($hostid, $templateid = null, $unlink_mode = false){
+ function delete_template_items($hostid, $templateids = null, $unlink_mode = false){
+ zbx_value2array($templateids);
+
$db_items = get_items_by_hostid($hostid);
while($db_item = DBfetch($db_items)){
if($db_item["templateid"] == 0)
continue;
if( !is_null($templateid)){
- if(!is_array($templateid)) $templateid = array($templateid);
-
$db_tmp_item = get_item_by_itemid($db_item["templateid"]);
- if(!uint_in_array($db_tmp_item["hostid"], $templateid)) continue;
+ if(!uint_in_array($db_tmp_item["hostid"], $templateids)) continue;
}
if($unlink_mode){
- if(DBexecute("update items set templateid=0 where itemid=".$db_item["itemid"])){
+ if(DBexecute('UPDATE items SET templateid=0 WHERE itemid='.$db_item["itemid"])){
info("Item '".$db_item["key_"]."' unlinked");
}
}
@@ -658,10 +658,8 @@
// Disable Item
function disable_item($itemid){
// first update status for child items
- $db_tmp_items = DBselect("select itemid, hostid from items where templateid=$itemid");
- while($db_tmp_item = DBfetch($db_tmp_items))
- {
- // recursion
+ $db_tmp_items = DBselect('SELECT itemid, hostid FROM items WHERE templateid='.$itemid);
+ while($db_tmp_item = DBfetch($db_tmp_items)){ // recursion
disable_item($db_tmp_item["itemid"]);
}
@@ -669,8 +667,9 @@
return $result;
}
- function get_items_by_hostid($hostid){
- return DBselect('select * from items where hostid='.$hostid);
+ function get_items_by_hostid($hostids){
+ zbx_value2array($hostids);
+ return DBselect('SELECT * FROM items WHERE '.DBcondition('hostid',$hostids));
}
function get_item_by_itemid($itemid){
@@ -733,43 +732,62 @@
* Comments: !!! Don't forget sync code with C !!! *
* *
******************************************************************************/
- function delete_item($itemid){
- $item = get_item_by_itemid($itemid);
- $host = get_host_by_itemid($itemid);
+ function delete_item($itemids){
+ zbx_value2array($itemids);
- // first delete child items
- $db_items = DBselect("select itemid from items where templateid=$itemid");
+// Get items INFO before delete them!
+ $items = array();
+ $item_res = DBselect('SELECT itemid, description, key_ FROM items WHERE '.DBcondition('itemid',$itemids));
+ while($item_rows = DBfetch($item_res)){
+ $items[$item_rows['itemid']] = $item_rows;
+ }
+// --
+ $hosts = array();
+ $hosts = get_host_by_itemid($itemids);
+
+// first delete child items
+ $del_cld_items = array();
+ $db_items = DBselect('SELECT itemid FROM items WHERE '.DBcondition('templateid',$itemids));
while($db_item = DBfetch($db_items)){// recursion
- $result = delete_item($db_item["itemid"]);
+ $del_cld_items[$db_item['itemid']] = $db_item['itemid'];
+ }
+ if(!empty($del_cld_items)){
+ $result = delete_item($del_cld_items);
if(!$result) return $result;
}
-
- $result = delete_triggers_by_itemid($itemid);
+//--
+// triggers
+ $result = delete_triggers_by_itemid($itemids);
if(!$result) return $result;
-
- $db_gitems = DBselect('select distinct graphid from graphs_items where itemid='.$itemid);
- while($db_gitem = DBfetch($db_gitems))
- {
- $result = delete_graph($db_gitem["graphid"]);
+//--
+// delete graphs
+ $del_graphs = array();
+ $db_gitems = DBselect('SELECT DISTINCT graphid FROM graphs_items WHERE '.DBcondition('itemid',$itemids));
+ while($db_gitem = DBfetch($db_gitems)){
+ $del_graphs[$db_gitem['graphid']] = $db_gitem['graphid'];
+ }
+ if(!empty($del_graphs)){
+ $result = delete_graph($del_graphs);
if(!$result) return $result;
}
+//--
- $result = delete_history_by_itemid($itemid, 1 /* use housekeeper */);
+ $result = delete_history_by_itemid($itemids, 1 /* use housekeeper */);
if(!$result) return $result;
- $result &= DBexecute('DELETE FROM screens_items WHERE resourceid='.$itemid.' AND resourcetype IN ('.
- (implode(',',array(
- SCREEN_RESOURCE_SIMPLE_GRAPH,
- SCREEN_RESOURCE_PLAIN_TEXT)
- )
- ).')');
+ $temp_arr = array(SCREEN_RESOURCE_SIMPLE_GRAPH,SCREEN_RESOURCE_PLAIN_TEXT);
+ $result &= DBexecute('DELETE FROM screens_items '.
+ ' WHERE '.DBcondition('resourceid',$itemids).
+ ' AND '.DBcondition('resourcetype', $temp_arr));
- $result &= DBexecute('delete from items_applications where itemid='.$itemid);
- $result &= DBexecute('delete from items where itemid='.$itemid);
- $result &= DBexecute("DELETE FROM profiles WHERE idx='web.favorite.graphids' AND source='itemid' AND value_id=$itemid");
+ $result &= DBexecute('DELETE FROM items_applications WHERE '.DBcondition('itemid',$itemids));
+ $result &= DBexecute('DELETE FROM items WHERE '.DBcondition('itemid',$itemids));
+ $result &= DBexecute("DELETE FROM profiles WHERE idx='web.favorite.graphids' AND source='itemid' AND ".DBcondition('value_id',$itemids));
if($result){
- info("Item '".$host["host"].":".$item["key_"]."' deleted");
+ foreach($items as $itemid => $item){
+ info("Item '".$hosts[$itemid]['host'].':'.$item['key_']."' deleted");
+ }
}
return $result;
}
@@ -1030,16 +1048,19 @@ COpt::profiling_stop('prepare table');
* Comments: !!! Don't forget sync code with C !!! *
* *
******************************************************************************/
- function get_applications_by_itemid($itemid, $field='applicationid')
- {
+ function get_applications_by_itemid($itemids, $field='applicationid'){
+ zbx_value2array($itemids);
+
$result = array();
- $db_applications = DBselect("select distinct app.".$field." as result from applications app, items_applications ia".
- " where app.applicationid=ia.applicationid and ia.itemid=".$itemid);
+ $db_applications = DBselect('SELECT DISTINCT app.'.$field.' as result '.
+ ' FROM applications app, items_applications ia '.
+ ' WHERE app.applicationid=ia.applicationid '.
+ ' AND '.DBcondition('ia.itemid',$itemids));
while($db_application = DBfetch($db_applications))
- array_push($result,$db_application["result"]);
+ array_push($result,$db_application['result']);
- return $result;
+ return $result;
}
/******************************************************************************
@@ -1047,35 +1068,48 @@ COpt::profiling_stop('prepare table');
* Comments: !!! Don't forget sync code with C !!! *
* *
******************************************************************************/
- function delete_history_by_itemid($itemid, $use_housekeeper=0){
- $result = delete_trends_by_itemid($itemid,$use_housekeeper);
+ function delete_history_by_itemid($itemids, $use_housekeeper=0){
+ zbx_value2array($itemids);
+
+ $result = delete_trends_by_itemid($itemids,$use_housekeeper);
if(!$result) return $result;
if($use_housekeeper){
- $housekeeperid = get_dbid('housekeeper','housekeeperid');
- DBexecute("insert into housekeeper (housekeeperid,tablename,field,value)".
- " values ($housekeeperid,'history_text','itemid',$itemid)");
- $housekeeperid = get_dbid('housekeeper','housekeeperid');
- DBexecute("insert into housekeeper (housekeeperid,tablename,field,value)".
- " values ($housekeeperid,'history_log','itemid',$itemid)");
- $housekeeperid = get_dbid('housekeeper','housekeeperid');
- DBexecute("insert into housekeeper (housekeeperid,tablename,field,value)".
- " values ($housekeeperid,'history_uint','itemid',$itemid)");
- $housekeeperid = get_dbid('housekeeper','housekeeperid');
- DBexecute("insert into housekeeper (housekeeperid,tablename,field,value)".
- " values ($housekeeperid,'history_str','itemid',$itemid)");
- $housekeeperid = get_dbid('housekeeper','housekeeperid');
- DBexecute("insert into housekeeper (housekeeperid,tablename,field,value)".
- " values ($housekeeperid,'history','itemid',$itemid)");
+ foreach($itemids as $id => $itemid){
+ $housekeeperid = get_dbid('housekeeper','housekeeperid');
+ $sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
+ " VALUES ($housekeeperid,'history_text','itemid',$itemid)";
+ DBexecute($sql);
+
+ $housekeeperid = get_dbid('housekeeper','housekeeperid');
+ $sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
+ " VALUES ($housekeeperid,'history_log','itemid',$itemid)";
+ DBexecute($sql);
+
+ $housekeeperid = get_dbid('housekeeper','housekeeperid');
+ $sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
+ " VALUES ($housekeeperid,'history_uint','itemid',$itemid)";
+ DBexecute($sql);
+
+ $housekeeperid = get_dbid('housekeeper','housekeeperid');
+ $sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
+ " VALUES ($housekeeperid,'history_str','itemid',$itemid)";
+ DBexecute($sql);
+
+ $housekeeperid = get_dbid('housekeeper','housekeeperid');
+ $sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
+ " VALUES ($housekeeperid,'history','itemid',$itemid)";
+ DBexecute($sql);
+ }
return TRUE;
}
- DBexecute("delete from history_text where itemid=$itemid");
- DBexecute("delete from history_log where itemid=$itemid");
- DBexecute("delete from history_uint where itemid=$itemid");
- DBexecute("delete from history_str where itemid=$itemid");
- DBexecute("delete from history where itemid=$itemid");
- return TRUE;
+ DBexecute('DELETE FROM history_text WHERE '.DBcondition('itemid',$itemids));
+ DBexecute('DELETE FROM history_log WHERE '.DBcondition('itemid',$itemids));
+ DBexecute('DELETE FROM history_uint WHERE '.DBcondition('itemid',$itemids));
+ DBexecute('DELETE FROM history_str WHERE '.DBcondition('itemid',$itemids));
+ DBexecute('DELETE FROM history WHERE '.DBcondition('itemid',$itemids));
+ return TRUE;
}
/******************************************************************************
@@ -1083,27 +1117,31 @@ COpt::profiling_stop('prepare table');
* Comments: !!! Don't forget sync code with C !!! *
* *
******************************************************************************/
- function delete_trends_by_itemid($itemid, $use_housekeeper=0){
+ function delete_trends_by_itemid($itemids, $use_housekeeper=0){
+ zbx_value2array($itemids);
+
if($use_housekeeper){
- $housekeeperid = get_dbid('housekeeper','housekeeperid');
- DBexecute("insert into housekeeper (housekeeperid,tablename,field,value)".
- " values ($housekeeperid, 'trends','itemid',$itemid)");
+ foreach($itemids as $id => $itemid){
+ $housekeeperid = get_dbid('housekeeper','housekeeperid');
+ DBexecute('INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
+ " VALUES ($housekeeperid, 'trends','itemid',$itemid)");
+ }
return TRUE;
}
- return DBexecute("delete from trends where itemid=$itemid");
+ return DBexecute('DELETE FROM trends WHERE '.DBcondition('itemid',$itemids));
}
- function format_lastvalue($db_item){
+ function format_lastvalue($db_item){
if($db_item["value_type"] == ITEM_VALUE_TYPE_LOG){
- $row=DBfetch(DBselect("select value from history_log where itemid=".$db_item["itemid"]." order by clock desc", 1));
+ $row=DBfetch(DBselect('SELECT value FROM history_log WHERE itemid='.$db_item['itemid'].' ORDER BY clock DESC', 1));
if($row){
- $lastvalue=/*nbsp(htmlspecialchars(*/$row["value"]/*))*/;
+ $lastvalue=/*nbsp(htmlspecialchars(*/$row['value']/*))*/;
if(strlen($lastvalue) > 20)
$lastvalue = substr($lastvalue,0,20)." ...";
$lastvalue = nbsp(htmlspecialchars($lastvalue));
}
else{
- $lastvalue="-";
+ $lastvalue='-';
}
}
diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php
index 75bddbb5..1e5fb9b8 100644
--- a/frontends/php/include/locales/en_gb.inc.php
+++ b/frontends/php/include/locales/en_gb.inc.php
@@ -751,6 +751,11 @@
'S_PROXY_NAME'=> 'Proxy name',
'S_LASTSEEN_AGE'=> 'Last seen (age)',
+ 'S_TRANSACTION'=> 'Transaction',
+ 'S_STARTED_BIG'=> 'STARTED!',
+ 'S_COMMITED_BIG'=> 'COMMITED!',
+ 'S_ROLLBACKED_BIG'=> 'ROLLBACKED!',
+
// Host profiles
'S_HOST_PROFILE'=> 'Host profile',
'S_DEVICE_TYPE'=> 'Device type',
diff --git a/frontends/php/include/maps.inc.php b/frontends/php/include/maps.inc.php
index e54c6e68..71731117 100644
--- a/frontends/php/include/maps.inc.php
+++ b/frontends/php/include/maps.inc.php
@@ -166,18 +166,21 @@
// Delete System Map
- function delete_sysmap( $sysmapid ){
- $result = delete_sysmaps_elements_with_sysmapid($sysmapid);
+ function delete_sysmap($sysmapids){
+ zbx_value2array($sysmapids);
+
+ $result = delete_sysmaps_elements_with_sysmapid($sysmapids);
if(!$result) return $result;
- $res=DBselect('SELECT linkid FROM sysmaps_links WHERE sysmapid='.$sysmapid);
+ $res=DBselect('SELECT linkid FROM sysmaps_links WHERE '.DBcondition('sysmapid',$sysmapids));
while($rows = DBfetch($res)){
$result&=delete_link($rows['linkid']);
}
- $result = DBexecute('DELETE FROM sysmaps_elements WHERE sysmapid='.$sysmapid);
- $result &= DBexecute("DELETE FROM profiles WHERE idx='web.favorite.sysmapids' AND source='sysmapid' AND value_id=$sysmapid");
- $result &= DBexecute('DELETE FROM sysmaps WHERE sysmapid='.$sysmapid);
+ $result = DBexecute('DELETE FROM sysmaps_elements WHERE '.DBcondition('sysmapid',$sysmapids));
+ $result &= DBexecute("DELETE FROM profiles WHERE idx='web.favorite.sysmapids' AND source='sysmapid' AND ".DBcondition('value_id',$sysmapids));
+ $result &= DBexecute('DELETE FROM screens_items WHERE '.DBcondition('resourceid',$sysmapids).' AND resourcetype='.SCREEN_RESOURCE_MAP);
+ $result &= DBexecute('DELETE FROM sysmaps WHERE '.DBcondition('sysmapid',$sysmapids));
return $result;
}
@@ -346,12 +349,14 @@
* Comments: !!! Don't forget sync code with C !!! *
* *
******************************************************************************/
- function delete_sysmaps_element($selementid){
+ function delete_sysmaps_element($selementids){
+ zbx_value2array($selementids);
$result=TRUE;
$sql = 'SELECT linkid FROM sysmaps_links '.
- ' WHERE selementid1='.$selementid.
- ' OR selementid2='.$selementid;
+ ' WHERE '.DBcondition('selementid1',$selementids).
+ ' OR '.DBcondition('selementid2',$selementids);
+
$res=DBselect($sql);
while($rows = DBfetch($res)){
$result&=delete_link($rows['linkid']);
@@ -360,7 +365,7 @@
if(!$result) return $result;
- return DBexecute("delete FROM sysmaps_elements WHERE selementid=$selementid");
+ return DBexecute('DELETE FROM sysmaps_elements WHERE '.DBcondition('selementid',$selementids));
}
/******************************************************************************
@@ -368,54 +373,67 @@
* Comments: !!! Don't forget sync code with C !!! *
* *
******************************************************************************/
- function delete_sysmaps_elements_with_hostid($hostid){
- $db_elements = DBselect("select selementid FROM sysmaps_elements".
- " WHERE elementid=$hostid AND elementtype=".SYSMAP_ELEMENT_TYPE_HOST);
+ function delete_sysmaps_elements_with_hostid($hostids){
+ zbx_value2array($hostids);
+
+ $db_elements = DBselect('SELECT selementid '.
+ ' FROM sysmaps_elements '.
+ ' WHERE '.DBcondition('elementid',$hostids).
+ ' AND elementtype='.SYSMAP_ELEMENT_TYPE_HOST);
+
while($db_element = DBfetch($db_elements)){
delete_sysmaps_element($db_element["selementid"]);
}
- return TRUE;
+ return TRUE;
}
- function delete_sysmaps_elements_with_sysmapid($sysmapid){
- $db_elements = DBselect("select selementid FROM sysmaps_elements".
- " WHERE elementid=$sysmapid AND elementtype=".SYSMAP_ELEMENT_TYPE_MAP);
- while($db_element = DBfetch($db_elements))
- {
- delete_sysmaps_element($db_element["selementid"]);
+ function delete_sysmaps_elements_with_sysmapid($sysmapids){
+ zbx_value2array($sysmapids);
+
+ $db_elements = DBselect('SELECT selementid '.
+ ' FROM sysmaps_elements '.
+ ' WHERE '.DBcondition('elementid',$sysmapids).
+ ' AND elementtype='.SYSMAP_ELEMENT_TYPE_MAP);
+ while($db_element = DBfetch($db_elements)){
+ delete_sysmaps_element($db_element['selementid']);
}
- return TRUE;
+ return TRUE;
}
- /******************************************************************************
- * *
- * Comments: !!! Don't forget sync code with C !!! *
- * *
- ******************************************************************************/
- function delete_sysmaps_elements_with_triggerid($triggerid){
- $db_elements = DBselect('SELECT selementid FROM sysmaps_elements '.
- ' WHERE elementid='.$triggerid.
- ' AND elementtype='.SYSMAP_ELEMENT_TYPE_TRIGGER);
-
+/******************************************************************************
+ * *
+ * Comments: !!! Don't forget sync code with C !!! *
+ * *
+ ******************************************************************************/
+ function delete_sysmaps_elements_with_triggerid($triggerids){
+ zbx_value2array($triggerids);
+
+ $db_elements = DBselect('SELECT selementid '.
+ ' FROM sysmaps_elements '.
+ ' WHERE '.DBcondition('elementid',$triggerids).
+ ' AND elementtype='.SYSMAP_ELEMENT_TYPE_TRIGGER);
while($db_element = DBfetch($db_elements)){
delete_sysmaps_element($db_element["selementid"]);
}
- return TRUE;
+ return TRUE;
}
- function delete_sysmaps_elements_with_groupid($groupid){
- $db_elements = DBselect('SELECT selementid FROM sysmaps_elements '.
- ' WHERE elementid='.$groupid.
- ' AND elementtype='.SYSMAP_ELEMENT_TYPE_HOST_GROUP);
+ function delete_sysmaps_elements_with_groupid($groupids){
+ zbx_value2array($groupids);
+
+ $db_elements = DBselect('SELECT selementid '.
+ ' FROM sysmaps_elements '.
+ ' WHERE '.DBcondition('elementid',$groupids).
+ ' AND elementtype='.SYSMAP_ELEMENT_TYPE_HOST_GROUP);
while($db_element = DBfetch($db_elements)){
delete_sysmaps_element($db_element["selementid"]);
}
- return TRUE;
+
+ return TRUE;
}
- function get_png_by_selementid($selementid)
- {
+ function get_png_by_selementid($selementid){
$elements = DBselect("select * FROM sysmaps_elements WHERE selementid=$selementid");
if(!$elements) return FALSE;
@@ -427,19 +445,19 @@
$image = get_image_by_imageid($info['iconid']);
if(!$image) return FALSE;
- return imagecreatefromstring($image['image']);
+ return imagecreatefromstring($image['image']);
}
- /*
- * Function: get_info_by_selementid
- *
- * Description:
- * Retrive information for map element
- *
- * Author:
- * Eugene Grigorjev
- *
- */
+/*
+ * Function: get_info_by_selementid
+ *
+ * Description:
+ * Retrive information for map element
+ *
+ * Author:
+ * Eugene Grigorjev
+ *
+ */
function get_info_by_selementid($selementid){
global $colors;
diff --git a/frontends/php/include/page_footer.php b/frontends/php/include/page_footer.php
index 2e67f9e9..4cfd4a67 100644
--- a/frontends/php/include/page_footer.php
+++ b/frontends/php/include/page_footer.php
@@ -58,7 +58,7 @@ catch(e){
-->
</script>
<?php
-
+//SDI(SBR.'SELECTS: '.$DB['SELECT_COUNT'].SPACE.SPACE.'EXECUTE: '.$DB['EXECUTE_COUNT'].SPACE.SPACE.'TOTAL: '.($DB['EXECUTE_COUNT']+$DB['SELECT_COUNT']));
if(!defined('ZBX_PAGE_NO_MENU') && !defined('ZBX_PAGE_NO_FOOTER')){
$table = new CTable(NULL,"page_footer");
$table->SetCellSpacing(0);
diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php
index 3ef8e0cf..acbd22c6 100644
--- a/frontends/php/include/triggers.inc.php
+++ b/frontends/php/include/triggers.inc.php
@@ -395,12 +395,14 @@
return FALSE;
}
- function get_hosts_by_triggerid($triggerid){
+ function get_hosts_by_triggerid($triggerids){
+ zbx_value2array($triggerids);
+
return DBselect('SELECT DISTINCT h.* '.
' FROM hosts h, functions f, items i '.
' WHERE i.itemid=f.itemid '.
- ' and h.hostid=i.hostid '.
- ' and f.triggerid='.$triggerid);
+ ' AND h.hostid=i.hostid '.
+ ' AND '.DBcondition('f.triggerid',$triggerids));
}
function get_functions_by_triggerid($triggerid){
@@ -457,8 +459,9 @@
return $trigger;
}
- function get_triggers_by_templateid($triggerid){
- return DBselect('select * from triggers where templateid='.$triggerid);
+ function get_triggers_by_templateid($triggerids){
+ zbx_value2array($triggerids);
+ return DBselect('SELECT * FROM triggers WHERE '.DBcondition('templateid',$triggerids));
}
/*
@@ -1058,22 +1061,31 @@
return $short_exp;
}
- function update_trigger_comments($triggerid,$comments){
- return DBexecute('UPDATE triggers SET comments='.zbx_dbstr($comments).
- ' WHERE triggerid='.$triggerid);
+ function update_trigger_comments($triggerids,$comments){
+ zbx_value2array($triggerids);
+
+ return DBexecute('UPDATE triggers '.
+ ' SET comments='.zbx_dbstr($comments).
+ ' WHERE '.DBcondition('triggerid',$triggerids));
}
# Update Trigger status
- function update_trigger_status($triggerid,$status){
+ function update_trigger_status($triggerids,$status){
+ zbx_value2array($triggerids);
+
// first update status for child triggers
- $db_chd_triggers = get_triggers_by_templateid($triggerid);
+ $upd_chd_triggers = array();
+ $db_chd_triggers = get_triggers_by_templateid($triggerids);
while($db_chd_trigger = DBfetch($db_chd_triggers)){
- update_trigger_status($db_chd_trigger["triggerid"],$status);
+ $upd_chd_triggers[$db_chd_trigger['triggerid']] = $db_chd_trigger['triggerid'];
+ }
+ if(!empty($upd_chd_triggers)){
+ update_trigger_status($upd_chd_triggers,$status);
}
- add_event($triggerid,TRIGGER_VALUE_UNKNOWN);
- return DBexecute('UPDATE triggers SET status='.$status.' WHERE triggerid='.$triggerid);
+ $triggerids = add_event($triggerids,TRIGGER_VALUE_UNKNOWN);
+ return DBexecute('UPDATE triggers SET status='.$status.' WHERE '.DBcondition('triggerid',$triggerids));
}
/*
@@ -1213,48 +1225,64 @@
return $description;
}
- function update_trigger_value_to_unknown_by_hostid($hostid){
+ function update_trigger_value_to_unknown_by_hostid($hostids){
+ zbx_value2array($hostids);
+
+ $triggers = array();
$result = DBselect('SELECT DISTINCT t.triggerid '.
- ' FROM hosts h,items i,triggers t,functions f '.
+ ' FROM items i,triggers t,functions f '.
' WHERE f.triggerid=t.triggerid '.
' AND f.itemid=i.itemid '.
- ' AND h.hostid=i.hostid '.
- ' AND h.hostid='.$hostid);
+ ' AND '.DBcondition('i.hostid',$hostids));
+
$now = time();
while($row=DBfetch($result)){
- if(!add_event($row["triggerid"],TRIGGER_VALUE_UNKNOWN,$now)) continue;
+ $triggers[$row['triggerid']] = $row['triggerid'];
+ }
+ if(!empty($triggers)){
+// returns updated triggers
+ $triggers = add_event($triggers,TRIGGER_VALUE_UNKNOWN,$now);
+ }
- DBexecute('update triggers set value='.TRIGGER_VALUE_UNKNOWN.' where triggerid='.$row["triggerid"]);
+ if(!empty($triggers)){
+ DBexecute('UPDATE triggers SET value='.TRIGGER_VALUE_UNKNOWN.', lastchange='.$now.' WHERE '.DBcondition('triggerid',$triggers));
}
+ return true;
}
- /******************************************************************************
- * *
- * Comments: !!! Don't forget sync code with C !!! *
- * *
- ******************************************************************************/
- function add_event($triggerid, $value, $time=NULL){
+/******************************************************************************
+ * *
+ * Comments: !!! Don't forget sync code with C !!! *
+ * !!! C code dosn't support TRIGGERS MULTI EVENT !!! *
+ * *
+ ******************************************************************************/
+ function add_event($triggerids, $value, $time=NULL){
+ zbx_value2array($triggerids);
if(is_null($time)) $time = time();
- $result = DBselect('SELECT value,clock '.
- ' FROM events '.
- ' WHERE objectid='.$triggerid.
- ' AND object='.EVENT_OBJECT_TRIGGER.
- ' ORDER BY clock desc',1);
- $last_value = DBfetch($result);
- if($last_value){
- if($value == $last_value['value'])
- return false;
+ $result = DBselect('SELECT DISTINCT triggerid, value, type FROM triggers WHERE '.DBcondition('triggerid',$triggerids));
+ while($trigger = DBfetch($result)){
+ if(($value == $trigger['value']) && !(($value == TRIGGER_VALUE_TRUE) && ($trigger['type'] == TRIGGER_MULT_EVENT_ENABLED))){
+ unset($triggerids[$trigger['triggerid']]);
+ }
}
- $eventid = get_dbid("events","eventid");
- $result = DBexecute('insert into events(eventid,source,object,objectid,clock,value) '.
- ' values('.$eventid.','.EVENT_SOURCE_TRIGGERS.','.EVENT_OBJECT_TRIGGER.','.$triggerid.','.$time.','.$value.')');
-
- if($value == TRIGGER_VALUE_FALSE || $value == TRIGGER_VALUE_TRUE){
- DBexecute('update alerts set retries=3,error=\'Trigger changed its status. Will not send repeats.\''.
- ' where eventid='.$eventid.' and repeats>0 and status='.ALERT_STATUS_NOT_SENT);
+
+ $events = array();
+ foreach($triggerids as $id => $triggerid){
+ $eventid = get_dbid('events','eventid');
+ $result = DBexecute('INSERT INTO events (eventid,source,object,objectid,clock,value) '.
+ ' VALUES ('.$eventid.','.EVENT_SOURCE_TRIGGERS.','.EVENT_OBJECT_TRIGGER.','.$triggerid.','.$time.','.$value.')');
+ $events[$eventid] = $eventid;
}
- return true;
+
+ if(!empty($events) && ($value == TRIGGER_VALUE_FALSE || $value == TRIGGER_VALUE_TRUE)){
+ DBexecute('UPDATE alerts '.
+ " SET retries=3,error='Trigger changed its status. Will not send repeats.'".
+ ' WHERE '.DBcondition('eventid',$events).
+ ' AND repeats>0 '.
+ ' AND status='.ALERT_STATUS_NOT_SENT);
+ }
+ return $triggerids;
}
function add_trigger_dependency($triggerid,$depid){
@@ -1268,67 +1296,86 @@
return $result;
}
- /******************************************************************************
- * *
- * Purpose: Delete Trigger definition *
- * *
- * Comments: !!! Don't forget sync code with C !!! *
- * *
- ******************************************************************************/
- function delete_trigger($triggerid){
- // first delete child triggers
- $db_triggers= get_triggers_by_templateid($triggerid);
+/******************************************************************************
+ * *
+ * Purpose: Delete Trigger definition *
+ * *
+ * Comments: !!! Don't forget sync code with C !!! *
+ * *
+ ******************************************************************************/
+ function delete_trigger($triggerids){
+ zbx_value2array($triggerids);
+
+// first delete child triggers
+ $del_chd_triggers = array();
+ $db_triggers= get_triggers_by_templateid($triggerids);
while($db_trigger = DBfetch($db_triggers)){// recursion
- $result = delete_trigger($db_trigger["triggerid"]);
- if(!$result) return $result;
+ $del_chd_triggers[$db_trigger['triggerid']] = $db_trigger['triggerid'];
+ }
+ if(!empty($del_chd_triggers)){
+ $result = delete_trigger($del_chd_triggers);
+ if(!$result) return $result;
}
- // get hosts before functions deletion !!!
- $trig_hosts = get_hosts_by_triggerid($triggerid);
+// get hosts before functions deletion !!!
+ $trig_hosts = array();
+ foreach($triggerids as $id => $triggerid){
+ $trig_hosts[$triggerid] = get_hosts_by_triggerid($triggerid);
+ }
- $result = delete_dependencies_by_triggerid($triggerid);
+ $result = delete_dependencies_by_triggerid($triggerids);
if(!$result) return $result;
- DBexecute("delete from trigger_depends where triggerid_up=$triggerid");
+ DBexecute('DELETE FROM trigger_depends WHERE '.DBcondition('triggerid_up',$triggerids));
- $result=delete_function_by_triggerid($triggerid);
+ $result = delete_function_by_triggerid($triggerids);
if(!$result) return $result;
- $result=delete_events_by_triggerid($triggerid);
+ $result = delete_events_by_triggerid($triggerids);
if(!$result) return $result;
- $result=delete_services_by_triggerid($triggerid);
+ $result = delete_services_by_triggerid($triggerids);
if(!$result) return $result;
- $result=delete_sysmaps_elements_with_triggerid($triggerid);
+ $result = delete_sysmaps_elements_with_triggerid($triggerids);
if(!$result) return $result;
- DBexecute("delete from sysmaps_link_triggers where triggerid=$triggerid");
+ DBexecute('DELETE FROM sysmaps_link_triggers WHERE '.DBcondition('triggerid',$triggerids));
- // disable actions
- $db_actions = DBselect('select distinct actionid from conditions '.
- " where conditiontype=".CONDITION_TYPE_TRIGGER." and value=".zbx_dbstr($triggerid));
+// disable actions
+ $db_actions = DBselect('SELECT DISTINCT actionid '.
+ ' FROM conditions '.
+ ' WHERE conditiontype='.CONDITION_TYPE_TRIGGER.
+ ' AND '.DBcondition('value',$triggerids)); // POSIBLE VALUE TYPE VIOLATION !!!!!!!!!!!!!!!
+
while($db_action = DBfetch($db_actions)){
- DBexecute("update actions set status=".ACTION_STATUS_DISABLED.
- " where actionid=".$db_action["actionid"]);
+ DBexecute('UPDATE actions SET status='.ACTION_STATUS_DISABLED.
+ ' WHERE actionid='.$db_action['actionid']);
}
- // delete action conditions
- DBexecute('delete from conditions where conditiontype='.CONDITION_TYPE_TRIGGER.' and value='.zbx_dbstr($triggerid));
-
- $trigger = get_trigger_by_triggerid($triggerid);
+
+// delete action conditions // POSIBLE VALUE TYPE VIOLATION !!!!!!!!!!!!!!!
+ DBexecute('DELETE FROM conditions WHERE conditiontype='.CONDITION_TYPE_TRIGGER.' AND '.DBcondition('value',$triggerids));
- $result = DBexecute("delete from triggers where triggerid=$triggerid");
+// Get triggers INFO before delete them!
+ $triggers = array();
+ $trig_res = DBselect('SELECT triggerid, description FROM triggers WHERE '.DBcondition('triggerid',$triggerids));
+ while($trig_rows = DBfetch($trig_res)){
+ $triggers[$trig_rows['triggerid']] = $trig_rows;
+ }
+// --
+ $result = DBexecute('DELETE FROM triggers WHERE '.DBcondition('triggerid',$triggerids));
if($result){
- $msg = "Trigger '".$trigger["description"]."' deleted";
- $trig_host = DBfetch($trig_hosts);
- if($trig_host)
- {
- $msg .= " from host '".$trig_host["host"]."'";
+ foreach($triggers as $triggerid => $trigger){
+ $msg = "Trigger '".$trigger["description"]."' deleted";
+ $trig_host = DBfetch($trig_hosts[$triggerid]);
+ if($trig_host){
+ $msg .= " from host '".$trig_host["host"]."'";
+ }
+ info($msg);
}
- info($msg);
}
- return $result;
+ return $result;
}
# Update Trigger definition
@@ -1401,16 +1448,16 @@
if($event_to_unknown) add_event($triggerid,TRIGGER_VALUE_UNKNOWN);
reset_items_nextcheck($triggerid);
- $sql="update triggers set";
- if(!is_null($expression)) $sql .= " expression=".zbx_dbstr($expression).",";
- if(!is_null($description)) $sql .= " description=".zbx_dbstr($description).",";
- if(!is_null($type)) $sql .= " type=$type,";
- if(!is_null($priority)) $sql .= " priority=$priority,";
- if(!is_null($status)) $sql .= " status=$status,";
- if(!is_null($comments)) $sql .= " comments=".zbx_dbstr($comments).",";
- if(!is_null($url)) $sql .= " url=".zbx_dbstr($url).",";
- if(!is_null($templateid)) $sql .= " templateid=$templateid,";
- $sql .= " value=2 where triggerid=$triggerid";
+ $sql="UPDATE triggers SET";
+ if(!is_null($expression)) $sql .= ' expression='.zbx_dbstr($expression).',';
+ if(!is_null($description)) $sql .= ' description='.zbx_dbstr($description).',';
+ if(!is_null($type)) $sql .= ' type='.$type.',';
+ if(!is_null($priority)) $sql .= ' priority='.$priority.',';
+ if(!is_null($status)) $sql .= ' status='.$status.',';
+ if(!is_null($comments)) $sql .= ' comments='.zbx_dbstr($comments).',';
+ if(!is_null($url)) $sql .= ' url='.zbx_dbstr($url).',';
+ if(!is_null($templateid)) $sql .= ' templateid='.$templateid.',';
+ $sql .= ' value=2 WHERE triggerid='.$triggerid;
$result = DBexecute($sql);
@@ -1461,16 +1508,20 @@
* Comments: !!! Don't forget sync code with C !!! *
* *
******************************************************************************/
- function delete_dependencies_by_triggerid($triggerid){
- $db_deps = DBselect('select triggerid_up, triggerid_down from trigger_depends'.
- ' where triggerid_down='.$triggerid);
+ function delete_dependencies_by_triggerid($triggerids){
+ zbx_value2array($triggerids);
+
+ $db_deps = DBselect('SELECT triggerid_up, triggerid_down '.
+ ' FROM trigger_depends '.
+ ' WHERE '.DBcondition('triggerid_down',$triggerids));
+
while($db_dep = DBfetch($db_deps)){
- DBexecute('update triggers set dep_level=dep_level-1 where triggerid='.$db_dep['triggerid_up']);
- DBexecute('delete from trigger_depends'.
- ' where triggerid_up='.$db_dep['triggerid_up'].
- ' and triggerid_down='.$db_dep['triggerid_down']);
+ DBexecute('UPDATE triggers SET dep_level=dep_level-1 WHERE triggerid='.$db_dep['triggerid_up']);
+ DBexecute('DELETE FROM trigger_depends'.
+ ' WHERE triggerid_up='.$db_dep['triggerid_up'].
+ ' AND triggerid_down='.$db_dep['triggerid_down']);
}
- return true;
+ return true;
}
/******************************************************************************
@@ -1526,12 +1577,14 @@
}
//*/
- function delete_function_by_triggerid($triggerid){
- return DBexecute("delete from functions where triggerid=$triggerid");
+ function delete_function_by_triggerid($triggerids){
+ zbx_value2array($triggerids);
+ return DBexecute('DELETE FROM functions WHERE '.DBcondition('triggerid',$triggerids));
}
- function delete_events_by_triggerid($triggerid){
- return DBexecute('delete from events where objectid='.$triggerid.' and object='.EVENT_OBJECT_TRIGGER);
+ function delete_events_by_triggerid($triggerids){
+ zbx_value2array($triggerids);
+ return DBexecute('DELETE FROM events WHERE '.DBcondition('objectid',$triggerids).' AND object='.EVENT_OBJECT_TRIGGER);
}
/******************************************************************************
@@ -1539,14 +1592,19 @@
* Comments: !!! Don't forget sync code with C !!! *
* *
******************************************************************************/
- function delete_triggers_by_itemid($itemid){
- $result=DBselect("select triggerid from functions where itemid=$itemid");
+ function delete_triggers_by_itemid($itemids){
+ zbx_value2array($itemids);
+
+ $del_triggers = array();
+ $result=DBselect('SELECT triggerid FROM functions WHERE '.DBcondition('itemid',$itemids));
while($row=DBfetch($result)){
- if(!delete_trigger($row["triggerid"])){
- return FALSE;
- }
+ $del_triggers[$row['triggerid']] = $row['triggerid'];
+ }
+ if(!empty($del_triggers)){
+ if(!delete_trigger($del_triggers)) return FALSE;
}
- return TRUE;
+
+ return TRUE;
}
/******************************************************************************
@@ -1556,12 +1614,14 @@
* Comments: !!! Don't forget sync code with C !!! *
* *
******************************************************************************/
- function delete_services_by_triggerid($triggerid){
- $result = DBselect("select serviceid from services where triggerid=$triggerid");
+ function delete_services_by_triggerid($triggerids){
+ zbx_value2array($triggerids);
+
+ $result = DBselect('SELECT serviceid FROM services WHERE '.DBcondition('triggerid',$triggerids));
while($row = DBfetch($result)){
- delete_service($row["serviceid"]);
+ delete_service($row['serviceid']);
}
- return TRUE;
+ return TRUE;
}
/*
@@ -1649,23 +1709,23 @@
* Comments: !!! Don't forget sync code with C !!!
*
*/
- function delete_template_triggers($hostid, $templateid = null, $unlink_mode = false){
+ function delete_template_triggers($hostid, $templateids = null, $unlink_mode = false){
+ zbx_value2array($templateids);
+
$triggers = get_triggers_by_hostid($hostid);
while($trigger = DBfetch($triggers)){
- if($trigger["templateid"]==0) continue;
+ if($trigger['templateid']==0) continue;
- if($templateid != null){
- if( !is_array($templateid)) $templateid = array($templateid);
-
+ if($templateid != null){
$db_tmp_hosts = get_hosts_by_triggerid($trigger["templateid"]);
$tmp_host = DBfetch($db_tmp_hosts);
- if(!uint_in_array($tmp_host["hostid"], $templateid)) continue;
+ if(!uint_in_array($tmp_host["hostid"], $templateids)) continue;
}
if($unlink_mode){
- if(DBexecute("update triggers set templateid=0 where triggerid=".$trigger["triggerid"])){
- info("Trigger '".$trigger["description"]."' unlinked");
+ if(DBexecute('UPDATE triggers SET templateid=0 WHERE triggerid='.$trigger['triggerid'])){
+ info('Trigger "'.$trigger["description"].'" unlinked');
}
}
else{
diff --git a/frontends/php/items.php b/frontends/php/items.php
index 799dca2c..731cb258 100644
--- a/frontends/php/items.php
+++ b/frontends/php/items.php
@@ -19,10 +19,10 @@
**/
?>
<?php
- require_once "include/config.inc.php";
- require_once "include/hosts.inc.php";
- require_once "include/items.inc.php";
- require_once "include/forms.inc.php";
+ require_once('include/config.inc.php');
+ require_once('include/hosts.inc.php');
+ require_once('include/items.inc.php');
+ require_once('include/forms.inc.php');
$page["title"] = "S_CONFIGURATION_OF_ITEMS";
$page["file"] = "items.php";
@@ -299,7 +299,7 @@ include_once "include/page_header.php";
unset($_REQUEST['hostid']);
}
- validate_group_with_host(PERM_READ_WRITE,array('always_select_first_host','only_current_node'),'web.last.conf.groupid', 'web.last.conf.hostid');
+ validate_group_with_host(PERM_READ_WRITE,array('always_select_first_group','always_select_first_host','only_current_node'),'web.last.conf.groupid', 'web.last.conf.hostid');
update_profile('web.items.showdisabled',$showdisabled, PROFILE_TYPE_INT);
?>
diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c
index a887d252..94720010 100644
--- a/src/libs/zbxdbhigh/db.c
+++ b/src/libs/zbxdbhigh/db.c
@@ -740,7 +740,8 @@ void DBdelete_trigger(zbx_uint64_t triggerid)
triggerid);
DBexecute("delete from functions where triggerid=" ZBX_FS_UI64,
triggerid);
- DBexecute("delete from events where triggerid=" ZBX_FS_UI64,
+ DBexecute("delete from events where object=%d AND objectid=" ZBX_FS_UI64,
+ EVENT_OBJECT_TRIGGER,
triggerid);
/* zbx_snprintf(sql,sizeof(sql),"delete from actions where triggerid=%d and scope=%d", triggerid, ACTION_SCOPE_TRIGGER);
DBexecute(sql);*/
diff --git a/src/libs/zbxdbhigh/host.c b/src/libs/zbxdbhigh/host.c
index 81159296..fe2f88bd 100644
--- a/src/libs/zbxdbhigh/host.c
+++ b/src/libs/zbxdbhigh/host.c
@@ -3053,8 +3053,7 @@ static int DBadd_event(
if( !now ) now = time(NULL);
- db_events = DBselect("select value,clock from events where objectid=" ZBX_FS_UI64 " and object=%i "
- " order by clock desc", triggerid, EVENT_OBJECT_TRIGGER);
+ db_events = DBselect("select lastvalue,type from triggers where triggerid=" ZBX_FS_UI64, triggerid);
if( (event_data = DBfetch(db_events)) )
{