From a1520c00730416a1414856b8325cc5cd12fede2f Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Tue, 20 Dec 2022 19:06:45 +0100 Subject: cmk timesort and line parse --- elisp/cmk.el | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/elisp/cmk.el b/elisp/cmk.el index 2b6f449..df424ad 100644 --- a/elisp/cmk.el +++ b/elisp/cmk.el @@ -67,10 +67,14 @@ Default is \"%Y-%m-%d %H:%M\"." " "))) (defconst cmk-problem-col-spec - '(("STATE" 5 t :column "service_state" :parser cmk-state-coloring ) + `(("STATE" 5 t :column "service_state" :parser cmk-state-coloring ) ("Host" 9 t :column "host_name") ("Service" 20 t :column "service_description") - ("Since" 16 nil :column "service_last_state_change" :parser cmk-timestamp-to-date) + ("Since" 16 ,(lambda (a b) + (time-less-p + (encode-time (parse-time-string (elt (cadr a) 3))) + (encode-time (parse-time-string (elt (cadr b) 3))))) + :column "service_last_state_change" :parser cmk-timestamp-to-date) ("Check output" 18 t :column "service_plugin_output" :parser cmk-purge-bangs))) (defconst cmk-log-col-spec @@ -92,16 +96,20 @@ Default is \"%Y-%m-%d %H:%M\"." "Return tabulated entries from BUFFER according to COLUMN-SPEC." (with-current-buffer buffer (goto-char (point-min)) - (cl-loop until (eobp) - collect - (list (count-lines 1 (point)) - (cl-map 'vector - (lambda (entry spec) - (let ((parser (or (plist-get (cdddr spec) :parser) #'identity))) - (funcall parser entry))) - (split-string (buffer-substring-no-properties (point) (line-end-position)) ";") - column-spec)) - do (forward-line)))) + (let (rows + (parsers (mapcar (lambda (spec) + (or (plist-get (cdddr spec) :parser) #'identity)) + column-spec))) + (while (not (eobp)) + (push + (list (count-lines 1 (point)) + (cl-map 'vector + (lambda (parser entry) (funcall parser entry)) + parsers + (split-string (thing-at-point 'line t) ";" nil "\n"))) + rows) + (forward-line)) + (nreverse rows)))) (defun cmk-livestatus-query (query) "One shot livestatus QUERY, return network process." -- cgit v1.2.3