Last active
January 22, 2016 05:22
-
-
Save myouju/90f6be7576aebcb251c2 to your computer and use it in GitHub Desktop.
rundeckからwebhookをウケる通知bot
This file contains 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
FROM alpine:3.2 | |
MAINTAINER yuki-maeno | |
RUN apk --update add ruby ruby-bundler \ | |
&& rm -fr /var/cache/apk/* \ | |
&& gem install xml-simple --no-ri --no-rdoc | |
ADD server.rb /tmp/server.rb | |
EXPOSE 8000 | |
CMD ruby /tmp/server.rb -d && /bin/sh |
This file contains 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/env ruby | |
require 'pp' | |
require 'webrick' | |
require 'net/http' | |
require 'xmlsimple' | |
class WebForm < WEBrick::HTTPServlet::AbstractServlet | |
def do_GET(request, response) | |
response.body = 'ok' | |
end | |
def do_POST(request, response) | |
rid = request.request_uri.path.split("/").last | |
return if rid.to_i == 0 | |
#dat = JSON.parse(request.body) | |
dat = XmlSimple.xml_in(request.body) | |
dat = dat['executions'][0]['execution'][0] | |
icon = "(devil)" | |
msg = "[info]" | |
msg += "#{dat['project']} #{dat['job'][0]['group'][0]} #{dat['job'][0]['name'][0]} #{icon}\n" | |
msg += "[hr]" | |
msg += "detail: #{dat['href']}" | |
msg += "[/info]" | |
Net::HTTP.post_form(URI.parse("http://<host>/send_chat"), {text: msg, rid: rid}) | |
end | |
end | |
if $0 == __FILE__ then | |
server = WEBrick::HTTPServer.new(:Port => 8000) | |
server.mount "/", WebForm | |
if ARGV[0] == "-d" | |
Process.daemon | |
end | |
trap "INT" do server.shutdown end | |
server.start | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment