From d9a5d441ca9b5ae766311702557bf9f1ff0255b1 Mon Sep 17 00:00:00 2001 From: AndrewRademacher Date: Sun, 28 Feb 2016 14:38:16 -0600 Subject: Added readme, license, and light commenting. --- LICENSE | 25 +++++++++---------------- README.md | 16 ++++++++++++++++ graylog.cabal | 7 ++++--- src/Graylog/Gelf.hs | 2 ++ src/Graylog/Types.hs | 8 +++++++- src/Graylog/UDP.hs | 1 + 6 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 README.md diff --git a/LICENSE b/LICENSE index d3a554d..ac298e2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,20 +1,13 @@ -Copyright (c) 2016 Andrew Rademacher + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + 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: + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION -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. + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..94fefbe --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Graylog +This library provides support for sending GELF formatted messages to Graylog. +Currently the UDP chunked method is the only method supported. + +```haskell +import Graylog.UDP + +main :: IO () +main = do + eglog <- openGraylog "192.168.99.100" "12201" defaultChunkSize + case eglog of + Left e -> assertFailure e + Right g -> sendLog g sample >> closeGraylog g + where + sample = simpleGelf "localhost" "hello world!" +``` diff --git a/graylog.cabal b/graylog.cabal index 47c8b7d..c1b0288 100644 --- a/graylog.cabal +++ b/graylog.cabal @@ -1,9 +1,10 @@ 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 +description: Support for sending GELF formatted messages to graylog over + chunked UDP. +homepage: https://github.com/AndrewRademacher/haskell-graylog +license: WTFPL license-file: LICENSE author: Andrew Rademacher maintainer: andrewrademacher@gmail.com diff --git a/src/Graylog/Gelf.hs b/src/Graylog/Gelf.hs index cd68e05..ee17e3d 100644 --- a/src/Graylog/Gelf.hs +++ b/src/Graylog/Gelf.hs @@ -2,6 +2,8 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-} +-- | Default formatting for Graylog messages, +-- see http://docs.graylog.org/en/latest/pages/gelf.html module Graylog.Gelf where import Data.Aeson (ToJSON (..), Value (..), genericToJSON, diff --git a/src/Graylog/Types.hs b/src/Graylog/Types.hs index 5c32a8b..5ec779b 100644 --- a/src/Graylog/Types.hs +++ b/src/Graylog/Types.hs @@ -22,8 +22,11 @@ import qualified Data.Text as T import Network.BSD import Network.Socket +-- | The maximum size of each datagram when using UDP transit methods. type ChunkSize = Word +-- | Handle for a socket connected to Graylog. In some cases this socket +-- is UDP and will not have a maintained session. data Graylog = Graylog { _graylogHost :: String @@ -38,7 +41,10 @@ defaultChunkSize :: ChunkSize defaultChunkSize = 8192 openGraylog - :: HostName -> ServiceName -> ChunkSize -> IO (Either String Graylog) + :: HostName -- ^ The host on which graylog is running. + -> ServiceName -- ^ The port on which graylog is running. + -> ChunkSize -- ^ The maximum size of each UDP datagram. + -> IO (Either String Graylog) openGraylog h p cksize | cksize < 1024 = return $ Left "ChunkSize must be at least 1024." | otherwise = getAddrInfo Nothing (Just h) (Just p) >>= \case diff --git a/src/Graylog/UDP.hs b/src/Graylog/UDP.hs index cd7fe5a..7c8eb84 100644 --- a/src/Graylog/UDP.hs +++ b/src/Graylog/UDP.hs @@ -1,3 +1,4 @@ +-- | UDP Chunked support for sending messages to graylog. module Graylog.UDP ( sendLog -- cgit v1.2.3