NotionCommotion Posted December 15, 2017 Share Posted December 15, 2017 I would like to allow an embedded webserver to view the server's system logs. The PHP UX will allow user to: Select start/finish dates or select "real time" mode which will mimic journalctl -f. Select the user(s) who is logging the data similar to journalctl -u httpd. Optionally save the output in a file which will be downloaded to the webclient after the log is run (or canceled if using real time mode). When a hard start and finish date is specified, my thoughts are probably to execute use exec() with journalctl with applicable flags including -o json, wrapping the data with HTML as required for viewing, and creating a CSV file for the optional file feature. The real time mode will be a bit trickier. Since this will not be continuously running but only on a as-needed basis, I would like to keep it simple. Options for PHP to access the data seem to be: Directly reading sockets (sounds complicated). Directly read the log files (how?) and use http://php.net/manual/en/book.inotify.php to determine when it was changed (sounds complicated). cUrl requests to https://www.freedesktop.org/software/systemd/man/systemd-journal-gatewayd.service.html. Security risk, however, I don't think it will ever be publicly accessible. Use http://php.net/manual/en/function.proc-open.php to create a stream. Call some sort of C library (sounds complicated) Something else? And then there is implementing how the webclient can access the data. Options seem to be: Bypass PHP and have the client directly query https://www.freedesktop.org/software/systemd/man/systemd-journal-gatewayd.service.html. Store the log obtained in one of the above strategies into a session, and have the client periodically poll the server using HTTP. Implement a websocket server. I am only using a RPi, and am a little concerned about resources. Something else? As you can likely tell, I haven't really vetted this out, and am really just looking for a general direction at this time. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/305920-reading-syslogjournalctl-with-php/ Share on other sites More sharing options...
kicken Posted December 15, 2017 Share Posted December 15, 2017 I'd probably just go for the gatewayd webservice and make it only accessible via localhost rather than via any network. Otherwise, proc_open + a websocket connection seems like the next best option. After that would be polling with some ajax requests for new data. journalctl has a cursor option that you can save on each request and pass back on the next poll to search for new log entries after the cursor. Quote Link to comment https://forums.phpfreaks.com/topic/305920-reading-syslogjournalctl-with-php/#findComment-1554695 Share on other sites More sharing options...
NotionCommotion Posted December 16, 2017 Author Share Posted December 16, 2017 (edited) Thanks kicken, The gatewayd webservice is pretty impressive, and will most likely use it. It comes with a UI http://10.120.11.40:19531/browse. Couldn't figure out where to configure ListenStream=[::1]:19531 to make accessible via localost only. Since accessible by localhost only, you mean query it via PHP curl, and that a websocket would still be required? If websockets, would you recommend using a framework such as ratchet over reactphp, or some other approach? Even if no websockets required, I've wanted to try out websockets, and would appreciate recommended initial direction. Edited December 16, 2017 by NotionCommotion Quote Link to comment https://forums.phpfreaks.com/topic/305920-reading-syslogjournalctl-with-php/#findComment-1554706 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.