Tail remote log files

This commit is contained in:
Marcus Kammer 2023-11-04 12:18:36 +01:00
parent 28938566c5
commit 4f0865b231
Signed by: marcuskammer
GPG key ID: C374817BE285268F

View file

@ -245,3 +245,29 @@ an ALIAS and SERVICE as arguments and call
actions)))
(mk/remote-define-systemctl-functions start stop status)
(defun mk/remote--log (alias service filename)
(let* ((filepath (concat "/var/log/" service (unless (string-empty-p filename) (concat "/" filename))))
(host (mk/remote--get-real-host alias))
(buffer (generate-new-buffer (format "*%s-%s-%s*" alias service filename)))
(process-name (format "log-%s-%s" service filename))
(sentinel (lambda (process signal)
(when (memq (process-status process) '(exit signal))
(message "Process: %s %s" process signal)))))
(make-process
:name process-name
:buffer buffer
:command `("ssh" ,host "sudo" "tail -f" ,filepath)
:sentinel sentinel)))
(defmacro mk/define-remote-log-function (alias service &optional filename)
"Define a function to asynchronously tail a remote log file."
(let ((fname (unless filename "")))
`(defun ,(intern (format "mk/remote-log-%s-%s" alias service)) ()
,(format "Tail the remote log file: %s" filename)
(interactive)
(mk/remote--log ,alias ,service ,fname))))
(mk/define-remote-log-function "metalisp" "nginx" "access.csv")
(mk/define-remote-log-function "metalisp" "syslog")
(mk/define-remote-log-function "metalisp" "fail2ban.log")