Ad Widget

Collapse

Failed import of templates via API. Zabbix 6.0.5

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eithor
    Member
    • May 2020
    • 50

    #1

    Failed import of templates via API. Zabbix 6.0.5

    Hi all,

    I'm trying to import the standard yaml templates from Zabbix after upgrade to 6.0.5. Since the web gui requires very many clicks to import all the templates, I wanted to use the API.

    I've used the pyzabbix api (now in version 1.0, https://github.com/lukecyca/pyzabbix) for exporting templates in yaml or xml format. Using the pyzabbix api for import gives no error messages, a "True" result code fromt he API - but no changes visible in the web. Also, I cannot see anything in the zabbix server logs (at level 3), or zabbix audit-logs. I also tried to export an existing template to xml, change it, then re-import the xml, same result: no errors but also no changes.

    I'm calling the pyzabbix like the below code after zapi login, taken from zabbix-gnomes ztmplimport.py and changed to py3 and yaml (it seems that code blocks is not allowing python indents, sorry about that).

    Please advice how I can test this further. Anyone else seen the same thing?

    Thanks,
    Eirik

    Code:
    for template in args.templates:
    Continue = True
    if Continue:
    try:
    # open file for reading
    with open(template,'r') as f:
    yamlfile = f.read()
    f.close()
    except:
    # If the file can't be opened, exit with error
    error = "Error: Something went wrong when trying to read the file" + template
    PrintError(error)
    Continue = False
    
    if Continue:
    try:
    # verify if the file is a valid YAML
    yparse = yaml.safe_load(yamlfile)
    except:
    # If the file isn't a valid YAML, exit with error
    error = "Error: YAML is not valid in " + template
    PrintError(error)
    Continue = False
    
    if Continue:
    try:
    # Everything looks good, let's try to import
    #result = zapi.configuration.Import(
    result = zapi.confimport( confformat="yaml", rules=rules, source=yamlfile)
    print(result)
    except ZabbixAPIException as e:
    print(e)
    # Something went wrong with the API call or import
    error = "Error: Something went wrong while importing " + \
    template + "\n" + str(e) + str(sys.exc_info()[1][0])
    PrintError(error)
    Continue = False
    if args.verbose:
    print(("Succesfully imported " + template))
    
    # And we're done...
  • Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1782

    #2
    What does the audit log say (Reports - Audit)?

    Markku

    Comment

    • eithor
      Member
      • May 2020
      • 50

      #3
      The audit logs have nothing about items from the template. Just some repeated entries - every 1 or 2 minutes, still ongoing, with the same resource-id and description, different recordset hash, from the System user.

      Description: IPMI: CPU1 Temp, C

      item.tag[14503]: Updated
      item.tag[14503].tag: sensor => component
      item.tag[14503].value: temperature => environment
      item.tag[82900]: Updated
      item.tag[82900].tag: component => sensor
      item.tag[82900].value: environment => temperature

      Could it be that part of the last template import in web gui is going on in a loop?

      Eirik

      Comment

      Working...