-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdora.rb
123 lines (99 loc) · 2.35 KB
/
dora.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
ENV['RACK_ENV'] ||= 'development'
require 'rubygems'
require 'sinatra/base'
require 'json'
ID = ((ENV["VCAP_APPLICATION"] && JSON.parse(ENV["VCAP_APPLICATION"])["instance_id"]) || SecureRandom.uuid).freeze
require "instances"
require "stress_testers"
require "log_utils"
require "curl"
require 'bundler'
Bundler.require :default, ENV['RACK_ENV'].to_sym
$stdout.sync = true
$stderr.sync = true
$counter = 0
class Dora < Sinatra::Base
use Instances
use StressTesters
use LogUtils
use Curl
get '/' do
"Hi, I'm Dora!"
end
get '/health' do
$stderr.puts("Called /health #{$counter}")
if $counter < 3
$counter += 1
status 500
body "Hit /health #{$counter} times"
else
"I'm alive"
end
end
get '/ping/:address' do
`ping -c 4 #{params[:address]}`
end
get '/lsb_release' do
`lsb_release --all`
end
get '/find/:filename' do
`find / -name #{params[:filename]}`
end
get '/sigterm' do
"Available sigterms #{Signal.list.keys}"
end
get '/dpkg/:package' do
puts "Sending dpkg output for #{params[:package]}"
`dpkg -l #{params[:package]}`
end
get '/delay/:seconds' do
sleep params[:seconds].to_i
"YAWN! Slept so well for #{params[:seconds].to_i} seconds"
end
get '/sigterm/:signal' do
pid = Process.pid
signal = params[:signal]
puts "Killing process #{pid} with signal #{signal}"
Process.kill(signal, pid)
end
get '/logspew/:kbytes' do
kb = "1" * 1024 ;
params[:kbytes].to_i.times { puts kb }
"Just wrote #{params[:kbytes]} kbytes to the log"
end
get '/echo/:destination/:output' do
redirect =
case params[:destination]
when "stdout"
""
when "stderr"
" 1>&2"
else
" > #{params[:destination]}"
end
system "echo '#{params[:output]}'#{redirect}"
"Printed '#{params[:output]}' to #{params[:destination]}!"
end
get '/env/:name' do
ENV[params[:name]]
end
get '/env' do
ENV.to_hash.to_s
end
get '/env.json' do
ENV.to_hash.to_json
end
get '/myip' do
`ip route get 1 | awk '{print $NF;exit}'`
end
get '/largetext/:kbytes' do
fiveMB = 5 * 1024
numKB = params[:kbytes].to_i
ktext="1" * 1024
text=""
size = numKB > fiveMB ? fiveMB : numKB
size.times {text+=ktext}
text
end
run! if app_file == $0
end