dist_os_SCRIPTS = ${srcdir}/create ${srcdir}/import ${srcdir}/export \
${srcdir}/rename ${srcdir}/verify ${srcdir}/pithcat \
${srcdir}/copy-monitor.py ${srcdir}/helper-monitor.py \
- ${srcdir}/stderr-monitor.py
+ ${srcdir}/host-monitor.py
dist_os_DATA = ${srcdir}/ganeti_api_version ${srcdir}/parameters.list \
${srcdir}/variants.list
log_info() {
echo "$*" >&2
- local type="$MSG_TYPE_INFO"
- local msg="[\"$(sed 's/"/\\"/g' <<< "$@")\"]"
-
- report="{\"type\":\"$type\","
- report+="\"timestamp\":$(date +%s.%N),"
- report+="\"messages\":$msg}"
+ local report="$(./host-monitor.py info <<< "$*")"
eval "echo $(printf "%q" "$report") >&${MONITOR_FD}"
}
report_error() {
local error_file=$1
-
- local type="$MSG_TYPE_ERROR"
-
+ local report=""
if [ ${#ERROR_MSGS[@]} -gt 0 ]; then
- report="{\"type\":\"$type\","
- report+="\"timestamp\":$(date +%s.%N),"
- local msg="["
+ local msg=""
for err in "${ERROR_MSGS[@]}"; do
- msg+="\"$(sed 's/"/\\"/g' <<< "$err")\","
+ msg+="$(echo "$err")"
done
- if [ ${#msg} -gt 1 ]; then
- # remove last comma (,)
- msg="${msg%?}"
- fi
- msg+="]"
- report+="\"messages\":$msg}"
+ report="$(./host-monitor.py error <<< "$msg")"
else
- report=$(tail -10 "$error_file" | ./stderr-monitor.py "$type")
+ report=$(tail -10 "$error_file" | ./host-monitor.py stderr)
fi
eval "echo $(printf "%q" "$report") >&${MONITOR_FD}"
#!/usr/bin/env python
-# Copyright (C) 2012 GRNET S.A.
+# Copyright (C) 2012 GRNET S.A.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
+"""Utility that generates monitoring messages for snf-image.
+
+This utility given a message type as option and the message body as input will
+print a monitoring message in stdout.
+"""
+
import sys
import os
import json
import time
+MSG_TYPE_ERROR = "image-error"
+MSG_TYPE_INFO = "image-info"
+
+PROTOCOL = {
+ "error": (MSG_TYPE_ERROR, "messages"),
+ "stderr": (MSG_TYPE_ERROR, "stderr"),
+ "info": (MSG_TYPE_INFO, "messages")
+}
+
PROGNAME = os.path.basename(sys.argv[0])
if __name__ == "__main__":
- usage="Usage: %s <msg-type>\n" % PROGNAME
-
+ usage = "Usage: %s <msg-type>\n" % PROGNAME
+
if len(sys.argv) != 2:
sys.stderr.write(usage)
sys.exit(1)
+ msg_type = sys.argv[1]
+
+ if msg_type not in PROTOCOL.keys():
+ sys.stderr.write("Unknown message type: %s\n" % msg_type)
+ sys.exit(1)
+
msg = {}
- msg['type'] = sys.argv[1]
- msg['stderr'] = sys.stdin.read()
- msg['timestamp'] = time.time()
+ msg['type'] = PROTOCOL[msg_type][0]
+
+ lines = []
+ while True:
+ line = sys.stdin.readline()
+ if not line:
+ break
+
+ lines.append(line.strip())
+
+ msg[PROTOCOL[msg_type][1]] = lines
+ msg['timestamp'] = time.time()
sys.stdout.write("%s\n" % json.dumps(msg))
sys.exit(0)