diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Graylog/Types.hs | 26 | ||||
-rw-r--r-- | src/Graylog/UDP.hs | 19 |
2 files changed, 32 insertions, 13 deletions
diff --git a/src/Graylog/Types.hs b/src/Graylog/Types.hs index e18826b..bfee38a 100644 --- a/src/Graylog/Types.hs +++ b/src/Graylog/Types.hs | |||
@@ -5,7 +5,11 @@ module Graylog.Types | |||
5 | , _graylogHost | 5 | , _graylogHost |
6 | , _graylogPort | 6 | , _graylogPort |
7 | , _graylogAddress | 7 | , _graylogAddress |
8 | , _graylogSocket | ||
9 | , _graylogHostName | ||
10 | , ChunkSize | ||
8 | 11 | ||
12 | , defaultChunkSize | ||
9 | , openGraylog | 13 | , openGraylog |
10 | , closeGraylog | 14 | , closeGraylog |
11 | ) where | 15 | ) where |
@@ -15,17 +19,23 @@ import qualified Data.Text as T | |||
15 | import Network.BSD | 19 | import Network.BSD |
16 | import Network.Socket | 20 | import Network.Socket |
17 | 21 | ||
22 | type ChunkSize = Word | ||
23 | |||
18 | data Graylog | 24 | data Graylog |
19 | = Graylog | 25 | = Graylog |
20 | { _graylogHost :: String | 26 | { _graylogHost :: String |
21 | , _graylogPort :: String | 27 | , _graylogPort :: String |
22 | , _graylogAddress :: AddrInfo | 28 | , _graylogAddress :: AddrInfo |
23 | , _graylogSocket :: Socket | 29 | , _graylogSocket :: Socket |
24 | , _graylogHostName :: Text | 30 | , _graylogHostName :: Text |
31 | , _graylogChunkSize :: ChunkSize | ||
25 | } | 32 | } |
26 | 33 | ||
27 | openGraylog :: HostName -> ServiceName -> IO (Either String Graylog) | 34 | defaultChunkSize :: ChunkSize |
28 | openGraylog host port = do | 35 | defaultChunkSize = 8192 |
36 | |||
37 | openGraylog :: HostName -> ServiceName -> ChunkSize -> IO (Either String Graylog) | ||
38 | openGraylog host port chksize = do | ||
29 | infos <- getAddrInfo Nothing (Just host) (Just port) | 39 | infos <- getAddrInfo Nothing (Just host) (Just port) |
30 | case infos of | 40 | case infos of |
31 | [] -> return $ Left "No address info found." | 41 | [] -> return $ Left "No address info found." |
@@ -33,7 +43,7 @@ openGraylog host port = do | |||
33 | sock <- socket (addrFamily info) Datagram defaultProtocol | 43 | sock <- socket (addrFamily info) Datagram defaultProtocol |
34 | connect sock (addrAddress info) | 44 | connect sock (addrAddress info) |
35 | hostname <- getHostName | 45 | hostname <- getHostName |
36 | return $ Right $ Graylog host port info sock (T.pack hostname) | 46 | return $ Right $ Graylog host port info sock (T.pack hostname) chksize |
37 | _ -> return $ Left "Too many address infos found." | 47 | _ -> return $ Left "Too many address infos found." |
38 | 48 | ||
39 | closeGraylog :: Graylog -> IO () | 49 | closeGraylog :: Graylog -> IO () |
diff --git a/src/Graylog/UDP.hs b/src/Graylog/UDP.hs index 00b6a12..dc172b9 100644 --- a/src/Graylog/UDP.hs +++ b/src/Graylog/UDP.hs | |||
@@ -1,13 +1,22 @@ | |||
1 | module Graylog.UDP | 1 | module Graylog.UDP |
2 | ( Graylog (..) | 2 | ( sendLog |
3 | , sendLog | ||
4 | 3 | ||
5 | , module Export | 4 | , module Export |
6 | ) where | 5 | ) where |
7 | 6 | ||
8 | import Graylog.Gelf as Export | 7 | import Data.Aeson |
9 | import Graylog.Types as Export | 8 | import qualified Data.ByteString.Lazy as LBS |
9 | import Network.Socket.ByteString.Lazy | ||
10 | import System.Random.MWC | ||
11 | |||
12 | import Graylog.Gelf as Export | ||
13 | import Graylog.Types as Export | ||
10 | 14 | ||
11 | sendLog :: Graylog -> GELF -> IO () | 15 | sendLog :: Graylog -> GELF -> IO () |
12 | sendLog glog msg = undefined | 16 | sendLog glog msg = mapM_ (send $ _graylogSocket glog) cks |
17 | where | ||
18 | raw = encode msg | ||
19 | cks = chunky raw | ||
13 | 20 | ||
21 | chunky :: LBS.ByteString -> [LBS.ByteString] | ||
22 | chunky = undefined | ||