and_cesbo

Astra. Sessions to InfluxDB

Oct 13th, 2017
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. -- Send session to InfluxDB
  2.  
  3. uptime_skip = 10 -- do not sessions less 10 seconds
  4.  
  5. function auth_request(session_id, request, callback)
  6.     if request ~= nil then
  7.         callback(true)
  8.         return nil
  9.     end
  10.  
  11.     local stat = http_output_client_list[session_id]
  12.     local ctime = os.time()
  13.     local uptime = ctime - stat.st
  14.     if uptime_skip > uptime then
  15.         return nil
  16.     end
  17.  
  18.     local content = "session" ..
  19.         ",host=" .. hostname ..
  20.         ",id=" .. stat.channel_id ..
  21.         ",name=" .. stat.channel_name ..
  22.         ",addr=" .. stat.request.addr ..
  23.         " uptime=" .. uptime ..
  24.         " " .. ctime .. "000000000"
  25.  
  26.     local event_config = {
  27.         host = _event_request.host,
  28.         port = _event_request.port,
  29.         path = _event_request.path,
  30.         method = "POST",
  31.         headers = {
  32.             "User-Agent: Astra " .. astra.version,
  33.             "Host: " .. _event_request.host .. ":" .. _event_request.port,
  34.             "Content-Type: application/x-www-form-urlencoded",
  35.             "Content-Length: " .. #content,
  36.             "Connection: close"
  37.         },
  38.         callback = function(self, response)
  39.             if response.code ~= 204 then
  40.                 log.error(("[stream.lua] event_request_send() failed %d:%s")
  41.                           :format(response.code, response.message))
  42.             end
  43.         end,
  44.         content = content,
  45.     }
  46.  
  47.     http_request(event_config)
  48. end
Advertisement
Add Comment
Please, Sign In to add comment