diff options
author | AndrewRademacher <andrew.rademacher@smrxt.com> | 2016-02-24 16:52:14 -0600 |
---|---|---|
committer | AndrewRademacher <andrew.rademacher@smrxt.com> | 2016-02-24 16:52:14 -0600 |
commit | 526966434f2248c1200427677dc3882668714693 (patch) | |
tree | aa4fb861b90abf2ee444465443afe9aa375abddf | |
download | haskell-graylog-526966434f2248c1200427677dc3882668714693.tar.gz haskell-graylog-526966434f2248c1200427677dc3882668714693.tar.zst haskell-graylog-526966434f2248c1200427677dc3882668714693.zip |
Project init; added Gelf format.
-rw-r--r-- | .gitignore | 12 | ||||
-rw-r--r-- | LICENSE | 20 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | Setup.hs | 2 | ||||
-rw-r--r-- | graylog.cabal | 30 | ||||
-rw-r--r-- | src/Graylog/Gelf.hs | 76 | ||||
-rw-r--r-- | stack.yaml | 35 |
7 files changed, 177 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..94d51e7 --- /dev/null +++ b/.gitignore | |||
@@ -0,0 +1,12 @@ | |||
1 | .stack-work/ | ||
2 | cabal.sandbox.config | ||
3 | .cabal-sandbox/ | ||
4 | |||
5 | dist/ | ||
6 | |||
7 | *.hi | ||
8 | *.o | ||
9 | |||
10 | *.swp | ||
11 | |||
12 | .DS_Store | ||
@@ -0,0 +1,20 @@ | |||
1 | Copyright (c) 2016 Andrew Rademacher | ||
2 | |||
3 | |||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
5 | this software and associated documentation files (the "Software"), to deal in | ||
6 | the Software without restriction, including without limitation the rights to | ||
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
8 | of the Software, and to permit persons to whom the Software is furnished to do | ||
9 | so, subject to the following conditions: | ||
10 | |||
11 | The above copyright notice and this permission notice shall be included in all | ||
12 | copies or substantial portions of the Software. | ||
13 | |||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
20 | SOFTWARE. | ||
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f577035 --- /dev/null +++ b/Makefile | |||
@@ -0,0 +1,2 @@ | |||
1 | graylog: | ||
2 | docker run -t -p 9000:9000 -p 12201:12201 -p 12201:12201/udp graylog2/allinone | ||
diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs | |||
@@ -0,0 +1,2 @@ | |||
1 | import Distribution.Simple | ||
2 | main = defaultMain | ||
diff --git a/graylog.cabal b/graylog.cabal new file mode 100644 index 0000000..d7d1163 --- /dev/null +++ b/graylog.cabal | |||
@@ -0,0 +1,30 @@ | |||
1 | name: graylog | ||
2 | version: 0.1.0.0 | ||
3 | synopsis: Support for graylog output. | ||
4 | description: Please see README.md | ||
5 | homepage: http://github.com/githubuser/graylog#readme | ||
6 | license: MIT | ||
7 | license-file: LICENSE | ||
8 | author: Andrew Rademacher | ||
9 | maintainer: andrewrademacher@gmail.com | ||
10 | copyright: 2016 Andrew Rademacher | ||
11 | category: Web | ||
12 | build-type: Simple | ||
13 | cabal-version: >=1.10 | ||
14 | |||
15 | library | ||
16 | hs-source-dirs: src | ||
17 | default-language: Haskell2010 | ||
18 | |||
19 | exposed-modules: Graylog.Gelf | ||
20 | |||
21 | ghc-options: -Wall -rtsopts | ||
22 | |||
23 | build-depends: base ==4.* | ||
24 | |||
25 | , aeson | ||
26 | , aeson-casing | ||
27 | , scientific | ||
28 | , text | ||
29 | , time | ||
30 | , vector | ||
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 | |||
diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..55ab633 --- /dev/null +++ b/stack.yaml | |||
@@ -0,0 +1,35 @@ | |||
1 | # This file was automatically generated by stack init | ||
2 | # For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration/ | ||
3 | |||
4 | # Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) | ||
5 | resolver: lts-5.4 | ||
6 | |||
7 | # Local packages, usually specified by relative directory name | ||
8 | packages: | ||
9 | - '.' | ||
10 | # Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) | ||
11 | extra-deps: [] | ||
12 | |||
13 | # Override default flag values for local packages and extra-deps | ||
14 | flags: {} | ||
15 | |||
16 | # Extra package databases containing global packages | ||
17 | extra-package-dbs: [] | ||
18 | |||
19 | # Control whether we use the GHC we find on the path | ||
20 | # system-ghc: true | ||
21 | |||
22 | # Require a specific version of stack, using version ranges | ||
23 | # require-stack-version: -any # Default | ||
24 | # require-stack-version: >= 1.0.0 | ||
25 | |||
26 | # Override the architecture used by stack, especially useful on Windows | ||
27 | # arch: i386 | ||
28 | # arch: x86_64 | ||
29 | |||
30 | # Extra directories used by stack for building | ||
31 | # extra-include-dirs: [/path/to/dir] | ||
32 | # extra-lib-dirs: [/path/to/dir] | ||
33 | |||
34 | # Allow a newer minor version of GHC than the snapshot specifies | ||
35 | # compiler-check: newer-minor | ||