Is it possible to import the xml file from the command line? I am looking at a way to automate the management of our device list.
Ad Widget
Collapse
Import Device XML command line
Collapse
X
-
It's on the list of ToDos for version 1.6, anyway.
XML import/export in the list means via command-line !
Regards
Norbert.Comment
-
Are you interpreting XML backup/restore as import/export. Because depending on how it is implemented can have dramatically different results.
I would like to be able to use a script to insert an XML file with all the hosts I want monitored and it will update/add any differences.
Does that clear it up at all?Version : 1.8.8
Current Configuration 1 Master and 3 Child NodesComment
-
I'm also doubtful. I'm pretty sure I've heard that this import/export is simply a way of making a back-up of the configuration -- hosts, items and all that. Which would be very helpfull in that the only way to do that right now is a full DB bump.
But since it's at 0% the exact meaning isn't all that important...Comment
-
using curl to import xml
I accomplished this using the commands below. substitute your hostname and admin password, and the appropriate path to your zabbix install.
Code:curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "enter=Enter" \ --form "name=Admin" \ --form "password=yourpassword" \ 'http://your.hostname.com/zabbix/index.php?login=1' # 0 - update , 1 - skip, 0 - add curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "config=1" \ --form "import_file=@/root/zabbix_templates.xml" \ --form "rules[host][exist]=0" \ --form "rules[host][missed]=0" \ --form "rules[template][exist]=0" \ --form "rules[template][missed]=1" \ --form "rules[item][exist]=0" \ --form "rules[item][missed]=0" \ --form "rules[trigger][exist]=0" \ --form "rules[trigger][missed]=0" \ --form "rules[graph][exist]=0" \ --form "rules[graph][missed]=0" \ --form "import=Import" \ 'http://your.hostname.com/zabbix/exp_imp.php'
Comment
-
No, I don't. I'm guessing that you would need to know the hostid to do this. If you'd like to try, you can use the commands above as a template, and the following firefox plugin to expose the form information on any page. This is how I derived the curl commands above.
Let us know if you find a way to do this.
Thank you.Comment
-
FIXED
field "sid" required
Code:#!/bin/sh zabbix_url="http://your.host.com/zabbix" xml="$1" if [ "$xml" == "" ]; then echo "Usage: $0 <xml>" exit fi curl -s --cookie /tmp/cookiejar.txt --cookie-jar /tmp/cookiejar.txt \ --form "enter=Enter" \ --form "name=admin" \ --form "password=zabbix" \ "${zabbix_url}/index.php?login=1" >/dev/null 2>&1 sid=$(curl -s --cookie /tmp/cookiejar.txt --cookie-jar /tmp/cookiejar.txt \ "${zabbix_url}/index.php?login=1" \ |grep sid |head -n 1 \ |awk -Fsid= '{print $2}' \ |awk -F\" '{print $1}') # 0 - update , 1 - skip, 0 - add curl -s --cookie /tmp/cookiejar.txt --cookie-jar /tmp/cookiejar.txt \ --form "sid=${sid}" \ --form "config=1" \ --form "import_file=@${xml}" \ --form "rules[host][exist]=0" \ --form "rules[host][missed]=0" \ --form "rules[template][exist]=0" \ --form "rules[template][missed]=1" \ --form "rules[item][exist]=0" \ --form "rules[item][missed]=0" \ --form "rules[trigger][exist]=0" \ --form "rules[trigger][missed]=0" \ --form "rules[graph][exist]=0" \ --form "rules[graph][missed]=0" \ --form "import=Import" \ "${zabbix_url}/exp_imp.php"Comment
-
FIXED add cut -c -16 for the sid
FIXED
Add cut -c -16 for the sid
FIXED
field "sid" required
Code:#!/bin/sh zabbix_url="http://your.host.com/zabbix" xml="$1" if [ "$xml" == "" ]; then echo "Usage: $0 <xml>" exit fi curl -s --cookie /tmp/cookiejar.txt --cookie-jar /tmp/cookiejar.txt \ --form "enter=Enter" \ --form "name=admin" \ --form "password=zabbix" \ "${zabbix_url}/index.php?login=1" >/dev/null 2>&1 sid=$(curl -s --cookie /tmp/cookiejar.txt --cookie-jar /tmp/cookiejar.txt \ "${zabbix_url}/index.php?login=1" \ |grep sid |head -n 1 \ |awk -Fsid= '{print $2}' \ |awk -F\" '{print $1}' |cut -c -16 ) # 0 - update , 1 - skip, 0 - add curl -s --cookie /tmp/cookiejar.txt --cookie-jar /tmp/cookiejar.txt \ --form "sid=${sid}" \ --form "config=1" \ --form "import_file=@${xml}" \ --form "rules[host][exist]=0" \ --form "rules[host][missed]=0" \ --form "rules[template][exist]=0" \ --form "rules[template][missed]=1" \ --form "rules[item][exist]=0" \ --form "rules[item][missed]=0" \ --form "rules[trigger][exist]=0" \ --form "rules[trigger][missed]=0" \ --form "rules[graph][exist]=0" \ --form "rules[graph][missed]=0" \ --form "import=Import" \ "${zabbix_url}/exp_imp.php"Comment
-
Fixed
Add cut -c -16 fot the sid
sid=$(curl -s --cookie /tmp/cookiejar.txt --cookie-jar /tmp/cookiejar.txt \
"${zabbix_url}/index.php?login=1" \
|grep sid |head -n 1 \
|awk -Fsid= '{print $2}' \
|awk -F\" '{print $1}'
|cut -c -16 )Comment
Comment