Created
June 6, 2015 12:58
-
-
Save jamtur01/711c58d3fab5e9678144 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns examplecom.email | |
"Riemann email alerting" | |
(:require [riemann.common :refer :all] | |
[riemann.core :refer :all] | |
[riemann.email :refer :all]) | |
) | |
(def header "Monitoring alert from Riemann\n\n") | |
(def footer "This is an automated Riemann notification. Please do not reply.") | |
(defn context | |
"Add some contextual event data" | |
[event service] | |
(prn (riemann.index/lookup (:index @core) (:host event) service)) | |
) | |
(defn format-subject | |
"Format the email subject" | |
[events] | |
(apply format "Service %s in state %s on host %s" (clojure.string/join ", " (map :service events)) (clojure.string/join ", " (map :state events)) (map :host events)) | |
) | |
(defn format-body | |
"Format the email body" | |
[events] | |
(clojure.string/join "\n\n\n" | |
(map | |
(fn [event] | |
(str | |
header | |
"At " (time-at (:time event)) "\n" | |
"Host: " (:host event) "\n" | |
"Service: " (:service event) "\n" | |
"State: " (:state event) "\n" | |
"Metric: " (if (ratio? (:metric event)) | |
(double (:metric event)) | |
(:metric event)) "\n" | |
"Tags: [" (clojure.string/join ", " (:tags event)) "]" | |
"\n\n" | |
"Description" (:description event) | |
"\n" | |
"Context" (context event "cpu-0/cpu-idle") "\n" | |
footer)) | |
events)) | |
) | |
(def email (mailer {:from "[email protected]" | |
:subject (fn [events] (format-subject events)) | |
:body (fn [events] (format-body events)) | |
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WARN [2015-06-06 12:58:12,677] Thread-5 - riemann.streams - riemann.email$mailer$make_stream__6539$stream__6540@910ff5c threw | |
java.lang.ClassCastException: riemann.core$core cannot be cast to java.util.concurrent.Future | |
at clojure.core$deref_future.invoke(core.clj:2180) | |
at clojure.core$deref.invoke(core.clj:2201) | |
at examplecom.email$context.invoke(email.clj:14) | |
at examplecom.email$format_body$fn__169.invoke(email.clj:42) | |
at clojure.core$map$fn__4245.invoke(core.clj:2559) | |
at clojure.lang.LazySeq.sval(LazySeq.java:40) | |
at clojure.lang.LazySeq.seq(LazySeq.java:49) | |
at clojure.lang.LazySeq.first(LazySeq.java:71) | |
at clojure.lang.RT.first(RT.java:577) | |
at clojure.core$first.invoke(core.clj:55) | |
at clojure.string$join.invoke(string.clj:185) | |
at examplecom.email$format_body.invoke(email.clj:27) | |
at examplecom.email$fn__174.invoke(email.clj:49) | |
at riemann.email$email_event.invoke(email.clj:15) | |
at riemann.email$mailer$make_stream__6539$stream__6540.invoke(email.clj:69) | |
at riemann.streams$adjust$stream__3756$fn__3767.invoke(streams.clj:1358) | |
at riemann.streams$adjust$stream__3756.invoke(streams.clj:1358) | |
at examplecom.monitoring.services$check_process$stream__218$fn__223.invoke(monitoring.clj:18) | |
at examplecom.monitoring.services$check_process$stream__218.invoke(monitoring.clj:18) | |
at riemann.streams$match$stream__3514$fn__3525.invoke(streams.clj:1209) | |
at riemann.streams$match$stream__3514.invoke(streams.clj:1209) | |
at riemann.config$eval267$stream__268$fn__273.invoke(riemann.config:23) | |
at riemann.config$eval267$stream__268.invoke(riemann.config:23) | |
at riemann.streams$default$stream__3731$fn__3742.invoke(streams.clj:1328) | |
at riemann.streams$default$stream__3731.invoke(streams.clj:1328) | |
at riemann.core$stream_BANG_$fn__4415.invoke(core.clj:19) | |
at riemann.core$stream_BANG_.invoke(core.clj:18) | |
at riemann.core$reaper$worker__4529$fn__4539.invoke(core.clj:303) | |
at riemann.core$reaper$worker__4529.invoke(core.clj:297) | |
at riemann.service.ThreadService$thread_service_runner__1973$fn__1974.invoke(service.clj:71) | |
at riemann.service.ThreadService$thread_service_runner__1973.invoke(service.clj:70) | |
at clojure.lang.AFn.run(AFn.java:22) | |
at java.lang.Thread.run(Thread.java:745) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment