From 526966434f2248c1200427677dc3882668714693 Mon Sep 17 00:00:00 2001 From: AndrewRademacher Date: Wed, 24 Feb 2016 16:52:14 -0600 Subject: Project init; added Gelf format. --- .gitignore | 12 +++++++++ LICENSE | 20 ++++++++++++++ Makefile | 2 ++ Setup.hs | 2 ++ graylog.cabal | 30 +++++++++++++++++++++ src/Graylog/Gelf.hs | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ stack.yaml | 35 ++++++++++++++++++++++++ 7 files changed, 177 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 Setup.hs create mode 100644 graylog.cabal create mode 100644 src/Graylog/Gelf.hs create mode 100644 stack.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..94d51e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +.stack-work/ +cabal.sandbox.config +.cabal-sandbox/ + +dist/ + +*.hi +*.o + +*.swp + +.DS_Store diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d3a554d --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2016 Andrew Rademacher + + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f577035 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +graylog: + 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 @@ +import Distribution.Simple +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 @@ +name: graylog +version: 0.1.0.0 +synopsis: Support for graylog output. +description: Please see README.md +homepage: http://github.com/githubuser/graylog#readme +license: MIT +license-file: LICENSE +author: Andrew Rademacher +maintainer: andrewrademacher@gmail.com +copyright: 2016 Andrew Rademacher +category: Web +build-type: Simple +cabal-version: >=1.10 + +library + hs-source-dirs: src + default-language: Haskell2010 + + exposed-modules: Graylog.Gelf + + ghc-options: -Wall -rtsopts + + build-depends: base ==4.* + + , aeson + , aeson-casing + , scientific + , text + , time + , 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 @@ +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE OverloadedStrings #-} + +module Graylog.Gelf where + +import Data.Aeson (ToJSON (..), Value (..), genericToJSON, + toJSON) +import Data.Aeson.Casing +import Data.Scientific +import Data.Text (Text) +import Data.Time +import Data.Typeable +import Data.Vector +import GHC.Generics + +data GELF + = GELF + { _gelfVersion :: Version + , _gelfHost :: Text + , _gelfShortMessage :: Text + , _gelfFullMessage :: Maybe Text + , _gelfTimestamp :: Maybe UTCTime + , _gelfLevel :: Maybe SyslogLevel + , _gelfLine :: Maybe Word + , _gelfFile :: Maybe Text + , _gelfAdditionalFields :: Vector Field + } + deriving (Show, Typeable, Generic) + +instance ToJSON GELF where + toJSON = genericToJSON $ aesonPrefix snakeCase + +-- + +data Version + = Version1x1 + deriving (Eq, Show, Typeable, Generic) + +instance ToJSON Version where + toJSON Version1x1 = String "1.1" + +-- + +data SyslogLevel + = Emergency + | Alert + | Critical + | Error + | Warning + | Notice + | Informational + | Debug + deriving (Eq, Ord, Show, Typeable, Generic) + +instance ToJSON SyslogLevel where + toJSON Emergency = Number 0 + toJSON Alert = Number 1 + toJSON Critical = Number 2 + toJSON Error = Number 3 + toJSON Warning = Number 4 + toJSON Notice = Number 5 + toJSON Informational = Number 6 + toJSON Debug = Number 7 + +-- + +data Field + = FieldString Text + | FieldNumber Scientific + deriving (Eq, Show, Typeable, Generic) + +instance ToJSON Field where + toJSON (FieldString s) = String s + toJSON (FieldNumber n) = Number n + diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..55ab633 --- /dev/null +++ b/stack.yaml @@ -0,0 +1,35 @@ +# This file was automatically generated by stack init +# For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration/ + +# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) +resolver: lts-5.4 + +# Local packages, usually specified by relative directory name +packages: +- '.' +# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) +extra-deps: [] + +# Override default flag values for local packages and extra-deps +flags: {} + +# Extra package databases containing global packages +extra-package-dbs: [] + +# Control whether we use the GHC we find on the path +# system-ghc: true + +# Require a specific version of stack, using version ranges +# require-stack-version: -any # Default +# require-stack-version: >= 1.0.0 + +# Override the architecture used by stack, especially useful on Windows +# arch: i386 +# arch: x86_64 + +# Extra directories used by stack for building +# extra-include-dirs: [/path/to/dir] +# extra-lib-dirs: [/path/to/dir] + +# Allow a newer minor version of GHC than the snapshot specifies +# compiler-check: newer-minor -- cgit v1.2.3