Skip to content

Instantly share code, notes, and snippets.

@jamtur01
Last active August 29, 2015 14:22
Show Gist options
  • Save jamtur01/b68af37bbddf7b34fc56 to your computer and use it in GitHub Desktop.
Save jamtur01/b68af37bbddf7b34fc56 to your computer and use it in GitHub Desktop.
(def header "Monitoring alert from Riemann\n\n")
(def footer "This is an automated Riemann notification. Please do not reply.")
(defn format-subject
"Format the email subject"
[events]
(apply format "Alert for service %s on host %s" (clojure.string/join ", " (map :service events)) (map :host events))
)
(defn format-body
"Format the email body"
[events]
(apply str header "Host: " (get-in (first events) [:host]) "\nService: " (get-in (first events) [:service]) "\nTime: " (riemann.common/time-at (get-in (first events) [:time])) "\nService state is " (get-in (first events) [:state]) "\n\n" footer))
(def email (mailer {:from "[email protected]"
:subject (fn [events] (format-subject events))
:body (fn [events] (format-body events))
}))
(defn alert
"Generic alert processor"
[destination & recipients]
(condp = destination
"email" (email (apply str recipients))
#(info "Invalid alert destination" destination "specified for event:" %))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment