summaryrefslogtreecommitdiffstats
path: root/frontends/php/include
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-11-22 15:15:31 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-11-22 15:15:31 +0000
commit9eaf3f1434d25e5940f28dd7d3683e965dcf0cc6 (patch)
treeaf6c48cc306eba8119128e9dbc2c56770614f4f9 /frontends/php/include
parent9875c11fb7e4dbca03f7775f81bf8e4eafa2b4d5 (diff)
downloadzabbix-9eaf3f1434d25e5940f28dd7d3683e965dcf0cc6.tar.gz
zabbix-9eaf3f1434d25e5940f28dd7d3683e965dcf0cc6.tar.xz
zabbix-9eaf3f1434d25e5940f28dd7d3683e965dcf0cc6.zip
- developed "Import/Export" system for ZABBIX configurations (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3504 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r--frontends/php/include/config.inc.php11
-rw-r--r--frontends/php/include/defines.inc.php19
-rw-r--r--frontends/php/include/export.inc.php361
-rw-r--r--frontends/php/include/forms.inc.php2
-rw-r--r--frontends/php/include/graphs.inc.php2
-rw-r--r--frontends/php/include/hosts.inc.php4
-rw-r--r--frontends/php/include/import.inc.php416
-rw-r--r--frontends/php/include/items.inc.php4
-rw-r--r--frontends/php/include/locales/en_gb.inc.php5
-rw-r--r--frontends/php/include/page_header.php12
-rw-r--r--frontends/php/include/triggers.inc.php4
11 files changed, 829 insertions, 11 deletions
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index 56befd92..861ed0bc 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -472,6 +472,9 @@ else
$width = max($width, ImageFontWidth(4) * strlen($msg) + 1);
$height += imagefontheight(4) + 1;
break;
+ case PAGE_TYPE_XML:
+ echo htmlspecialchars($msg)."\n";
+ break;
case PAGE_TYPE_HTML:
default:
echo "<p align=center>";
@@ -486,7 +489,6 @@ else
if(isset($ZBX_MESSAGES))
{
-
if($page["type"] == PAGE_TYPE_IMAGE)
{
foreach($ZBX_MESSAGES as $msg)
@@ -509,6 +511,13 @@ else
$height += imagefontheight(2) + 1;
}
}
+ elseif($page["type"] == PAGE_TYPE_XML)
+ {
+ foreach($ZBX_MESSAGES as $msg)
+ {
+ echo '['.$msg['type'].'] '.$msg['message']."\n";
+ }
+ }
else
{
$lst_error = new CList(null,'messages');
diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php
index 6b558b3c..28dd140f 100644
--- a/frontends/php/include/defines.inc.php
+++ b/frontends/php/include/defines.inc.php
@@ -19,8 +19,27 @@
**/
?>
<?php
+ define("XML_TAG_ZABBIX_EXPORT", 'zabbix_export');
+ define("XML_TAG_HOSTS", 'hosts');
+ define("XML_TAG_HOST", 'host');
+ define("XML_TAG_GROUPS", 'groups');
+ define("XML_TAG_GROUP", 'group');
+ define("XML_TAG_ITEMS", 'items');
+ define("XML_TAG_ITEM", 'item');
+ define("XML_TAG_TRIGGERS", 'triggers');
+ define("XML_TAG_TRIGGER", 'trigger');
+ define("XML_TAG_GRAPHS", 'graphs');
+ define("XML_TAG_GRAPH", 'graph');
+ define("XML_TAG_GRAPH_ELEMENT", 'graph_element');
+ define("XML_TAG_GRAPH_ELEMENTS", 'graph_elements');
+ define("XML_TAG_SCREENS", 'screens');
+ define("XML_TAG_SCREEN", 'screen');
+ define("XML_TAG_SCREEN_ELEMENT", 'screen_element');
+ define("XML_TAG_SCREEN_ELEMENTS", 'screen_elements');
+
define("PAGE_TYPE_HTML", 0);
define("PAGE_TYPE_IMAGE", 1);
+ define("PAGE_TYPE_XML", 2);
define("T_ZBX_STR", 0);
define("T_ZBX_INT", 1);
diff --git a/frontends/php/include/export.inc.php b/frontends/php/include/export.inc.php
new file mode 100644
index 00000000..0ae10b7e
--- /dev/null
+++ b/frontends/php/include/export.inc.php
@@ -0,0 +1,361 @@
+<?php
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+ require_once "include/defines.inc.php";
+?>
+<?php
+ global $ZBX_EXPORT_MAP;
+
+ $ZBX_EXPORT_MAP = array(
+ XML_TAG_HOST => array(
+ 'attribures' => array(
+ 'host' => 'name'),
+ 'elements' => array(
+ 'useip' => '',
+ 'ip' => '',
+ 'port' => '',
+ 'status' => '')
+ ),
+ XML_TAG_ITEM => array(
+ 'attribures' => array(
+ 'type' => '',
+ 'key_' => 'key',
+ 'value_type' => ''),
+ 'elements' => array(
+ 'description' => '',
+ 'delay' => '',
+ 'history' => '',
+ 'trends' => '',
+ 'status' => '',
+ 'units' => '',
+ 'multiplier' => '',
+ 'delta' => '',
+ 'formula' => '',
+ 'lastlogsize' => '',
+ 'logtimefmt' => '',
+ 'delay_flex' => '',
+ 'trapper_hosts' => '',
+ 'snmp_community' => '',
+ 'snmp_oid' => '',
+ 'snmp_port' => '',
+ 'snmpv3_securityname' => '',
+ 'snmpv3_securitylevel' => '',
+ 'snmpv3_authpassphrase' => '',
+ 'snmpv3_privpassphrase' => '')
+ ),
+ XML_TAG_TRIGGER => array(
+ 'attribures' => array(),
+ 'elements' => array(
+ 'description' => '',
+ 'expression' => '',
+ 'url' => '',
+ 'status' => '',
+ 'priority' => '',
+ 'comments' => '')
+ ),
+ XML_TAG_GRAPH => array(
+ 'attribures' => array(
+ 'name' => '',
+ 'width' => '',
+ 'height' => ''),
+ 'elements' => array(
+ 'yaxistype' => '',
+ 'show_work_period' => '',
+ 'show_triggers' => '',
+ 'graphtype' => '',
+ 'yaxismin' => '',
+ 'yaxismax' => '')
+ ),
+ XML_TAG_GRAPH_ELEMENT => array(
+ 'attribures' => array(
+ 'item' => ''),
+ 'elements' => array(
+ 'drawtype' => '',
+ 'sortorder' => '',
+ 'color' => '',
+ 'yaxisside' => '',
+ 'calc_fnc' => '',
+ 'type' => '',
+ 'periods_cnt' => '')
+ )
+ );
+
+ function zbx_xmlwriter_open_memory()
+ {
+ return array('tabs' => 0, 'tag'=>array());
+ }
+
+ function zbx_xmlwriter_set_indent($mem, $val)
+ {
+ return true;
+ }
+
+ function zbx_xmlwriter_start_document(&$mem, $ver)
+ {
+ echo '<?xml version="'.$ver.'"?';
+ return true;
+ }
+
+ function zbx_xmlwriter_start_element(&$mem, $tag)
+ {
+ array_push($mem['tag'], $tag);
+ echo '>'."\n".str_repeat("\t",$mem['tabs']).'<'.$tag;
+ $mem['tabs']++;
+ return true;
+ }
+ function zbx_xmlwriter_write_attribute(&$mem, $name, $val)
+ {
+ echo ' '.$name.'="'.htmlspecialchars($val).'"';
+ return true;
+ }
+
+ function zbx_xmlwriter_end_element(&$mem)
+ {
+ $teg = array_pop($mem['tag']);
+ $mem['tabs']--;
+ echo '>'."\n".str_repeat("\t",$mem['tabs']).'</'.$teg;
+ }
+
+ function zbx_xmlwriter_output_memory(&$mem, $val)
+ {
+ echo '>';
+ }
+
+ function zbx_xmlwriter_write_element(&$mem, $name, $val)
+ {
+ echo '>'."\n".str_repeat("\t",$mem['tabs']).'<'.$name.'>'.htmlspecialchars($val).'</'.$name;
+ }
+
+ class CZabbixXMLExport
+ {
+ function CZabbixXMLExport(){}
+
+ function export_item(&$memory, $itemid)
+ {
+ global $ZBX_EXPORT_MAP;
+
+ $data = DBfetch(DBselect('select * from items where itemid='.$itemid));
+ if(!$data) return false;
+
+ zbx_xmlwriter_start_element ($memory,XML_TAG_ITEM);
+
+ $map =& $ZBX_EXPORT_MAP[XML_TAG_ITEM];
+
+ foreach($map['attribures'] as $db_name => $xml_name)
+ {
+ if(empty($xml_name)) $xml_name = $db_name;
+ zbx_xmlwriter_write_attribute($memory, $xml_name, $data[$db_name]);
+ }
+ foreach($map['elements'] as $db_name => $xml_name)
+ {
+ if(empty($data[$db_name])) continue;
+ if(empty($xml_name)) $xml_name = $db_name;
+ zbx_xmlwriter_write_element ($memory, $xml_name, $data[$db_name]);
+ }
+ zbx_xmlwriter_end_element($memory); // XML_TAG_ITEM
+ }
+
+ function export_trigger(&$memory, $triggerid)
+ {
+ global $ZBX_EXPORT_MAP;
+
+ $data = DBfetch(DBselect('select * from triggers where triggerid='.$triggerid));
+ if(!$data) return false;
+
+ $data['expression'] = explode_exp($data["expression"],0,true);
+
+ zbx_xmlwriter_start_element ($memory,XML_TAG_TRIGGER);
+
+ $map =& $ZBX_EXPORT_MAP[XML_TAG_TRIGGER];
+
+ foreach($map['attribures'] as $db_name => $xml_name)
+ {
+ if(empty($xml_name)) $xml_name = $db_name;
+ zbx_xmlwriter_write_attribute($memory, $xml_name, $data[$db_name]);
+ }
+ foreach($map['elements'] as $db_name => $xml_name)
+ {
+ if(empty($data[$db_name])) continue;
+ if(empty($xml_name)) $xml_name = $db_name;
+ zbx_xmlwriter_write_element ($memory, $xml_name, $data[$db_name]);
+ }
+ zbx_xmlwriter_end_element($memory); // XML_TAG_TRIGGER
+ }
+
+ function export_graph_element(&$memory, $gitemid)
+ {
+ global $ZBX_EXPORT_MAP;
+
+ $data = DBfetch(DBselect('select gi.*,i.key_,h.host from graphs_items gi, items i, hosts h'.
+ ' where h.hostid=i.hostid and i.itemid=gi.itemid and gi.gitemid='.$gitemid));
+ if(!$data) return false;
+
+ $data['item'] = '{HOSTNAME}:'.$data['key_'];
+
+ zbx_xmlwriter_start_element ($memory,XML_TAG_GRAPH_ELEMENT);
+
+ $map =& $ZBX_EXPORT_MAP[XML_TAG_GRAPH_ELEMENT];
+
+ foreach($map['attribures'] as $db_name => $xml_name)
+ {
+ if(empty($xml_name)) $xml_name = $db_name;
+ zbx_xmlwriter_write_attribute($memory, $xml_name, $data[$db_name]);
+ }
+ foreach($map['elements'] as $db_name => $xml_name)
+ {
+ if(empty($data[$db_name])) continue;
+ if(empty($xml_name)) $xml_name = $db_name;
+ zbx_xmlwriter_write_element ($memory, $xml_name, $data[$db_name]);
+ }
+ zbx_xmlwriter_end_element($memory); // XML_TAG_GRAPH_ELEMENT
+ }
+
+ function export_graph(&$memory, $graphid)
+ {
+ global $ZBX_EXPORT_MAP;
+
+ $data = DBfetch(DBselect('select * from graphs where graphid='.$graphid));
+ if(!$data) return false;
+
+ zbx_xmlwriter_start_element ($memory,XML_TAG_GRAPH);
+
+ $map =& $ZBX_EXPORT_MAP[XML_TAG_GRAPH];
+
+ foreach($map['attribures'] as $db_name => $xml_name)
+ {
+ if(empty($xml_name)) $xml_name = $db_name;
+ zbx_xmlwriter_write_attribute($memory, $xml_name, $data[$db_name]);
+ }
+ foreach($map['elements'] as $db_name => $xml_name)
+ {
+ if(empty($data[$db_name])) continue;
+ if(empty($xml_name)) $xml_name = $db_name;
+ zbx_xmlwriter_write_element ($memory, $xml_name, $data[$db_name]);
+ }
+ zbx_xmlwriter_start_element ($memory,XML_TAG_GRAPH_ELEMENTS);
+ $db_elements = DBselect('select gitemid from graphs_items where graphid='.$graphid);
+ while($element = DBfetch($db_elements))
+ {
+ $this->export_graph_element($memory, $element['gitemid']);
+ }
+
+ zbx_xmlwriter_end_element($memory); // XML_TAG_GRAPH_ELEMENTS
+ zbx_xmlwriter_end_element($memory); // XML_TAG_GRAPH
+ }
+
+ function export_host(&$memory, $hostid, $export_items, $export_triggers, $export_graphs)
+ {
+ global $ZBX_EXPORT_MAP;
+
+ $data = DBfetch(DBselect('select * from hosts where hostid='.$hostid));
+ if(!$data) return false;
+
+ zbx_xmlwriter_start_element ($memory,XML_TAG_HOST);
+
+ $map =& $ZBX_EXPORT_MAP[XML_TAG_HOST];
+
+ foreach($map['attribures'] as $db_name => $xml_name)
+ {
+ if(empty($xml_name)) $xml_name = $db_name;
+ zbx_xmlwriter_write_attribute($memory, $xml_name, $data[$db_name]);
+ }
+ foreach($map['elements'] as $db_name => $xml_name)
+ {
+ if(empty($data[$db_name])) continue;
+ if(empty($xml_name)) $xml_name = $db_name;
+ zbx_xmlwriter_write_element ($memory, $xml_name, $data[$db_name]);
+ }
+
+ zbx_xmlwriter_start_element ($memory,XML_TAG_GROUPS);
+ $db_groups = DBselect('select g.name from groups g, hosts_groups hg'.
+ ' where g.groupid=hg.groupid and hg.hostid='.$hostid);
+ while($group = DBfetch($db_groups))
+ {
+ zbx_xmlwriter_write_element ($memory, XML_TAG_GROUP, $group['name']);
+ }
+ zbx_xmlwriter_end_element($memory); // XML_TAG_GROUP
+
+ if($export_items)
+ {
+ zbx_xmlwriter_start_element ($memory,XML_TAG_ITEMS);
+ $db_items=DBselect('select itemid from items where hostid='.$hostid);
+ while($item_id = DBfetch($db_items))
+ {
+ $this->export_item($memory, $item_id['itemid']);
+ }
+ zbx_xmlwriter_end_element($memory); // XML_TAG_ITEMS
+ }
+ if($export_triggers)
+ {
+ zbx_xmlwriter_start_element ($memory,XML_TAG_TRIGGERS);
+ $db_triggers = DBselect('select f.triggerid, i.hostid, count(distinct i.hostid) as cnt '.
+ ' from functions f, items i '.
+ ' where f.itemid=i.itemid group by f.triggerid');
+ while($trigger = DBfetch($db_triggers))
+ {
+ if($trigger['hostid'] != $hostid || $trigger['cnt']!=1) continue;
+ $this->export_trigger($memory, $trigger['triggerid']);
+ }
+ zbx_xmlwriter_end_element($memory); // XML_TAG_TRIGGERS
+ }
+ if($export_graphs)
+ {
+ zbx_xmlwriter_start_element ($memory, XML_TAG_GRAPHS);
+ $db_graphs = DBselect('select gi.graphid, i.hostid, count(distinct i.hostid) as cnt '.
+ ' from graphs_items gi, items i '.
+ ' where gi.itemid=i.itemid group by gi.graphid');
+ while($graph = DBfetch($db_graphs))
+ {
+ if($graph['hostid'] != $hostid || $graph['cnt']!=1) continue;
+ $this->export_graph($memory, $graph['graphid']);
+ }
+ zbx_xmlwriter_end_element($memory); // XML_TAG_GRAPHS
+ }
+ /* export screens */
+ zbx_xmlwriter_end_element($memory); // XML_TAG_HOST
+ return true;
+ }
+
+ function Export(&$hosts, &$items, &$triggers, &$graphs)
+ {
+ $memory = zbx_xmlwriter_open_memory();
+ zbx_xmlwriter_set_indent($memory, true);
+ zbx_xmlwriter_start_document($memory,'1.0');
+ zbx_xmlwriter_start_element ($memory,XML_TAG_ZABBIX_EXPORT);
+ zbx_xmlwriter_write_attribute($memory, 'version', '1.0');
+ zbx_xmlwriter_write_attribute($memory, 'date', date('d.m.y'));
+ zbx_xmlwriter_write_attribute($memory, 'time', date('h.i'));
+ zbx_xmlwriter_start_element ($memory,XML_TAG_HOSTS);
+ foreach(array_keys($hosts) as $hostid)
+ {
+ $this->export_host(
+ $memory,
+ $hostid,
+ isset($items[$hostid]),
+ isset($triggers[$hostid]),
+ isset($graphs[$hostid])
+ );
+ }
+ zbx_xmlwriter_end_element($memory); // XML_TAG_HOSTS
+ zbx_xmlwriter_end_element($memory); // XML_TAG_ZABBIX_EXPORT
+ die(zbx_xmlwriter_output_memory($memory,true));
+ }
+ }
+?>
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index 227877ed..da0d1d3c 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -1474,7 +1474,7 @@
else
{
$itemid = get_request("itemid", 0);
- $color = get_request("color", 0);
+ $color = get_request("color", 'Dark Green');
$drawtype = get_request("drawtype", 0);
$sortorder = get_request("sortorder", 0);
$yaxisside = get_request("yaxisside", 1);
diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php
index 63def897..66bc2bb5 100644
--- a/frontends/php/include/graphs.inc.php
+++ b/frontends/php/include/graphs.inc.php
@@ -68,7 +68,7 @@
function get_graphitem_by_itemid($itemid)
{
- $result=DBselect("select * from graphs_items where itemid=$itemid");
+ $result = DBfetch(DBselect('select * from graphs_items where itemid='.$itemid));
$row=DBfetch($result);
if($row)
{
diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php
index 2b9c8384..fdb729b7 100644
--- a/frontends/php/include/hosts.inc.php
+++ b/frontends/php/include/hosts.inc.php
@@ -28,7 +28,7 @@ require_once "include/items.inc.php";
function add_host_to_group($hostid, $groupid)
{
if(!is_numeric($hostid) || !is_numeric($groupid)){
- error("incorrect parameters for 'add_host_to_group'");
+ error("incorrect parameters for 'add_host_to_group' [hostid:".$hostid."][groupid:".$groupid."]");
return false;
}
$hostgroupid=get_dbid("hosts_groups","hostgroupid");
@@ -198,6 +198,8 @@ require_once "include/items.inc.php";
$hostid = db_save_host($host,$port,$status,$useip,$ip,$templates);
if(!$hostid)
return $hostid;
+ else
+ info('Added new host ['.$host.']');
update_host_groups($hostid,$groups);
diff --git a/frontends/php/include/import.inc.php b/frontends/php/include/import.inc.php
new file mode 100644
index 00000000..e25da3cf
--- /dev/null
+++ b/frontends/php/include/import.inc.php
@@ -0,0 +1,416 @@
+<?php
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+ require_once "include/defines.inc.php";
+ include_once "include/hosts.inc.php";
+?>
+<?php
+ class CZabbixXMLImport
+ {
+ function CZabbixXMLImport()
+ {
+ $this->main_node = null;
+ $this->sub_node = null;
+ $this->data = null;
+ }
+
+ function StartElement($parser, $name, $attrs)
+ {
+ $data = &$this->data[$name];
+
+ foreach($attrs as $id => $val)
+ $attrs[$id] = html_entity_decode($val);
+
+ switch($name)
+ {
+ case XML_TAG_HOST:
+ $this->main_node= array($name);
+ $this->sub_node = null;
+ $data = $attrs;
+ $data['groups'] = array();
+ $data['hostid'] = add_host(
+ $data['name'],
+ 10050,
+ HOST_STATUS_TEMPLATE,
+ 'no',
+ 0,
+ array(),
+ null,
+ array());
+ break;
+ case XML_TAG_GRAPH:
+ $data = $attrs;
+ if(isset($this->data[XML_TAG_HOST]['hostid']) && $this->data[XML_TAG_HOST]['hostid'])
+ {
+ $this->sub_node = null;
+ array_push($this->main_node, $name);
+ $data['graphid'] = add_graph(
+ $data['name'],
+ $data['width'],
+ $data['height'],
+ 0,0,0,1,1,0);
+ }
+ else
+ {
+ error('Graph ['.$data['name'].'] skipped');
+ }
+ break;
+ case XML_TAG_ITEM:
+ case XML_TAG_TRIGGER:
+ case XML_TAG_GRAPH_ELEMENT:
+ /*case XML_TAG_SCREEN:
+ case XML_TAG_SCREEN_ELEMENT:*/
+ $data = $attrs;
+ $this->sub_node = null;
+ array_push($this->main_node, $name);
+ break;
+ case XML_TAG_HOSTS:
+ case XML_TAG_ZABBIX_EXPORT:
+ case XML_TAG_ITEMS:
+ case XML_TAG_TRIGGERS:
+ case XML_TAG_GRAPHS:
+ /* case XML_TAG_SCREENS:*/
+ $this->sub_node = null;
+ break;
+ default:
+ $this->sub_node = $name;
+ break;
+ }
+ $this->element_data = '';
+ }
+
+ function CharacterData($parser, $data)
+ {
+ $this->element_data .= html_entity_decode($data);
+
+ }
+
+ function EndElement($parser, $name)
+ {
+ $data = &$this->data[$name];
+
+ switch($name)
+ {
+ case XML_TAG_HOST:
+ if(isset($this->data[XML_TAG_HOST]['hostid']) && $this->data[XML_TAG_HOST]['hostid'])
+ {
+ if(!isset($data['port'])) $data['port'] = 10050;
+ if(!isset($data['status'])) $data['status'] = 0;
+ if(!isset($data['ip']))
+ {
+ $data['useip'] = 'no';
+ $data['ip'] = 0;
+ }
+ else
+ {
+ $data['useip'] = 'yes';
+ }
+
+ update_host(
+ $data['hostid'],
+ $data['name'],
+ $data['port'],
+ $data['status'],
+ $data['useip'],
+ $data['ip'],
+ array(),
+ null,
+ $data['groups']);
+ }
+ break;
+ case XML_TAG_GROUP:
+ if(isset($this->data[XML_TAG_HOST]['hostid']) && $this->data[XML_TAG_HOST]['hostid'])
+ {
+ global $USER_DETAILS;
+ global $ZBX_CURNODEID;
+
+ if($group = DBfetch(DBselect('select groupid, name from groups'.
+ ' where '.DBid2nodeid('groupid').'='.$ZBX_CURNODEID.
+ ' and name='.zbx_dbstr($this->element_data))))
+ {
+ if(in_array($group["groupid"],
+ get_accessible_groups_by_user(
+ $USER_DETAILS,
+ PERM_READ_WRITE,
+ null,
+ PERM_RES_IDS_ARRAY,
+ $ZBX_CURNODEID)))
+ {
+ array_push($this->data[XML_TAG_HOST]['groups'], $group["groupid"]);
+ }
+ else
+ {
+ error('Skipped group ['.$this->element_data.'] - Access deny.');
+ }
+ }
+ else
+ {
+ error('Missed group ['.$this->element_data.']');
+ }
+ }
+ break;
+ case XML_TAG_ITEM:
+ if(isset($this->data[XML_TAG_HOST]['hostid']) && $this->data[XML_TAG_HOST]['hostid'])
+ {
+ if(!isset($data['description'])) $data['description'] = "";
+ if(!isset($data['delay'])) $data['delay'] = 30;
+ if(!isset($data['history'])) $data['history'] = 90;
+ if(!isset($data['trends'])) $data['trends'] = 365;
+ if(!isset($data['status'])) $data['status'] = 0;
+ if(!isset($data['units'])) $data['units'] = '';
+ if(!isset($data['multiplier'])) $data['multiplier'] = 0;
+ if(!isset($data['delta'])) $data['delta'] = 0;
+ if(!isset($data['formula'])) $data['formula'] = '';
+ if(!isset($data['lastlogsize'])) $data['lastlogsize'] = 0;
+ if(!isset($data['logtimefmt'])) $data['logtimefmt'] = '';
+ if(!isset($data['delay_flex'])) $data['delay_flex'] = '';
+ if(!isset($data['trapper_hosts'])) $data['trapper_hosts'] = '';
+ if(!isset($data['snmp_community'])) $data['snmp_community'] = '';
+ if(!isset($data['snmp_oid'])) $data['snmp_oid'] = '';
+ if(!isset($data['snmp_port'])) $data['snmp_port'] = 161;
+ if(!isset($data['snmpv3_securityname'])) $data['snmpv3_securityname'] = '';
+ if(!isset($data['snmpv3_securitylevel'])) $data['snmpv3_securitylevel'] = 0;
+ if(!isset($data['snmpv3_authpassphrase'])) $data['snmpv3_authpassphrase'] = '';
+ if(!isset($data['snmpv3_privpassphrase'])) $data['snmpv3_privpassphrase'] = '';
+
+ $data['realid'] = add_item(
+ $data['description'],
+ $data['key'],
+ $this->data[XML_TAG_HOST]['hostid'],
+ $data['delay'],
+ $data['history'],
+ $data['status'],
+ $data['type'],
+ $data['snmp_community'],
+ $data['snmp_oid'],
+ $data['value_type'],
+ $data['trapper_hosts'],
+ $data['snmp_port'],
+ $data['units'],
+ $data['multiplier'],
+ $data['delta'],
+ $data['snmpv3_securityname'],
+ $data['snmpv3_securitylevel'],
+ $data['snmpv3_authpassphrase'],
+ $data['snmpv3_privpassphrase'],
+ $data['formula'],
+ $data['trends'],
+ $data['logtimefmt'],
+ 0,
+ $data['delay_flex'],
+ array());
+ }
+ else
+ {
+ error('Item ['.$data['description'].'] skipped');
+ }
+ break;
+ case XML_TAG_TRIGGER:
+ if(isset($this->data[XML_TAG_HOST]['hostid']) && $this->data[XML_TAG_HOST]['hostid'])
+ {
+ if(!isset($data['expression'])) $data['expression'] = '';
+ if(!isset($data['description'])) $data['description'] = '';
+ if(!isset($data['priority'])) $data['priority'] = 0;
+ if(!isset($data['status'])) $data['status'] = 0;
+ if(!isset($data['comments'])) $data['comments'] = '';
+ if(!isset($data['url'])) $data['url'] = '';
+
+
+
+ add_trigger(
+ str_replace('{HOSTNAME}',$this->data[XML_TAG_HOST]['name'],$data['expression']),
+ $data['description'],
+ $data['priority'],
+ $data['status'],
+ $data['comments'],
+ $data['url']);
+ }
+ else
+ {
+ error('Trigger ['.$data['description'].'] skipped');
+ }
+ break;
+ case XML_TAG_GRAPH:
+ if(isset($data['graphid']))
+ {
+ if(!isset($data['yaxistype'])) $data['yaxistype'] = 0;
+ if(!isset($data['show_work_period'])) $data['show_work_period'] = 1;
+ if(!isset($data['show_triggers'])) $data['show_triggers'] = 1;
+ if(!isset($data['graphtype'])) $data['graphtype'] = 0;
+ if(!isset($data['yaxismin'])) $data['yaxismin'] = 0;
+ if(!isset($data['yaxismax'])) $data['yaxismax'] = 0;
+
+ update_graph(
+ $data['graphid'],
+ $data['name'],
+ $data['width'],
+ $data['height'],
+ $data['yaxistype'],
+ $data['yaxismin'],
+ $data['yaxismax'],
+ $data['show_work_period'],
+ $data['show_triggers'],
+ $data['graphtype']);
+ }
+ break;
+ case XML_TAG_GRAPH_ELEMENT:
+ if(isset($this->data[XML_TAG_GRAPH]['graphid']))
+ {
+ $data['key'] = explode(':', $data['item']);
+ if(count($data['key']) >= 2)
+ {
+ $data['host'] = array_shift($data['key']);
+ $data['key'] = implode(':', $data['key']);
+ }
+ else
+ {
+ error('Incorrect element for graph ['.$data['name'].']');
+ break;
+ }
+
+ if(isset($this->data[XML_TAG_HOST]['name']))
+ {
+ $data['host'] = str_replace('{HOSTNAME}',$this->data[XML_TAG_HOST]['name'],$data['host']);
+ }
+
+ if(!isset($data['drawtype'])) $data['drawtype'] = 0;
+ if(!isset($data['sortorder'])) $data['sortorder'] = 0;
+ if(!isset($data['color'])) $data['color'] = 'Dark Green';
+ if(!isset($data['yaxisside'])) $data['yaxisside'] = 1;
+ if(!isset($data['calc_fnc'])) $data['calc_fnc'] = 2;
+ if(!isset($data['type'])) $data['type'] = 0;
+ if(!isset($data['periods_cnt'])) $data['periods_cnt'] = 5;
+
+ if($item = DBfetch(DBselect('select i.itemid from items i,hosts h'.
+ ' where h.hostid=i.hostid and i.key_='.zbx_dbstr($data['key']).
+ ' and h.host='.zbx_dbstr($data['host']))))
+ {
+ add_item_to_graph(
+ $this->data[XML_TAG_GRAPH]['graphid'],
+ $item['itemid'],
+ $data['color'],
+ $data['drawtype'],
+ $data['sortorder'],
+ $data['yaxisside'],
+ $data['calc_fnc'],
+ $data['type'],
+ $data['periods_cnt']);
+ }
+ else
+ {
+ error('Missed item ['.$data['key'].'] for host ['.$data['host'].']');
+ break;
+ }
+ }
+ break;
+ /*case XML_TAG_SCREEN:
+ case XML_TAG_SCREEN_ELEMENT:
+ break;*/
+ default:
+ if(isset($this->sub_node) && isset($this->main_node))
+ {
+ $main_node = array_pop($this->main_node);
+ $this->data[$main_node][$this->sub_node] = $this->element_data;
+ array_push($this->main_node, $main_node);
+ }
+ $this->sub_node = null;
+ return;
+ }
+
+ unset($this->data[$name], $data);
+
+ array_pop($this->main_node);
+ }
+
+ function Parse($file)
+ {
+ $this->main_node = null;
+ $this->sub_node = null;
+ $this->data = null;
+
+ $xml_parser = xml_parser_create();
+
+ xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
+
+ xml_set_element_handler($xml_parser, array(&$this, "StartElement"), array(&$this, "EndElement"));
+
+ xml_set_character_data_handler($xml_parser, array(&$this, "characterData"));
+
+ if (!($fp = fopen($file, "r")))
+ {
+ error("could not open XML input");
+ xml_parser_free($xml_parser);
+ return false;
+ }
+ else
+ {
+ while ($data = fread($fp, 4096))
+ {
+ if (!xml_parse($xml_parser, $data, feof($fp)))
+ {
+ error( sprintf("XML error: %s at line %d",
+ xml_error_string(xml_get_error_code($xml_parser)),
+ xml_get_current_line_number($xml_parser))
+ );
+ fclose($fp);
+ xml_parser_free($xml_parser);
+ return false;
+ }
+ }
+ fclose($fp);
+ }
+ xml_parser_free($xml_parser);
+
+ $this->main_node = null;
+ $this->sub_node = null;
+ $this->data = null;
+
+ return true;
+ }
+ }
+
+ class CZabbixHostImport
+ {
+ function CZabbixHostImport()
+ {
+ }
+
+ function Parse($file)
+ {
+ if (!($fp = fopen($file, "r")))
+ {
+ error("could not open XML input");
+ xml_parser_free($xml_parser);
+ return false;
+ }
+ else
+ {
+ while(!feof($fp))
+ {
+ $len = fgets($fp);
+ echo $len.'<br/>'."\n";
+ }
+ fclose($fp);
+ }
+
+ info('Underconstructor!');
+ return true;
+ }
+ }
+?>
diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php
index 98a25bba..31473819 100644
--- a/frontends/php/include/items.inc.php
+++ b/frontends/php/include/items.inc.php
@@ -577,10 +577,10 @@
$result = delete_triggers_by_itemid($itemid);
if(!$result) return $result;
- $db_gitems = get_graphitem_by_itemid($itemid);
+ $db_gitems = DBselect('select * from graphs_items where itemid='.$itemid);
while($db_gitem = DBfetch($db_gitems))
{
- $result = delete_graph_by_itemid($db_gitem["graphid"]);
+ $result = delete_graph($db_gitem["graphid"]);
if(!$result) return $result;
}
diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php
index 0d5a3ecc..e7ad4b4d 100644
--- a/frontends/php/include/locales/en_gb.inc.php
+++ b/frontends/php/include/locales/en_gb.inc.php
@@ -28,6 +28,8 @@
"S_HTML_CHARSET"=> "iso-8859-1",
// exp_imp.php
+ "S_ELEMENTS"=> "Elements",
+ "S_ONLY_HOST_INFO"=> "Only host info",
"S_EXPORT_IMPORT"=> "Export/Import",
"S_IMPORT_FILE"=> "Import file",
"S_IMPORT"=> "Import",
@@ -37,6 +39,9 @@
"S_EXPORT"=> "Export",
"S_EXPORT_FILE"=> "Export file",
"S_EXPORT_BIG"=> "EXPORT",
+ "S_PREVIEW"=> "Preview",
+ "S_BACK"=> "Back",
+ "S_NO_DATA_FOR_EXPORT"=> "No data for export",
// admin.php
"S_PREVIOUS"=> "<< Previous",
diff --git a/frontends/php/include/page_header.php b/frontends/php/include/page_header.php
index 0fd17254..f0afac3e 100644
--- a/frontends/php/include/page_header.php
+++ b/frontends/php/include/page_header.php
@@ -75,7 +75,11 @@ COpt::profiling_start("page");
set_image_header();
define('ZBX_PAGE_NO_MENU', 1);
break;
-
+ case PAGE_TYPE_XML:
+ header('Content-Type: text/xml');
+ header('Content-Disposition: attachment; filename="'.$page['file'].'"');
+ define('ZBX_PAGE_NO_MENU', 1);
+ break;
case PAGE_TYPE_HTML:
default:
?>
@@ -96,7 +100,7 @@ COpt::profiling_start("page");
if(defined('ZBX_PAGE_DO_REFRESH') && $USER_DETAILS["refresh"])
{
?>
- <meta http-equiv=\"refresh\" content="<?php echo $USER_DETAILS["refresh"] ?>">
+ <meta http-equiv="refresh" content="<?php echo $USER_DETAILS["refresh"] ?>">
<?php
$page['title'] .= ' [refreshed every '.$USER_DETAILS['refresh'].' sec]';
}
@@ -401,12 +405,12 @@ COpt::compare_files_with_menu($ZBX_MENU);
unset($db_nodes, $node_data);
unset($sub_menu_table, $sub_menu_row);
- if((!isset($page_exist) || isset($denyed_page_requested)) && !isset($_REQUEST['message']))
+ if(((!isset($page_exist) && $page['type']!=PAGE_TYPE_XML) || isset($denyed_page_requested)) && !isset($_REQUEST['message']))
{
access_deny();
}
- if(version_compare(phpversion(), '5.1.0RC1', '>=') && $page['type'] != PAGE_TYPE_IMAGE)
+ if(version_compare(phpversion(), '5.1.0RC1', '>=') && $page['type'] == PAGE_TYPE_HTML)
{
$tmezone = ini_get('date.timezone');
if(empty($tmezone))
diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php
index ed85afbd..5ed85d0f 100644
--- a/frontends/php/include/triggers.inc.php
+++ b/frontends/php/include/triggers.inc.php
@@ -457,7 +457,7 @@
# Translate {10}>10 to something like localhost:procload.last(0)>10
- function explode_exp ($expression, $html)
+ function explode_exp ($expression, $html,$template=false)
{
# echo "EXPRESSION:",$expression,"<Br>";
@@ -479,6 +479,8 @@
' from items i,functions f,hosts h'.
' where functionid='.$functionid.' and i.itemid=f.itemid and h.hostid=i.hostid')))
{
+ if($template) $function_data["host"] = '{HOSTNAME}';
+
if($html == 0)
{
$exp .= "{".$function_data["host"].":".$function_data["key_"].".".