Skip to content

Instantly share code, notes, and snippets.

@papoanaya
Created December 28, 2012 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save papoanaya/4393679 to your computer and use it in GitHub Desktop.
Save papoanaya/4393679 to your computer and use it in GitHub Desktop.
Xymon to Status.net Bridge
#!/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