Created
December 28, 2012 01:14
-
-
Save papoanaya/4393679 to your computer and use it in GitHub Desktop.
Xymon to Status.net Bridge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/newlisp | |
(xml-type-tags nil nil nil nil) ; no extra tags | |
(define (url-encode str) | |
(replace {([^a-zA-Z0-9])} | |
str (format "%%%2X" (char $1)) 0)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FUNCTIONS REQUIRING AUTHENTICATION ;;;;;;;;;;;;;;;;;; | |
(set 'user-pass "username:password") | |
(set 'auth (append "Authorization: Basic " (base64-enc user-pass) "\r\n")) | |
(set 'url (string "http://status.net.site/api/statuses/update.xml")) | |
(set 'msg | |
(format "!xymon; Server %s turned %s for %s " | |
(env "BBHOSTNAME") | |
(env "BBCOLORLEVEL") | |
(env "BBSVCNAME"))) | |
(set 'text (append "status=" (url-encode msg))) | |
(set 'content-type "application/x-www-form-urlencoded") | |
(set 'xml (post-url url text content-type 5000 auth)) | |
(begin | |
(if (find "<text>(.*)</text>" xml 0) | |
(println "posted: " $1)) | |
(if (find "<error>(.*)</error>" xml 0) | |
(println "error: " $1))) | |
(exit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment