3 # Copyright (C) 2012 GRNET S.A.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 """Utility that generates monitoring messages for snf-image.
22 This utility given a message type as option and the message body as input will
23 print a monitoring message to stdout.
31 MSG_TYPE_ERROR = "image-error"
32 MSG_TYPE_INFO = "image-info"
35 "error": (MSG_TYPE_ERROR, "messages"),
36 "stderr": (MSG_TYPE_ERROR, "stderr"),
37 "info": (MSG_TYPE_INFO, "messages")
40 PROGNAME = os.path.basename(sys.argv[0])
42 if __name__ == "__main__":
43 usage = "Usage: %s <msg-type>\n" % PROGNAME
45 if len(sys.argv) != 2:
46 sys.stderr.write(usage)
49 msg_type = sys.argv[1]
51 if msg_type not in PROTOCOL.keys():
52 sys.stderr.write("Unknown message type: %s\n" % msg_type)
56 msg['type'] = PROTOCOL[msg_type][0]
59 if msg_type == 'stderr':
60 msg['stderr'] = sys.stdin.read()
63 line = sys.stdin.readline()
68 lines.append(line.strip())
69 msg[PROTOCOL[msg_type][1]] = lines
71 msg['timestamp'] = time.time()
72 sys.stdout.write("%s\n" % json.dumps(msg))
76 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :