Menu

Webhook payload and public_log with new line character

2022-02-02
2024-10-10
  • Michal Bohata

    Michal Bohata - 2022-02-02

    Hello all ,
    first thanks for new webhook for API .
    I have succesfully simple integration between zabbix and iTOP 2.7 , but one problem still exist. When create new entry in public log without new line , POST method to zabbix rest API working fine. When text include new line character , JSON structure is bad and POST failed .

    Example Payload :

    {
    "jsonrpc": "2.0",
    "method": "event.acknowledge",
    "params": {
    "eventids": "$this->ext_ref$",
    "action": 6,
    "message": "Ticket owner $this->agent_name$ added test:$this->head(public_log)$"
    },
    "auth": "sessionkey_xxxx",
    "id": 2
    }

    Any idea how to sent public_log with new lines to rest API ?

    Many thanks for help .

    Michal

     
  • Guillaume Lajarige

    Hello Michal,

    Can you go to the object on which you updated the public log, then on the notifications tab and open the corresponding EventWebhook, then copy / paste us the complete "Payload" field (mind to ofuscate sensitive information)

    Thanks,
    Guillaume

     
  • Michal Bohata

    Michal Bohata - 2022-02-03

    Hello Guillaume ,
    many thanks for quick response . In bellow two examples with message in one line and message with new line character.

    This is OK :

    Date
    03.02.2022 15:22:45
    Message
    TEST - Sent
    Final class
    ActionWebhook
    Webhook URL
    http://xxxxxxxx/zabbix/api_jsonrpc.php
    Headers
    Raw:
    Content-Type: application/json

    After preparation:
    Content-Type: application/json
    Payload
    Raw:
    {
    "jsonrpc": "2.0",
    "method": "event.acknowledge",
    "params": {
    "eventids": "$this->ext_ref$",
    "action": 6,
    "message": "Ticket owner $this->agent_name$ new message:$this->head(public_log)$"
    },
    "auth": "auth_key",
    "id": 2
    }

    After preparation:
    {
    "jsonrpc": "2.0",
    "method": "event.acknowledge",
    "params": {
    "eventids": "289077997",
    "action": 6,
    "message": "Ticket owner new message:This is test message."
    },
    "auth": "auth_key",
    "id": 2
    }
    Response
    {"jsonrpc":"2.0","result":{"eventids":[289077997]},"id":2}

    And second try with text with new lines :

    Date
    03.02.2022 15:27:00
    Message
    TEST - Sent
    Final class
    ActionWebhook
    Webhook URL
    http://xxxxxxxxxx/zabbix/api_jsonrpc.php
    Headers
    Raw:
    Content-Type: application/json

    After preparation:
    Content-Type: application/json
    Payload
    Raw:
    {
    "jsonrpc": "2.0",
    "method": "event.acknowledge",
    "params": {
    "eventids": "$this->ext_ref$",
    "action": 6,
    "message": "Ticket owner $this->agent_name$ new message:$this->head(public_log)$"
    },
    "auth": "auth_key",
    "id": 2
    }

    After preparation:
    {
    "jsonrpc": "2.0",
    "method": "event.acknowledge",
    "params": {
    "eventids": "289077997",
    "action": 6,
    "message": "Ticket owner new message:This

    is

    test

    message."
    },
    "auth": "auth_key",
    "id": 2
    }
    Response
    {"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error","data":"Invalid JSON. An error occurred on the server while parsing the JSON text."},"id":null}

    Many thanks for help

    Michal

     
  • Guillaume Lajarige

    Hello Michal,

    New lines should encoded as "\n" instead of a real new line. I'm puzzled that the use of $this->head(public_log)$ does not encode correctly, especially as we used it for several app connections (iTop, Mantis, Slack, ...).

    Are you using the "Payload" attribute or are you using a "Prepare payload callback"?

    Guillaume

     
  • Michal Bohata

    Michal Bohata - 2022-02-07

    Hello Guillaume ,
    i'm using just Payload attribute without any preparation of payload . It's possible to fix this problem ?

    Thanks for help

    With best regards

    Michal

     
  • Guillaume Lajarige

    I think, the problem lies in the generic webhook action.
    As it is meant to work with API that may not use REST/JSON, we leave the payload as is and don't encode its content into JSON format, which in your case is to convert new lines to "\n".

    For the moment, the only workaround I see for you is to use the "prepare request" callback, but this will require you to create an extension in order to add you PHP method. 😕

    PS: I'll check how we can fix it, but it might not be this week.

    Cheers,
    Guillaume

     

    Last edit: Guillaume Lajarige 2022-02-07
  • Michal Bohata

    Michal Bohata - 2022-02-07

    Hello Guillaume ,
    That's bad new for me , i'm not php programmer :-( . I really appreciate your time . I was looking for some examples for solution , but not luck.
    If you have any fix/tip please let me know.

    With best regards
    Michal

     
  • Guillaume Lajarige

    Hello Michal,

    I think I just fixed it, it's available on GitHub under this commit. The corresponding version will be available on iTop Hub around mid-March.

    If you feel like beta-testing it, I'm attaching a development version of the extension on this post but you should NOT deploy it on production! Only versions from the Hub should be deployed on production.

    In any case, we are grateful that you pointed this issue! Could you send me your full name and postal address via PM so we can send you thank-you stickers?

    Cheers,
    Guillaume

     
  • Michal Bohata

    Michal Bohata - 2022-02-08

    Hello Guillaume .

    I'm very happy and many thanks for quick fix this issue . After applying this update on test installation existing webhook doesn't work , but when create new one all working flawlessly .
    I'll send you PM with my address for stickers :-) .
    With best regards

    Michal

     
  • Guillaume Lajarige

    Great! Thanks for the feedback ✌

    Have a nice day,
    Guillaume

     
  • oussama ouaissa

    oussama ouaissa - 2023-12-26

    Hello,

    could any one share with me how to configure itop with zabbix

    thanks

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2023-12-26

    One of the questions is already: do you want to send data from iTop to Zabbix, or the other way around?

    For one of my customers, I added some extra functionality to the publicly available example somewhere on a Zabbix repository of webhooks.

     
  • Alexey

    Alexey - 2024-10-10

    sorry for necroposting, put seems like the issue is still here...
    when I send $this->head(public_log)$ with newlines inside, in payload
    I always get the error :

      'json_last_error' => 3,
      'json_last_error_msg' => 'Control character error, possibly incorrectly encoded',
    

    the whole error from log

    2024-10-10 11:20:58 | Error   | 1     | Webhook Action failed: Wrong JSON format for input | notifications |||
    array (
      'action_class' => 'ActionWebhook',
      'action_id' => '7',
      'action_name' => 'comment added',
      'payload' => '{
      "event": "comment_added",
      "ticket_id": "$this->id$",
      "title": "$this->title$",
      "contact": "$this->caller_id$",
      "contactEmail": "$this->caller_id->email$",
      "agent":"$this->agent_id$",
      "current_username": "$current_contact->friendlyname$",
      "new_comment": "$this->head(public_log)$",
      "current_contact_id": "$current_contact->phone$"
    }',
      'json_last_error' => 3,
      'json_last_error_msg' => 'Control character error, possibly incorrectly encoded',
    )
    
     

    Last edit: Alexey 2024-10-10

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.