aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Graylog/UDP.hs
blob: 656cbc88676b15bd46e988afcfd2bc583c1b4558 (plain) (blame)
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
module Graylog.UDP
   ( sendLog

   , module Export
   ) where

import           Data.Aeson
import qualified Data.ByteString.Lazy           as LBS
import           Data.Word
import           Network.Socket.ByteString.Lazy
import           System.Random

import           Graylog.Gelf                   as Export
import           Graylog.Types                  as Export

sendLog :: Graylog -> GELF -> IO ()
sendLog glog msg = mapM_ (send $ _graylogSocket glog) cks
   where
      raw = encode msg
      cks = chunky glog raw

chunky :: Graylog -> LBS.ByteString -> IO [LBS.ByteString]
chunky glog raw = do
   groupId <- randomIO
   splitAt gsize
   where
      magic = undefined
      seq   = undefined
      total = undefined
      hlen  = 12
      gsize = (fromIntegral (_graylogChunkSize glog)) - hlen