X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FGraylog%2FUDP.hs;fp=src%2FGraylog%2FUDP.hs;h=c925d7ead33d339be0280e02796f0fb1cb9a8da9;hb=b23afe7b9089b3177d9aee994464f72e52efbd2a;hp=656cbc88676b15bd46e988afcfd2bc583c1b4558;hpb=640e69ef77aea530af800741e453b05e2802d188;p=github%2Ffretlink%2Fhaskell-graylog.git diff --git a/src/Graylog/UDP.hs b/src/Graylog/UDP.hs index 656cbc8..c925d7e 100644 --- a/src/Graylog/UDP.hs +++ b/src/Graylog/UDP.hs @@ -5,27 +5,37 @@ module Graylog.UDP ) where import Data.Aeson -import qualified Data.ByteString.Lazy as LBS -import Data.Word +{-import Data.ByteString.Builder-} +{-import qualified Data.ByteString.Lazy as LBS-} +{-import Data.Word-} import Network.Socket.ByteString.Lazy -import System.Random +{-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 +sendLog glog msg = do + _ <- send (_graylogSocket glog) raw + print raw + return () 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 +{-sendLog :: Graylog -> GELF -> IO ()-} +{-sendLog glog msg = do-} + {-cks <- chunky glog raw-} + {-mapM_ (send $ _graylogSocket glog) cks-} + {-where-} + {-raw = encode msg-} + +{-chunky :: Graylog -> LBS.ByteString -> IO [LBS.ByteString]-} +{-chunky glog raw = do-} + {-groupId <- randomIO-} + {-splitAt gsize-} + {-where-} + {-magic = word8 0x1e <> word8 0x0f-} + {-seqNum = undefined-} + {-(count, excess) = quotRem (LBS.length raw) gzie-} + {-hlen = 12-} + {-gsize = (fromIntegral (_graylogChunkSize glog)) - hlen-}