aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrewRademacher <andrew.rademacher@smrxt.com>2016-02-24 20:39:47 -0600
committerAndrewRademacher <andrew.rademacher@smrxt.com>2016-02-24 20:39:47 -0600
commit2ff46fce748b0e813f13f03c034065092145a28d (patch)
tree1c70beb0058dba6c3edebe8b7efbfc73c8ea7350
parent15981d57cda18a19fcb3012172a9f0994abfd97a (diff)
downloadhaskell-graylog-2ff46fce748b0e813f13f03c034065092145a28d.tar.gz
haskell-graylog-2ff46fce748b0e813f13f03c034065092145a28d.tar.zst
haskell-graylog-2ff46fce748b0e813f13f03c034065092145a28d.zip
Defined Graylog type to contain connection informaiton.
-rw-r--r--graylog.cabal3
-rw-r--r--src/Graylog/Types.hs42
-rw-r--r--src/Graylog/UDP.hs14
3 files changed, 49 insertions, 10 deletions
diff --git a/graylog.cabal b/graylog.cabal
index b3c1a53..cab25b9 100644
--- a/graylog.cabal
+++ b/graylog.cabal
@@ -17,6 +17,9 @@ library
17 default-language: Haskell2010 17 default-language: Haskell2010
18 18
19 exposed-modules: Graylog.Gelf 19 exposed-modules: Graylog.Gelf
20 , Graylog.UDP
21
22 other-modules: Graylog.Types
20 23
21 ghc-options: -Wall -rtsopts 24 ghc-options: -Wall -rtsopts
22 25
diff --git a/src/Graylog/Types.hs b/src/Graylog/Types.hs
new file mode 100644
index 0000000..e18826b
--- /dev/null
+++ b/src/Graylog/Types.hs
@@ -0,0 +1,42 @@
1{-# LANGUAGE RecordWildCards #-}
2
3module Graylog.Types
4 ( Graylog
5 , _graylogHost
6 , _graylogPort
7 , _graylogAddress
8
9 , openGraylog
10 , closeGraylog
11 ) where
12
13import Data.Text (Text)
14import qualified Data.Text as T
15import Network.BSD
16import Network.Socket
17
18data Graylog
19 = Graylog
20 { _graylogHost :: String
21 , _graylogPort :: String
22 , _graylogAddress :: AddrInfo
23 , _graylogSocket :: Socket
24 , _graylogHostName :: Text
25 }
26
27openGraylog :: HostName -> ServiceName -> IO (Either String Graylog)
28openGraylog host port = do
29 infos <- getAddrInfo Nothing (Just host) (Just port)
30 case infos of
31 [] -> return $ Left "No address info found."
32 [info] -> do
33 sock <- socket (addrFamily info) Datagram defaultProtocol
34 connect sock (addrAddress info)
35 hostname <- getHostName
36 return $ Right $ Graylog host port info sock (T.pack hostname)
37 _ -> return $ Left "Too many address infos found."
38
39closeGraylog :: Graylog -> IO ()
40closeGraylog Graylog{..} = close _graylogSocket
41
42
diff --git a/src/Graylog/UDP.hs b/src/Graylog/UDP.hs
index 6aec108..00b6a12 100644
--- a/src/Graylog/UDP.hs
+++ b/src/Graylog/UDP.hs
@@ -2,18 +2,12 @@ module Graylog.UDP
2 ( Graylog (..) 2 ( Graylog (..)
3 , sendLog 3 , sendLog
4 4
5 , module Graylog.Gelf 5 , module Export
6 ) where 6 ) where
7 7
8import Network.Socket 8import Graylog.Gelf as Export
9 9import Graylog.Types as Export
10import Graylog.Gelf
11
12data Graylog
13 = Graylog
14 { _graylogHost :: String
15 , _graylogPort :: String
16 }
17 10
18sendLog :: Graylog -> GELF -> IO () 11sendLog :: Graylog -> GELF -> IO ()
19sendLog glog msg = undefined 12sendLog glog msg = undefined
13