]> git.immae.eu Git - github/fretlink/haskell-graylog.git/commitdiff
Defined sendLog function.
authorAndrewRademacher <andrew.rademacher@smrxt.com>
Thu, 25 Feb 2016 03:02:15 +0000 (21:02 -0600)
committerAndrewRademacher <andrew.rademacher@smrxt.com>
Thu, 25 Feb 2016 03:02:15 +0000 (21:02 -0600)
graylog.cabal
src/Graylog/Types.hs
src/Graylog/UDP.hs

index cab25b9f3e777b6319ecba77d1d164b34d16b33d..3eaa8125da3a2bf5162c8cae8c4df5bdf07b3503 100644 (file)
@@ -27,6 +27,8 @@ library
    
                      ,  aeson
                      ,  aeson-casing
+                     ,  bytestring
+                     ,  mwc-random
                      ,  network
                      ,  scientific
                      ,  text
index e18826bcd01ac53893a425520e590bb9e23af3e2..bfee38aca7cc6d342cb94bc4364c9a9d3da01a34 100644 (file)
@@ -5,7 +5,11 @@ module Graylog.Types
    , _graylogHost
    , _graylogPort
    , _graylogAddress
+   , _graylogSocket
+   , _graylogHostName
+   , ChunkSize
 
+   , defaultChunkSize
    , openGraylog
    , closeGraylog
    ) where
@@ -15,17 +19,23 @@ import qualified Data.Text      as T
 import           Network.BSD
 import           Network.Socket
 
+type ChunkSize = Word
+
 data Graylog
    = Graylog
-      { _graylogHost     :: String
-      , _graylogPort     :: String
-      , _graylogAddress  :: AddrInfo
-      , _graylogSocket   :: Socket
-      , _graylogHostName :: Text
+      { _graylogHost      :: String
+      , _graylogPort      :: String
+      , _graylogAddress   :: AddrInfo
+      , _graylogSocket    :: Socket
+      , _graylogHostName  :: Text
+      , _graylogChunkSize :: ChunkSize
       }
 
-openGraylog :: HostName -> ServiceName -> IO (Either String Graylog)
-openGraylog host port = do
+defaultChunkSize :: ChunkSize
+defaultChunkSize = 8192
+
+openGraylog :: HostName -> ServiceName -> ChunkSize -> IO (Either String Graylog)
+openGraylog host port chksize = do
    infos <- getAddrInfo Nothing (Just host) (Just port)
    case infos of
       []     -> return $ Left "No address info found."
@@ -33,7 +43,7 @@ openGraylog host port = do
          sock <- socket (addrFamily info) Datagram defaultProtocol
          connect sock (addrAddress info)
          hostname <- getHostName
-         return $ Right $ Graylog host port info sock (T.pack hostname)
+         return $ Right $ Graylog host port info sock (T.pack hostname) chksize
       _      -> return $ Left "Too many address infos found."
 
 closeGraylog :: Graylog -> IO ()
index 00b6a1244d395004b35d0647a189d4930e10b803..dc172b906ed5fafe7e821e027b9ce76073400d9e 100644 (file)
@@ -1,13 +1,22 @@
 module Graylog.UDP
-   ( Graylog (..)
-   , sendLog
+   ( sendLog
 
    , module Export
    ) where
 
-import           Graylog.Gelf  as Export
-import           Graylog.Types as Export
+import           Data.Aeson
+import qualified Data.ByteString.Lazy           as LBS
+import           Network.Socket.ByteString.Lazy
+import           System.Random.MWC
+
+import           Graylog.Gelf                   as Export
+import           Graylog.Types                  as Export
 
 sendLog :: Graylog -> GELF -> IO ()
-sendLog glog msg = undefined
+sendLog glog msg = mapM_ (send $ _graylogSocket glog) cks
+   where
+      raw = encode msg
+      cks = chunky raw
 
+chunky :: LBS.ByteString -> [LBS.ByteString]
+chunky = undefined