ffpb_status.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # -*- coding: utf-8 -*-
  2. from __future__ import print_function
  3. import willie
  4. def setup(bot):
  5. pass
  6. @willie.module.commands('status')
  7. def ffpb_status(bot, trigger):
  8. """Status des FFPB-Netzes: Anzahl (aktiver) Knoten + Clients"""
  9. stats = bot.memory['ffpb_stats'] if 'ffpb_stats' in bot.memory else None
  10. if stats is None:
  11. bot.say('Uff, kein Plan wo der Zettel ist. Fragst du später nochmal?')
  12. return
  13. bot.say('Es sind {0} Knoten und ca. {1} Clients online.'.format(stats["nodes_active"], stats["clients"]))
  14. @willie.module.commands('highscore')
  15. def ffpb_highscore(bot, trigger):
  16. highscores = bot.memory['highscores'] if 'highscores' in bot.memory else None
  17. if highscores is None:
  18. bot.reply('Sorry, ich habe gerade keine Highscore-Daten parat. Und würfeln ist auch eher uncool.')
  19. return
  20. bot.say('Highscore: {0} Knoten ({1}), {2} Clients ({3})'.format(
  21. highscores['nodes'], pretty_date(int(highscores['nodes_ts'])),
  22. highscores['clients'], pretty_date(int(highscores['clients_ts']))))
  23. @willie.module.commands('rollout-status')
  24. def ffpb_rolloutstatus(bot, trigger):
  25. """Zeigt eine Statistik über alle Knoten an die die gegebene
  26. Firmware-Version installiert haben."""
  27. # initialize result dictionary
  28. result = { }
  29. for branch in [ 'stable', 'testing' ]:
  30. result[branch] = None
  31. skipped = 0
  32. # command is restricted to bot-admins via PM or OPs in the channel
  33. if (not (trigger.admin and trigger.is_privmsg)) and (not trigger.nick in bot.ops[trigger.sender]):
  34. bot.say('Geh zur dunklen Seite, die haben Kekse - ohne Keks kein Rollout-Status.')
  35. return
  36. # get expected firmware version from command arguments
  37. expected_release = trigger.group(2)
  38. if expected_release is None or len(expected_release) == 0:
  39. bot.say('Von welcher Firmware denn?')
  40. return
  41. # check each node in ALFRED data
  42. for nodeid in alfred_data:
  43. item = alfred_data[nodeid]
  44. if (not 'software' in item) or (not 'firmware' in item['software']) or (not 'autoupdater' in item['software']):
  45. skipped+=1
  46. continue
  47. release = item['software']['firmware']['release']
  48. branch = item['software']['autoupdater']['branch']
  49. enabled = item['software']['autoupdater']['enabled']
  50. if not branch in result or result[branch] is None:
  51. result[branch] = { 'auto_count': 0, 'auto_not': 0, 'manual_count': 0, 'manual_not': 0, 'total': 0 }
  52. result[branch]['total'] += 1
  53. match = 'count' if release == expected_release else 'not'
  54. mode = 'auto' if enabled else 'manual'
  55. result[branch][mode+'_ '+match] += 1
  56. # respond to user
  57. output = "Rollout von '{0}':".format(expected_release)
  58. for branch in result:
  59. auto_count = result[branch]['auto_count']
  60. auto_total = auto_count + result[branch]['auto_not']
  61. manual_count = result[branch]['manual_count']
  62. manual_total = manual_count + result[branch]['manual_not']
  63. bot.say("Rollout von '{0}': {1} = {2}/{3} per Auto-Update, {4}/{5} manuell".format(expected_release, branch, auto_count, auto_total, manual_count, manual_total))
  64. # output count of nodes for which the autoupdater-branch and/or firmware version could not be retrieved
  65. if skipped > 0:
  66. bot.say("Rollout von '{0}': {1} Knoten unklar".format(expected_release, skipped))