aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--elisp/cmk.el74
1 files changed, 38 insertions, 36 deletions
diff --git a/elisp/cmk.el b/elisp/cmk.el
index 0451dd4..1a6729d 100644
--- a/elisp/cmk.el
+++ b/elisp/cmk.el
@@ -20,17 +20,16 @@
;;; Code:
(require 'dash)
-(let* ((buffer "CMK")
- (close (kill-buffer buffer))
- (cmks (make-network-process
+(let* ((cmks (make-network-process
:name "Checkmk"
:remote "/tmp/ingridcmk.socket"
;; :coding '(binary . binary)
- :buffer buffer
+ :buffer "CMK"
;; :filter (lambda (_process string)
;; (message "%S" string))
:sentinel (lambda (process event)
- (message "Process: %s had the event '%s'" process event)))))
+ (message "Process: %s had the event '%s'" process event)
+ (kill-buffer (process-buffer process))))))
;; (process-send-string cmks "GET hosts\nColumns: address name\n\n")
;; (process-send-string cmks
;; "GET log
@@ -41,6 +40,7 @@
;; Filter: class = 8
;; Or: 3\n\n")
+ (with-current-buffer (process-buffer cmks) (erase-buffer))
(process-send-string cmks "GET services
Columns: service_state host_name service_description service_last_state_change service_plugin_output
Filter: service_state = 0
@@ -63,37 +63,39 @@ Negate:\n\n")
(accept-process-output cmks 0.1)
(with-current-buffer (process-buffer cmks)
(goto-char (point-min))
- (setq tabulated-list-entries nil)
- (while (not (eobp))
- (let* ((row
- (split-string (buffer-substring-no-properties (point) (line-end-position)) ";"))
- (state (pcase (string-to-number (car row))
- (1 (propertize "WARN" 'face 'font-lock-warning-face))
- (2 (propertize "CRIT" 'face 'font-lock-keyword-face))
- (a (number-to-string a))))
- (date (->> (nth 3 row)
- (string-to-number)
- (seconds-to-time)
- (format-time-string "%Y-%m-%d %H:%M")))
- (msg (->> (nth 4 row)
- (replace-regexp-in-string (rx "(" (+ "!") ")") ""))))
- (push (list (count-lines 1 (point))
- (vector state (cadr row)
- (caddr row)
- date msg)) tabulated-list-entries))
- (forward-line))
- (erase-buffer)
- (tabulated-list-mode)
- (setq tabulated-list-format `[("STATE" 5 t)
- ("HOST" 9 t)
- ("Service" 20 t)
- ("when" 16)
- ("Message" 18 t)
- ])
- (setq tabulated-list-sort-key '("STATE" . nil))
- (tabulated-list-init-header)
- (tabulated-list-print)
- (display-buffer (current-buffer))))
+ (let (data)
+ (while (not (eobp))
+ (let* ((row
+ (split-string (buffer-substring-no-properties (point) (line-end-position)) ";"))
+ (state (pcase (string-to-number (car row))
+ (1 (propertize "WARN" 'face 'font-lock-warning-face))
+ (2 (propertize "CRIT" 'face 'font-lock-keyword-face))
+ (a (number-to-string a))))
+ (date (->> (nth 3 row)
+ (string-to-number)
+ (seconds-to-time)
+ (format-time-string "%Y-%m-%d %H:%M")))
+ (msg (->> (nth 4 row)
+ (replace-regexp-in-string (rx "(" (+ "!") ")") ""))))
+ (push (list (count-lines 1 (point))
+ (vector state (cadr row)
+ (caddr row)
+ date msg)) data))
+ (forward-line))
+ (with-current-buffer (get-buffer-create "CMK Problems")
+ (erase-buffer)
+ (tabulated-list-mode)
+ (setq tabulated-list-format `[("STATE" 5 t)
+ ("HOST" 9 t)
+ ("Service" 20 t)
+ ("Since" 16)
+ ("Message" 18 t)
+ ])
+ (setq tabulated-list-sort-key '("STATE" . nil))
+ (setq tabulated-list-entries data)
+ (tabulated-list-init-header)
+ (tabulated-list-print)
+ (display-buffer (current-buffer))))))
(provide 'cmk)