-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,69 @@ | ||
(in-package #:monitor) | ||
|
||
(defun api-output* (data &optional message url-format &rest url-args) | ||
(let ((target (when url-format | ||
(uri-to-url (if (stringp url-format) | ||
(apply #'format NIL url-format url-args) | ||
url-format) | ||
:representation :external | ||
:query `(("message" . ,message)))))) | ||
(if (and target (string= "true" (post/get "browser"))) | ||
(redirect target) | ||
(api-output data :message (or message "Ok.") :target target)))) | ||
|
||
(define-api monitor/series (id) (:access (perm monitor)) | ||
(api-output* (ensure-series id))) | ||
|
||
(define-api monitor/series/list () (:access (perm monitor)) | ||
(api-output* (list-series))) | ||
|
||
(define-api monitor/series/new (type &optional title interval argument[]) (:access (perm monitor)) | ||
(let ((series (add-series type :title (or* title (string-downcase type)) | ||
:interval (parse-float:parse-float (or* interval "1.0")) | ||
:arguments argument[]))) | ||
(api-output* series | ||
"Series created." | ||
(series-url series)))) | ||
|
||
(define-api monitor/series/remove (id) (:access (perm monitor)) | ||
(remove-series id) | ||
(api-output* NIL | ||
"Series deleted." | ||
"monitor/")) | ||
|
||
(define-api monitor/series/data (id &optional since before) (:access (perm monitor)) | ||
(let ((series (ensure-series id))) | ||
(api-output* (list-measurements series :since (time? since) :before (time? before))))) | ||
|
||
(define-api monitor/alert (id) (:access (perm monitor)) | ||
(api-output* (ensure-alert id))) | ||
|
||
(define-api monitor/alert/list () (:access (perm monitor)) | ||
(api-output* (list-alerts))) | ||
|
||
(define-api monitor/alert/new (series threshold &optional title duration) (:access (perm monitor)) | ||
(api-output* (add-alert series (parse-float:parse-float threshold) | ||
:title title | ||
:duration (parse-float:parse-float (or* duration "0.0"))) | ||
"Alert created." | ||
"monitor/alerts")) | ||
|
||
(define-api monitor/alert/remove (id) (:access (perm monitor)) | ||
(remove-alert id) | ||
(api-output* NIL | ||
"Alert deleted." | ||
"monitor/alerts")) | ||
|
||
(define-api monitor/alert/subscribe (id email &optional name) (:access (perm monitor)) | ||
(let ((alert (ensure-alert id))) | ||
(add-subscription alert email (or* name email)) | ||
(api-output* NIL | ||
"Subscription created." | ||
(alert-url alert)))) | ||
|
||
(define-api monitor/alert/unsubscribe (id email) (:access (perm monitor)) | ||
(let ((alert (ensure-alert id))) | ||
(remove-subscription alert email (or* name email)) | ||
(api-output* NIL | ||
"Subscription deleted." | ||
(alert-url alert)))) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,29 @@ | ||
(in-package #:monitor) | ||
|
||
(defun alert-url (alert) | ||
(uri-to-url (format NIL "monitor/alert/~a" (dm:id (ensure-alert alert))) | ||
:representation :external)) | ||
|
||
(defun series-url (series) | ||
(uri-to-url (format NIL "monitor/series/~a" (dm:field (ensure-series series) "title")) | ||
:representation :external)) | ||
|
||
(defun time? (var) | ||
(when (and var (string/= var "")) | ||
(org.shirakumo.fuzzy-dates:parse var))) | ||
|
||
(define-page dashboard "monitor/^$" (:access (perm monitor)) :clip "dashboard.ctml" | ||
(r-clip:process T :series (list-series) | ||
:alerts (list-alerts))) | ||
|
||
(define-page series "monitor/^series/(.*)$" (:uri-groups (series) :access (perm monitor) :clip "series.ctml") | ||
(let ((series (ensure-series series))) | ||
(r-clip:process T :series alert | ||
:measurements (list-measurements series | ||
:since (time? (post/get "since")) | ||
:before (time? (post/get "before")))))) | ||
|
||
(define-page alert "monitor/^alert/(.*)$" (:uri-groups (alert) :access (perm monitor) :clip "alert.ctml") | ||
(let ((alert (ensure-alert alert))) | ||
(r-clip:process T :alert alert | ||
:subscriptions (list-subscriptions alert)))) |
This file contains 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