lukecyca/pyzabbix

Import template

priprd opened this issue · 4 comments

Zabbix-version: 6.2.1
pyzabbix: 1.20

Hi,
i try import template after upgrade zabbix and pyzabbix a got error message:
('Error -32602: Invalid params., Invalid parameter "/": unexpected parameter "0".', -32602)

importin via new class:
zapi.configuration['import']('xml', template, rules)

when i try old class
zapi.confimport('xml', template, rules)

i have got another error:
('Error -32602: Invalid params., Invalid parameter "/rules": unexpected parameter "applications".', -32602)

Could you provide a full code sample ?

Fix its edit rules delete rules and use depreceted function fo debuging. But bug its around new function to tricky to debug whats its the error when you got only / and 0.

old code with error:

rules = {
    "applications": {
        "createMissing": True,
    },
    "discoveryRules": {"createMissing": True, "updateExisting": True},
    "graphs": {"createMissing": True, "updateExisting": True},
    "groups": {"createMissing": True},
    "hosts": {"createMissing": True, "updateExisting": True},
    "images": {"createMissing": True, "updateExisting": True},
    "items": {"createMissing": True, "updateExisting": True},
    "maps": {"createMissing": True, "updateExisting": True},
    "screens": {"createMissing": True, "updateExisting": True},
    "templateLinkage": {"createMissing": True},
    "templates": {"createMissing": True, "updateExisting": True},
    "templateScreens": {"createMissing": True, "updateExisting": True},
    "triggers": {"createMissing": True, "updateExisting": True},
    "valueMaps": {"createMissing": True, "updateExisting": True},
}


if os.path.isdir(path):
    #path = path/*.xml
    files = glob.glob(path+'/*.xml')
    for file in files:
        print(file)
        with open(file, 'r') as f:
            template = f.read()
            try:
                id_template = zapi.configuration['import']("xml", template, rules)
            except ZabbixAPIException as e:
                print(e)
                sys.exit(1)
        print('')
elif os.path.isfile(path):
    files = glob.glob(path)
    for file in files:
        with open(file, 'r') as f:
            template = f.read()
            try:
                id_template = zapi.configuration['import']("xml", template, rules)
            except ZabbixAPIException as e:
                print(e)
                sys.exit(1)

Fixed code:

rules = {

    "discoveryRules": {"createMissing": True, "updateExisting": True},
    "graphs": {"createMissing": True, "updateExisting": True},
    "hosts": {"createMissing": True, "updateExisting": True},
    "images": {"createMissing": True, "updateExisting": True},
    "items": {"createMissing": True, "updateExisting": True},
    "maps": {"createMissing": True, "updateExisting": True},
    "templateLinkage": {"createMissing": True},
    "templates": {"createMissing": True, "updateExisting": True},
    "triggers": {"createMissing": True, "updateExisting": True},
    "valueMaps": {"createMissing": True, "updateExisting": True},
}

if os.path.isdir(path):
    #path = path/*.xml
    files = glob.glob(path+'/*.xml')
    for file in files:
        print(file)
        with open(file, 'r') as f:
            template = f.read()
            try:
                id_template = zapi.confimport'("xml", template, rules)
            except ZabbixAPIException as e:
                print(e)
                sys.exit(1)
        print('')
elif os.path.isfile(path):
    files = glob.glob(path)
    for file in files:
        with open(file, 'r') as f:
            template = f.read()
            try:
                id_template = zapi.confimport'("xml", template, rules)
            except ZabbixAPIException as e:
                print(e)
                sys.exit(1)               

You need to use kwargs instead of args in the function call, this was previously handled for you with the custom confimport function, but is now required.

zapi.configuration['import'](format="xml", source=template, rules=rules)

aah this the problem.
Thanks man. Maybe update documenations