lib/sysdig/get_alert_notifications.rb in sysdig-0.2.4 vs lib/sysdig/get_alert_notifications.rb in sysdig-0.3.0
- old
+ new
@@ -1,11 +1,26 @@
class Sysdig::GetAlertNotifications < Sysdig::Request
def real(from, to)
- from_i = from.to_i * 1_000_000
- to_i = to.to_i * 1_000_000
+ from_i, to_i = timestamps(from, to)
service.request(
:path => "/api/notifications",
:params => {"from" => from_i, "to" => to_i},
+ )
+ end
+
+ def timestamps(*args)
+ args.map { |a| a.to_i * 1_000_000 }
+ end
+
+ def mock(from, to)
+ from_i, to_i = timestamps(from, to)
+
+ notifications = service.data[:alert_notifications].values.select { |an|
+ an["timestamp"] >= from_i && an["timestamp"] <= to_i
+ }
+
+ service.response(
+ :body => { "notifications" => notifications },
)
end
end