aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrewRademacher <andrew.rademacher@smrxt.com>2016-02-24 16:52:14 -0600
committerAndrewRademacher <andrew.rademacher@smrxt.com>2016-02-24 16:52:14 -0600
commit526966434f2248c1200427677dc3882668714693 (patch)
treeaa4fb861b90abf2ee444465443afe9aa375abddf
downloadhaskell-graylog-526966434f2248c1200427677dc3882668714693.tar.gz
haskell-graylog-526966434f2248c1200427677dc3882668714693.tar.zst
haskell-graylog-526966434f2248c1200427677dc3882668714693.zip
Project init; added Gelf format.
-rw-r--r--.gitignore12
-rw-r--r--LICENSE20
-rw-r--r--Makefile2
-rw-r--r--Setup.hs2
-rw-r--r--graylog.cabal30
-rw-r--r--src/Graylog/Gelf.hs76
-rw-r--r--stack.yaml35
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/
2cabal.sandbox.config
3.cabal-sandbox/
4
5dist/
6
7*.hi
8*.o
9
10*.swp
11
12.DS_Store
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d3a554d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
1Copyright (c) 2016 Andrew Rademacher
2
3
4Permission is hereby granted, free of charge, to any person obtaining a copy of
5this software and associated documentation files (the "Software"), to deal in
6the Software without restriction, including without limitation the rights to
7use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8of the Software, and to permit persons to whom the Software is furnished to do
9so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20SOFTWARE.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..f577035
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
1graylog:
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 @@
1import Distribution.Simple
2main = 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 @@
1name: graylog
2version: 0.1.0.0
3synopsis: Support for graylog output.
4description: Please see README.md
5homepage: http://github.com/githubuser/graylog#readme
6license: MIT
7license-file: LICENSE
8author: Andrew Rademacher
9maintainer: andrewrademacher@gmail.com
10copyright: 2016 Andrew Rademacher
11category: Web
12build-type: Simple
13cabal-version: >=1.10
14
15library
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
5module Graylog.Gelf where
6
7import Data.Aeson (ToJSON (..), Value (..), genericToJSON,
8 toJSON)
9import Data.Aeson.Casing
10import Data.Scientific
11import Data.Text (Text)
12import Data.Time
13import Data.Typeable
14import Data.Vector
15import GHC.Generics
16
17data 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
31instance ToJSON GELF where
32 toJSON = genericToJSON $ aesonPrefix snakeCase
33
34--
35
36data Version
37 = Version1x1
38 deriving (Eq, Show, Typeable, Generic)
39
40instance ToJSON Version where
41 toJSON Version1x1 = String "1.1"
42
43--
44
45data 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
56instance 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
68data Field
69 = FieldString Text
70 | FieldNumber Scientific
71 deriving (Eq, Show, Typeable, Generic)
72
73instance 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)
5resolver: lts-5.4
6
7# Local packages, usually specified by relative directory name
8packages:
9- '.'
10# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)
11extra-deps: []
12
13# Override default flag values for local packages and extra-deps
14flags: {}
15
16# Extra package databases containing global packages
17extra-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