[cl-net-snmp-cvs] r18 - trunk
ctian at common-lisp.net
ctian at common-lisp.net
Thu May 24 16:53:43 UTC 2007
Author: ctian
Date: Thu May 24 12:53:42 2007
New Revision: 18
Added:
trunk/deliver.lisp
trunk/sabrina.lisp
trunk/scripts.lisp
Modified:
trunk/asn1.lisp
trunk/classes.lisp
trunk/constants.lisp
trunk/net-snmp-dff.lisp
trunk/net-snmp.asd
trunk/net-snmp.h
Log:
Add sabrina, a snmp app
Modified: trunk/asn1.lisp
==============================================================================
--- trunk/asn1.lisp (original)
+++ trunk/asn1.lisp Thu May 24 12:53:42 2007
@@ -30,3 +30,32 @@
(read-objid name c-oids c-oid-len)
(setf length (fli:dereference c-oid-len))))))
+#-lispworks
+(defun snmp-var->value (v)
+ (case (foreign-slot-value v 'c-variable-list 'c-type)
+ ;; ASN_INTEGER
+ (#x02
+ (mem-ref (foreign-slot-value v 'c-variable-list 'c-val)
+ :uint32))
+ ;; ASN_OCTET_STR
+ (#x04
+ (foreign-string-to-lisp
+ (foreign-slot-value v 'c-variable-list 'c-val)
+ (foreign-slot-value v 'c-variable-list 'c-val-len)))
+ (otherwise :others)))
+
+#+lispworks
+(defun snmp-var->value (v)
+ (case (fli:foreign-slot-value v 'type)
+ ;; ASN_INTEGER
+ (#x02
+ (fli:dereference
+ (fli:foreign-slot-value (fli:foreign-slot-pointer v 'val)
+ 'integer)))
+ ;; ASN_OCTET_STR
+ (#x04
+ (fli:convert-from-foreign-string
+ (fli:foreign-slot-value (fli:foreign-slot-pointer v 'val)
+ 'string)
+ :length (fli:foreign-slot-value v 'val-len)))
+ (otherwise (fli:foreign-slot-value v 'type))))
Modified: trunk/classes.lisp
==============================================================================
--- trunk/classes.lisp (original)
+++ trunk/classes.lisp Thu May 24 12:53:42 2007
@@ -220,33 +220,3 @@
(defmethod snmp-msg-get-list ((s string) (oids list))
(snmp-msg-get-list (make-instance 'snmp-session :peername s) oids))
-
-#-lispworks
-(defun snmp-var->value (v)
- (case (foreign-slot-value v 'c-variable-list 'c-type)
- ;; ASN_OCTET_STR
- (+asn-octet-str+
- (foreign-string-to-lisp
- (foreign-slot-value v 'c-variable-list 'c-val)
- (foreign-slot-value v 'c-variable-list 'c-val-len)))
- ;; ASN_COUNTER
- (+asn-counter+
- (mem-ref (foreign-slot-value v 'c-variable-list 'c-val)
- :uint32))
- (otherwise :others)))
-
-#+lispworks
-(defun snmp-var->value (v)
- (case (fli:foreign-slot-value v 'type)
- ;; ASN_INTEGER
- (#x02
- (fli:dereference
- (fli:foreign-slot-value (fli:foreign-slot-pointer v 'val)
- 'integer)))
- ;; ASN_OCTET_STR
- (#x04
- (fli:convert-from-foreign-string
- (fli:foreign-slot-value (fli:foreign-slot-pointer v 'val)
- 'string)
- :length (fli:foreign-slot-value v 'val-len)))
- (otherwise (fli:foreign-slot-value v 'type))))
Modified: trunk/constants.lisp
==============================================================================
--- trunk/constants.lisp (original)
+++ trunk/constants.lisp Thu May 24 12:53:42 2007
@@ -38,6 +38,9 @@
(defconstant +asn-counter64+ (logior +asn-application+ 6))
(defconstant +asn-uinteger+ (logior +asn-application+ 7))
+(defconstant +asn-float+ (logior +asn-application+ 8))
+(defconstant +asn-double+ (logior +asn-application+ 9))
+
;;; from snmp.h
(defconstant +snmp-version-1+ 0)
(defconstant +snmp-version-2c+ 1)
Added: trunk/deliver.lisp
==============================================================================
--- (empty file)
+++ trunk/deliver.lisp Thu May 24 12:53:42 2007
@@ -0,0 +1,12 @@
+(in-package :cl-user)
+
+(clc:clc-require :net-snmp)
+
+(defun main ()
+ (format t "~A~%"
+ (snmp:snmp-msg-get "binghe.people.163.org" ".1.3.6.1.2.1.1.4.0")))
+
+(compile 'main)
+
+(deliver 'main "/tmp/net-snmp" 0
+ :multiprocessing nil)
Modified: trunk/net-snmp-dff.lisp
==============================================================================
--- trunk/net-snmp-dff.lisp (original)
+++ trunk/net-snmp-dff.lisp Thu May 24 12:53:42 2007
@@ -262,4 +262,4 @@
:result-type
:int
:language
- :ansi-c)
+ :ansi-c)
\ No newline at end of file
Modified: trunk/net-snmp.asd
==============================================================================
--- trunk/net-snmp.asd (original)
+++ trunk/net-snmp.asd Thu May 24 12:53:42 2007
@@ -5,19 +5,27 @@
(in-package :net-snmp-system)
-;;(require "foreign-parser")
-;;(foreign-parser:process-foreign-file "net-snmp.h" :case-sensitive :split-name)
+(require "foreign-parser")
+(require "sql")
(defsystem net-snmp
:description "Common Lisp interface for Net-SNMP"
- :version "0.50"
- :author "Chun Tian (binghe)"
- ;;:depends-on (:cffi)
+ :version "0.5"
+ :author "Chun Tian (binghe) <binghe.lisp at gmail.com>"
+ :depends-on (#-lispworks :cffi)
:components ((:file "package")
(:file "constants" :depends-on ("package"))
#-lispworks (:file "typedefs" :depends-on ("constants"))
#+lispworks (:file "lw-dff" :depends-on ("package"))
#+lispworks (:file "net-snmp-dff" :depends-on ("package"))
#-lispworks (:file "snmp-api" :depends-on ("constants" "typedefs"))
- (:file "asn1" :depends-on (#-lispworks "typedefs" #+lispworks "net-snmp-dff"))))
- ;;(:file "classes" :depends-on ("snmp-api"))))
+ (:file "asn1" :depends-on (#-lispworks "typedefs" #+lispworks "net-snmp-dff"))
+ (:file "classes" :depends-on ("asn1"))))
+
+(defsystem sabrina
+ :description "Sabrina - Update server status into database"
+ :version "0.1"
+ :author "Chun Tian (binghe) <binghe.lisp at gmail.com>"
+ :depends-on (:net-snmp
+ :net-telent-date)
+ :components ((:file "sabrina")))
Modified: trunk/net-snmp.h
==============================================================================
--- trunk/net-snmp.h (original)
+++ trunk/net-snmp.h Thu May 24 12:53:42 2007
@@ -1,3 +1,7 @@
+typedef unsigned long u_long;
+typedef unsigned long size_t;
+typedef u_long oid;
+
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
@@ -300,7 +304,6 @@
netsnmp_pdu *snmp_pdu_create(int);
void snmp_free_pdu(netsnmp_pdu *);
const char * snmp_pdu_type(int type);
-int get_node(const char *, oid *, size_t *);
netsnmp_variable_list *snmp_add_null_var(netsnmp_pdu *, const oid *, size_t);
int snmp_synch_response(netsnmp_session *, netsnmp_pdu *,
netsnmp_pdu **);
Added: trunk/sabrina.lisp
==============================================================================
--- (empty file)
+++ trunk/sabrina.lisp Thu May 24 12:53:42 2007
@@ -0,0 +1,54 @@
+(defpackage :org.net-snmp.sabrina
+ (:nicknames :sabrina)
+ (:use :cl :org.net-snmp :net.telent.date))
+
+(in-package :org.net-snmp.sabrina)
+
+(defvar *oid-map* (make-hash-table))
+(defvar *session-map* (make-hash-table))
+
+(defparameter *connect-spec* "dbname=sabrina user=binghe host=fs-30.space.163.org port=5433")
+
+(eval-when (:compile-toplevel :load-toplevel)
+ (sql:enable-sql-reader-syntax))
+
+(defun connect-to-db ()
+ (sql:connect *connect-spec* :database-type :postgresql))
+
+(defun update-oid-map ()
+ (mapcar #'(lambda (x) (unless (gethash (first x) *oid-map*)
+ (setf (gethash (first x) *oid-map*)
+ (make-instance 'oid :name (second x)))))
+ (sql:select [id] [oid] :from [vars])))
+
+(defun update-session-map ()
+ (mapcar #'(lambda (x) (unless (gethash (first x) *session-map*)
+ (setf (gethash (first x) *session-map*)
+ (make-instance 'snmp-session
+ :peername (second x)
+ :version +snmp-version-2c+
+ :community "private"))))
+ (sql:select [id] [hostname] :from [nodes])))
+
+(defun update-node-status ()
+ (dolist (n (sql:select [id] [hostname] :from [nodes]))
+ (destructuring-bind (node-id hostname) n
+ (format t "Processing ~A~%" hostname)
+ (let ((vars (mapcar #'(lambda (x) (car x))
+ (sql:select [vid] :from [n2v] :where [= [nid] node-id]))))
+ (commit-data node-id
+ vars
+ (snmp-msg-get-list (gethash node-id *session-map*)
+ (mapcar #'(lambda (x) (gethash x *oid-map*)) vars)))))))
+
+(defun commit-data (node-id vars datas)
+ (let ((current-time (universal-time-to-rfc2822-date (get-universal-time) -8)))
+ (sql:with-transaction
+ (loop for v in vars
+ for d in datas
+ do (sql:insert-records :into [status]
+ :attributes '(nid ts vid data)
+ :values (list node-id
+ current-time
+ v
+ d))))))
Added: trunk/scripts.lisp
==============================================================================
--- (empty file)
+++ trunk/scripts.lisp Thu May 24 12:53:42 2007
@@ -0,0 +1,10 @@
+(in-package :cl-user)
+
+(defun make-fli-dff ()
+ (foreign-parser:process-foreign-file "net-snmp.h"
+ :dff "net-snmp-dff-temp.lisp" :case-sensitive :split-name))
+
+;; (fli:start-collecting-template-info)
+(defun make-fli-templates ()
+ (with-open-file (stream "fli-templates.lisp" :direction :output)
+ (fli:print-collected-template-info :output-stream stream)))
More information about the Cl-net-snmp-cvs
mailing list