From imattsson at common-lisp.net Wed Oct 22 19:41:10 2008 From: imattsson at common-lisp.net (imattsson) Date: Wed, 22 Oct 2008 19:41:10 +0000 Subject: [noctool-cvs] CVS source Message-ID: Update of /project/noctool/cvsroot/source In directory cl-net:/tmp/cvs-serv5967 Modified Files: utils.lisp Log Message: IM Added another global and two functions for CRC32 (needed for Nagios interop, but these may well go in now). The CRC32 implementation has been tseted for output on an empty string and on a test string found on the webb, so no exhaustive testing has been done. TODO: Maybe, at least. Call (initialize-crc32) from within (compute-crc32) or, even better, move the initialisation into the DEFVAR (though that may get ugly, I don't know). --- /project/noctool/cvsroot/source/utils.lisp 2008/06/14 12:41:43 1.10 +++ /project/noctool/cvsroot/source/utils.lisp 2008/10/22 19:41:10 1.11 @@ -2,7 +2,7 @@ (defvar *base64* "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") (defvar *random-file* nil) - +(defvar *crc32-table* nil) (defmacro with-pty (ptyspec &body body) @@ -231,3 +231,27 @@ (defun get-class (name) (find-class (find-symbol (string name) *noctool-package*))) + +(defun initialize-crc32 () + (unless *crc32-table* + (let ((poly #xEDB88320)) + (setf *crc32-table* (make-array 256 + :element-type '(unsigned-byte 32) + :initial-element 0)) + (loop for ix from 0 to 255 + do (loop with crc = ix + for cnt from 8 downto 1 + do (setf crc (if (oddp crc) + (logxor poly (ash crc -1)) + (ash crc -1))) + finally (setf (aref *crc32-table* ix) + crc)))))) + +(defun compute-crc32 (octet-vector) + "Computes the CRC32 of an octet vector" + (let ((crc #xFFFFFFFF)) + (loop for octet across octet-vector + for ix = (logand (logxor crc octet) #xFF) + do (setf crc (logxor (ash crc -8) + (aref *crc32-table* ix)))) + (logxor crc #xFFFFFFFF))) From imattsson at common-lisp.net Fri Oct 24 18:07:56 2008 From: imattsson at common-lisp.net (imattsson) Date: Fri, 24 Oct 2008 18:07:56 +0000 Subject: [noctool-cvs] CVS source Message-ID: Update of /project/noctool/cvsroot/source In directory cl-net:/tmp/cvs-serv23558 Added Files: nagios-shim.lisp Log Message: IM INitial check-in, should now have ALMOST enough scaffolding to mangle NRPE packets on an as-needed basis. Still need to finish PROCESS off in a sensible way. --- /project/noctool/cvsroot/source/nagios-shim.lisp 2008/10/24 18:07:56 NONE +++ /project/noctool/cvsroot/source/nagios-shim.lisp 2008/10/24 18:07:56 1.1 (in-package #:noctool) (defclass nagios-monitor (monitor) ((args :accessor args :initarg :args :initform nil))) (defvar *nagios-protocol-version* 2) (defvar *nagios-query-type* 1) (defvar *nagios-response-type* 2) (defparameter *nagios-buffer-size* 1034) ;;; NB: fix this... (defgeneric nagios-app-name (object) ) (defmethod nagios-app-name ((o nagios-monitor)) (declare (ignorable o)) "_NRPE_CHECK") (defmacro defnagios (class-name app-name &rest default-args) `(progn (initialize-crc32) (defclass ,class-name (nagios-monitor) ) (defmethod nagios-app-name ((o ,class-name)) (declare (ignorable o)) ,(string app-name)))) (defun make-nagios-buffer () (let ((rv (make-array *nagios-buffer-size* :elment-type '(unsigned-byte 8) :initial-element 0))) (loop for ix from 0 below *nagios-buffer-size* do (setf (aref rv ix) (random 256))) rv)) (defun nagios-endian-convert (endian &rest octets) (case endian (:big (loop for octet in octets for acc = octet then (+ (* 256 acc) octet) finally (return acc))) (:little (loop for octet in octets for scale = 1 then (* 256 scale) sum (* octet scale))))) (defun nagios-octetify (integer endian octets) (let ((rv (make-array octets :element-type '(unsigned-byte 8) :initial-element 0))) (loop for octet from 0 below octets do (setf (aref rv (if (eql endian :little) octet (- octets octet 1))) (ldb (byte 8 (* 8 octet)) integer))) rv)) (defun nagios-set-value (array integer offset octets endian) (let ((octet-array (nagios-octetify integer endian octets))) (loop for ix from offset for new across octet-array do (setf (aref (array ix) new))))) (defun nagios-packet-version (packet &key (endian :little)) (let ((octet1 (aref packet 0)) (octet2 (aref packet 1))) (nagios-endian-convert endian octet1 octet2))) (defun (setf nagios-packet-version) (new packet &key (endian :little)) (nagios-set-value packet new 0 2 endian) new) (defun nagios-packet-type (packet &key (endian :little)) (let ((octet1 (aref packet 2)) (octet2 (aref packet 3))) (nagios-endian-convert endian octet1 octet2))) (defun (setf nagios-packet-type) (new packet &key (endian :little)) (nagios-set-value packet new 2 2 endian) new) (defun nagios-packet-crc32 (packet &key (endian :little)) (let ((octet1 (aref packet 4)) (octet2 (aref packet 5)) (octet3 (aref packet 6)) (octet4 (aref packet 7))) (nagios-endian-convert endian octet1 octet2 octet3 octet4))) (defun (setf nagios-packet-crc32) (crc packet &key (endian :little)) (nagios-set-value packet crc 4 4 endian) crc) (defun nagios-packet-result (packet &key (endian :little)) (let ((octet1 (aref packet 8)) (octet2 (aref packet 9))) (nagios-endian-convert endian octet1 octet2))) ;;; Should not need a setter! (defmethod process ((mon nagios-monitor)) (let ((request (octetify (format nil "~s ~{~s~^ ~}" (nagios-app-name mon) (args mon)))) (send-buffer (make-nagios-buffer)) (recv-buffer (make-nagios-buffer))) From imattsson at common-lisp.net Fri Oct 24 18:34:29 2008 From: imattsson at common-lisp.net (imattsson) Date: Fri, 24 Oct 2008 18:34:29 +0000 Subject: [noctool-cvs] CVS source Message-ID: Update of /project/noctool/cvsroot/source In directory cl-net:/tmp/cvs-serv31148 Modified Files: nagios-shim.lisp Log Message: IM Added two extra slots (for traceability, may be taken away in future versions) --- /project/noctool/cvsroot/source/nagios-shim.lisp 2008/10/24 18:07:56 1.1 +++ /project/noctool/cvsroot/source/nagios-shim.lisp 2008/10/24 18:34:22 1.2 @@ -1,7 +1,10 @@ (in-package #:noctool) (defclass nagios-monitor (monitor) - ((args :accessor args :initarg :args :initform nil))) + ((args :accessor args :initarg :args :initform nil) + (last-sent :accessor last-sent :initarg :last-sent :initform nil) + (last-received :accessor last-received :initarg :last-received :initform nil) + )) (defvar *nagios-protocol-version* 2) (defvar *nagios-query-type* 1) From imattsson at common-lisp.net Mon Oct 27 07:29:42 2008 From: imattsson at common-lisp.net (imattsson) Date: Mon, 27 Oct 2008 07:29:42 +0000 Subject: [noctool-cvs] CVS source Message-ID: Update of /project/noctool/cvsroot/source In directory cl-net:/tmp/cvs-serv16398 Modified Files: nagios-shim.lisp Log Message: IM Now compiles cleanly. Still missing a bit from DEFNAGIOS (we need to map result value to alert level, somehow) and from PROCESS (we need to actually interpret what comes back). Question, do we actually need to deal with multiple endians? Looking at the Nagios code, it sure as hell look that way. Following on that, how do we do that cleanly? On a reply, it's not too bad, we can simply extrapolate from the Nagios packet version., but when we send? Maybe another generic function, specialising on types of equipment? --- /project/noctool/cvsroot/source/nagios-shim.lisp 2008/10/24 18:34:22 1.2 +++ /project/noctool/cvsroot/source/nagios-shim.lisp 2008/10/27 07:29:42 1.3 @@ -4,12 +4,14 @@ ((args :accessor args :initarg :args :initform nil) (last-sent :accessor last-sent :initarg :last-sent :initform nil) (last-received :accessor last-received :initarg :last-received :initform nil) + (port :reader port :initarg :port) )) (defvar *nagios-protocol-version* 2) (defvar *nagios-query-type* 1) (defvar *nagios-response-type* 2) (defparameter *nagios-buffer-size* 1034) ;;; NB: fix this... +(defvar *nagios-nrpe-port* 5666) (defgeneric nagios-app-name (object) ) @@ -17,10 +19,15 @@ (declare (ignorable o)) "_NRPE_CHECK") -(defmacro defnagios (class-name app-name &rest default-args) +(defmacro defnagios (class-name (app-name + &key (port *nagios-nrpe-port*) + ) + &rest default-args) `(progn (initialize-crc32) (defclass ,class-name (nagios-monitor) + () + (:default-initargs :port ,port :args ,default-args) ) (defmethod nagios-app-name ((o ,class-name)) (declare (ignorable o)) @@ -28,7 +35,7 @@ (defun make-nagios-buffer () (let ((rv (make-array *nagios-buffer-size* - :elment-type '(unsigned-byte 8) + :element-type '(unsigned-byte 8) :initial-element 0))) (loop for ix from 0 below *nagios-buffer-size* do (setf (aref rv ix) (random 256))) @@ -58,7 +65,7 @@ (let ((octet-array (nagios-octetify integer endian octets))) (loop for ix from offset for new across octet-array - do (setf (aref (array ix) new))))) + do (setf (aref array ix) new)))) (defun nagios-packet-version (packet &key (endian :little)) @@ -93,11 +100,39 @@ (nagios-endian-convert endian octet1 octet2))) ;;; Should not need a setter! +(defun nagios-packet-payload (packet) + (make-array 1024 :element-type '(unsigned-byte 8) :displaced-to packet :displaced-index-offset 10)) + +;;; This should work, however... there should be reading back and stuff (defmethod process ((mon nagios-monitor)) (let ((request (octetify (format nil "~s ~{~s~^ ~}" (nagios-app-name mon) (args mon)))) (send-buffer (make-nagios-buffer)) (recv-buffer (make-nagios-buffer))) + (setf (nagios-packet-version send-buffer) *nagios-protocol-version*) + (setf (nagios-packet-type send-buffer) *nagios-query-type*) + (setf (nagios-packet-crc32 send-buffer) 0) + (let ((request-buffer (nagios-packet-payload send-buffer))) + (loop for octet across request + for ix from 0 + do (setf (aref request-buffer ix) octet) + finally (setf (aref request-buffer ix) 0)) + (setf (aref request-buffer 1023) 0)) + (setf (nagios-packet-crc32 send-buffer) (compute-crc32 send-buffer)) + (setf (last-sent mon) send-buffer) + (let ((stream (socket-stream (socket-connect (address (equipment mon)) + *nagios-nrpe-port*)))) + (when stream + (unwind-protect + (progn + (write-sequence send-buffer stream) + (finish-output stream) + (unwind-protect (read-sequence recv-buffer stream)) + (setf (last-received mon) recv-buffer)) + (close stream)))) + )) + + \ No newline at end of file From imattsson at common-lisp.net Mon Oct 27 19:43:01 2008 From: imattsson at common-lisp.net (imattsson) Date: Mon, 27 Oct 2008 19:43:01 +0000 Subject: [noctool-cvs] CVS source Message-ID: Update of /project/noctool/cvsroot/source In directory cl-net:/tmp/cvs-serv16808 Modified Files: default-settings.lisp Log Message: IM No one actually has a CPU monitor written, making that go away, for now. --- /project/noctool/cvsroot/source/default-settings.lisp 2008/03/17 08:27:58 1.1.1.1 +++ /project/noctool/cvsroot/source/default-settings.lisp 2008/10/27 19:43:01 1.2 @@ -1,6 +1,6 @@ (in-package #:net.hexapodia.noctool) -(default-monitor unix-host cpu-monitor) +;;(default-monitor unix-host cpu-monitor) (default-monitor unix-host load-monitor) (default-monitor unix-host disk-container) From jprewett at common-lisp.net Tue Oct 28 20:52:55 2008 From: jprewett at common-lisp.net (jprewett) Date: Tue, 28 Oct 2008 20:52:55 +0000 Subject: [noctool-cvs] CVS source Message-ID: Update of /project/noctool/cvsroot/source In directory cl-net:/tmp/cvs-serv28622 Modified Files: classes.lisp Log Message: added macos-host class (so the paper won't be a lie! :P ) --- /project/noctool/cvsroot/source/classes.lisp 2008/08/26 16:09:21 1.14 +++ /project/noctool/cvsroot/source/classes.lisp 2008/10/28 20:52:54 1.15 @@ -1,6 +1,5 @@ (in-package #:noctool) - ;; a hash so we can look up objects by their ID (defvar *id-objects* (make-hash-table :test #'equal)) (defclass id-object () @@ -193,6 +192,9 @@ (defclass linux-host (unix-host) ()) +(defclass macos-host (unix-host) + ()) + (defmethod store ((graph disk-monitor) &optional filename) (labels ((fname (subtype) (merge-pathnames (make-pathname :name (format nil "~a%~a" filename subtype))