Class: SimpleGetForm

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/rvc/modules/vsan.rb

Instance Method Summary collapse

Constructor Details

#initialize(server, tasksAnalyzer, inventoryAnalyzer, erbFileContent, vcInfo, hosts_props) ⇒ SimpleGetForm

Returns a new instance of SimpleGetForm.



2035
2036
2037
2038
2039
2040
2041
2042
2043
# File 'lib/rvc/modules/vsan.rb', line 2035

def initialize(server, tasksAnalyzer, inventoryAnalyzer, 
               erbFileContent, vcInfo, hosts_props)
  super server
  @tasksAnalyzer = tasksAnalyzer 
  @inventoryAnalyzer = inventoryAnalyzer
  @erbFileContent = erbFileContent
  @vcInfo = vcInfo
  @hosts_props = hosts_props
end

Instance Method Details

#do_GET(request, response) ⇒ Object

Process the request, return response



2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
# File 'lib/rvc/modules/vsan.rb', line 2046

def do_GET(request, response)
  staticFiles = [
    "/graphs.js", "/graphs.html",
    "/observer.css",
    "/vmw_logo_white.png",
    "/bg_pattern.png",
    "/vm-graph.svg"
  ]
  if request.path == "/"
    status, content_type, body = mainpage(request)
  elsif staticFiles.member?(request.path)
    status, content_type, body = servefile(request)
  # elsif request.path =~ /^\/css\//
    # status, content_type, body = servefile(request)
  elsif request.path =~ /^\/jsonstats\/(dom|pcpu|mem|lsom|vm|cmmds|misc)\/(.*).json$/
    group = $1
    file = $2
    opts = {}
    if file =~ /^(.*)_thumb$/
      file = $1
      opts[:points] = 60
    end
    status, content_type, body = servejson(group, file, opts)
  else
    super(request, response)
  end
  
  response.status = status
  response['Content-Type'] = content_type
  response.body = body
end

#json_dump(out) ⇒ Object



2103
2104
2105
# File 'lib/rvc/modules/vsan.rb', line 2103

def json_dump out
  @inventoryAnalyzer.json_dump out
end

#mainpage(request) ⇒ Object



2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
# File 'lib/rvc/modules/vsan.rb', line 2226

def mainpage request
  tasksAnalyzer = @tasksAnalyzer 
  inventoryAnalyzer = @inventoryAnalyzer
  
  html = VsanObserver.new.generate_observer_html(
    @tasksAnalyzer, @inventoryAnalyzer, @vcInfo, @hosts_props
  )
      
  [200, "text/html", html]
end

#servefile(request) ⇒ Object



2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
# File 'lib/rvc/modules/vsan.rb', line 2078

def servefile request
  filename = "#{analyser_lib_dirname}#{request.path}"
  content = open(filename, 'r').read
  if filename =~ /\.js$/
    return [200, "text/javascript", content]
  end
  if filename =~ /\.html$/
    return [200, "text/html", content]
  end
  if filename =~ /\.less$/
    return [200, "text/css", content]
  end
  if filename =~ /\.css$/
    return [200, "text/css", content]
  end
  if filename =~ /\.png$/
    return [200, "image/png", content]
  end
  if filename =~ /\.svg$/
    return [200, "image/svg+xml", content]
  end
  
  [404, "text/html", "Not found"]
end

#servejson(group, file, opts = {}) ⇒ Object



2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
# File 'lib/rvc/modules/vsan.rb', line 2107

def servejson group, file, opts = {}
  points = opts[:points]
  if group == "misc"
    if file =~ /^distribution$/
      out = @inventoryAnalyzer.dumpDistribution(:points => points)
      return [200, "text/json", json_dump(out)]
    end
    if file =~ /^crbc-(.*)$/
      hostname = $1
      out = @inventoryAnalyzer.dumpCbrc(hostname)
      return [200, "text/json", json_dump(out)]
    end
    if file =~ /^pnics-(.*)$/
      hostname = $1
      out = @inventoryAnalyzer.dumpPnics(hostname)
      return [200, "text/json", json_dump(out)]
    end
  end
  if group == "vm"
    if file =~ /^list$/
      out = @inventoryAnalyzer.dumpVmList()
      return [200, "text/json", json_dump(out)]
    end
    if file =~ /^vscsi-([^-]*)-(.*)$/
      disk = $1
      vm = $2
      out = @inventoryAnalyzer.dumpVscsi(vm, disk, nil, :points => points)
      return [200, "text/json", json_dump(out)]
    end
  end
  if group == "cmmds"
    if file =~ /^disks$/
      out = @inventoryAnalyzer.dumpCmmdsDisks()
      return [200, "text/json", json_dump(out)]
    end
    if file =~ /^cmmds-(.*)$/
      uuid = $1
      out = @inventoryAnalyzer.dumpCmmdsUuid(uuid)
      return [200, "text/json", json_dump(out)]
    end
  end
  if group == "dom"
    if file =~ /^domobj-(client|total|compmgr)-(.*)$/
      uuid = "#{$1}-#{$2}"
      out = @inventoryAnalyzer.dumpDom(uuid, nil, :points => points)
      return [200, "text/json", json_dump(out)]
    elsif file =~ /^domobj-(.*)$/
      uuid = $1
      out = @inventoryAnalyzer.dumpDom(uuid, nil, :points => points)
      return [200, "text/json", json_dump(out)]
    end
  end
  if group == "pcpu"
    if file =~ /^wdt-(.*)-([^-]*)$/
      hostname = $1
      wdt = $2
      out = @inventoryAnalyzer.dumpWdt(hostname, wdt, nil, :points => points)
      return [200, "text/json", json_dump(out)]
    end
    if file =~ /^pcpu-(.*)$/
      hostname = $1
      out = @inventoryAnalyzer.dumpPcpu(hostname, :points => points)
      return [200, "text/json", json_dump(out)]
    end
  end
  if group == "mem"
    if file =~ /^heaps-(.*)$/
      hostname = $1
      out = @inventoryAnalyzer.dumpHeaps(hostname, nil, :points => points)
      return [200, "text/json", json_dump(out)]
    end
    if file =~ /^slabs-(.*)$/
      hostname = $1
      out = @inventoryAnalyzer.dumpSlabs(hostname, nil, :points => points)
      return [200, "text/json", json_dump(out)]
    end
    if file =~ /^system-(.*)$/
      hostname = $1
      out = @inventoryAnalyzer.dumpSystemMem(hostname, nil, :points => points)
      return [200, "text/json", json_dump(out)]
    end
  end
  if group == "lsom"
    if file =~ /^lsomcomp-(.*)$/
      uuid = $1
      out = @inventoryAnalyzer.dumpLsomComp(uuid, nil, :points => points)
      return [200, "text/json", json_dump(out)]
    end
    if file =~ /^lsomhost-(.*)$/
      hostname = $1
      out = @inventoryAnalyzer.dumpLsomHost(hostname, nil, :points => points)
      return [200, "text/json", json_dump(out)]
    end
    if file =~ /^ssd-(.*)$/
      uuid = $1
      out = @inventoryAnalyzer.dumpSsd(uuid, nil, nil, :points => points)
      return [200, "text/json", json_dump(out)]
    end
    if file =~ /^plog-(.*)$/
      dev = $1
      out = @inventoryAnalyzer.dumpPlog(dev, nil, nil, nil, :points => points)
      return [200, "text/json", json_dump(out)]
    end
    if file =~ /^disk-(.*)$/
      dev = $1
      out = @inventoryAnalyzer.dumpDisk(dev, nil, nil, :points => points)
      return [200, "text/json", json_dump(out)]
    end
    if file =~ /^physdisk-(.*)-([^-]*)$/
      hostname = $1
      dev = $2
      out = @inventoryAnalyzer.dumpPhysDisk(hostname, dev, nil, :points => points)
      return [200, "text/json", json_dump(out)]
    end
  end
  
  [404, "text/html", "Not found"]
end