(ns riemann.campfire
  "Forwards events to Campfire"
  (:use [clojure.string :only [join]])
  (:require [clj-campfire.core :as cf]))

(defn cf-settings
  "Setup settings for campfire. Required information is your api-token, ssl connection
  true or false, and your campfire sub-domain."
  [token ssl sub-domain]
  {:api-token token, :ssl ssl, :sub-domain sub-domain})

(defn room
  "Sets up the room to send events too. Pass in the settings created with cf-settings
  and the room name"
  [settings room-name]
  (cf/room-by-name settings room-name))

(defn format_string
  [e]
  (str (join " " ["HOST:" (str (:host e)) "SERVICE:" (str (:service e)) "STATE:" (str (:state e)) "DESC:" (str (:description e))]))
  )

(defn campfire
  "Creates an adaptor to forward events to campfire.
  TODO: write more here once the event formatting is better.
  TODO: tests
  Tested with:
  (streams
    (by [:host, :service]
      (let [camp (campfire \"token\", true, \"sub-domain\", \"room\")]
        camp)))"
  [token ssl sub-domain room-name]
  (fn [e]
    (let [string (format_string e)
          settings (cf-settings token ssl sub-domain)
          ]
      (cf/message (room settings room-name) string))))

(ns riemann.campfire
  "Forwards events to Campfire"
  (:use [clojure.string :only [join upper-case]])
  (:require [clj-campfire.core :as cf]))

(defn cf-settings
  "Setup settings for campfire. Required information is your api-token, ssl connection
  true or false, and your campfire sub-domain."
  [token ssl sub-domain]
  {:api-token token, :ssl ssl, :sub-domain sub-domain})

(defn room
  "Sets up the room to send events too. Pass in the settings created with cf-settings
  and the room name"
  [settings room-name]
  (cf/room-by-name settings room-name))

(defn campfire_message
  "Formats an event into a string"
  [e]
  (str (join " " ["Riemann alert on" (str (:host e)) "-" (str (:service e)) "is" (upper-case (str (:state e))) "- Description:" (str (:description e))])))

(defn campfire
  "Creates an adaptor to forward events to campfire. The campfire event will
  contain the host, state, service, metric and description.

  Tested with:
  (streams
    (by [:host, :service]
      (let [camp (campfire \"token\", true, \"sub-domain\", \"room\")]
        camp)))"
  [token ssl sub-domain room-name]
  (fn [e]
    (let [string (campfire_message e)
          settings (cf-settings token ssl sub-domain)]
      (cf/message (room settings room-name) string))))

Improve message formatting and fn descriptions
Improve message formatting and fn descriptions

eric/riemann,bg451/riemann,counsyl/riemann,patrox/riemann,irudyak/riemann,pradeepchhetri/riemann,rekhajoshm/riemann,forter/riemann,cswaroop/riemann,topecz/riemann,nelhage/riemann,topecz/riemann,VideoAmp/riemann-1,pyr/riemann,vincentbernat/riemann,VideoAmp/riemann-1,counsyl/riemann,pradeepchhetri/riemann,ClodoCorp/riemann,aphyr/riemann,mirwan/riemann,jamtur01/riemann,bfritz/riemann,twosigma/riemann,patrox/riemann,bmhatfield/riemann,rekhajoshm/riemann,hugoduncan/riemann,nelhage/riemann,cswaroop/riemann,tzach/riemann,fullcontact/riemann,pharaujo/riemann,hugoduncan/riemann,micrub/riemann,stanislas/riemann,vixns/riemann,timbuchwaldt/riemann,bg451/riemann,ClodoCorp/riemann,shokunin/riemann,twosigma/riemann,mirwan/riemann,mfournier/riemann,rhysr/riemann,micrub/riemann,cswaroop/riemann,bowlofstew/riemann,vincentbernat/riemann,jamtur01/riemann,mbuczko/riemann,patrickod/riemann,LubyRuffy/riemann,rhysr/riemann,twosigma/riemann,joerayme/riemann,DasAllFolks/riemann,lispmeister/riemann,algernon/riemann,hugoduncan/riemann,alq666/riemann,lispmeister/riemann,udoprog/riemann,abailly/riemann,riemann/riemann,algernon/riemann,jeanpralo/riemann,DasAllFolks/riemann,vixns/riemann,robashton/riemann,LubyRuffy/riemann,nelhage/riemann,joerayme/riemann,patrox/riemann,Anvil/riemann,fullcontact/riemann,nberger/riemann,bmhatfield/riemann,nberger/riemann,yeller/riemann,fullcontact/riemann,moonranger/riemann,forter/riemann,stanislas/riemann,udoprog/riemann,moonranger/riemann,yeller/riemann,pyr/riemann,tzach/riemann,timbuchwaldt/riemann,lispmeister/riemann,abailly/riemann,stanislas/riemann,robashton/riemann,bowlofstew/riemann,Anvil/riemann,AkihiroSuda/riemann,mfournier/riemann,shokunin/riemann,bwilber/riemann,jeanpralo/riemann,tzach/riemann,irudyak/riemann,patrickod/riemann,alq666/riemann,rhysr/riemann,riemann/riemann,mfournier/riemann,aphyr/riemann,algernon/riemann,yeller/riemann,mirwan/riemann,mbuczko/riemann,micrub/riemann,eric/riemann,forter/riemann,bwilber/riemann,pharaujo/riemann,topecz/riemann,shokunin/riemann,ClodoCorp/riemann,zamaterian/riemann,bfritz/riemann,zamaterian/riemann,udoprog/riemann,AkihiroSuda/riemann,rekhajoshm/riemann,patrickod/riemann