packages feed

pub (empty) → 1.0.0

raw patch · 7 files changed

+248/−0 lines, 7 filesdep +ConfigFiledep +basedep +bytestringsetup-changed

Dependencies added: ConfigFile, base, bytestring, cmdargs, containers, groom, hedis, hslogger, mtl, network, pipes, pipes-bytestring, safe, system-filepath, text, time, transformers

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Parnell++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Parnell nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Makefile view
@@ -0,0 +1,21 @@+.PHONY: test++prog = ghc+path = /usr/bin/ghc-7.6.3++all: deps build install++tags:+	hasktags --etags --output='TAGS' *++build:+	cabal configure --with-$(prog)=$(path) && cabal build --with-$(prog)=$(path)++install:+	cabal install -w $(path)++deps:+	cabal install --only-dependencies -w $(path)++test: build+	cabal test
+ README.org view
@@ -0,0 +1,8 @@+* Welcome!+  This CLI utility pipes from stdin to a redis pub/sub channel.++** Install+   You can either get a binary or compile it.++** Example+   =tail -F /some/log/file | grep "logfileProperty" | pub -c "logline"=
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ pub.cabal view
@@ -0,0 +1,79 @@+Name:                   pub+Version:                1.0.0+Author:                 Parnell Springmeyer <parnell@digitalmentat.com>+Maintainer:             Parnell Springmeyer <parnell@digitalmentat.com>+License:                BSD3+License-File:           LICENSE+Synopsis:               Pipe stdin to a redis pub/sub channel++Description:++  `pub` is an executable for piping data from stdin to a specified+  Redis pub/sub channel.+  .+  A typical use for this tool is to tail a log file, match a specific+  line with grep, and pipe it into Redis where multiple consumers can+  do something different with each incoming log line:+  .+  > tail -F /var/log/somelogfile.log | grep "tracker.gps.parsed" | pub loglines++Cabal-Version:          >= 1.10+Build-Type:             Simple++Data-Files:+  Makefile+  LICENSE+  README.org++Executable pub+  Default-Language:     Haskell2010+  HS-Source-Dirs:       src+  GHC-Options:          -threaded -Wall -fwarn-tabs -funbox-strict-fields -O2+                        -fno-warn-orphans -fno-warn-unused-do-bind -rtsopts -with-rtsopts=-N+  Main-Is:              Main.hs+  Other-Modules:        Pub.Internal++  Build-Depends:+    base                      >= 4        && < 5,+    network                   >= 2.4.2.2  && < 2.5,+    bytestring                >= 0.10.0.2 && < 0.10.1,+    cmdargs                   >= 0.10.7   && < 0.11,+    hslogger                  >= 1.2.3    && < 1.3,+    ConfigFile                >= 1.1.1    && < 1.2,+    text                      >= 1.1.0.1  && < 1.2,+    safe                      >= 0.3      && < 0.4,+    containers                >= 0.5.0.0  && < 0.6,+    hedis                     >= 0.6      && < 0.7,+    pipes                     >= 4.1.1    && < 4.2,+    pipes-bytestring          >= 2        && < 3,+    mtl                       >= 2.1      && < 2.3,+    system-filepath           >= 0.4.12   && < 0.5,+    groom                     >= 0.1.2    && < 0.2,+    time                      >= 1.4      && < 1.5,+    transformers              >= 0.4      && < 0.5++-- Test-Suite tests+--   Type:                 exitcode-stdio-1.0+--   Default-Language:     Haskell2010+--   Hs-Source-Dirs:       test, src+--   Ghc-Options:          -Wall+--   Main-Is:              Test.hs+--   Other-Modules:        Pub.Internal++--   Build-Depends:+--     base                       >= 4.4      && < 5,+--     groom                      >= 0.1.2    && < 0.2,+--     cmdargs                    >= 0.10.7   && < 0.11,+--     hslogger                   >= 1.2.3    && < 1.3,+--     system-filepath            >= 0.4.12   && < 0.5,+--     bytestring                 >= 0.9.1    && < 0.11,+--     QuickCheck                 >= 2.6      && < 2.8,+--     HUnit                      >= 1.2.5.2  && < 1.3,+--     tasty                      >= 0.8      && < 0.9,+--     tasty-golden               >= 2.2.1    && < 2.3,+--     tasty-hunit                >= 0.8.0.1  && < 0.9,+--     tasty-quickcheck           >= 0.8      && < 0.9++Source-Repository head+  Type:                 git+  Location:             https://github.com/ixmatus/pub
+ src/Main.hs view
@@ -0,0 +1,42 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Main+-- Copyright   :  (C) 2014 Parnell Springmeyer+-- License     :  AllRightsReserved+-- Maintainer  :  Parnell Springmeyer <parnell@digitalmentat.com>+-- Stability   :  stable+--+-- This is the entry point for the `pub` executable. Main sets up+-- the cli options configuration and parses configuration file options.+----------------------------------------------------------------------------++{-# LANGUAGE OverloadedStrings #-}++module Main where++import           Data.Version           (showVersion)+import           Paths_pub              (version)+import           System.Console.CmdArgs++import           Pub+import           Pub.Internal++-- | Command line argument configuration.+--+-- Help messages, switches, options, and the human-readable version+-- number is configured here.+programArgs :: PArgs+programArgs = PArgs+    { chan  = def &= argPos 0 &= typ "CHANNEL"+    , host  = def &= name "h" &= typ "STRING" &= help "Redis host (default `localhost`)"+    , port  = def &= name "p" &= help "Redis port (default `6379`)"+    , db    = def &= name "d" &= help "Redis database (default `0`)"+    } &=+    verbosity &=+    help    "Pipe stdin to a pub/sub channel." &=+    summary ("pub v" ++ showVersion version) &=+    noAtExpand &=+    details ["Given an input on stdin, pipe to a redis pub/sub channel."]++main :: IO ()+main = cmdArgs programArgs >>= handleOpts >>= pipePublish
+ src/Pub/Internal.hs view
@@ -0,0 +1,66 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Pub.Internal+-- Copyright   :  (C) 2014 Parnell Springmeyer+-- License     :  AllRightsReserved+-- Maintainer  :  Parnell Springmeyer <parnell@digitalmentat.com>+-- Stability   :  stable+--+-- Internal functions and types for the `Main` program. Mostly+-- responsible for defining the `cmdargs` data type, parsing+-- configuration, and setting the log level.+----------------------------------------------------------------------------++{-# LANGUAGE DataKinds          #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE OverloadedStrings  #-}+{-# LANGUAGE StandaloneDeriving #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}++module Pub.Internal where++import           Control.Applicative+import qualified Data.ByteString.Char8   as C8+import           Database.Redis          as R+import           Network.Socket.Internal as NSI (PortNumber)+import           System.Console.CmdArgs+import           System.Log.Logger+import           Text.Groom              (groom)++-- | Data type for program CLI options.+data PArgs = PArgs+    { chan :: String+    , host :: Maybe String+    , port :: Maybe Integer+    , db   :: Maybe Integer+    } deriving (Data, Typeable, Show, Eq)++-- | Data type for settings once merged from CLI.+data Settings = Settings+    { loglevel  :: !Priority+    , channel   :: C8.ByteString+    , redisHost :: Maybe HostName+    , redisPort :: Maybe PortID+    , redisDB   :: Maybe Integer+    } deriving (Show, Eq)++-- | Given options, set the logging level, and create the settings+-- record.+handleOpts :: PArgs -> IO Settings+handleOpts cliopts = do+    whenNormal $ updateGlobalLogger "Console" (setLevel ERROR)+    whenLoud   $ updateGlobalLogger "Console" (setLevel DEBUG)++    let c    = C8.pack $ chan cliopts+        p    = (fromInteger <$> (port cliopts)) :: Maybe NSI.PortNumber+        conf = Settings { loglevel  = INFO+                        , channel   = c+                        , redisHost = host cliopts+                        , redisPort = R.PortNumber <$> p+                        , redisDB   = db cliopts+                        }++    debugM "Console" "Configuration parsed"+    debugM "Console" $ groom conf++    return conf