Icinga / icingaweb2-module-pdfexport

PDF export functionality for Icinga Web 2
GNU General Public License v2.0
31 stars 16 forks source link

Enhance export #19

Closed nilmerg closed 4 years ago

nilmerg commented 4 years ago

fixes #17

cristorrian commented 4 years ago

Thanks @nilmerg for the fix. :+1: With this fix and the patch of @durzo the pdfexport module work properly. But the pdf file sent trought job schedule of reporting module is sent without red and green bubbles. I think that this issue is related with the reporting module.

I have posted this issue here: https://github.com/Icinga/icingaweb2-module-reporting/issues/47

netphantm commented 4 years ago

It works nice w/ php7.3, but in php7.4 it still hangs and you'll get this in the browser window:

Empty read; connection dead? Stream state: {"timed_out":false,"blocked":true,"eof":true,"stream_type":"tcp_socket\/ssl","mode":"r+","unread_bytes":0,"seekable":false}

and this (from the icingaweb2.log):

2020-02-24T14:08:29+01:00 - ERROR - Terminated browser process after 10 seconds elapsed without the expected output
2020-02-24T14:08:31+01:00 - ERROR - WebSocket\ConnectionException in /usr/share/icingaweb2/modules/pdfexport/vendor/textalk/websocket/lib/Base.php:202 with message: Empty read; connection dead?  Stream state: {"timed_out":false,"blocked":true,"eof":true,"stream_type":"tcp_socket\/ssl","mode":"r+","unread_bytes":0,"seekable":false}
#0 /usr/share/icingaweb2/modules/pdfexport/vendor/textalk/websocket/lib/Base.php(92): WebSocket\Base->read()
#1 /usr/share/icingaweb2/modules/pdfexport/vendor/textalk/websocket/lib/Base.php(173): WebSocket\Base->receive()
#2 /usr/share/icingaweb2/modules/pdfexport/library/Pdfexport/HeadlessChrome.php(314): WebSocket\Base->close()
#3 /usr/share/icingaweb2/modules/pdfexport/library/Pdfexport/HeadlessChrome.php(235): Icinga\Module\Pdfexport\HeadlessChrome->printToPDF()
#4 /usr/share/icingaweb2/modules/reactbundle/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(70): Icinga\Module\Pdfexport\HeadlessChrome->Icinga\Module\Pdfexport\{closure}()
#5 /usr/share/icingaweb2/modules/reactbundle/vendor/react/stream/src/ReadableResourceStream.php(146): Evenement\EventEmitter->emit()
#6 /usr/share/icingaweb2/modules/reactbundle/vendor/react/event-loop/src/StreamSelectLoop.php(244): React\Stream\ReadableResourceStream->handleData()
#7 /usr/share/icingaweb2/modules/reactbundle/vendor/react/event-loop/src/StreamSelectLoop.php(211): React\EventLoop\StreamSelectLoop->waitForStreamActivity()
#8 /usr/share/icingaweb2/modules/pdfexport/library/Pdfexport/HeadlessChrome.php(245): React\EventLoop\StreamSelectLoop->run()
#9 /usr/share/icingaweb2/modules/pdfexport/library/Pdfexport/ProvidedHook/Pdfexport.php(87): Icinga\Module\Pdfexport\HeadlessChrome->toPdf()
#10 /usr/share/icingaweb2/modules/reporting/application/controllers/ReportController.php(118): Icinga\Module\Pdfexport\ProvidedHook\Pdfexport->streamPdfFromHtml()
#11 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action.php(507): Icinga\Module\Reporting\Controllers\ReportController->downloadAction()
#12 /usr/share/icingaweb2/library/Icinga/Web/Controller/Dispatcher.php(76): Zend_Controller_Action->dispatch()
#13 /usr/share/icingaweb2/library/vendor/Zend/Controller/Front.php(937): Icinga\Web\Controller\Dispatcher->dispatch()
#14 /usr/share/icingaweb2/library/Icinga/Application/Web.php(300): Zend_Controller_Front->dispatch()
#15 /usr/share/icingaweb2/library/Icinga/Application/webrouter.php(99): Icinga\Application\Web->dispatch()
#16 /usr/share/icingaweb2/public/index.php(4): require_once(String)
#17 {main}
nilmerg commented 4 years ago

@netphantm Could you please run the following manually on the host with PHP 7.4?

HOME=/tmp /usr/local/bin/google-chrome --bwsi --headless --disable-gpu --no-sandbox --no-first-run --disable-dev-shm-usage --remote-debugging-port=0 --homedir=/tmp --user-data-dir=/tmp

or turn on DEBUG logging for icingaweb2.

Either way, the actual output of the browser should be visible. Please include that in your reply.

netphantm commented 4 years ago

I omitted this info, sorry: I use chromium-browser, since it's on an armhf odroid device. hmm, I had to try it a few times, since it suddenly worked sometimes, until it didn't and here it is:

2020-02-24T14:30:33+01:00 - DEBUG - Caught browser output: 
DevTools listening on ws://127.0.0.1:39011/devtools/browser/4bcc3df0-1063-4251-a880-73bb2e895599

2020-02-24T14:30:33+01:00 - DEBUG - Transmitting CDP call: Target.createTarget(url)
2020-02-24T14:30:33+01:00 - DEBUG - Received CDP result: targetId
2020-02-24T14:30:33+01:00 - DEBUG - Transmitting CDP call: Page.enable()
2020-02-24T14:30:33+01:00 - DEBUG - Received CDP result: none
2020-02-24T14:30:33+01:00 - DEBUG - Transmitting CDP call: Page.navigate(url)
2020-02-24T14:30:33+01:00 - DEBUG - Received CDP result: frameId,loaderId
2020-02-24T14:30:33+01:00 - DEBUG - Awaiting CDP event: Page.frameStoppedLoading(frameId)
2020-02-24T14:30:33+01:00 - DEBUG - Received CDP event: Page.frameStartedLoading(frameId)
2020-02-24T14:30:33+01:00 - DEBUG - Received CDP event: Page.frameNavigated(frame)
2020-02-24T14:30:33+01:00 - DEBUG - Received CDP event: Page.domContentEventFired(timestamp)
2020-02-24T14:30:33+01:00 - DEBUG - Received CDP event: Page.loadEventFired(timestamp)
2020-02-24T14:30:33+01:00 - DEBUG - Received CDP event: Page.frameStoppedLoading(frameId)
2020-02-24T14:30:33+01:00 - DEBUG - Transmitting CDP call: Page.printToPDF(headerTemplate,displayHeaderFooter,footerTemplate,transferMode,printBackground)
2020-02-24T14:30:33+01:00 - DEBUG - Received CDP event: Page.frameResized()
2020-02-24T14:30:33+01:00 - DEBUG - Received CDP event: Page.frameResized()
2020-02-24T14:30:34+01:00 - DEBUG - Received CDP result: data
2020-02-24T14:30:34+01:00 - ERROR - WebSocket\ConnectionException in /usr/share/icingaweb2/modules/pdfexport/vendor/textalk/websocket/lib/Base.php:202 with message: Empty read; connection dead?  Stream state: {"timed_out":false,"blocked":true,"eof":true,"stream_type":"tcp_socket\/ssl","mode":"r+","unread_bytes":0,"seekable":false}
#0 /usr/share/icingaweb2/modules/pdfexport/vendor/textalk/websocket/lib/Base.php(92): WebSocket\Base->read()
#1 /usr/share/icingaweb2/modules/pdfexport/vendor/textalk/websocket/lib/Base.php(173): WebSocket\Base->receive()
#2 /usr/share/icingaweb2/modules/pdfexport/library/Pdfexport/HeadlessChrome.php(314): WebSocket\Base->close()
#3 /usr/share/icingaweb2/modules/pdfexport/library/Pdfexport/HeadlessChrome.php(235): Icinga\Module\Pdfexport\HeadlessChrome->printToPDF()
#4 /usr/share/icingaweb2/modules/reactbundle/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(70): Icinga\Module\Pdfexport\HeadlessChrome->Icinga\Module\Pdfexport\{closure}()
#5 /usr/share/icingaweb2/modules/reactbundle/vendor/react/stream/src/ReadableResourceStream.php(146): Evenement\EventEmitter->emit()
#6 /usr/share/icingaweb2/modules/reactbundle/vendor/react/event-loop/src/StreamSelectLoop.php(244): React\Stream\ReadableResourceStream->handleData()
#7 /usr/share/icingaweb2/modules/reactbundle/vendor/react/event-loop/src/StreamSelectLoop.php(211): React\EventLoop\StreamSelectLoop->waitForStreamActivity()
#8 /usr/share/icingaweb2/modules/pdfexport/library/Pdfexport/HeadlessChrome.php(245): React\EventLoop\StreamSelectLoop->run()
#9 /usr/share/icingaweb2/modules/pdfexport/library/Pdfexport/ProvidedHook/Pdfexport.php(78): Icinga\Module\Pdfexport\HeadlessChrome->toPdf()
#10 /usr/share/icingaweb2/modules/reporting/application/controllers/ReportController.php(118): Icinga\Module\Pdfexport\ProvidedHook\Pdfexport->streamPdfFromHtml()
#11 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action.php(507): Icinga\Module\Reporting\Controllers\ReportController->downloadAction()
#12 /usr/share/icingaweb2/library/Icinga/Web/Controller/Dispatcher.php(76): Zend_Controller_Action->dispatch()
#13 /usr/share/icingaweb2/library/vendor/Zend/Controller/Front.php(937): Icinga\Web\Controller\Dispatcher->dispatch()
#14 /usr/share/icingaweb2/library/Icinga/Application/Web.php(300): Zend_Controller_Front->dispatch()
#15 /usr/share/icingaweb2/library/Icinga/Application/webrouter.php(99): Icinga\Application\Web->dispatch()
#16 /usr/share/icingaweb2/public/index.php(4): require_once(String)
#17 {main}
nilmerg commented 4 years ago

Hmmm, okay. Though this is different than what you initially posted. Please report back (again with the browser's output) in case the error is this: Terminated browser process after 10 seconds elapsed without the expected output

While the log you just posted is of course valuable it doesn't explain the error above.

netphantm commented 4 years ago

hm, I cannot get it to throw the same error again, it's this last one again and again (Empty read; connection dead?), and sometimes it just works. I ran what you posted tho, perhaps this helps:


DevTools listening on ws://127.0.0.1:43339/devtools/browser/61a7484f-f2e1-463a-85e0-bd1d66887fed
[0224/153636.061778:ERROR:devtools_http_handler.cc(293)] Error writing DevTools active port to file
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.

and there it hangs.

nilmerg commented 4 years ago

Yes this might be of help. Thanks!

netphantm commented 4 years ago

I noticed that on very rare occasions, it works even with php-7.4 on this system (Ubuntu 18.04.4 LTS, 4.14.150-170 armv7l, chromium). On the company server (debian 10, 4.19.0-6-amd64 with php-7.3 and chrome) it works almost all the times (one user reported an error tho). If I encounter another error, I will post it here.