Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added suport for :mute-for on alerts

  • Loading branch information...
commit 21bf5f784c0cebb8bf27fab0a8d6dd8d95f869a6 1 parent 5113f11
Paulo Suzart authored April 12, 2012
8  server-stats.cfg
@@ -91,7 +91,9 @@
91 91
    :alerts [{:value-type bool
92 92
              :msg "MySql is not running"
93 93
              :handlers [email]
94  
-             :trigger (= false)}]})
  94
+             :trigger (= false)
  95
+             :mute-for 300000}]})  ; does not send mail before 5 minutes passed
  96
+                                     ; since las send.
95 97
 
96 98
 (add-cmd is-apache 
97 99
   {:doc "Is Apache Running?"
@@ -100,7 +102,9 @@
100 102
    :alerts [{:value-type bool
101 103
              :msg "Apache is not running"
102 104
              :handlers [email]
103  
-             :trigger (= false)}]})
  105
+             :trigger (= false)
  106
+             :mute-for 1860000}]}); does not send mail before 30 minutes passed
  107
+                                  ; since las send.
104 108
 
105 109
 (add-cmd show-queries
106 110
   {:doc "Show a list of currently running queries"
23  src/server_stats/core.clj
@@ -13,6 +13,25 @@
13 13
      :bool #(if (= % "true") true false)
14 14
      :number #(read-string (re-find #"\d+\.?\d*" %))})
15 15
 
  16
+(defn- sanitize [w]
  17
+  (clojure.string/replace w #"\W+" "_"))
  18
+
  19
+(defn- alert? 
  20
+  "Check if the alert should be activated based on :mute-for key of a Given
  21
+  alert. Stores a file name `(str \".\" (sanitize :alert-msg))` to compare
  22
+  `lastModified`.
  23
+  Since Alerts are unamed, asumes `alert-msg` as unique among alerts."
  24
+  [f-name ms]
  25
+    (let [sf-name (str "." (sanitize f-name))
  26
+          f (clojure.java.io/file sf-name)]
  27
+    (if (.exists f)
  28
+      (let [lmodif (.lastModified f)
  29
+            now    (System/currentTimeMillis)]
  30
+            (< ms (- now lmodif)))
  31
+      (do 
  32
+        (spit sf-name "")
  33
+        true))))
  34
+
16 35
 (defn check-and-trigger-alerts 
17 36
   [^parallel_ssh.core.CommandResult cmdresult 
18 37
    ^server_stats.config.Alert alert]
@@ -22,6 +41,7 @@
22 41
                                           (fn [x#] (eval `(~(first condition-tuple) ~x# ~@(rest condition-tuple)))))
23 42
             out-lines (split-lines out)
24 43
             alert-msg (:msg alert)
  44
+            mute-for (or (:mute-for alert) -1)
25 45
             does-value-trigger-alert? (make-alert-trigger-checker (:trigger alert))
26 46
             string-to-value ((keyword (:value-type alert)) value-type-parsers)
27 47
             is-column-formatted-output? (not (nil? (:column alert)))
@@ -35,7 +55,8 @@
35 55
             alert-handler-functions (map #((keyword %) @cfg/alert-handlers) (:handlers alert))]
36 56
                 (doseq [row rows-that-triggered-an-alert,
37 57
                         handler alert-handler-functions] 
38  
-                  (handler alert-msg server row))))
  58
+                  (and (alert? alert-msg mute-for) 
  59
+                    (handler alert-msg server row)))))
39 60
 
40 61
 (defn execute-command
41 62
   "For every server, run the command, and return the result records"

0 notes on commit 21bf5f7

Please sign in to comment.
Something went wrong with that request. Please try again.