GithubHelp home page GithubHelp logo

glpi-webhook's Introduction

glpi-webhook's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

glpi-webhook's Issues

Unable to Add New Webhook Configuration in GLPI Webhook Plugin

Hello,

I am experiencing an issue with the GLPI Webhook plugin. I am attempting to add a new webhook configuration to integrate GLPI with external services, but I am unable to do so.

Issue Details:

Page URL: marketplace/webhook/front/config.php
Expected Behavior: There should be an "Add" or "Insert" button on the webhook configuration page to allow for the creation of new webhook entries.
Actual Behavior: The page does not display any option to add or insert a new webhook configuration. This prevents the creation of new webhooks.
Steps to Reproduce:

Navigate to the webhook configuration page at marketplace/webhook/front/config.php.
Observe the lack of an "Add" or "Insert" button to create a new webhook.
Possible Causes:

Environment:

GLPI Version: 10.0.10
Webhook Plugin Version: 1.0.18

Thank's

image

Headers customization

Hi,

TLDR : It would be nice to allow customization of http headers sent + a pre-login phase

Long version :
I want to use Webhook (latest version 1.0.12) to send a message to our instance of Rocket Chat.
I don't actually understand how the multiple platforms are managed. I saw the 3 authentication methods (None / Basic Auth / Encoded Basic Auth), but none of them apply to Rocket Chat, since it requires two specific headers : X-Auth-Token and X-User-Id (source).

For my testing purposes, I used secret field for X-Auth-Token and user field for X-User-Id, and I didn't bother to add a new Auth Method, so I simply added following lines in inc/notificationeventwebhook.class.php :

case 1: // No Authentication
   $headers = 
      [
         'Content-type: application/json',
         'X-Auth-Token: '.$webhook_infos['additionnaloption']['secret'],
         'X-User-Id: '.$webhook_infos['additionnaloption']['user']
      ];
      break;

I don't know how long token is valid, so I'm fully aware this piece of code is messy (not to mention I broke the "no authentication" case). A better approach would be to log in first, get token, and then post message.

I'm surprised this problem doesn't occur more often : it seems to me each platform has its own method, and headers can't literally be anything.
Since follow all platforms and all possible actions and update the code accordingly is impossible, I think it would be a great addition if user could set http headers.

However, it would solve half of the problem with rocket chat, since it requires to be logged in before the message posting.
I'm not quite sure it would address every problem, but an option allowing us to login (login url + name of token field to be used in "real" request) in a first place may be useful.

For the record, there is a wrapper to use rocket chat. Not quite sure it's useful (post message in chat and send message to single user are the two only functions which make sense IMHO), but an option to use a library could be a possible solution too.

FOREACH doesnt work

Hello! How can I use FOREACH with webhooks plugin?
Actually, I need to send tasks to telegram, but it doesnt work with "curl error" every time or it just send ##task.description## (literaly)
Thanks

Not all Notification Tags are working

Hi , wonderful project.
I have it working on my GLPI 10.0.9 and notifications works fine but I have noticed that authors and actors loops are not working. For example, if I use:
##FOREACHactors## ##actor.itemtype## ##actor.mobile## ##actor.name## ##ENDFOREACHactors##
I get an empty payload, But if I use the exact same notification template with a mail notification, the actors appear with no problem. (Yes, I know I have to use { } for the payload and I am using them, this is just an example)

This leads to believe that this webhook is not passing the FOREACH variables because the other variables work well.

Can somebody help?

ticket.url

It seems my sent webhook does not send properly the ##ticket.url## tag. I've activated the debug function.

This is my template


{
  "type": "message",
  "attachments": [
    {
      "contentType": "application/vnd.microsoft.card.adaptive",
      "contentUrl": null,
      "content": {
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
        "type": "AdaptiveCard",
        "version": "1.5",
        "body": [
          {
            "type": "TextBlock",
            "text": "Nouveau ticket :  [##ticket.title##](##ticket.url##)"
          },
          {
            "type": "TextBlock",
            "text": "Envoyé par : ##ticket.authors## "
          },
          {
            "type": "TextBlock",
            "text": "Catégorie : ##ticket.category## "
          },
          {
            "type": "TextBlock",
            "text": "Lien GLPI : ##ticket.url## "
          }
        ]
      }
    }
  ]
}

And this is the debug log :


HTTP Headers : Array
(
    [0] => Content-type: application/json
)

POST Content : {
  "type": "message",
  "attachments": [
    {
      "contentType": "application/vnd.microsoft.card.adaptive",
      "contentUrl": null,
      "content": {
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
        "type": "AdaptiveCard",
        "version": "1.5",
        "body": [
          {
            "type": "TextBlock",
            "text": "Nouveau ticket :  [Exécution de scripts Powershell]()"
          },
          {
            "type": "TextBlock",
            "text": "Envoyé par : Raphaël "
          },
          {
            "type": "TextBlock",
            "text": "Catégorie : MATÉRIEL (ORDI, ÉCRAN,...) > Infrastructure systèmes et réseaux "
          },
          {
            "type": "TextBlock",
            "text": "Lien GLPI :  "
          }
        ]
      }
    }
  ]
}

Bad Request error. v1.0.10

Sending a ticket description with two paragraphs leads to a Bad Request error

image

Ticket description source code:

<p>1</p>
<p>2</p>

Notification template translation body

{
"ID": "##ticket.id##",
"Events":"##ticket.action##",
"Locations":"##ticket.location##",
"Room Number":"##ticket.location.room##",
"Title":"##ticket.title##",
"Category":"##ticket.category##",
"Requesters":"##ticket.authors##",
"Description":"##ticket.content##"
}

Error 400 with Ms teams

Hi,

I got an issue using webhook plugin into glpi 10.14 with Teams channel. I follewd the webhook wiki step-by-step for the configuration and now I got this error :

Error : call to URL https://montenant.webhook.office.com/webhookb2/b34a3f0f-045b-4276-bf50-14f45269039e@25b4356d5-b067-455c-a78d-9e6b83626a69/IncomingWebhook/e7e2f1222a9f44b1995d0f034ed17eaa/d57fe641-c15d-4ac9-89fa-58c56b4a1444 failed with status 400, response Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: a. Path '', line 0, position 0., curl_error , curl_errno 0
HTTP Headers : Array

On this I got no authentication required.

Thx for your helps

webhook - zulip

Tried to use webhook sending to send messages to zulip (I did a migration from RC to zulip), but I found that there is no way to do the sending as zulip has a completely different integration method.

https://zulip.com/api/send-message

# For stream messages
curl -X POST https://yourZulipDomain.zulipchat.com/api/v1/messages \
    -u BOT_EMAIL_ADDRESS:BOT_API_KEY \
    --data-urlencode type=stream \
    --data-urlencode 'to="Denmark"' \
    --data-urlencode topic=Castle \
    --data-urlencode 'content=I come not, friends, to steal away your hearts.'

# For direct messages
curl -X POST https://yourZulipDomain.zulipchat.com/api/v1/messages \
    -u BOT_EMAIL_ADDRESS:BOT_API_KEY \
    --data-urlencode type=direct \
    --data-urlencode 'to=[9]' \
    --data-urlencode 'content=With mirth and laughter let old wrinkles come.'

It would be cool if it was possible to configure webhook for zulip - is it possible to add this in a future update?

doesnt send ##ticket.url##

Hello dear creator!

Webhook doesnt send a ##ticket.url## to telegram. What could be the reason. No problem with other ## ##

thanks

How to use conditional statements in the beginning of payload?

Hello,

Env: GLPI 10.0.9
Plugin: 1.0.14

I'm trying to send some notifications to Teams with one conditional at the beginning.
If the condition doesn't match, nothing will be sent to the webhook.

When I tried to send the payload below, I get the error of invalid JSON:

##IFchange.urgency=0##
{
    "@type": "MessageCard",
    "@context": "http://schema.org/extensions",
    "themeColor": "0076D7",
    "summary": "##change.title##",
    "sections": [{
        "activityTitle": "##change.title##",
        "activitySubtitle": "##change.content##",
        "facts": [{
            "name": "##lang.change.authors##",
            "value": "##IFchange.authors## ##change.authors## ##ENDIFchange.authors## ##ELSEchange.authors##--##ENDELSEchange.authors##"
        }, {
            "name": "##lang.change.creationdate##",
            "value": "##change.creationdate##"
        }, {
            "name": "##lang.change.status##",
            "value": "##change.status##"
        }, {
            "name": "##lang.change.impact##",
            "value": "##change.impact##"
        }, {
            "name": "##lang.change.content##",
            "value": "##change.content##"
        }],
        "markdown": true
    }],
    "potentialAction": [{
        "@type": "OpenUri",
        "name": "Learn More",
        "targets": [{
            "os": "default",
            "uri": "https://glpi.url.com/front/change.form.php?id=##change.id##"
        }]
    }
    ]
}
##ENDIFchange.urgency##

Error:

Error: call to URL ttps://domain.webhook.office.com/webhookb2/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingWebhook/XXXXXXXXXXXXXXXXXXXXXXXxx failed with status 400, response Invalid webhook request - Empty Payload, curl_error , curl_errno 0

How can I use this conditional statements in the JSON payload ?

"Webhooks configuration" button in GLPI does not shows off

I decompressed and installed the plugin in my GLPI instance. I enabled it as well.
But, when following the wiki, the "Setup > Webhooks configuration" does not shows off.

I don't know why and I did a lot of research trying to make it work, but I couldn't find anything.

Here's the "Plugins" page:

Captura de tela de 2023-10-18 16-23-33

Here's the options ("Configurar" stands for "Setup" in Portuguese):

Captura de tela de 2023-10-18 16-24-23

If you guys could help me I would really appreciate it.

plugin review for plugins.glpi-project.org

Hello @ericferon

I review the plugin for your submission on plugin directory.

Here is some issues to fix to get an approval:

  • the current screenshot url targets a 404 url
  • the description invites the user to see the plugin wiki or readme for help, but both are not helpful
  • the plugin is indicated to be functional on GLPI 10.0.x, but there is deprecated calls on installation and usage (check files/_logs/php_errors.logs)
  • targets of notifications seems to be send only for your plugin statecheck, is it wanted ? events of core cannot be supported ?

additional remarks:

  • Is there a way to customize the payload ?
  • i see you added a download_url tag in your xml, are you interested by a publication on the GLPI marketplace ?

Regards

Configure telegram webhook on glpi

I would like to know how to configure the Telegram webhook on glpi.

What information do I need to put in the Address, Secret and user fields?

Grateful

PHP function Problem - Autocompletion feature has been removed.

I have completed the setup, but the webhook does not run.
tried it with php 7.4 and 8.0.

this file is php-error.log


PHP User deprecated function (16384): Autocompletion feature has been removed.

glpiphplog.NOTICE: *** PHP User deprecated function (16384): Autocompletion feature has been removed. in /web/glpi10/src/Toolbox.php at line 546
Backtrace :
src/Toolbox.php:546 trigger_error()
src/Html.php:3756 Toolbox::deprecated()
plugins/webhook/inc/config.class.php:165 Html::autocompletionTextField()
src/CommonGLPI.php:657 PluginWebhookConfig->showForm()
src/CommonGLPI.php:634 CommonGLPI::displayStandardTab()
ajax/common.tabs.php:111 CommonGLPI::displayStandardTab()

No Webhook in Recipients

Hi,
I'm trying to set up the webhook as described in the wiki. In the last point, I need to choose the recipient. But I don't have webhook options in the list.
WebHookNotification

Webhook is not working

Hi everybody!
I set to get a notification when ticket is being updated. I do get notification via email and browser but not via webhook. What should I do?

Debug data

This is more a question than an issue. Please point at me where I can ask if this not the appropriate place.

I would like to debug Json message send by Glpi because I have not the same result when I trigger webhook notification and directly make a request with the same Json.

Is there logs somewhere or a debug mode so I can track very accurately what is send from GLPI.

Thank you for your work, your time and your skill. It really enhance our work.

Escaping backslash

Hi,

We use webhooks to send messages to a python script. Code is following :

        data = request.data.decode('utf-8')
        data_json = json.loads(data)

Unfortunately, if user (or tech) used a \ (as part in windows path) in description (or comments, solution, ...), this throws an exception, because \ are not escaped and output is not json-compatible.

I added \ in str_replace :

$data = str_replace_deep(["\n", "\r", "\t", '"'], ['\\n', '\\r', '\\t', '\\"'], $data);

=>

$data = str_replace_deep(["\\", "\n", "\r", "\t", '"'], ['\\\\', '\\n', '\\r', '\\t', '\\"'], $data);

I don't know if there is a better solution.

Error in auth when there are special characters in password

Hi!

If we set password to &D and get it with $webhook_infos['additionnaloption']['secret'] => it will be &#38;D.

So, the base64 string for auth will be wrong.

We need to unescape html chars when creating the header.

In inc/notificationeventwebhook.class.php:

case 3: // Basic Authentication with base64 encoding
$headers = 
    [
        'Content-type: application/json',
        'Authorization: Basic '.base64_encode(htmlspecialchars_decode($webhook_infos['additionnaloption']['user']) .":".htmlspecialchars_decode($webhook_infos['additionnaloption']['secret']))
    ];
break;

Webhook version 1.0.17 won't install

Tried upgrading my install from 1.0.16 to 1.0.17, but the "upgrade" never finishes and just asks me to upgrade again. Doing this from within the Marketplace, and running GLPI 10.0.10. Manually removed the Webhook plugin as there was no uninstall option. After removing, was able to clean the plugin, and then attempted a new install of 1.0.17, with no change. After installing, refreshing the Marketplace just shows the folder with a +....clicking it makes it look as though it's installing, but afterwards refreshing the Marketplace page still shows the same status. Rinse and repeat.

Please let me know if you need more info or need anything else attempted. Thanks!

Dont accept tags LOOPS

Hi,

Does not accept GLPI loop tags, Some tags only work within other tags

Ex:
##FOREACHauthors## ##author.phone## ##ENDFOREACHauthors##

Returns empty

GLPI 10.0.7
Webhooks 1.0.12

Integration Slack

It's works for URL's that no need authentication?

I can't sent message to slack here.

Tks,

Setup portion is not shown in GLPI menu

Hi,

After installation of plugin via marketplace link to setup seems to be broken.
Configure link from plugin details is (your_enviroment_name)/marketplace/webhook/front/config.php, but this seems to be a blank page, and no option webhook configuration in Setup menu:
image
Plugin version is 1.0.14, GLPI version is 10.0.5

Configuration not showing

I install plugin using marketplace and enable plugin. After i click in configure e in next screen configuration is blank screen.
image
image
My version is
image

Webhook Error 400

failed with status 400, response {"id":"model.incoming_hook.parse_data.app_error","message":"Unable to parse incoming data.","detailed_error":"","request_id":"t8rzm8qzaiyuxfxed5ckf5mz6r","status_code":400}, curl_error , curl_errno 0

Error send webhook notification

When I try to open a ticket with the webhook activated to send the request via webhook, the screen goes white. Returning the information from the photo below with debugging enabled\

photo_2024-02-13_22-29-49

PHP Deprecated function (8192): str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

glpi 10.0.11 and php 8.2

A validation is missing so that $subject does not have a null value

glpiphplog.NOTICE:   *** PHP Deprecated function (8192): str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /html/marketplace/webhook/inc/notificationeventwebhook.class.php at line 40
  Backtrace :
  ...bhook/inc/notificationeventwebhook.class.php:40 str_replace()
  ...bhook/inc/notificationeventwebhook.class.php:36 str_replace_deep()
  ...hook/inc/notificationeventwebhook.class.php:172 str_replace_deep()
  src/NotificationEventAbstract.php:85               PluginWebhookNotificationEventWebhook::extraRaise()
  src/NotificationEvent.php:187                      NotificationEventAbstract::raise()
  src/Ticket.php:1752                                NotificationEvent::raiseEvent()
  src/CommonDBTM.php:1721                            Ticket->post_updateItem()
  front/ticket.form.php:84                           CommonDBTM->update()
  public/index.php:82                                require()

Special characters in webhook payloads not encoded properly

When a webhook is created in GLPI and a notification template is used, something in the notification template translates text characters to URL encoding. For example, the character "<" becomes "%3C". Some webhook require these characters to be passed directly through, and this automatic encoding breaks this functionality.

An example:
Microsoft Teams has the ability using Webhooks to mention a user in a feed. The json looks like this (Example from here):

{
    "type": "message",
    "attachments": [
        {
        "contentType": "application/vnd.microsoft.card.adaptive",
        "content": {
            "type": "AdaptiveCard",
            "body": [
                {
                    "type": "TextBlock",
                    "size": "Medium",
                    "weight": "Bolder",
                    "text": "Sample Adaptive Card with User Mention"
                },
                {
                    "type": "TextBlock",
                    "text": "Hi <at>Adele UPN</at>, <at>Adele Azure AD</at>"
                }
            ],
            "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
            "version": "1.0",
            "msteams": {
                "entities": [
                    {
                        "type": "mention",
                        "text": "<at>Adele UPN</at>",
                        "mentioned": {
                          "id": "[email protected]",
                          "name": "Adele Vance"
                        }
                      },
                      {
                        "type": "mention",
                        "text": "<at>Adele Azure AD</at>",
                        "mentioned": {
                          "id": "87d349ed-44d7-43e1-9a83-5f2406dee5bd",
                          "name": "Adele Vance"
                        }
                      }
                ]
            }
        }
    }]
}

As you can see, the and tags are required for the user mention to be passed through to Teams. These tags are being encoded into URL strings, and teams rejects the message because of this.

Apparently, there is a way to mitigate this. In GLPI there is a function you can run within the plugin system to undo the sanitization that is occurring in GLPI:

https://github.com/glpi-project/glpi/blob/78c83ac4a6e070c4f1b7c0294adadaafe84e8ac2/src/NotificationTemplate.php#L287-L288

as according to the folks at GLPI: glpi-project/glpi#14162 (comment)

Webhook does not work with Slack.

$ curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/....

I want to make the webhook work in the form above.

I made a connection using the method shown in the guide you gave me.
https://github.com/ericferon/glpi-webhook/wiki/Webhook

Secret and type are not set, but registered in the form of being called only by URL, but it does not work.

The settings are as follows.

Home > Setup > Webhooks configuration

** Home > Setup > Notification > Notification Template >**

  • Template translation - Template translation
    • Email text body(leave the field empty for a generation from HTML)
      • {"text":"Hello, World!"}

image


Thanks for your help.

Passing Parameters in url request

Is it possible to specify parameters in the query to execute the following command ?

curl -X POST JENKINS_URL/job/JOB_NAME/build \
  --user USER:TOKEN \
  --data-urlencode json='{"parameter": [{"name":"id", "value":"123"}, {"name":"verbosity", "value":"high"}]}'

In fact I want to build a jenkins job by passing glpi variables as parameters

Thank you in advance for your help,

Have a nice day

Сomment information is not added to webhook data

Сomment information is not added to webhook data
GLPI 10.0.7
Webhooks Version: 1.0.12
"chat_id": "string",
"comment": "##FOREACH LAST 1 timelineitems## ##timelineitems.description####ENDFOREACHtimelineitems##",
"status": "##ticket.status##",
"title": "##ticket.title##",
"category": "##ticket.category##",
"entity": "##ticket.shortentity##",
"author": "##ticket.authors##",
"description": "##ticket.description##",
"priority": "##ticket.priority##"
}

Can't find

Is there any step i'm missing? Cause i can't find Config > Webhooks on my setup.

image

I'm using your latest version

401 Unauthorized

Thanks for the work you've done.
The plugin is trying to send a notification, but I am facing the following problem.
he does not want to log in to the api.
in the log I see the message:

cat /var/www/html/files/_log/webhook.log
2022-10-18 13:24:04 [9@glpi]
Error: call to URL https://mysite/api/v1/chat.postMessage failed with status 401, response {"status":"error","message":"You must be logged in to do this."}, curl_error , curl_errno 0

direct curl request works correctly:
curl -H "X-Auth-Token: My-Token-ID"
-H "X-User-Id: My-User-ID"
-H "Content-type:application/json"
https://mysite/api/v1/chat.postMessage
-d '{ "channel": "@user", "text": "This is a direct message!" }'
webhook6

P.S.
I dreamed of such a plugin for a very long time.
so I really appreciate your work!

what could be the reason of this fault?

Hello!

Uncaught Exception Error: Call to a member function getByLanguage() on string in /var/www/glpi/marketplace/webhook/inc/notificationeventwebhook.class.php at line 145

Thanks!

Error with Google Spaces

Greetings,

While trying to create a link to a Google Spaces chat, I've received an error caused by the Webhook system not correctly parsing the token to the system. The error goes as follows:

Error: call to URL https://chat.googleapis.com/v1/spaces/REDACTED/messages?key=REDACTED&#38;token=REDACTED failed with status 403, response { "error": { "code": 403, "message": "The API is called without a valid token. Instructions on how to use incoming webhooks can be found at https://developers.google.com/chat/how-tos/webhooks", "status": "PERMISSION_DENIED" } } , curl_error , curl_errno 0

Checking in the internet, someone mentioned that the "&" character may have to be commented with an "^", and when I tried that, the error got different as well.

Error: call to URL https://chat.googleapis.com/v1/spaces/REDACTED/messages?key=REDACTED^&#38;token=REDACTED failed with status 400, response { "error": { "code": 400, "message": "API key not valid. Please pass a valid API key.", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "API_KEY_INVALID", "domain": "googleapis.com", "metadata": { "service": "chat.googleapis.com" } } ] } } , curl_error , curl_errno 0

Can you provide some support at this issue?

Error send webhook notification

When I try to open a ticket with the webhook activated to send the request via webhook, the screen goes white. Returning the information from the photo below with debugging enabled

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.