init
This commit is contained in:
commit
5aa99bbc9b
2 changed files with 49 additions and 0 deletions
BIN
package-updates-exporter
Executable file
BIN
package-updates-exporter
Executable file
Binary file not shown.
49
package-updates-exporter.ros
Executable file
49
package-updates-exporter.ros
Executable file
|
@ -0,0 +1,49 @@
|
|||
#!/bin/sh
|
||||
#|-*- mode:lisp -*-|#
|
||||
#|
|
||||
exec ros -Q -- $0 "$@"
|
||||
|#
|
||||
(progn ;;init forms
|
||||
(ros:ensure-asdf)
|
||||
#+quicklisp(ql:quickload '() :silent t)
|
||||
)
|
||||
|
||||
(defpackage :ros.script.package-updates-exporter.3936516038
|
||||
(:use :cl))
|
||||
(in-package :ros.script.package-updates-exporter.3936516038)
|
||||
|
||||
(defun get-distribution ()
|
||||
(with-open-file (in "/etc/os-release" :direction :input)
|
||||
(let ((os-names '("debian" "alpine" "arch"))
|
||||
(found nil))
|
||||
(loop for line = (read-line in nil) while line do
|
||||
(loop for os in os-names
|
||||
when (search os (string-downcase line))
|
||||
do (setf found os)))
|
||||
found)))
|
||||
|
||||
(defun get-package-manager (distro)
|
||||
(let ((package-managers '(("debian" . "apt") ("alpine" . "apk") ("arch" . "pacman"))))
|
||||
(cdr (assoc distro package-managers :test #'string=))))
|
||||
|
||||
(defvar *distribution* (get-distribution))
|
||||
(defvar *package-manager* (get-package-manager *distribution*))
|
||||
|
||||
|
||||
(defun get-upgradable (package-manager)
|
||||
(let ((package-managers '(("apt" . "list --upgradable | grep \"upgradable\"")
|
||||
("apk" . "list --upgradable")
|
||||
("pacman" . "-Qu"))))
|
||||
(let ((command (assoc package-manager package-managers :test #'string=)))
|
||||
(if command
|
||||
(count #\Newline (or (uiop:run-program `(,package-manager ,(cdr command)) :output :string :ignore-error-status t) ""))
|
||||
(error "Unknown package manager: ~A" package-manager)))))
|
||||
|
||||
(defun main (&rest argv)
|
||||
(let* ((architecture (uiop:run-program "sh" :args '("-c" "uname -m | tr -d '\n'") :output :string))
|
||||
(upgradable (get-upgradable *package-manager*)))
|
||||
(format t "# HELP ~a_upgrades_pending Packages pending updates by origin~%" *package-manager*)
|
||||
(format t "# TYPE ~a_upgrades_pending gauge~%" *package-manager*)
|
||||
(format t "~a_package_pending_update{arch=\"~a\"} ~d~%" *package-manager* architecture upgradable)))
|
||||
|
||||
;;; vim: set ft=lisp lisp:
|
Loading…
Add table
Reference in a new issue