Forked from longdongjohn/gist:2b274f1b6d786ce07373
Last active
February 26, 2016 06:58
-
-
Save tommyettinger/9a4aec92a8ec742a6f41 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(include "globals.clj") | |
(def c-subj (atom "")) | |
(def temp1 (atom 0)) | |
(def m1_flag (atom "")) | |
(def m2_flag (atom "")) | |
(def temp3 (atom 0)) | |
(def flag (atom 0)) | |
(def temp2 (atom 0)) | |
(def email-c (mailer {:host "smtp.gmail.com" | |
:port 587 | |
:user "[email protected]" | |
:pass "pwd" | |
:tls "true" | |
:subject (fn [events](str "Cpu Threshold reached")) | |
:body (fn [eve](str @temp3 "\nHost:"@c-subj)) | |
:from "[email protected]"})) | |
(defn user [& children] | |
(fn [e] (let [new-event (assoc e :warning "warning-limit-file")] | |
(reset! temp1 (get e :metric)) | |
(reset! m1_flag 1) | |
))) | |
(defn system [& children] | |
(fn [e] (let [new-event (assoc e :warning "warning-limit-file")] | |
(reset! temp2 (get e :metric)) | |
(reset! m2_flag 1) | |
))) | |
(defn gt [& children] | |
(fn [e] | |
(reset! c-subj (str (get e :host))); I get java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFnon this line | |
(if (= @flag 0); the reason behind the flag atom here is coz rollup wasnt working as expected and im getting bombarded with mails | |
((email-c "[email protected]") e) | |
(swap! flag inc)) | |
(if (> @flag 5) (reset! flag 0)) | |
)) | |
(streams | |
(by [:host :time] | |
(where (service #"aggregation-cpu-sum/cpu-user") | |
(user) | |
) | |
(where | |
(service #"aggregation-cpu-sum/cpu-system") | |
(system) | |
) | |
(where (and (= 1 @m2_flag) (= 1 @m1_flag) (false? (= @temp3 0))); I get an java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn on this line | |
(do | |
(reset! temp3 (+ @temp1 @temp2)) ; which is because where expects a bunch of fn values, not the number that this returns | |
(reset! m2_flag 0) ; the do makes these run, but only what the last call evaluates to will be given to where | |
(reset! m1_flag 0) | |
(if (< @temp3 cpu_threshold) (fn [& children] (prn @temp3)) | |
(gt))) | |
))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment