1
0
mirror of https://github.com/limosek/zaf.git synced 2024-11-24 03:19:05 +01:00

Added more objects to import/export

This commit is contained in:
Lukas Macura 2016-04-14 15:10:42 +02:00
parent 9c6cd711ee
commit 844193fd23

View File

@ -237,21 +237,25 @@ zaf_zbxapi_gethostsingroup() {
zaf_zbxapi_do_cache "$hstr" | zaf_zbxapi_getresult | tr ',' '\n' | cut -d '"' -f 4 zaf_zbxapi_do_cache "$hstr" | zaf_zbxapi_getresult | tr ',' '\n' | cut -d '"' -f 4
} }
# Host backup # Object backup
# $1 hostid # $1 object
zaf_zbxapi_export_host(){ # $2 id
zaf_zbxapi_export_object(){
local bkpstr local bkpstr
local host local obj
local id
host="$1" obj="$1"
id="$2"
bkpstr=' bkpstr='
{ {
"method": "configuration.export", "method": "configuration.export",
"jsonrpc": "2.0", "jsonrpc": "2.0",
"params": { "params": {
"options": { "options": {
"hosts": [ "'$obj'": [
"'$host'" "'$id'"
] ]
}, },
"format": "xml" "format": "xml"
@ -262,42 +266,36 @@ zaf_zbxapi_export_host(){
zaf_zbxapi_do_cache "$bkpstr" | zaf_zbxapi_getxml zaf_zbxapi_do_cache "$bkpstr" | zaf_zbxapi_getxml
} }
# Host backup
# $1 hostid
zaf_zbxapi_export_host(){
zaf_zbxapi_export_object hosts "$1"
}
# Template backup # Template backup
# $1 templateid # $1 templateid
zaf_zbxapi_export_template(){ zaf_zbxapi_export_template(){
local bkpstr zaf_zbxapi_export_object templates "$1"
local host }
host="$1" # Map backup
bkpstr=' # $1 mapid
{ zaf_zbxapi_export_map(){
"method": "configuration.export", zaf_zbxapi_export_object maps "$1"
"jsonrpc": "2.0",
"params": {
"options": {
"templates": [
"'$host'"
]
},
"format": "xml"
},
"auth": "'$ZAF_ZBXAPI_AUTH'",
"id": 1
}'
zaf_zbxapi_do_cache "$bkpstr" | zaf_zbxapi_getxml
} }
# Import template into zabbix # Import template into zabbix
# $1 template file or stdin # $1 template file or stdin
zaf_zbxapi_import_template(){ zaf_zbxapi_import_config(){
local tmplstr local xmlstr
local impstr local impstr
if [ -z "$1" ]; then if [ -z "$1" ]; then
tmplstr=$(zaf_strescape '"') xmlstr=$(zaf_strescape '"')
else else
! [ -f "$1" ] && return 1 ! [ -f "$1" ] && return 1
tmplstr=$(zaf_strescape '"\n\r' <$1) xmlstr=$(zaf_strescape '"\n\r' <$1)
fi fi
impstr=' impstr='
{ {
@ -306,22 +304,56 @@ zaf_zbxapi_import_template(){
"params": { "params": {
"format": "xml", "format": "xml",
"rules": { "rules": {
"applications": {
"createMissing": true,
"updateExisting": true
},
"discoveryRules": {
"createMissing": true,
"updateExisting": true
},
"graphs": {
"createMissing": true,
"updateExisting": true
},
"hosts": { "hosts": {
"createMissing": true, "createMissing": true,
"updateExisting": true "updateExisting": true
}, },
"items": { "items": {
"createMissing": true, "createMissing": true,
"updateExisting": true, "updateExisting": true
"deleteMissing": true },
"templates": {
"createMissing": true,
"updateExisting": true
},
"triggers": {
"createMissing": true,
"updateExisting": true
},
"maps": {
"createMissing": true,
"updateExisting": true
},
"screens": {
"createMissing": true,
"updateExisting": true
},
"items": {
"createMissing": true,
"updateExisting": true
},
"valueMaps": {
"createMissing": true,
"updateExisting": true
} }
}, },
"source": "'$tmplstr'" "source": "'$xmlstr'"
}, },
"auth": "'$ZAF_ZBXAPI_AUTH'", "auth": "'$ZAF_ZBXAPI_AUTH'",
"id": 3 "id": 3
}' }'
echo "$impstr";exit
zaf_zbxapi_do "$impstr" | zaf_zbxapi_getresult | grep -q true zaf_zbxapi_do "$impstr" | zaf_zbxapi_getresult | grep -q true
} }