-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.rb
64 lines (52 loc) · 1.62 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
require 'json'
require 'net/http'
require 'uri'
require 'pry'
set :bind, '0.0.0.0'
set :port, '8081'
Dir["#{File.dirname(__FILE__)}/lib/*.rb"].each { |f| require f }
# Authenticate all requests with an API key
before do
# X-Api-Key
secret = ENV["ENV_HTTP_X_API_KEY"]
puts secret
puts env["HTTP_X_API_KEY"]
if env["HTTP_X_API_KEY"] != secret
if request.path.to_s == '/ok'
'ok'
else
error 401
end
end
end
#curl -X POST -H 'Content-Type: application/json' -H 'X-Api-Key: secret' -d '{ "app": "host12.apple.com", "msg": "informa que termine" }' http://localhost:8081/to-tg
post '/to-tg' do
request_params = JSON.parse(request.body.read)
chat_id = ENV["ENV_TG_CHATID"]
out = to_tg(chat_id, request_params["msg"])
# Add record to forward and reverse zones, via TCP
#error 500 unless $? == 0
#status 201
out.code
end
#curl -X POST -H 'Content-Type: application/json' -H 'X-Api-Key: secret' -d '{ "app": "host12.apple.com", "msg": "informa que termine" }' http://localhost:8081/to-slack
post '/to-slack' do
request_params = JSON.parse(request.body.read)
request_params["channel"] = "#general" if request_params["channel"].nil?
request_params["username"] = "Tell-me_bot" if request_params["username"].nil?
request_params["attachments"] = "" if request_params["attachments"].nil?
out = to_slack(request_params["channel"], request_params["username"], request_params["msg"], request_params["attachments"])
#error 500 unless $? == 0
out.code
end
get '/help' do
content_type :json
a = File.read("README.md")
a
end
get '/ok' do
"OK"
end