I am using ELK (logstash, ES, Kibana) stack for log analysis and Riemann for alerting. I have logs in which users is one of the fields parsed by logstash and I send the events to riemann from riemann output plugin.
Logstash parses logs and user is one of the field. Eg: logs parsed
Timestamp user command-name
2014-06-07... root sh ./scripts/abc.sh
2014-06-08... sid sh ./scripts/xyz.sh
2014-06-08... abc sh ./scripts/xyz.sh
2014-06-09... root sh ./scripts/xyz.sh
Logstash:
riemann {
riemann_event => {
"service" => "logins"
"unique_user" => "%{user}"
}
}
So users values will be like: root, sid, abc, root, sid, def, etc....
So I split stream by user i.e one stream for each unique user. Now, I want to alert when number of unique users count go more than 3. I wrote the following but it's not achieving my purpose.
Riemann:
(streams
(where (service "logins")
(by :unique_user
(moving-time-window 3600
(smap (fn [events]
(let
[users (count events)]
(if (> users 3)
(email "abc@gmail.com")
))))))))
I am new to Riemann and clojure. Any help is appreciated.