summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dmt/config.sh2
-rwxr-xr-xdmt/dmt34
2 files changed, 35 insertions, 1 deletions
diff --git a/dmt/config.sh b/dmt/config.sh
new file mode 100644
index 0000000..a19e14f
--- /dev/null
+++ b/dmt/config.sh
@@ -0,0 +1,2 @@
+# Number of lines of text to show per job on the main page
+CYCHE_LOG_TAIL_LENGTH=25
diff --git a/dmt/dmt b/dmt/dmt
index 9de6e37..7923580 100755
--- a/dmt/dmt
+++ b/dmt/dmt
@@ -7,11 +7,17 @@
CYCHE_LOG_DIR="/data/logs"
CYCHE_STATUS_FILE="/data/status"
CYCHE_VERSION_FILE="/version"
+source config.sh
integer() {
[ "$1" -eq "$1" ] >/dev/null 2>&1
}
+escape() {
+ sed 's/\\/\\\\/g; s/\r/\\r/g; s/\t/\\t/g; s/"/\\"/g' \
+ | awk '{printf "%s\\n", $0}'
+}
+
newest_job() {
ls -A "$CYCHE_LOG_DIR" | sort -rn | head -n1
}
@@ -20,6 +26,10 @@ oldest_job() {
ls -A "$CYCHE_LOG_DIR" | sort -n | head -n1
}
+log_tail() {
+ tail -n "$CYCHE_LOG_TAIL_LENGTH" "$CYCHE_LOG_DIR/$1/log" | sed 's/\r//g'
+}
+
api_status() {
status=$(cat "$CYCHE_STATUS_FILE")
[ "$status" == "" ] && active="false" || active="true"
@@ -33,4 +43,26 @@ api_status() {
printf '"oldest":%i}' "$(oldest_job)"
}
-api_status
+api_job() {
+ [ -z "$1" ] && job="$(newest_job)" || job="$1"
+ jobdir="$CYCHE_LOG_DIR/$job"
+
+ if [ -d "$jobdir" ]; then
+ status=$(cat "$CYCHE_STATUS_FILE")
+
+ result=$( ([ "$status" == "$job" ] && echo "active") \
+ || ([ -f "$jobdir/fail" ] && echo "fail") \
+ || echo "pass" )
+
+ printf 'Content-type: text/json\n\n{'
+ printf '"job":%i,' "$job"
+ printf '"hash":"%s",' "$(cat "$jobdir/hash")"
+ printf '"reason":"%s",' "$(cat "$jobdir/reason")"
+ printf '"service":"%s",' "$(cat "$jobdir/service")"
+ printf '"time":%i,' "$(cat "$jobdir/time")"
+ printf '"result":"%s",' "$result"
+ printf '"log":"%s"}' "$(log_tail "$job" | escape)"
+ fi
+}
+
+api_job