2blane / OctoPrint-Webhooks

Make OctoPrint events call your custom webhooks!
GNU Affero General Public License v3.0
28 stars 19 forks source link

Bug in simulating test #8

Closed rickyzhang82 closed 4 years ago

rickyzhang82 commented 4 years ago

Thanks for writing this plugin.

I wrote a web hook server to trigger a web hook to turn off 3D printer with a delay when the print is done.

But your simulation test fail when I only select one event. But if I select all events, the test passed.

Here is my test scenario:

URL:  http://192.168.2.30:12000/done?delay=30 
Events: only Done is selected
Testing: simulate Print Done
Headers: clear 
Data: clear
2blane commented 4 years ago

@rickyzhang82 I just pushed a major update that allows you to have multiple webhooks. Should also fix this issue as I just tested your case. Let me know if it is still happening to you or if the problem is fixed.

rickyzhang82 commented 4 years ago

I upgraded to Webhook 3.0.0 last night. I don't see it actually trigger my printer to turn off when the print is done.

How can I debug it or enable logging for Webhook? I don't see it output anything in the Octoprint print log file.

thanks!

2blane commented 4 years ago

@rickyzhang82 So it should look something like this photo. Under Testing -> you'll pick the event -> Print Done and then hit the "Simulate Webhook" button. Then, you should see a popup in the top right saying the web hook succeeded or failed like in the second picture. If there is an error sending the webhook, the message should tell you what the problem is. I need to update the readme to explain this better.

Screen Shot 2020-05-13 at 11 32 41 AM Screen Shot 2020-05-13 at 11 34 01 AM
rickyzhang82 commented 4 years ago

The problem is still there. Please register only one event such as "Done" in the webhook. Then, pick “Print Done” in test simulation. It doesn't work in the test simulation. It didn't invoke the hook. I did not see a green window or a red window pops up.

2blane commented 4 years ago

@rickyzhang82 I tried simulating your conditions and couldn't. It works fine for me. The only time I haven't received a red/green window was when the server took too long to respond. The green/red window will only popup once the server has responded or if there was an error. If I understand your API, you are delaying 30+ seconds before returning a response to the client. The green/red window will only popup when the server has responded (30+ seconds later).

rickyzhang82 commented 4 years ago

My web hook server runs the at command, e.g. at + [x] hours /bin/command directly and return the response immediately. I tested it fine from a web browser.

Can you output something in the Octoprint log file beside pops up a green/red window?

2blane commented 4 years ago

@rickyzhang82 Can you screenshot and upload what every parameter looks like for your webhook? Then, I'll download your plugin and test it out.

rickyzhang82 commented 4 years ago

Sure. My web hook server is in 192.168.2.30. Clone my repo. make; sudo make install should deploy it as systemd service. You can find the server log by journalctl even you don't have my sonoff turn off command. It should show web hook get trigger but fail to execute when you test the URL below on web browser.

octo-debug-p1 octo-debug-p2 octo-debug-p3 octo-debug-p4 octo-debug-p5

rickyzhang82 commented 4 years ago

Any update? I found that if I select all events for web hook, the simulation test and real test passed. But it failed in both tests if I select just one event -- Done.

2blane commented 4 years ago

@rickyzhang82 So, I tested out your plugin. Couldn't get it to install under systemd (on a Mac), but ran it anyways locally. I had to change the command though as I didn't have permission to /usr/bin/at. Worked fine for me. The only thing I noticed is you have blank data in the HEADERS and DATA field. Should be {} instead of blank to be proper JSON. The plugin should warn you of this though with a red popup when you try to test it out (maybe red popups in general don't show up for you)? Also, I added in a 30 second timeout for web requests, so if it is a timeout issue you'll see a red notification popup after 30 seconds. Also, there are a bunch of INFO logs that are generated when the API request is being created/sent so you should be able to see what is happening. I couldn't reproduce your issue of selecting all events vs. one event so I'm not sure what to tell you about that. Do you have this issue if you try to send a request to https://www.google.com or some site we are sure works? If it works with Google and not your service, then it's probably an issue with your service. If it doesn't work with Google, then it could be an issue with my service. Also a quick note on your service. For me at least, and maybe this is because I couldn't install it as systemd, once the API is called once, the service shuts down and has to be run again. Test out this upgrade and see if it works for you and let me know what you figure out!

rickyzhang82 commented 4 years ago

I downloaded 3.0.1 version. But the problem is still there. I only subscribed Print Done event and kept the JSON structure intact in advance section. I don't see the webhook triggers Done event in the log file after the print was done.

I did see a log message when I stopped the 3D printer. But this is wrong. Because I only subscribed the done event.

2020-05-23 20:53:44,164 - octoprint.plugins.webhooks - INFO - Hello World from WebhooksPlugin!
2020-05-23 20:58:20,791 - octoprint.plugins.webhooks - INFO - hook: {'oauth_content_type': 'JSON', 'event_print_progress': False, 'oauth_data': '{\n  "client_id":"myClient",\n  "client_secret":"mySecret",\n  "grant_type":"client_credentials"\n}', 'oauth_http_method': 'POST', 'http_method': 'POST', 'eventUserActionNeededMessage': 'User action needed. You might need to change the filament color.', 'eventUserActionNeeded': False, 'deviceIdentifier': '', 'eventPrintProgressMessage': 'Your print is @percentCompleteMilestone % complete.', 'eventPrintPaused': False, 'eventPrintFailedMessage': 'Something went wrong and your print has failed.', 'eventErrorMessage': 'There was an error.', 'eventPrintStartedMessage': 'Your print has started', 'webhook_enabled': True, 'test_event': 'PrintStarted', 'eventPrintStarted': False, 'event_print_progress_interval': '50', 'apiSecret': '', 'oauth_headers': '{\n  "Content-Type": "application/json"\n}', 'content_type': 'JSON', 'oauth': False, 'data': '{\n  "deviceIdentifier":"@deviceIdentifier",\n  "apiSecret":"@apiSecret",\n  "topic":"@topic",\n  "message":"@message",\n  "extra":"@extra",\n  "state": "@state",\n  "job": "@job",\n  "progress": "@progress",\n  "currentZ": "@currentZ",\n  "offsets": "@offsets",\n  "meta": "@meta",\n  "currentTime": "@currentTime",\n  "snapshot": "@snapshot"\n}', 'eventPrintFailed': False, 'eventPrintPausedMessage': 'Your print has paused. You might need to change the filament color.', 'eventError': False, 'eventPrintDone': True, 'url': 'http://192.168.2.30:12000/done?delay=30', 'headers': '{\n  "Content-Type": "application/json"\n}', 'eventPrintDoneMessage': 'Your print is done.', 'oauth_url': ''}
2020-05-23 20:58:20,839 - octoprint.plugins.webhooks - INFO - hook: {'oauth_content_type': 'JSON', 'event_print_progress': False, 'oauth_data': '{\n  "client_id":"myClient",\n  "client_secret":"mySecret",\n  "grant_type":"client_credentials"\n}', 'oauth_http_method': 'POST', 'http_method': 'POST', 'eventUserActionNeededMessage': 'User action needed. You might need to change the filament color.', 'eventUserActionNeeded': False, 'deviceIdentifier': '', 'eventPrintProgressMessage': 'Your print is @percentCompleteMilestone % complete.', 'eventPrintPaused': False, 'eventPrintFailedMessage': 'Something went wrong and your print has failed.', 'eventErrorMessage': 'There was an error.', 'eventPrintStartedMessage': 'Your print has started', 'webhook_enabled': True, 'test_event': 'PrintStarted', 'eventPrintStarted': False, 'event_print_progress_interval': '50', 'apiSecret': '', 'oauth_headers': '{\n  "Content-Type": "application/json"\n}', 'content_type': 'JSON', 'oauth': False, 'data': '{\n  "deviceIdentifier":"@deviceIdentifier",\n  "apiSecret":"@apiSecret",\n  "topic":"@topic",\n  "message":"@message",\n  "extra":"@extra",\n  "state": "@state",\n  "job": "@job",\n  "progress": "@progress",\n  "currentZ": "@currentZ",\n  "offsets": "@offsets",\n  "meta": "@meta",\n  "currentTime": "@currentTime",\n  "snapshot": "@snapshot"\n}', 'eventPrintFailed': False, 'eventPrintPausedMessage': 'Your print has paused. You might need to change the filament color.', 'eventError': False, 'eventPrintDone': True, 'url': 'http://192.168.2.30:12000/done?delay=30', 'headers': '{\n  "Content-Type": "application/json"\n}', 'eventPrintDoneMessage': 'Your print is done.', 'oauth_url': ''}

When the print was done, your plugin didn't trigger my webhook. I verified it form the Octoprint log file and my app server log in systemd.

I'm not sure if you expect any event will trigger my webhook even I explicitly ask for the trigger is for done event only. In any case, it still doesn't work in my use case.

Regarding to my Go app, you don't have to run it as a systemd service. You can run it in Mac from the backround like ./app&. That's it.

2blane commented 4 years ago

Hey @rickyzhang82 just pushed out an update 3.0.2 that fixed a separate issue #9 . Not sure if it's related to your issue, but it might be worth giving it a try and seeing if it's fixed.

Also, if it doesn't work, can you try the following:

  1. Set the Advanced - Data param to {}
  2. Only have the Done Event Enabled, uncheck all others.
  3. Click the Send Test Webhook button for Print Done.
  4. Don't click anything or do anything for 60 seconds. Wait for a green or red box to appear in the top right of the screen. There is a timeout on the request, if nothing happens within a certain amount of time, the webhook will fail and a red dialog will show.
  5. Report back if a red or green box shows, or if nothing happens. If nothing happens, look at the log file, there could be some internal error occurring.