本节很简单,仅仅是添加一个发送状态到web server的功能。
1表示进程或者,0表示进程已经不存在。
process.lsp全部代码:
#!/usr/bin/newlisp
(set 'cur-path "/opt/detector")
(load (append cur-path "/filter.lsp"))
(load (append cur-path "/config.lsp"))
(define (check-process filter-str)
(set 'r (exec (append "ps -def | grep " filter-str)))
(set 'l (length r))
(> l 2))
(define (add-log msg)
(println msg)
(append-file (append cur-path "/process.log") (append "\n" (string (now 480)) " "))
(append-file (append cur-path "/process.log") (append ": " msg))
)
(define (call-api process-status)
(set 'data (format "ip=%s&hostName=%s&time=%lld&status=%lld" ip host_name (date-value) process-status))
(println data)
(set 'r3 (post-url (format "http://%s/wind_tunnel/api/post/process" server) data))
(println r3))
(dolist (sub-list filters)
(if (check-process (first sub-list))
(begin
(add-log (append (sub-list 1) " is alive\n"))
(call-api 0)
)
(begin
(add-log (append (sub-list 1) " is dead\n"))
(eval (sub-list 2))
(call-api 0))))
(exit)