summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorartem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-06-01 12:02:22 +0000
committerartem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-06-01 12:02:22 +0000
commiteebf8121ea8f616317d67f04bf577e4c5bdca0d1 (patch)
treef1ad35fa41d124eea270a1056c0ad8246680a71c
parent1d0d7ac11023dd1eccac147f9e1b2abf41d95334 (diff)
downloadzabbix-eebf8121ea8f616317d67f04bf577e4c5bdca0d1.tar.gz
zabbix-eebf8121ea8f616317d67f04bf577e4c5bdca0d1.tar.xz
zabbix-eebf8121ea8f616317d67f04bf577e4c5bdca0d1.zip
- added availability to export/import templates for hosts (Artem)
- added permissions for hosts on import (Artem) git-svn-id: svn://svn.zabbix.com/trunk@4220 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--ChangeLog1
-rw-r--r--frontends/php/exp_imp.php879
-rw-r--r--frontends/php/include/config.inc.php4
-rw-r--r--frontends/php/include/defines.inc.php2
-rw-r--r--frontends/php/include/export.inc.php781
-rw-r--r--frontends/php/include/hosts.inc.php26
-rw-r--r--frontends/php/include/import.inc.php1412
-rw-r--r--frontends/php/include/locales/en_gb.inc.php4
8 files changed, 1609 insertions, 1500 deletions
diff --git a/ChangeLog b/ChangeLog
index f323264a..4d7feb72 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
Changes for 1.5:
+ - added availability to export/import templates for hosts (Artem)
- added availability of using '%' character for key (Eugene)
- added login/logout (Artem)
- changed how is showed messages (Artem)
diff --git a/frontends/php/exp_imp.php b/frontends/php/exp_imp.php
index b42418d7..f2d1d648 100644
--- a/frontends/php/exp_imp.php
+++ b/frontends/php/exp_imp.php
@@ -1,430 +1,449 @@
-<?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/config.inc.php";
- require_once "include/forms.inc.php";
-?>
-<?php
- if(isset($_REQUEST['export']) && isset($_REQUEST['hosts']))
- {
- $EXPORT_DATA = true;
- $page["type"] = PAGE_TYPE_XML;
- $page["file"] = "zabbix_export.xml";
- }
- else
- {
- $page["title"] = "S_EXPORT_IMPORT";
- $page["file"] = "exp_imp.php";
- }
-
-include_once "include/page_header.php";
-
- $_REQUEST["config"] = get_request("config",get_profile("web.exp_imp.config",0));
-
-?>
-<?php
- $fields=array(
-// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
- "config"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("0,1"), null), /* 0 - export, 1 - import */
-
- "groupid"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
- "hosts"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
- "items"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
- "triggers"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
- "graphs"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
-
- "update"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
- "rules"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
- /*,
- "screens"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null) */
-/* actions */
- "preview"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
- "export"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
- "import"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL)
- );
-
- check_fields($fields);
-
- $preview = isset($_REQUEST['preview']) ? true : false;
- $config = get_request('config', 0);
- $update = get_request('update', null);
-
- update_profile("web.exp_imp.config", $config);
-?>
-<?php
- if($config == 1)
- {
- $rules = get_request('rules', array());
- foreach(array('host', 'item', 'trigger', 'graph') as $key)
- {
- if(!isset($rules[$key]['exist'])) $rules[$key]['exist'] = 0;
- if(!isset($rules[$key]['missed'])) $rules[$key]['missed'] = 0;
- }
-
- }
- else
- {
- validate_group(PERM_READ_ONLY);
-
- $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,null,PERM_RES_IDS_ARRAY,$ZBX_CURNODEID);
-
- $hosts = get_request('hosts', array());
- $items = get_request('items', array());
- $graphs = get_request('graphs', array());
- $triggers = get_request('triggers', array());
-
- function &zbx_array_val_inc($arr, $inc_size = 1)
- {
- foreach($arr as $id => $val)
- {
- $arr[$id] = $val + $inc_size;
- }
- return $arr;
- }
-
- $hosts = zbx_array_val_inc(array_flip(array_intersect(array_keys($hosts), $available_hosts)));
- $items = zbx_array_val_inc(array_flip(array_intersect(array_keys($items), array_keys($hosts))));
- $graphs = zbx_array_val_inc(array_flip(array_intersect(array_keys($graphs), array_keys($hosts))));
- $triggers = zbx_array_val_inc(array_flip(array_intersect(array_keys($triggers), array_keys($hosts))));
-
- if(count($hosts)==0) $hosts[-1] = 1;
-
- $available_hosts = implode(',', $available_hosts);
- }
-
- if(isset($EXPORT_DATA))
- {
- include_once "include/export.inc.php";
-
- $exporter = new CZabbixXMLExport();
- $exporter->Export($hosts,$items,$triggers,$graphs);
-
- unset($exporter);
- }
-?>
-<?php
- switch($config)
- {
- case 1:
- $title = S_IMPORT_BIG;
- $frm_title = S_IMPORT;
- break;
- case 0:
- default:
- $title = S_EXPORT_BIG;
- $frm_title = S_EXPORT;
- }
-
- $form = new CForm();
- $cmbConfig = new CComboBox('config', $config, 'submit()');
- $cmbConfig->AddItem(0, S_EXPORT);
- $cmbConfig->AddItem(1, S_IMPORT);
- $form->AddItem($cmbConfig);
-
- show_table_header($title, $form);
- echo BR;
-
- if($config == 1)
- {
- if(isset($_FILES['import_file']))
- {
- include_once "include/import.inc.php";
-
- $importer = new CZabbixXMLImport();
- $importer->SetRules($rules['host'],$rules['item'],$rules['trigger'],$rules['graph']);
- $importer->Parse($_FILES['import_file']['tmp_name']);
-
- unset($importer);
- }
- show_messages();
-
- $form = new CFormTable($frm_title,null,"post","multipart/form-data");
- $form->AddVar('config', $config);
- $form->AddRow(S_IMPORT_FILE, new CFile('import_file'));
-
- $table = new CTable();
- $table->SetHeader(array(S_ELEMENT, S_EXISTING, S_MISSING),'bold');
-
- foreach(array( 'host' => S_HOST,
- 'item' => S_ITEM,
- 'trigger' => S_TRIGGER,
- 'graph' => S_GRAPH)
- as $key => $title)
- {
- $cmbExist = new CComboBox('rules['.$key.'][exist]', $rules[$key]['exist']);
- $cmbExist->AddItem(0, S_UPDATE);
- $cmbExist->AddItem(1, S_SKIP);
-
- $cmbMissed = new CComboBox('rules['.$key.'][missed]', $rules[$key]['missed']);
- $cmbMissed->AddItem(0, S_ADD);
- $cmbMissed->AddItem(1, S_SKIP);
-
- $table->AddRow(array($title, $cmbExist, $cmbMissed));
- }
-
- $form->AddRow(S_RULES, $table);
-
- $form->AddItemToBottomRow(new CButton('import', S_IMPORT));
- $form->Show();
- }
- else
- {
-
- if($preview)
- {
- $table = new CTableInfo(S_NO_DATA_FOR_EXPORT);
- $table->SetHeader(array(S_HOST, S_ELEMENTS));
- $table->ShowStart();
-
- $db_hosts = DBselect('select * from hosts where hostid in ('.implode(',',array_keys($hosts)).')');
- while($host = DBfetch($db_hosts))
- {
- $el_table = new CTableInfo(S_ONLY_HOST_INFO);
- $sqls = array(
- S_ITEM => !isset($items[$host['hostid']]) ? null :
- ' select hostid, description as info, 1 as cnt from items'.
- ' where hostid='.$host['hostid'],
- S_TRIGGER => !isset($triggers[$host['hostid']]) ? null :
- 'select i.hostid, t.description as info, count(distinct i.hostid) as cnt'.
- ' from functions f, items i, triggers t'.
- ' where t.triggerid=f.triggerid and f.itemid=i.itemid'.
- ' group by f.triggerid, i.hostid, t.description',
- S_GRAPH => !isset($graphs[$host['hostid']]) ? null :
- 'select g.name as info, i.hostid, count(distinct i.hostid) as cnt'.
- ' from graphs_items gi, items i, graphs g '.
- ' where g.graphid=gi.graphid and gi.itemid=i.itemid'.
- ' group by gi.graphid, i.hostid'
-
- );
- foreach($sqls as $el_type => $sql)
- {
- if(!isset($sql)) continue;
-
- $db_els = DBselect($sql);
- while($el = DBfetch($db_els))
- {
- if($el['cnt'] != 1 || $el['hostid'] != $host['hostid']) continue;
- $el_table->AddRow(array($el_type, $el['info']));
- }
- }
-
- $table->ShowRow(array(new CCol($host['host'], 'top'),$el_table));
- unset($el_table);
- }
-
- $form = new CForm(null,'post');
- $form->SetName('hosts');
- $form->AddVar("config", $config);
- $form->AddVar('update', true);
- $form->AddVar('hosts', $hosts);
- $form->AddVar('items', $items);
- $form->AddVar('graphs', $graphs);
- $form->AddVar('triggers', $triggers);
-
- $form->AddItem(array(
- new CButton('back', S_BACK),
- new CButton('preview', S_REFRESH),
- new CButton('export', S_EXPORT)
- ));
-
- $table->SetFooter(new CCol($form));
-
- $table->ShowEnd();
- }
- else
- {
- /* table HOSTS */
- $form = new CForm(null,'post');
- $form->SetName('hosts');
- $form->AddVar("config",$config);
- $form->AddVar('update', true);
-
- $cmbGroups = new CComboBox("groupid",get_request("groupid",0),"submit()");
- $cmbGroups->AddItem(0,S_ALL_SMALL);
- $result=DBselect("select distinct g.groupid,g.name from groups g,hosts_groups hg,hosts h".
- " where h.hostid in (".$available_hosts.") ".
- " and g.groupid=hg.groupid and h.hostid=hg.hostid".
- " order by g.name");
- while($row=DBfetch($result))
- {
- $cmbGroups->AddItem($row["groupid"],$row["name"]);
- if($row["groupid"] == $_REQUEST["groupid"]) $correct_host = 1;
- }
- if(!isset($correct_host))
- {
- unset($_REQUEST["groupid"]);
- $cmbGroups->SetValue(0);
- }
-
- $header =& get_table_header(S_HOSTS_BIG, array(S_GROUP.SPACE, $cmbGroups));
-
- $form->AddItem($header);
-
- $table = new CTableInfo(S_NO_HOSTS_DEFINED);
- $table->SetHeader(array(
- array( new CCheckBox("all_hosts",true, "CheckAll('".$form->GetName()."','all_hosts','hosts');"),
- S_NAME),
- S_DNS,
- S_IP,
- S_PORT,
- S_STATUS,
- array( new CCheckBox("all_items",true, "CheckAll('".$form->GetName()."','all_items','items');"),
- S_ITEMS),
- array( new CCheckBox("all_triggers",true, "CheckAll('".$form->GetName()."','all_triggers','triggers');"),
- S_TRIGGERS),
- array( new CCheckBox("all_graphs",true, "CheckAll('".$form->GetName()."','all_graphs','graphs');"),
- S_GRAPHS)
- /*
- array( new CCheckBox("all_screens",true, "CheckAll('".$form->GetName()."','all_screens','screens');")
- S_GRAPHS)
- */
- ));
-
- $sql = "select h.* from";
- if(isset($_REQUEST["groupid"]))
- {
- $sql .= " hosts h,hosts_groups hg where";
- $sql .= " hg.groupid=".$_REQUEST["groupid"]." and hg.hostid=h.hostid and";
- } else $sql .= " hosts h where";
- $sql .= " h.hostid in (".$available_hosts.") ".
- " order by h.host";
-
- $result=DBselect($sql);
-
- while($row=DBfetch($result))
- {
- $host=new CCol(array(
- new CCheckBox('hosts['.$row['hostid'].']',
- isset($hosts[$row['hostid']]) || !isset($update),
- NULL,true),
- SPACE,
- $row["host"]
- ));
-
- if($row["status"] == HOST_STATUS_MONITORED){
- $status=new CSpan(S_MONITORED, "off");
- } else if($row["status"] == HOST_STATUS_NOT_MONITORED) {
- $status=new CSpan(S_NOT_MONITORED, "on");
- } else if($row["status"] == HOST_STATUS_TEMPLATE)
- $status=new CCol(S_TEMPLATE,"unknown");
- else if($row["status"] == HOST_STATUS_DELETED)
- $status=new CCol(S_DELETED,"unknown");
- else
- $status=S_UNKNOWN;
-
- /* calculate items */
- $item_cnt = DBfetch(DBselect('select count(itemid) as cnt from items where hostid='.$row['hostid']));
- if($item_cnt['cnt'] > 0)
- {
- $item_cnt = array(new CCheckBox('items['.$row['hostid'].']',
- isset($items[$row['hostid']]) || !isset($update),
- NULL,true),
- $item_cnt['cnt']);
- }
- else
- {
- $item_cnt = '-';
- }
-
- /* calculate triggers */
- $trigger_cnt = 0;
- $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, i.hostid');
- while($db_tr = DBfetch($db_triggers)) if($db_tr['cnt'] == 1 && $db_tr['hostid'] == $row['hostid']) $trigger_cnt++;
- if($trigger_cnt > 0)
- {
- $trigger_cnt = array(new CCheckBox('triggers['.$row['hostid'].']',
- isset($triggers[$row['hostid']]) || !isset($update),
- NULL,true),
- $trigger_cnt);
- }
- else
- {
- $trigger_cnt = '-';
- }
-
- /* calculate graphs */
- $graph_cnt = 0;
- $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, i.hostid');
- while($db_tr = DBfetch($db_graphs)) if($db_tr['cnt'] == 1 && $db_tr['hostid'] == $row['hostid']) $graph_cnt++;
- if($graph_cnt > 0)
- {
- $graph_cnt = array(new CCheckBox('graphs['.$row['hostid'].']',
- isset($graphs[$row['hostid']]) || !isset($update),
- NULL,true),
- $graph_cnt);
- }
- else
- {
- $graph_cnt = '-';
- }
-
- /* $screens = 0; */
-
- if($row["status"] == HOST_STATUS_TEMPLATE)
- {
- $ip = $dns = $port = '-';
- }
- else
- {
- $ip = $row["ip"];
- $dns = $row["dns"];
-
- if($row["useip"]==1)
- $ip = bold($ip);
- else
- $dns = bold($dns);
-
- $port = $row["port"];
- }
-
- $table->AddRow(array(
- $host,
- $dns,
- $ip,
- $port,
- $status,
- $item_cnt,
- $trigger_cnt,
- $graph_cnt
- /*,
- array(new CCheckBox('screens['.$row['hostid'].']',
- isset($screens[$row['hostid']]) || !isset($update),
- NULL,true),
- $screens)*/
- ));
- $table->SetFooter(new CCol(array(
- new CButton('preview', S_PREVIEW),
- new CButton('export', S_EXPORT)
- )));
- }
- $form->AddItem($table);
- $form->Show();
- }
- }
-
-?>
-<?php
-
-include_once "include/page_footer.php";
-
-?>
+<?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/config.inc.php";
+ require_once "include/forms.inc.php";
+?>
+<?php
+ if(isset($_REQUEST['export']) && isset($_REQUEST['hosts']))
+ {
+ $EXPORT_DATA = true;
+ $page["type"] = PAGE_TYPE_XML;
+ $page["file"] = "zabbix_export.xml";
+ }
+ else
+ {
+ $page["title"] = "S_EXPORT_IMPORT";
+ $page["file"] = "exp_imp.php";
+ }
+
+include_once "include/page_header.php";
+
+ $_REQUEST["config"] = get_request("config",get_profile("web.exp_imp.config",0));
+
+?>
+<?php
+ $fields=array(
+// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
+ "config"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("0,1"), null), /* 0 - export, 1 - import */
+
+ "groupid"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
+ "hosts"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
+ "templates"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
+ "items"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
+ "triggers"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
+ "graphs"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
+
+ "update"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
+ "rules"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null),
+ /*,
+ "screens"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null) */
+/* actions */
+ "preview"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
+ "export"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
+ "import"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL)
+ );
+
+ check_fields($fields);
+
+ $preview = isset($_REQUEST['preview']) ? true : false;
+ $config = get_request('config', 0);
+ $update = get_request('update', null);
+
+ update_profile("web.exp_imp.config", $config);
+?>
+<?php
+ if($config == 1)
+ {
+ $rules = get_request('rules', array());
+ foreach(array('host', 'template', 'item', 'trigger', 'graph') as $key)
+ {
+ if(!isset($rules[$key]['exist'])) $rules[$key]['exist'] = 0;
+ if(!isset($rules[$key]['missed'])) $rules[$key]['missed'] = 0;
+ }
+
+ }
+ else
+ {
+ validate_group(PERM_READ_ONLY);
+
+ $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,null,PERM_RES_IDS_ARRAY,$ZBX_CURNODEID);
+
+ $hosts = get_request('hosts', array());
+ $templates = get_request('templates', array());
+ $items = get_request('items', array());
+ $graphs = get_request('graphs', array());
+ $triggers = get_request('triggers', array());
+
+ function &zbx_array_val_inc($arr, $inc_size = 1)
+ {
+ foreach($arr as $id => $val)
+ {
+ $arr[$id] = $val + $inc_size;
+ }
+ return $arr;
+ }
+
+ $hosts = zbx_array_val_inc(array_flip(array_intersect(array_keys($hosts), $available_hosts)));
+ $templates = zbx_array_val_inc(array_flip(array_intersect(array_keys($templates), array_keys($hosts))));
+ $items = zbx_array_val_inc(array_flip(array_intersect(array_keys($items), array_keys($hosts))));
+ $graphs = zbx_array_val_inc(array_flip(array_intersect(array_keys($graphs), array_keys($hosts))));
+ $triggers = zbx_array_val_inc(array_flip(array_intersect(array_keys($triggers), array_keys($hosts))));
+
+ if(count($hosts)==0) $hosts[-1] = 1;
+
+ $available_hosts = implode(',', $available_hosts);
+ }
+
+ if(isset($EXPORT_DATA))
+ {
+ include_once "include/export.inc.php";
+
+ $exporter = new CZabbixXMLExport();
+ $exporter->Export($hosts,$templates,$items,$triggers,$graphs);
+
+ unset($exporter);
+ }
+?>
+<?php
+ switch($config)
+ {
+ case 1:
+ $title = S_IMPORT_BIG;
+ $frm_title = S_IMPORT;
+ break;
+ case 0:
+ default:
+ $title = S_EXPORT_BIG;
+ $frm_title = S_EXPORT;
+ }
+
+ $form = new CForm();
+ $cmbConfig = new CComboBox('config', $config, 'submit()');
+ $cmbConfig->AddItem(0, S_EXPORT);
+ $cmbConfig->AddItem(1, S_IMPORT);
+ $form->AddItem($cmbConfig);
+
+ show_table_header($title, $form);
+ echo BR;
+
+ if($config == 1)
+ {
+ if(isset($_FILES['import_file']))
+ {
+ include_once "include/import.inc.php";
+
+ $importer = new CZabbixXMLImport();
+ $importer->SetRules($rules['host'],$rules['template'],$rules['item'],$rules['trigger'],$rules['graph']);
+ $importer->Parse($_FILES['import_file']['tmp_name']);
+
+ unset($importer);
+ }
+ show_messages();
+
+ $form = new CFormTable($frm_title,null,"post","multipart/form-data");
+ $form->AddVar('config', $config);
+ $form->AddRow(S_IMPORT_FILE, new CFile('import_file'));
+
+ $table = new CTable();
+ $table->SetHeader(array(S_ELEMENT, S_EXISTING, S_MISSING),'bold');
+
+ foreach(array( 'host' => S_HOST,
+ 'template' => S_TEMPLATE,
+ 'item' => S_ITEM,
+ 'trigger' => S_TRIGGER,
+ 'graph' => S_GRAPH)
+ as $key => $title)
+ {
+ $cmbExist = new CComboBox('rules['.$key.'][exist]', $rules[$key]['exist']);
+ $cmbExist->AddItem(0, S_UPDATE);
+ $cmbExist->AddItem(1, S_SKIP);
+
+ $cmbMissed = new CComboBox('rules['.$key.'][missed]', $rules[$key]['missed']);
+ ($key == 'template')?(''):($cmbMissed->AddItem(0, S_ADD));
+ $cmbMissed->AddItem(1, S_SKIP);
+
+ $table->AddRow(array($title, $cmbExist, $cmbMissed));
+ }
+
+ $form->AddRow(S_RULES, $table);
+
+ $form->AddItemToBottomRow(new CButton('import', S_IMPORT));
+ $form->Show();
+ }
+ else
+ {
+
+ if($preview)
+ {
+ $table = new CTableInfo(S_NO_DATA_FOR_EXPORT);
+ $table->SetHeader(array(S_HOST, S_ELEMENTS));
+ $table->ShowStart();
+
+ $db_hosts = DBselect('select * from hosts where hostid in ('.implode(',',array_keys($hosts)).')');
+ while($host = DBfetch($db_hosts))
+ {
+ $el_table = new CTableInfo(S_ONLY_HOST_INFO);
+ $sqls = array(
+ S_TEMPLATE => !isset($templates[$host['hostid']]) ? null :
+ ' SELECT ht.hostid, h.host as info, count(distinct ht.hosttemplateid) as cnt '.
+ ' FROM hosts h, hosts_templates ht '.
+ ' WHERE ht.templateid = h.hostid '.
+ ' GROUP BY h.host',
+ S_ITEM => !isset($items[$host['hostid']]) ? null :
+ ' select hostid, description as info, 1 as cnt from items'.
+ ' where hostid='.$host['hostid'],
+ S_TRIGGER => !isset($triggers[$host['hostid']]) ? null :
+ 'select i.hostid, t.description as info, count(distinct i.hostid) as cnt'.
+ ' from functions f, items i, triggers t'.
+ ' where t.triggerid=f.triggerid and f.itemid=i.itemid'.
+ ' group by f.triggerid, i.hostid, t.description',
+ S_GRAPH => !isset($graphs[$host['hostid']]) ? null :
+ 'select g.name as info, i.hostid, count(distinct i.hostid) as cnt'.
+ ' from graphs_items gi, items i, graphs g '.
+ ' where g.graphid=gi.graphid and gi.itemid=i.itemid'.
+ ' group by gi.graphid, i.hostid'
+
+ );
+ foreach($sqls as $el_type => $sql)
+ {
+ if(!isset($sql)) continue;
+
+ $db_els = DBselect($sql);
+ while($el = DBfetch($db_els))
+ {
+ if($el['cnt'] != 1 || $el['hostid'] != $host['hostid']) continue;
+ $el_table->AddRow(array($el_type, $el['info']));
+ }
+ }
+
+ $table->ShowRow(array(new CCol($host['host'], 'top'),$el_table));
+ unset($el_table);
+ }
+
+ $form = new CForm(null,'post');
+ $form->SetName('hosts');
+ $form->AddVar("config", $config);
+ $form->AddVar('update', true);
+ $form->AddVar('hosts', $hosts);
+ $form->AddVar('templates', $templates);
+ $form->AddVar('items', $items);
+ $form->AddVar('graphs', $graphs);
+ $form->AddVar('triggers', $triggers);
+
+ $form->AddItem(array(
+ new CButton('back', S_BACK),
+ new CButton('preview', S_REFRESH),
+ new CButton('export', S_EXPORT)
+ ));
+
+ $table->SetFooter(new CCol($form));
+
+ $table->ShowEnd();
+ }
+ else
+ {
+ /* table HOSTS */
+ $form = new CForm(null,'post');
+ $form->SetName('hosts');
+ $form->AddVar("config",$config);
+ $form->AddVar('update', true);
+
+ $cmbGroups = new CComboBox("groupid",get_request("groupid",0),"submit()");
+ $cmbGroups->AddItem(0,S_ALL_SMALL);
+ $result=DBselect("select distinct g.groupid,g.name from groups g,hosts_groups hg,hosts h".
+ " where h.hostid in (".$available_hosts.") ".
+ " and g.groupid=hg.groupid and h.hostid=hg.hostid".
+ " order by g.name");
+ while($row=DBfetch($result))
+ {
+ $cmbGroups->AddItem($row["groupid"],$row["name"]);
+ if($row["groupid"] == $_REQUEST["groupid"]) $correct_host = 1;
+ }
+ if(!isset($correct_host))
+ {
+ unset($_REQUEST["groupid"]);
+ $cmbGroups->SetValue(0);
+ }
+
+ $header =& get_table_header(S_HOSTS_BIG, array(S_GROUP.SPACE, $cmbGroups));
+
+ $form->AddItem($header);
+
+ $table = new CTableInfo(S_NO_HOSTS_DEFINED);
+ $table->SetHeader(array(
+ array( new CCheckBox("all_hosts",true, "CheckAll('".$form->GetName()."','all_hosts','hosts');"),
+ S_NAME),
+ S_DNS,
+ S_IP,
+ S_PORT,
+ S_STATUS,
+ array( new CCheckBox("all_templates",true, "CheckAll('".$form->GetName()."','all_templates','templates');"),
+ S_TEMPLATES),
+ array( new CCheckBox("all_items",true, "CheckAll('".$form->GetName()."','all_items','items');"),
+ S_ITEMS),
+ array( new CCheckBox("all_triggers",true, "CheckAll('".$form->GetName()."','all_triggers','triggers');"),
+ S_TRIGGERS),
+ array( new CCheckBox("all_graphs",true, "CheckAll('".$form->GetName()."','all_graphs','graphs');"),
+ S_GRAPHS)
+ /*
+ array( new CCheckBox("all_screens",true, "CheckAll('".$form->GetName()."','all_screens','screens');")
+ S_GRAPHS)
+ */
+ ));
+
+ $sql = "select h.* from";
+ if(isset($_REQUEST["groupid"]))
+ {
+ $sql .= " hosts h,hosts_groups hg where";
+ $sql .= " hg.groupid=".$_REQUEST["groupid"]." and hg.hostid=h.hostid and";
+ } else $sql .= " hosts h where";
+ $sql .= " h.hostid in (".$available_hosts.") ".
+ " order by h.host";
+
+ $result=DBselect($sql);
+
+ while($row=DBfetch($result))
+ {
+ $host=new CCol(array(
+ new CCheckBox('hosts['.$row['hostid'].']',
+ isset($hosts[$row['hostid']]) || !isset($update),
+ NULL,true),
+ SPACE,
+ $row["host"]
+ ));
+
+ $status = new CCol(host_status2str($row['status']),host_status2style($row['status']));
+
+
+ /* calculate template */
+ $template_cnt = DBfetch(DBselect('select count(hosttemplateid) as cnt from hosts_templates where hostid='.$row['hostid']));
+ if($template_cnt['cnt'] > 0)
+ {
+ $template_cnt = array(new CCheckBox('templates['.$row['hostid'].']',
+ isset($templates[$row['hostid']]) || !isset($update),
+ NULL,true),
+ $template_cnt['cnt']);
+ }
+ else
+ {
+ $template_cnt = '-';
+ }
+
+ /* calculate items */
+ $item_cnt = DBfetch(DBselect('select count(itemid) as cnt from items where hostid='.$row['hostid']));
+ if($item_cnt['cnt'] > 0)
+ {
+ $item_cnt = array(new CCheckBox('items['.$row['hostid'].']',
+ isset($items[$row['hostid']]) || !isset($update),
+ NULL,true),
+ $item_cnt['cnt']);
+ }
+ else
+ {
+ $item_cnt = '-';
+ }
+
+ /* calculate triggers */
+ $trigger_cnt = 0;
+ $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, i.hostid');
+ while($db_tr = DBfetch($db_triggers)) if($db_tr['cnt'] == 1 && $db_tr['hostid'] == $row['hostid']) $trigger_cnt++;
+ if($trigger_cnt > 0)
+ {
+ $trigger_cnt = array(new CCheckBox('triggers['.$row['hostid'].']',
+ isset($triggers[$row['hostid']]) || !isset($update),
+ NULL,true),
+ $trigger_cnt);
+ }
+ else
+ {
+ $trigger_cnt = '-';
+ }
+
+ /* calculate graphs */
+ $graph_cnt = 0;
+ $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, i.hostid');
+ while($db_tr = DBfetch($db_graphs)) if($db_tr['cnt'] == 1 && $db_tr['hostid'] == $row['hostid']) $graph_cnt++;
+ if($graph_cnt > 0)
+ {
+ $graph_cnt = array(new CCheckBox('graphs['.$row['hostid'].']',
+ isset($graphs[$row['hostid']]) || !isset($update),
+ NULL,true),
+ $graph_cnt);
+ }
+ else
+ {
+ $graph_cnt = '-';
+ }
+
+ /* $screens = 0; */
+
+ if($row["status"] == HOST_STATUS_TEMPLATE)
+ {
+ $ip = $dns = $port = '-';
+ }
+ else
+ {
+ $ip = $row["ip"];
+ $dns = $row["dns"];
+
+ if($row["useip"]==1)
+ $ip = bold($ip);
+ else
+ $dns = bold($dns);
+
+ $port = $row["port"];
+ }
+
+ $table->AddRow(array(
+ $host,
+ $dns,
+ $ip,
+ $port,
+ $status,
+ $template_cnt,
+ $item_cnt,
+ $trigger_cnt,
+ $graph_cnt
+ /*,
+ array(new CCheckBox('screens['.$row['hostid'].']',
+ isset($screens[$row['hostid']]) || !isset($update),
+ NULL,true),
+ $screens)*/
+ ));
+ $table->SetFooter(new CCol(array(
+ new CButton('preview', S_PREVIEW),
+ new CButton('export', S_EXPORT)
+ )));
+ }
+ $form->AddItem($table);
+ $form->Show();
+ }
+ }
+
+?>
+<?php
+
+include_once "include/page_footer.php";
+
+?>
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index d808aacd..100504b4 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -682,8 +682,8 @@ else
if($msg_count > $msg_show) $msg_count = $msg_show;
- $msg_count = ($msg_count * $msg_font_size *2);
- $lst_error->AddOption('style',' font-size: '.$msg_font_size.'pt; height: '.$msg_count.';');
+ $msg_count = ($msg_count * $msg_font_size *2) + 2;
+ $lst_error->AddOption('style','font-size: '.$msg_font_size.'pt; height: '.$msg_count.';');
//---
$lst_error->Show();
diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php
index 24209da4..3558c34d 100644
--- a/frontends/php/include/defines.inc.php
+++ b/frontends/php/include/defines.inc.php
@@ -28,6 +28,8 @@
define('XML_TAG_APPLICATION', 'application');
define('XML_TAG_ITEMS', 'items');
define('XML_TAG_ITEM', 'item');
+ define('XML_TAG_TEMPLATES', 'templates');
+ define('XML_TAG_TEMPLATE', 'template');
define('XML_TAG_TRIGGERS', 'triggers');
define('XML_TAG_TRIGGER', 'trigger');
define('XML_TAG_GRAPHS', 'graphs');
diff --git a/frontends/php/include/export.inc.php b/frontends/php/include/export.inc.php
index 1c3acb81..68609b90 100644
--- a/frontends/php/include/export.inc.php
+++ b/frontends/php/include/export.inc.php
@@ -1,381 +1,400 @@
-<?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' => '',
- 'dns' => '',
- '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)
- { /* NOTE: use this function only in the end of xml file creation */
- 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]);
- }
-
- if( !empty($data['valuemapid']) && $valuemap = DBfetch(DBselect('select name from valuemaps where valuemapid='.$data['valuemapid'])))
- {
- zbx_xmlwriter_write_element($memory, 'valuemap', $valuemap['name']);
- }
-
- $db_applications=DBselect('select distinct a.name from applications a,items_applications ia '.
- ' where ia.applicationid=a.applicationid and ia.itemid='.$itemid);
- if ($application = DBfetch($db_applications))
- {
- zbx_xmlwriter_start_element ($memory,XML_TAG_APPLICATIONS);
- do {
- zbx_xmlwriter_write_element ($memory, XML_TAG_APPLICATION, $application['name']);
- } while($application = DBfetch($db_applications));
- zbx_xmlwriter_end_element($memory); // XML_TAG_APPLICATIONS
- }
-
- 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]);
- }
-
- if($db_groups = DBselect('select g.name from groups g, hosts_groups hg'.
- ' where g.groupid=hg.groupid and hg.hostid='.$hostid))
- {
- zbx_xmlwriter_start_element ($memory,XML_TAG_GROUPS);
- 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, i.hostid');
- 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, i.hostid');
- 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));
- }
- }
-?>
+<?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' => '',
+ 'dns' => '',
+ '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)
+ { /* NOTE: use this function only in the end of xml file creation */
+ 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]);
+ }
+
+ if( !empty($data['valuemapid']) && $valuemap = DBfetch(DBselect('select name from valuemaps where valuemapid='.$data['valuemapid'])))
+ {
+ zbx_xmlwriter_write_element($memory, 'valuemap', $valuemap['name']);
+ }
+
+ $db_applications=DBselect('select distinct a.name from applications a,items_applications ia '.
+ ' where ia.applicationid=a.applicationid and ia.itemid='.$itemid);
+ if ($application = DBfetch($db_applications))
+ {
+ zbx_xmlwriter_start_element ($memory,XML_TAG_APPLICATIONS);
+ do {
+ zbx_xmlwriter_write_element ($memory, XML_TAG_APPLICATION, $application['name']);
+ } while($application = DBfetch($db_applications));
+ zbx_xmlwriter_end_element($memory); // XML_TAG_APPLICATIONS
+ }
+
+ 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_templates, $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]);
+ }
+
+ if($db_groups = DBselect('select g.name from groups g, hosts_groups hg'.
+ ' where g.groupid=hg.groupid and hg.hostid='.$hostid))
+ {
+ zbx_xmlwriter_start_element ($memory,XML_TAG_GROUPS);
+ 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_templates){
+ $query = 'SELECT t.host '.
+ ' FROM hosts t, hosts_templates ht'.
+ ' WHERE t.hostid=ht.templateid AND ht.hostid='.$hostid;
+
+ if($db_templates = DBselect($query)){
+ zbx_xmlwriter_start_element ($memory,XML_TAG_TEMPLATES);
+
+ while($template = DBfetch($db_templates)){
+ zbx_xmlwriter_write_element ($memory, XML_TAG_TEMPLATE, $template['host']);
+ }
+ }
+ zbx_xmlwriter_end_element($memory); // XML_TAG_TEMPLATES
+ }
+
+ 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, i.hostid');
+ 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, i.hostid');
+ 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, &$templates, &$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($templates[$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/hosts.inc.php b/frontends/php/include/hosts.inc.php
index 5ccae673..52f8b3ef 100644
--- a/frontends/php/include/hosts.inc.php
+++ b/frontends/php/include/hosts.inc.php
@@ -915,4 +915,30 @@ require_once "include/items.inc.php";
return $result;
}
+
+ function host_status2str($status)
+ {
+ switch($status)
+ {
+ case HOST_STATUS_MONITORED: $status = S_MONITORED; break;
+ case HOST_STATUS_NOT_MONITORED: $status = S_NOT_MONITORED; break;
+ case HOST_STATUS_TEMPLATE: $status = S_TEMPLATE; break;
+ case HOST_STATUS_DELETED: $status = S_DELETED; break;
+ default:
+ $status = S_UNKNOWN; break;
+ }
+ return $status;
+ }
+
+ function host_status2style($status)
+ {
+ switch($status)
+ {
+ case HOST_STATUS_MONITORED: $status = 'off'; break;
+ case HOST_STATUS_NOT_MONITORED: $status = 'on'; break;
+ default:
+ $status = 'unknown'; break;
+ }
+ return $status;
+ }
?>
diff --git a/frontends/php/include/import.inc.php b/frontends/php/include/import.inc.php
index 38e53ac5..6a36a968 100644
--- a/frontends/php/include/import.inc.php
+++ b/frontends/php/include/import.inc.php
@@ -1,686 +1,726 @@
-<?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()
- {
- global $USER_DETAILS, $ZBX_CURNODEID;
-
- $this->main_node= null;
- $this->sub_node = null;
- $this->data = null;
- $this->host = array('exist' => 0, 'missed' => 0);
- $this->item = array('exist' => 0, 'missed' => 0);
- $this->trigger = array('exist' => 0, 'missed' => 0);
- $this->graph = array('exist' => 0, 'missed' => 0);
-
- $this->accessible_groups = get_accessible_groups_by_user($USER_DETAILS,
- PERM_READ_WRITE, null, PERM_RES_IDS_ARRAY, $ZBX_CURNODEID);
- }
-
- function CharacterData($parser, $data)
- {
- $this->element_data .= html_entity_decode($data);
- }
-
- function StartElement($parser, $name, $attrs)
- {
- $this->element_data = '';
-
- if(!isset($this->root))
- {
- if($name == XML_TAG_ZABBIX_EXPORT)
- if(isset($attrs['version']))
- if($attrs['version'] == '1.0')
- {
- $this->root = true;
- return;
- }
- else
- {
- error('Unsupported version of imported data');
- }
- error('Unsupported file format');
- $this->root = false;
- }
- elseif(!$this->root)
- {
- return false;
- }
-
- global $ZBX_CURNODEID;
-
- $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['skip'] = false;
-
- if($host_data = DBfetch(DBselect('select hostid from hosts'.
- ' where host='.zbx_dbstr($data['name']).
- ' and '.DBid2nodeid('hostid').'='.$ZBX_CURNODEID)))
- { /* exist */
- if($this->host['exist']==1) /* skip */
- {
- $data['skip'] = true;
- info('Host ['.$data['name'].'] skipped - user rule');
- break; // case
- }
-
- $data['hostid'] = $host_data['hostid'];
- $data['templates'] = get_templates_by_hostid($host_data['hostid']);
- }
- else
- { /* missed */
- if($this->host['missed']==1) /* skip */
- {
- $data['skip'] = true;
- info('Host ['.$data['name'].'] skipped - user rule');
- break; // case
- }
-
- $data['templates'] = array();
- $data['hostid'] = add_host(
- $data['name'],
- 10050,
- HOST_STATUS_TEMPLATE,
- 0, /* useip */
- "", /* dns */
- "", /* ip */
- array(),
- null,
- array());
- }
- break; // case
- case XML_TAG_GRAPH:
- $data = $attrs;
- $data['items'] = array();
- $this->sub_node = null;
- array_push($this->main_node, $name);
- break; // case
- 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
- case XML_TAG_HOSTS:
- case XML_TAG_GROUPS:
- case XML_TAG_ZABBIX_EXPORT:
- case XML_TAG_APPLICATIONS:
- case XML_TAG_ITEMS:
- case XML_TAG_TRIGGERS:
- case XML_TAG_GRAPHS:
- /* case XML_TAG_SCREENS:*/
- $this->sub_node = null;
- break; // case
- case XML_TAG_GROUP:
- case XML_TAG_APPLICATION:
- default:
- $this->sub_node = $name;
- break; // case
- }
- }
-
- function EndElement($parser, $name)
- {
- if(!$this->root)
- {
- return false;
- }
-
- global $USER_DETAILS;
- global $ZBX_CURNODEID;
-
- $data = &$this->data[$name];
-
- switch($name)
- {
- case XML_TAG_HOST:
- if($data['skip'] || !$data['hostid'])
- break; // case
-
- if(!isset($data['port'])) $data['port'] = 10050;
- if(!isset($data['status'])) $data['status'] = 0;
- if(!isset($data['useip'])) $data['useip'] = 0;
- if(!isset($data['dns'])) $data['dns'] = "";
- if(!isset($data['ip'])) $data['ip'] = "";
-
- if(update_host($data['hostid'], $data['name'], $data['port'], $data['status'],
- $data['useip'], $data['dns'], $data['ip'], $data['templates'], null, $data['groups']))
- {
- info('Host ['.$data['name'].'] updated');
- }
-
- break; // case
- case XML_TAG_GROUP:
- if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
- break; //case
-
- if(!($group = DBfetch(DBselect('select groupid, name from groups'.
- ' where '.DBid2nodeid('groupid').'='.$ZBX_CURNODEID.
- ' and name='.zbx_dbstr($this->element_data)))))
- {
- error('Missed group ['.$this->element_data.']');
- break; // case
- }
-
- if(!in_array($group["groupid"], $this->accessible_groups))
- {
- error('Group ['.$this->element_data.'] skipped - Access deny.');
- break; // case
- }
-
- array_push($this->data[XML_TAG_HOST]['groups'], $group["groupid"]);
-
- break; // case
- case XML_TAG_APPLICATION:
- if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
- break; //case
-
- if(!isset($this->data[XML_TAG_ITEM]))
- break; //case
-
- if(!($application = DBfetch(DBselect('select applicationid from applications'.
- ' where '.DBid2nodeid('applicationid').'='.$ZBX_CURNODEID.
- ' and name='.zbx_dbstr($this->element_data).
- ' and hostid='.$this->data[XML_TAG_HOST]['hostid']))))
- {
- $applicationid = add_application($this->element_data, $this->data[XML_TAG_HOST]['hostid']);
- }
- else
- {
- $applicationid = $application['applicationid'];
- }
-
- $this->data[XML_TAG_ITEM]['applications'][] = $applicationid;
-
- break; // case
- case XML_TAG_ITEM:
- if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
- {
- if(isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip'])
- {
- info('Item ['.$data['description'].'] skipped - user rule for host');
- break; // case
- }
-
- error('Item ['.$data['description'].'] skipped - missed host');
- break; // case
- }
-
- 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'] = '';
- if(!isset($data['valuemap'])) $data['valuemap'] = '';
- if(!isset($data['applications'])) $data['applications'] = array();
-
- if(!empty($data['valuemap']))
- {
- if( $valuemap = DBfetch(DBselect('select valuemapid from valuemaps '.
- ' where '.DBid2nodeid('valuemapid').'='.$ZBX_CURNODEID.
- ' and name='.zbx_dbstr($data['valuemap']))) )
- {
- $data['valuemapid'] = $valuemap['valuemapid'];
- }
- else
- {
- $data['valuemapid'] = add_valuemap($data['valuemap'],array());
- }
- }
-
- if($item = DBfetch(DBselect('select itemid,valuemapid,templateid from items'.
- ' where key_='.zbx_dbstr($data['key']).
- ' and hostid='.$this->data[XML_TAG_HOST]['hostid'].' and '.
- DBid2nodeid('itemid').'='.$ZBX_CURNODEID)))
- { /* exist */
- if($this->item['exist']==1) /* skip */
- {
- info('Item ['.$data['description'].'] skipped - user rule');
- break;
- }
-
- if( !isset($data['valuemapid']) )
- $data['valuemapid'] = $item['valuemapid'];
-
- update_item(
- $item['itemid'],
- $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'],
- $data['valuemapid'],
- $data['delay_flex'],
- array_unique(array_merge(
- $data['applications'],
- get_applications_by_itemid($item['itemid'])
- )),
- $item['templateid']);
- }
- else
- { /* missed */
- if($this->item['missed']==1) /* skip */
- {
- info('Item ['.$data['description'].'] skipped - user rule');
- break; // case
- }
-
- if( !isset($data['valuemapid']) )
- $data['valuemapid'] = 0;
-
- 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'],
- $data['valuemapid'],
- $data['delay_flex'],
- $data['applications']);
- }
-
- break; // case
- case XML_TAG_TRIGGER:
- 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'] = '';
-
- if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
- {
- if(isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip'])
- {
- info('Trigger ['.$data['description'].'] skipped - user rule for host');
- break; // case
- }
- if(strstr($data['expression'],'{HOSTNAME}'))
- {
- error('Trigger ['.$data['description'].'] skipped - missed host');
- break; // case
- }
- }
- else
- {
- $data['expression'] = str_replace('{HOSTNAME}',
- $this->data[XML_TAG_HOST]['name'],
- $data['expression']);
-
- if($trigger = DBfetch(DBselect('select distinct t.triggerid,t.templateid '.
- ' from triggers t,functions f,items i '.
- ' where t.triggerid=f.triggerid and f.itemid=i.itemid'.
- ' and i.hostid='.$this->data[XML_TAG_HOST]['hostid'].
- ' and t.description='.zbx_dbstr($data['description']))))
- { /* exist */
- if($this->trigger['exist']==1) /* skip */
- {
- info('Trigger ['.$data['description'].'] skipped - user rule');
- break; // case
- }
-
- update_trigger(
- $trigger['triggerid'],
- $data['expression'],
- $data['description'],
- $data['priority'],
- $data['status'],
- $data['comments'],
- $data['url'],
- get_trigger_dependences_by_triggerid($trigger['triggerid']),
- $trigger['templateid']);
-
- break; // case
- }
- else /* missed */
- {
- // continue [add_trigger]
- }
- }
-
- if($this->trigger['missed']==1) /* skip */
- {
- info('Trigger ['.$data['description'].'] skipped - user rule');
- break; // case
- }
-
- add_trigger(
- $data['expression'],
- $data['description'],
- $data['priority'],
- $data['status'],
- $data['comments'],
- $data['url']);
-
- break; // case
- case XML_TAG_GRAPH:
- if(isset($data['error']))
- {
- error('Graph ['.$data['name'].'] skipped - error occured');
- break; // case
- }
-
- 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;
- if(!isset($data['items'])) $data['items'] = array();
-
- if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
- {
- if(isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip'])
- {
- info('Graph ['.$data['name'].'] skipped - user rule for host');
- break; // case
- }
- foreach($data['items'] as $id)
-
- if(strstr($data['name'],'{HOSTNAME}'))
- {
- error('Graph ['.$data['name'].'] skipped - missed host');
- break; // case
- }
- }
- else
- {
- if($graph = DBfetch(DBselect('select distinct g.graphid, g.templateid'.
- ' from graphs g, graphs_items gi, items i'.
- ' where g.graphid=gi.graphid and gi.itemid=i.itemid'.
- ' and g.name='.zbx_dbstr($data['name']).
- ' and i.hostid='.$this->data[XML_TAG_HOST]['hostid'])))
- { /* exist */
- if($this->graph['exist']==1) /* skip */
- {
- info('Graph ['.$data['name'].'] skipped - user rule');
- break; // case
- }
-
- $data['graphid'] = $graph['graphid'];
-
- 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'],
- $graph['templateid']);
-
- DBexecute('delete from graphs_items where graphid='.$data['graphid']);
- }
- else
- { /* missed */
- // continue [add_group]
- }
- }
-
- if(!isset($data['graphid']))
- {
- if($this->graph['missed']==1) /* skip */
- {
- info('Graph ['.$data['name'].'] skipped - user rule');
- break; // case
- }
-
- $data['graphid'] = add_graph(
- $data['name'],
- $data['width'],
- $data['height'],
- $data['yaxistype'],
- $data['yaxismin'],
- $data['yaxismax'],
- $data['show_work_period'],
- $data['show_triggers'],
- $data['graphtype']);
- }
-
- foreach($data['items'] as $item)
- {
- add_item_to_graph(
- $data['graphid'],
- $item['itemid'],
- $item['color'],
- $item['drawtype'],
- $item['sortorder'],
- $item['yaxisside'],
- $item['calc_fnc'],
- $item['type'],
- $item['periods_cnt']);
- }
- break; // case
- case XML_TAG_GRAPH_ELEMENT:
- if(!isset($this->data[XML_TAG_GRAPH]))
- break; // case
-
- $data['key'] = explode(':', $data['item']);
- if(count($data['key']) < 2)
- {
- $this->data[XML_TAG_GRAPH]['error'] = true;
- error('Incorrect element for graph ['.$data['name'].']');
- break; // case
- }
-
- $data['host'] = array_shift($data['key']);
- $data['key'] = implode(':', $data['key']);
-
- 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'])))))
- {
- $this->data[XML_TAG_GRAPH]['error'] = true;
-
- error('Missed item ['.$data['key'].'] for host ['.$data['host'].']');
- break; // case
- }
-
- $data['itemid'] = $item['itemid'];
-
- array_push($this->data[XML_TAG_GRAPH]['items'], $data);
-
- break; // case
- /*case XML_TAG_SCREEN:
- case XML_TAG_SCREEN_ELEMENT:
- break; // case*/
- 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;
- }
-
- function SetRules($host, $item, $trigger, $graph)
- {
- $this->host = $host;
- $this->item = $item;
- $this->trigger = $trigger;
- $this->graph = $graph;
- }
- }
-
- 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;
- }
- }
-?>
+<?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()
+ {
+ global $USER_DETAILS, $ZBX_CURNODEID;
+
+ $this->main_node= null;
+ $this->sub_node = null;
+ $this->data = null;
+ $this->host = array('exist' => 0, 'missed' => 0);
+ $this->template = array('exist' => 0, 'missed' => 0);
+ $this->item = array('exist' => 0, 'missed' => 0);
+ $this->trigger = array('exist' => 0, 'missed' => 0);
+ $this->graph = array('exist' => 0, 'missed' => 0);
+
+ $this->accessible_groups = get_accessible_groups_by_user($USER_DETAILS,
+ PERM_READ_WRITE, null, PERM_RES_IDS_ARRAY, $ZBX_CURNODEID);
+
+ $this->accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS,
+ PERM_READ_WRITE, null, PERM_RES_IDS_ARRAY, $ZBX_CURNODEID);
+
+ $this->accessible_nodes = get_accessible_nodes_by_user($USER_DETAILS,
+ PERM_READ_WRITE, null, PERM_RES_IDS_ARRAY, $ZBX_CURNODEID);
+ }
+
+ function CharacterData($parser, $data)
+ {
+ $this->element_data .= html_entity_decode($data);
+ }
+
+ function StartElement($parser, $name, $attrs)
+ {
+ $this->element_data = '';
+
+ if(!isset($this->root))
+ {
+ if($name == XML_TAG_ZABBIX_EXPORT)
+ if(isset($attrs['version']))
+ if($attrs['version'] == '1.0')
+ {
+ $this->root = true;
+ return;
+ }
+ else
+ {
+ error(S_UNSUPPORTED_VERSION_OF_IMPORTED_DATA);
+ }
+ error(S_UNSUPPORTED_FILE_FORMAT);
+ $this->root = false;
+ }
+ elseif(!$this->root)
+ {
+ return false;
+ }
+
+ global $ZBX_CURNODEID;
+
+ $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['skip'] = false;
+
+ if($host_data = DBfetch(DBselect('select hostid from hosts'.
+ ' where host='.zbx_dbstr($data['name']).
+ ' and '.DBid2nodeid('hostid').'='.$ZBX_CURNODEID)))
+ { /* exist */
+ if($this->host['exist']==1) /* skip */
+ {
+ $data['skip'] = true;
+ info('Host ['.$data['name'].'] skipped - user rule');
+ break; // case
+ }
+ if(!in_array($host_data['hostid'], $this->accessible_hosts)){
+ error('Host ['.$data['name'].'] skipped - Access deny.');
+ break; // case
+ }
+
+ $data['hostid'] = $host_data['hostid'];
+ $data['templates'] = get_templates_by_hostid($host_data['hostid']);
+ }
+ else
+ { /* missed */
+ if($this->host['missed']==1) /* skip */
+ {
+ $data['skip'] = true;
+ info('Host ['.$data['name'].'] skipped - user rule');
+ break; // case
+ }
+
+ if(!in_array($ZBX_CURNODEID, $this->accessible_nodes)){
+ error('Host ['.$data['name'].'] skipped - Access deny.');
+ break; // case
+ }
+
+ $data['templates'] = array();
+ $data['hostid'] = add_host(
+ $data['name'],
+ 10050,
+ HOST_STATUS_TEMPLATE,
+ 0, /* useip */
+ "", /* dns */
+ "", /* ip */
+ array(),
+ null,
+ array());
+ }
+ break; // case
+ case XML_TAG_GRAPH:
+ $data = $attrs;
+ $data['items'] = array();
+ $this->sub_node = null;
+ array_push($this->main_node, $name);
+ break; // case
+ case XML_TAG_TEMPLATE:
+ 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
+ case XML_TAG_HOSTS:
+ case XML_TAG_GROUPS:
+ case XML_TAG_ZABBIX_EXPORT:
+ case XML_TAG_APPLICATIONS:
+ case XML_TAG_TEMPLATES:
+ case XML_TAG_ITEMS:
+ case XML_TAG_TRIGGERS:
+ case XML_TAG_GRAPHS:
+ /* case XML_TAG_SCREENS:*/
+ $this->sub_node = null;
+ break; // case
+ case XML_TAG_GROUP:
+ case XML_TAG_APPLICATION:
+ default:
+ $this->sub_node = $name;
+ break; // case
+ }
+ }
+
+ function EndElement($parser, $name)
+ {
+ if(!$this->root)
+ {
+ return false;
+ }
+
+ global $USER_DETAILS;
+ global $ZBX_CURNODEID;
+
+ $data = &$this->data[$name];
+
+ switch($name)
+ {
+ case XML_TAG_HOST:
+ if($data['skip'] || !isset($data['hostid']) || !$data['hostid'])
+ break; // case
+
+ if(!isset($data['port'])) $data['port'] = 10050;
+ if(!isset($data['status'])) $data['status'] = 0;
+ if(!isset($data['useip'])) $data['useip'] = 0;
+ if(!isset($data['dns'])) $data['dns'] = "";
+ if(!isset($data['ip'])) $data['ip'] = "";
+
+ if(update_host($data['hostid'], $data['name'], $data['port'], $data['status'],
+ $data['useip'], $data['dns'], $data['ip'], $data['templates'], null, $data['groups']))
+ {
+ info('Host ['.$data['name'].'] updated');
+ }
+
+ break; // case
+ case XML_TAG_GROUP:
+ if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
+ break; //case
+
+ if(!($group = DBfetch(DBselect('select groupid, name from groups'.
+ ' where '.DBid2nodeid('groupid').'='.$ZBX_CURNODEID.
+ ' and name='.zbx_dbstr($this->element_data)))))
+ {
+ error('Missed group ['.$this->element_data.']');
+ break; // case
+ }
+
+ if(!in_array($group["groupid"], $this->accessible_groups))
+ {
+ error('Group ['.$this->element_data.'] skipped - Access deny.');
+ break; // case
+ }
+
+ array_push($this->data[XML_TAG_HOST]['groups'], $group["groupid"]);
+
+ break; // case
+ case XML_TAG_APPLICATION:
+ if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
+ break; //case
+
+ if(!isset($this->data[XML_TAG_ITEM]))
+ break; //case
+
+ if(!($application = DBfetch(DBselect('select applicationid from applications'.
+ ' where '.DBid2nodeid('applicationid').'='.$ZBX_CURNODEID.
+ ' and name='.zbx_dbstr($this->element_data).
+ ' and hostid='.$this->data[XML_TAG_HOST]['hostid']))))
+ {
+ $applicationid = add_application($this->element_data, $this->data[XML_TAG_HOST]['hostid']);
+ }
+ else
+ {
+ $applicationid = $application['applicationid'];
+ }
+
+ $this->data[XML_TAG_ITEM]['applications'][] = $applicationid;
+
+ break; // case
+ case XML_TAG_TEMPLATE:
+ if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
+ break; //case
+
+ if(!($template = DBfetch(DBselect('SELECT DISTINCT host, hostid '.
+ ' FROM hosts'.
+ ' WHERE '.DBid2nodeid('hostid').'='.$ZBX_CURNODEID.
+ ' AND host='.zbx_dbstr($this->element_data)))))
+ {
+ error('Missed template ['.$this->element_data.']');
+ break; // case
+ }
+
+ if(!in_array($template["hostid"], $this->accessible_hosts))
+ {
+ error('Template ['.$this->element_data.'] skipped - Access deny.');
+ break; // case
+ }
+
+ $this->data[XML_TAG_HOST]['templates'][$template["hostid"]] = $template['host'];
+ break; // case
+ case XML_TAG_ITEM:
+ if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
+ {
+ if(isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip'])
+ {
+ info('Item ['.$data['description'].'] skipped - user rule for host');
+ break; // case
+ }
+
+ error('Item ['.$data['description'].'] skipped - missed host');
+ break; // case
+ }
+
+ 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'] = '';
+ if(!isset($data['valuemap'])) $data['valuemap'] = '';
+ if(!isset($data['applications'])) $data['applications'] = array();
+
+ if(!empty($data['valuemap']))
+ {
+ if( $valuemap = DBfetch(DBselect('select valuemapid from valuemaps '.
+ ' where '.DBid2nodeid('valuemapid').'='.$ZBX_CURNODEID.
+ ' and name='.zbx_dbstr($data['valuemap']))) )
+ {
+ $data['valuemapid'] = $valuemap['valuemapid'];
+ }
+ else
+ {
+ $data['valuemapid'] = add_valuemap($data['valuemap'],array());
+ }
+ }
+
+ if($item = DBfetch(DBselect('select itemid,valuemapid,templateid from items'.
+ ' where key_='.zbx_dbstr($data['key']).
+ ' and hostid='.$this->data[XML_TAG_HOST]['hostid'].' and '.
+ DBid2nodeid('itemid').'='.$ZBX_CURNODEID)))
+ { /* exist */
+ if($this->item['exist']==1) /* skip */
+ {
+ info('Item ['.$data['description'].'] skipped - user rule');
+ break;
+ }
+
+ if( !isset($data['valuemapid']) )
+ $data['valuemapid'] = $item['valuemapid'];
+
+ update_item(
+ $item['itemid'],
+ $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'],
+ $data['valuemapid'],
+ $data['delay_flex'],
+ array_unique(array_merge(
+ $data['applications'],
+ get_applications_by_itemid($item['itemid'])
+ )),
+ $item['templateid']);
+ }
+ else
+ { /* missed */
+ if($this->item['missed']==1) /* skip */
+ {
+ info('Item ['.$data['description'].'] skipped - user rule');
+ break; // case
+ }
+
+ if( !isset($data['valuemapid']) )
+ $data['valuemapid'] = 0;
+
+ 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'],
+ $data['valuemapid'],
+ $data['delay_flex'],
+ $data['applications']);
+ }
+
+ break; // case
+ case XML_TAG_TRIGGER:
+ 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'] = '';
+
+ if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
+ {
+ if(isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip'])
+ {
+ info('Trigger ['.$data['description'].'] skipped - user rule for host');
+ break; // case
+ }
+ if(strstr($data['expression'],'{HOSTNAME}'))
+ {
+ error('Trigger ['.$data['description'].'] skipped - missed host');
+ break; // case
+ }
+ }
+ else
+ {
+ $data['expression'] = str_replace('{HOSTNAME}',
+ $this->data[XML_TAG_HOST]['name'],
+ $data['expression']);
+
+ if($trigger = DBfetch(DBselect('select distinct t.triggerid,t.templateid '.
+ ' from triggers t,functions f,items i '.
+ ' where t.triggerid=f.triggerid and f.itemid=i.itemid'.
+ ' and i.hostid='.$this->data[XML_TAG_HOST]['hostid'].
+ ' and t.description='.zbx_dbstr($data['description']))))
+ { /* exist */
+ if($this->trigger['exist']==1) /* skip */
+ {
+ info('Trigger ['.$data['description'].'] skipped - user rule');
+ break; // case
+ }
+
+ update_trigger(
+ $trigger['triggerid'],
+ $data['expression'],
+ $data['description'],
+ $data['priority'],
+ $data['status'],
+ $data['comments'],
+ $data['url'],
+ get_trigger_dependences_by_triggerid($trigger['triggerid']),
+ $trigger['templateid']);
+
+ break; // case
+ }
+ else /* missed */
+ {
+ // continue [add_trigger]
+ }
+ }
+
+ if($this->trigger['missed']==1) /* skip */
+ {
+ info('Trigger ['.$data['description'].'] skipped - user rule');
+ break; // case
+ }
+
+ add_trigger(
+ $data['expression'],
+ $data['description'],
+ $data['priority'],
+ $data['status'],
+ $data['comments'],
+ $data['url']);
+
+ break; // case
+ case XML_TAG_GRAPH:
+ if(isset($data['error']))
+ {
+ error('Graph ['.$data['name'].'] skipped - error occured');
+ break; // case
+ }
+
+ 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;
+ if(!isset($data['items'])) $data['items'] = array();
+
+ if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
+ {
+ if(isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip'])
+ {
+ info('Graph ['.$data['name'].'] skipped - user rule for host');
+ break; // case
+ }
+ foreach($data['items'] as $id)
+
+ if(strstr($data['name'],'{HOSTNAME}'))
+ {
+ error('Graph ['.$data['name'].'] skipped - missed host');
+ break; // case
+ }
+ }
+ else
+ {
+ if($graph = DBfetch(DBselect('select distinct g.graphid, g.templateid'.
+ ' from graphs g, graphs_items gi, items i'.
+ ' where g.graphid=gi.graphid and gi.itemid=i.itemid'.
+ ' and g.name='.zbx_dbstr($data['name']).
+ ' and i.hostid='.$this->data[XML_TAG_HOST]['hostid'])))
+ { /* exist */
+ if($this->graph['exist']==1) /* skip */
+ {
+ info('Graph ['.$data['name'].'] skipped - user rule');
+ break; // case
+ }
+
+ $data['graphid'] = $graph['graphid'];
+
+ 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'],
+ $graph['templateid']);
+
+ DBexecute('delete from graphs_items where graphid='.$data['graphid']);
+ }
+ else
+ { /* missed */
+ // continue [add_group]
+ }
+ }
+
+ if(!isset($data['graphid']))
+ {
+ if($this->graph['missed']==1) /* skip */
+ {
+ info('Graph ['.$data['name'].'] skipped - user rule');
+ break; // case
+ }
+
+ $data['graphid'] = add_graph(
+ $data['name'],
+ $data['width'],
+ $data['height'],
+ $data['yaxistype'],
+ $data['yaxismin'],
+ $data['yaxismax'],
+ $data['show_work_period'],
+ $data['show_triggers'],
+ $data['graphtype']);
+ }
+
+ foreach($data['items'] as $item)
+ {
+ add_item_to_graph(
+ $data['graphid'],
+ $item['itemid'],
+ $item['color'],
+ $item['drawtype'],
+ $item['sortorder'],
+ $item['yaxisside'],
+ $item['calc_fnc'],
+ $item['type'],
+ $item['periods_cnt']);
+ }
+ break; // case
+ case XML_TAG_GRAPH_ELEMENT:
+ if(!isset($this->data[XML_TAG_GRAPH]))
+ break; // case
+
+ $data['key'] = explode(':', $data['item']);
+ if(count($data['key']) < 2)
+ {
+ $this->data[XML_TAG_GRAPH]['error'] = true;
+ error('Incorrect element for graph ['.$data['name'].']');
+ break; // case
+ }
+
+ $data['host'] = array_shift($data['key']);
+ $data['key'] = implode(':', $data['key']);
+
+ 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'])))))
+ {
+ $this->data[XML_TAG_GRAPH]['error'] = true;
+
+ error('Missed item ['.$data['key'].'] for host ['.$data['host'].']');
+ break; // case
+ }
+
+ $data['itemid'] = $item['itemid'];
+
+ array_push($this->data[XML_TAG_GRAPH]['items'], $data);
+
+ break; // case
+ /*case XML_TAG_SCREEN:
+ case XML_TAG_SCREEN_ELEMENT:
+ break; // case*/
+ 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;
+ }
+
+ function SetRules($host, $template, $item, $trigger, $graph)
+ {
+ $this->host = $host;
+ $this->template = $template;
+ $this->item = $item;
+ $this->trigger = $trigger;
+ $this->graph = $graph;
+ }
+ }
+
+ 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/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php
index c3518f06..16d3c185 100644
--- a/frontends/php/include/locales/en_gb.inc.php
+++ b/frontends/php/include/locales/en_gb.inc.php
@@ -1307,6 +1307,8 @@
// Errors
'S_INCORRECT_DESCRIPTION'=> 'Incorrect description',
- 'S_CANT_FORMAT_TREE'=> 'Can\'t format Tree'
+ 'S_CANT_FORMAT_TREE'=> 'Can\'t format Tree',
+ 'S_UNSUPPORTED_FILE_FORMAT'=> 'Unsupported file format',
+ 'S_UNSUPPORTED_VERSION_OF_IMPORTED_DATA'=> 'Unsupported version of imported data'
);
?>