[noctool-cvs] CVS source
imattsson
imattsson at common-lisp.net
Mon Oct 27 07:29:42 UTC 2008
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
More information about the noctool-cvs
mailing list