Ad Widget

Collapse

Improving API Integration for Zabbix: Handling Success and Error Messages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dodoxkos
    Junior Member
    • Mar 2024
    • 2

    #1

    Improving API Integration for Zabbix: Handling Success and Error Messages

    I am currently developing an API for Zabbix designed to automatically trigger a script in the event of a problem or incident. However, I'm encountering an issue where success messages are not being displayed as expected. Specifically, information is only shown when an error occurs, as illustrated in an attached image. Below is a snippet of the code:

    Code:
    try:
    raiz=chamadoaberto['TChamado']
    mensagem_sucesso = "Chamado " + str(raiz['Referencia']) + " aberto com sucesso!"
    print(mensagem_sucesso)
    with open("/var/log/api/secret.log", "a") as arquivo:
    arquivo.write("\nDados: " + stringchamado)
    arquivo.write("\n" + mensagem_sucesso)
    except KeyError:
    mensagem_erro = "Erro ao abrir chamado: resposta inesperada."
    print(mensagem_erro)
    with open("/var/log/api/secret.log", "a") as arquivo:
    arquivo.write("\n********************************* **************\n")
    arquivo.write(str(chamadoaberto))
    sys.exit(0)
    Ideally, upon successful execution, the system should display a message indicating that a reference call has been successfully opened. When I replace sys.exit(0) with 100, the message is correctly displayed, albeit as an error, even though the operation was successful. My goal is to have the message appear as 'sent' along with the corresponding information.
    Attached Files
Working...