aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÓscar Nájera <hi@oscarnajera.com>2022-08-28 20:40:27 +0200
committerÓscar Nájera <hi@oscarnajera.com>2022-08-28 20:40:37 +0200
commit16135d8e56e93448987bc01dc7e32e607d414115 (patch)
treeab196d16d7924122e3c8e1faac207d5d3e1621ac
parent1ce1552763ceae4219e4f99bcbb8df3d29c55ef8 (diff)
downloaddotfiles-16135d8e56e93448987bc01dc7e32e607d414115.tar.gz
dotfiles-16135d8e56e93448987bc01dc7e32e607d414115.tar.bz2
dotfiles-16135d8e56e93448987bc01dc7e32e607d414115.zip
Refresh filters on livestatus query
-rw-r--r--elisp/cmk.el62
1 files changed, 46 insertions, 16 deletions
diff --git a/elisp/cmk.el b/elisp/cmk.el
index 4ef87e2..a139258 100644
--- a/elisp/cmk.el
+++ b/elisp/cmk.el
@@ -118,25 +118,55 @@ Default is \"%Y-%m-%d %H:%M\"."
;; Filter: class = 8
;; Or: 3\n\n")
-(defun cmk-problems ()
- (interactive)
- (let ((cmks (cmk-oneshot 'keep))
- (buffer (get-buffer-create "*CMK Problems*")))
+(defun cmk-livestatus-query (query)
+ "One shot livestatus QUERY, return network process."
+ (let ((cmks (cmk-oneshot 'keep)))
(with-current-buffer (process-buffer cmks) (erase-buffer))
- (process-send-string cmks
- (concat (string-join `("GET services"
- ,(cmk-colums-from-spec cmk-problem-col-spec)
- "Filter: service_description ~ load") "\n")
- "\n\n"))
- (with-current-buffer buffer
- (tabulated-list-mode)
- (setq tabulated-list-format (vconcat cmk-problem-col-spec))
- (setq tabulated-list-sort-key '("STATE" . nil))
+ (process-send-string cmks query)
+ cmks))
+
+(defvar-local cmk-livestatus-query ""
+ "Livestatus query in buffer.")
+
+(defun cmk-table--refresh ()
+ "Query and reprint the Livestatus query result table."
+ (let ((cmks (cmk-livestatus-query cmk-livestatus-query)))
(accept-process-output cmks 0.1)
(setq tabulated-list-entries (cmk-parse-rows (process-buffer cmks) cmk-problem-col-spec))
- (tabulated-list-init-header)
- (tabulated-list-print)
- (display-buffer (current-buffer)))))
+ (tabulated-list-print 'remember)))
+
+(defun cmk-edit-lq (query buffer)
+ (interactive (list cmk-livestatus-query (current-buffer)))
+ (with-current-buffer (get-buffer-create "*LQ*")
+ (prog-mode)
+ (insert query)
+ (local-set-key "\C-c\C-c"
+ (lambda ()
+ (interactive)
+ (let ((new-query (-> (buffer-string) (string-trim) (concat "\n\n"))))
+ (kill-buffer)
+ (switch-to-buffer buffer)
+ (setq-local cmk-livestatus-query new-query)
+ (cmk-table--refresh))))
+ (switch-to-buffer (current-buffer))))
+
+(defun cmk-problems ()
+ (interactive)
+ (with-current-buffer (get-buffer-create "*CMK Problems*")
+ (tabulated-list-mode)
+ (setq-local cmk-livestatus-query
+ (concat (string-join `("GET services"
+ ,(cmk-colums-from-spec cmk-problem-col-spec)
+ "Filter: service_description ~ load") "\n")
+ "\n\n"))
+ (setq tabulated-list-format (vconcat cmk-problem-col-spec))
+ (setq tabulated-list-sort-key '("STATE" . nil))
+
+ (local-set-key "Q" #'cmk-edit-lq)
+ (add-hook 'tabulated-list-revert-hook #'cmk-table--refresh nil t)
+ (tabulated-list-init-header)
+ (cmk-table--refresh)
+ (switch-to-buffer (current-buffer))))
;;; Get a different csv
;; (let* ((cmks (cmk-oneshot t)))