diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Graylog/Gelf.hs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/Graylog/Gelf.hs b/src/Graylog/Gelf.hs new file mode 100644 index 0000000..67e0de7 --- /dev/null +++ b/src/Graylog/Gelf.hs | |||
@@ -0,0 +1,76 @@ | |||
1 | {-# LANGUAGE DeriveDataTypeable #-} | ||
2 | {-# LANGUAGE DeriveGeneric #-} | ||
3 | {-# LANGUAGE OverloadedStrings #-} | ||
4 | |||
5 | module Graylog.Gelf where | ||
6 | |||
7 | import Data.Aeson (ToJSON (..), Value (..), genericToJSON, | ||
8 | toJSON) | ||
9 | import Data.Aeson.Casing | ||
10 | import Data.Scientific | ||
11 | import Data.Text (Text) | ||
12 | import Data.Time | ||
13 | import Data.Typeable | ||
14 | import Data.Vector | ||
15 | import GHC.Generics | ||
16 | |||
17 | data GELF | ||
18 | = GELF | ||
19 | { _gelfVersion :: Version | ||
20 | , _gelfHost :: Text | ||
21 | , _gelfShortMessage :: Text | ||
22 | , _gelfFullMessage :: Maybe Text | ||
23 | , _gelfTimestamp :: Maybe UTCTime | ||
24 | , _gelfLevel :: Maybe SyslogLevel | ||
25 | , _gelfLine :: Maybe Word | ||
26 | , _gelfFile :: Maybe Text | ||
27 | , _gelfAdditionalFields :: Vector Field | ||
28 | } | ||
29 | deriving (Show, Typeable, Generic) | ||
30 | |||
31 | instance ToJSON GELF where | ||
32 | toJSON = genericToJSON $ aesonPrefix snakeCase | ||
33 | |||
34 | -- | ||
35 | |||
36 | data Version | ||
37 | = Version1x1 | ||
38 | deriving (Eq, Show, Typeable, Generic) | ||
39 | |||
40 | instance ToJSON Version where | ||
41 | toJSON Version1x1 = String "1.1" | ||
42 | |||
43 | -- | ||
44 | |||
45 | data SyslogLevel | ||
46 | = Emergency | ||
47 | | Alert | ||
48 | | Critical | ||
49 | | Error | ||
50 | | Warning | ||
51 | | Notice | ||
52 | | Informational | ||
53 | | Debug | ||
54 | deriving (Eq, Ord, Show, Typeable, Generic) | ||
55 | |||
56 | instance ToJSON SyslogLevel where | ||
57 | toJSON Emergency = Number 0 | ||
58 | toJSON Alert = Number 1 | ||
59 | toJSON Critical = Number 2 | ||
60 | toJSON Error = Number 3 | ||
61 | toJSON Warning = Number 4 | ||
62 | toJSON Notice = Number 5 | ||
63 | toJSON Informational = Number 6 | ||
64 | toJSON Debug = Number 7 | ||
65 | |||
66 | -- | ||
67 | |||
68 | data Field | ||
69 | = FieldString Text | ||
70 | | FieldNumber Scientific | ||
71 | deriving (Eq, Show, Typeable, Generic) | ||
72 | |||
73 | instance ToJSON Field where | ||
74 | toJSON (FieldString s) = String s | ||
75 | toJSON (FieldNumber n) = Number n | ||
76 | |||