aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmonitor/bot-status.py42
1 files changed, 21 insertions, 21 deletions
diff --git a/monitor/bot-status.py b/monitor/bot-status.py
index 9ca4092..e27a7ee 100755
--- a/monitor/bot-status.py
+++ b/monitor/bot-status.py
@@ -116,40 +116,35 @@ def get_bot_status(session, bot, base_url, builder_url, build_url):
return status
-def bot_status(config, output_file):
- temp = tempfile.NamedTemporaryFile(mode='w+', delete=False)
-
- today = "{}\n".format(datetime.today().ctime())
-
+# Get status for all bots named in the config
+# Return a dictionary of (base_url, bot name) -> status info
+def get_bots_status(config):
session = requests.Session()
-
- # Get status for all bots
bot_cache = {}
- # Whether we should show the fail favicon
- found_failure = False
for server in filter(not_ignored, config):
base_url = server['base_url']
- builder_url = server['builder_url']
- build_url = server['build_url']
logging.debug('Parsing server {}...'.format(server['name']))
for builder in server['builders']:
logging.debug(' Parsing builders {}...'.format(builder['name']))
for bot in builder['bots']:
- bot_key = "{}/{}".format(base_url, bot['name'])
+ bot_key = (base_url, bot['name'])
if bot_key in bot_cache:
continue
+
logging.debug(' Parsing bot {}...'.format(bot['name']))
- status = get_bot_status(session, bot['name'], base_url, builder_url,
- build_url)
- if not_ignored(bot):
- found_failure |= status['fail']
+ status = get_bot_status(session, bot['name'], base_url, server['builder_url'],
+ server['build_url'])
logging.debug(" FAIL" if status['fail'] else " PASS")
bot_cache[bot_key] = status
- temp.write("<link rel=\"shortcut icon\" href=\"{}\" "
- "type=\"image/x-icon\"/>\n".format(
- 'fail.ico' if found_failure else 'ok.ico'))
+ return bot_cache
+
+def write_bot_status(config, output_file, bots_status):
+ temp = tempfile.NamedTemporaryFile(mode='w+', delete=False)
+ today = "{}\n".format(datetime.today().ctime())
+ # Whether we use the fail favicon or not
+ found_failure = False
# Dump all servers / bots
for server in filter(not_ignored, config):
@@ -168,7 +163,8 @@ def bot_status(config, output_file):
"<th>Build #</th><th>Commits</th><th>Failing steps</th></tr>\n")
for bot in builder['bots']:
temp.write("<tr>\n")
- status = bot_cache["{}/{}".format(base_url, bot['name'])]
+ status = bots_status[(base_url, bot['name'])]
+ found_failure |= status['fail']
url = "{}/#/{}/{}".format(base_url, builder_url, status['builderid'])
temp.write(" <td><a href='{}'>{}</a></td>\n".format(url, bot['name']))
temp.write(" <td><font color='{}'>{}</font></td>\n"
@@ -198,6 +194,10 @@ def bot_status(config, output_file):
temp.write("</tr>\n")
temp.write("</table>\n")
+ temp.write("<link rel=\"shortcut icon\" href=\"{}\" "
+ "type=\"image/x-icon\"/>\n".format(
+ 'fail.ico' if found_failure else 'ok.ico'))
+
# Move temp to main (atomic change)
temp.close()
shutil.move(temp.name, output_file)
@@ -222,4 +222,4 @@ if __name__ == "__main__":
print("error: failed to read {} config file: {}".format(args.config_file, e))
sys.exit(os.EX_CONFIG)
- bot_status(config, args.output_file)
+ write_bot_status(config, args.output_file, get_bots_status(config))