From a462384c236b560463a98e3936f8803cae227ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20N=C3=A1jera?= Date: Fri, 8 Jul 2022 16:08:53 +0200 Subject: some checkmk data --- config/shepherd/init.d/cmk.scm | 14 ++++++ elisp/cmk.el | 100 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 config/shepherd/init.d/cmk.scm create mode 100644 elisp/cmk.el diff --git a/config/shepherd/init.d/cmk.scm b/config/shepherd/init.d/cmk.scm new file mode 100644 index 0000000..4c98f1c --- /dev/null +++ b/config/shepherd/init.d/cmk.scm @@ -0,0 +1,14 @@ +(register-services + (make + #:docstring "SSH tunnel to ingrid CMK server for socket" + #:provides '(ingrid-cmk) + #:start (make-forkexec-constructor + (list "ssh" "-NTv" + "-o" "ServerAliveInterval=60" + "-o" "ExitOnForwardFailure=yes" + "-o" "StreamLocalBindUnlink=yes" + "-L" "/tmp/ingridcmk.socket:/omd/sites/ingrid/tmp/run/live" + "ingrid@ingrid") + #:log-file "/tmp/ingrid-cmk.log") + #:stop (make-kill-destructor 2) ;; 2 is SIGINT - interupt process stream, ctrl-C + #:respawn? #t)) diff --git a/elisp/cmk.el b/elisp/cmk.el new file mode 100644 index 0000000..0451dd4 --- /dev/null +++ b/elisp/cmk.el @@ -0,0 +1,100 @@ +;;; cmk.el --- CMK livestatus -*- lexical-binding: t; -*- +;; +;; Copyright (C) 2022 Óscar Nájera +;; +;; Author: Óscar Nájera +;; Maintainer: Óscar Nájera +;; Created: July 08, 2022 +;; Modified: July 08, 2022 +;; Version: 0.0.1 +;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp +;; Homepage: https://github.com/titan/cmk +;; Package-Requires: ((emacs "24.3")) +;; +;; This file is not part of GNU Emacs. +;; +;;; Commentary: +;; +;; CMK livestatus +;; +;;; Code: +(require 'dash) + +(let* ((buffer "CMK") + (close (kill-buffer buffer)) + (cmks (make-network-process + :name "Checkmk" + :remote "/tmp/ingridcmk.socket" + ;; :coding '(binary . binary) + :buffer buffer + ;; :filter (lambda (_process string) + ;; (message "%S" string)) + :sentinel (lambda (process event) + (message "Process: %s had the event '%s'" process event))))) + ;; (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") + + (process-send-string cmks "GET services +Columns: service_state host_name service_description service_last_state_change service_plugin_output +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") + (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)))) + + +(provide 'cmk) +;;; cmk.el ends here -- cgit v1.2.3