Hello all,
im trying to get a little php script to import xml templates generated using a modified perl script i found on this forum, and would like you guys to point to some api doc, or some advice to get this to work.
At this time, i started taking the part ot the hosts.php that does the import and seems to be working but nothing is added on the zabbix manager. If i add the xml file through the web its working, so theres no issue with the xml.
IF i enter bad chrs on the xml, the script complaints about it and failed to end, so seems like the basic functionality is ok, this i miss some parameters to get to the db maybe ?
Thank you all
Javi
im trying to get a little php script to import xml templates generated using a modified perl script i found on this forum, and would like you guys to point to some api doc, or some advice to get this to work.
At this time, i started taking the part ot the hosts.php that does the import and seems to be working but nothing is added on the zabbix manager. If i add the xml file through the web its working, so theres no issue with the xml.
IF i enter bad chrs on the xml, the script complaints about it and failed to end, so seems like the basic functionality is ok, this i miss some parameters to get to the db maybe ?
PHP Code:
#!/usr/bin/php
<?php
# Zabbix
# Copyright (C) 2000-2011 Zabbix SIA
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
?>
<?php
require_once('config2.inc.php');
require_once('include/db.inc.php');
require_once('include/export.inc.php');
$rules = array(T_ZBX_STR, O_OPT, null, DB_ID, null);
if ($argc != 2 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
print "PHP script to import xml item templates to zabbix from commandline\n";
print "Syntax: import.php <xml_file>\n\n";
exit (1);
} else {
$file= $argv[1];
}
print "[+] Started import from file $file\n";
DBstart();
$result = zbxXML::import($file);
if($result) {
print "[+] Parging XML file $file\n";
$result = zbxXML::parseMain($rules);
if ($result) {
$result = DBend($result);
if ($result) print "[+] Data imported and commited on DB\n";
} else {
print "\n[-] Failed while parsing $file\n";
}
} else {
print "\n[-] Failed while loading XML file $file\n";
}
print "\n";
?>
Thank you all
Javi
Comment