aboutsummaryrefslogtreecommitdiffstats
path: root/elisp
diff options
context:
space:
mode:
authorÓscar Nájera <hi@oscarnajera.com>2022-10-08 16:38:03 +0200
committerÓscar Nájera <hi@oscarnajera.com>2022-10-08 16:38:03 +0200
commit406d8ddbceb2d0e33cebccf709b5b13ab2065f58 (patch)
tree010c9571b6797aefa7249cb6d8fcfae5db094ba0 /elisp
parentf4baef952b1f054aa632b86bc336650ce6d6e767 (diff)
downloaddotfiles-406d8ddbceb2d0e33cebccf709b5b13ab2065f58.tar.gz
dotfiles-406d8ddbceb2d0e33cebccf709b5b13ab2065f58.tar.bz2
dotfiles-406d8ddbceb2d0e33cebccf709b5b13ab2065f58.zip
cmk event log view
Diffstat (limited to 'elisp')
-rw-r--r--elisp/cmk.el112
1 files changed, 66 insertions, 46 deletions
diff --git a/elisp/cmk.el b/elisp/cmk.el
index 6e2b7e0..61b71df 100644
--- a/elisp/cmk.el
+++ b/elisp/cmk.el
@@ -22,25 +22,6 @@
(require 'cl-lib)
(require 'dash)
-(defconst cmk-lq-problems-filter
- "Filter: service_state = 0
-Filter: service_has_been_checked = 1
-And: 2
-Negate:
-Filter: service_has_been_checked = 1
-Filter: service_scheduled_downtime_depth = 0
-Filter: host_scheduled_downtime_depth = 0
-And: 2
-Filter: service_acknowledged = 0
-Filter: host_state = 1
-Filter: host_has_been_checked = 1
-And: 2
-Negate:
-Filter: host_state = 2
-Filter: host_has_been_checked = 1
-And: 2
-Negate:\n\n")
-
(defun cmk-state-coloring (state)
"Font color for numeric STATE input as string."
(cl-check-type state string)
@@ -90,8 +71,22 @@ Default is \"%Y-%m-%d %H:%M\"."
("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)
- ("Check output" 18 t :column "service_plugin_output" :parser cmk-purge-bangs)
- ))
+ ("Check output" 18 t :column "service_plugin_output" :parser cmk-purge-bangs)))
+
+(defconst cmk-log-col-spec
+ '(("host_state" 5 t :column "host_state" :parser cmk-state-coloring)
+ ("Host" 9 t :column "host_name")
+ ("Service" 12 t :column "service_description")
+ ("log_time" 16 t :column "log_time" :parser cmk-timestamp-to-date)
+ ("log_command_name" 10 t :column "log_command_name")
+ ("log_comment" 15 t :column "log_comment")
+ ("lineno" 8 t :column "log_lineno")
+ ("lstate" 8 t :column "log_state")
+ ("lsttype" 8 t :column "log_state_type")
+ ("log_type" 8 t :column "log_type")
+ ("host_scheduled_downtime_depth" 5 t :column "host_scheduled_downtime_depth")
+ ("host_has_been_checked" 5 t :column "host_has_been_checked")
+ ("log_plugin_output" 5 t :column "log_plugin_output")))
(defun cmk-parse-rows (buffer column-spec)
"Return tabulated entries from BUFFER according to COLUMN-SPEC."
@@ -108,16 +103,6 @@ Default is \"%Y-%m-%d %H:%M\"."
column-spec))
do (forward-line))))
-;; (process-send-string cmks "GET hosts\nColumns: address name\n\n")
-;; (process-send-string cmks
-;; "GET log
-;; Columns: host_name service_description log_type log_plugin_output log_state log_state_type log_time
-;; Filter: log_time >= 1657270676
-;; Filter: class = 1
-;; Filter: class = 3
-;; Filter: class = 8
-;; Or: 3\n\n")
-
(defun cmk-livestatus-query (query)
"One shot livestatus QUERY, return network process."
(let ((cmks (cmk-oneshot 'keep)))
@@ -131,9 +116,9 @@ Default is \"%Y-%m-%d %H:%M\"."
(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-print 'remember)))
+ (accept-process-output cmks 0.1)
+ (setq tabulated-list-entries (cmk-parse-rows (process-buffer cmks) tabulated-list-format))
+ (tabulated-list-print 'remember)))
(define-derived-mode cmk-livestatus-mode prog-mode "livestatus"
"Major mode for viewing journalctl output."
@@ -162,24 +147,60 @@ Default is \"%Y-%m-%d %H:%M\"."
(cmk-table--refresh)))))
(switch-to-buffer edit-buffer)))
-(defun cmk-problems ()
- (interactive)
- (with-current-buffer (get-buffer-create "*CMK Problems*")
+(defun cmk-view (table spec filters)
+ "Render a tabular view for livestatus TABLE with SPEC columns using FILTERS."
+ (with-current-buffer (get-buffer-create "*CMK View*")
(tabulated-list-mode)
(setq-local cmk-livestatus-query
- (concat (string-join `("GET services"
- ,(cmk-colums-from-spec cmk-problem-col-spec)
- ,cmk-lq-problems-filter) "\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)
+ (format "GET %s\n%s\n%s\n\n"
+ table
+ (cmk-colums-from-spec spec)
+ filters))
+ (setq tabulated-list-format (vconcat spec))
(add-hook 'tabulated-list-revert-hook #'cmk-table--refresh nil t)
+ (local-set-key "Q" #'cmk-edit-lq)
(tabulated-list-init-header)
(cmk-table--refresh)
(switch-to-buffer (current-buffer))))
+(defun cmk-problems ()
+ "Render default problems view."
+ (interactive)
+ (cmk-view "services" cmk-problem-col-spec
+ "Filter: service_state = 0
+Filter: service_has_been_checked = 1
+And: 2
+Negate:
+Filter: service_has_been_checked = 1
+Filter: service_scheduled_downtime_depth = 0
+Filter: host_scheduled_downtime_depth = 0
+And: 2
+Filter: service_acknowledged = 0
+Filter: host_state = 1
+Filter: host_has_been_checked = 1
+And: 2
+Negate:
+Filter: host_state = 2
+Filter: host_has_been_checked = 1
+And: 2
+Negate:"))
+
+
+(defun cmk-log-prob ()
+ "Render default event log view."
+ (interactive)
+ (cmk-view "log" cmk-log-col-spec
+ (format
+ "Filter: log_time >= %d
+Filter: class = 1
+Filter: class = 3
+Filter: class = 8
+Or: 3"
+ (floor
+ (- (time-to-seconds (current-time))
+ (* 4 3600))))))
+
+
;;; Get a different csv
;; (let* ((cmks (cmk-oneshot t)))
;; (with-current-buffer (process-buffer cmks) (erase-buffer))
@@ -206,6 +227,5 @@ Default is \"%Y-%m-%d %H:%M\"."
;; (display-buffer (current-buffer))
;; (json-parse-buffer)))
-
(provide 'cmk)
;;; cmk.el ends here