Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.3 KiB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # kate: space-indent on; indent-width 4; replace-tabs on;
  4. """
  5. * Copyright (C) 2009, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  6. *
  7. * Mumble-Django is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This package is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. """
  17. # Set this to the same path you used in settings.py, or None for auto-detection.
  18. MUMBLE_DJANGO_ROOT = None
  19. ### DO NOT CHANGE ANYTHING BELOW THIS LINE ###
  20. import os, sys
  21. from os.path import join, dirname, abspath, exists
  22. # Path auto-detection
  23. if not MUMBLE_DJANGO_ROOT or not exists( MUMBLE_DJANGO_ROOT ):
  24. MUMBLE_DJANGO_ROOT = dirname(abspath(__file__))
  25. # environment variables
  26. sys.path.append( MUMBLE_DJANGO_ROOT )
  27. sys.path.append( join( MUMBLE_DJANGO_ROOT, 'pyweb' ) )
  28. os.environ['DJANGO_SETTINGS_MODULE'] = 'pyweb.settings'
  29. # If you get an error about Python not being able to write to the Python
  30. # egg cache, the egg cache path might be set awkwardly. This should not
  31. # happen under normal circumstances, but every now and then, it does.
  32. # Uncomment this line to point the egg cache to /tmp.
  33. #os.environ['PYTHON_EGG_CACHE'] = '/tmp/pyeggs'
  34. import locale
  35. from django.conf import settings
  36. from mumble.models import MumbleServer, Mumble
  37. warn = getattr( settings, "MUNIN_WARNING", 0.80 )
  38. crit = getattr( settings, "MUNIN_CRITICAL", 0.95 )
  39. title = getattr( settings, "MUNIN_TITLE", "Mumble Users" )
  40. categ = getattr( settings, "MUNIN_CATEGORY", "network" )
  41. def get_running_instances():
  42. for server in MumbleServer.objects.all():
  43. if not server.online:
  44. continue
  45. runinst = server.ctl.getBootedServers()
  46. for inst in server.mumble_set.order_by("srvid").filter( srvid__in=runinst ):
  47. yield inst
  48. if sys.argv[-1] == 'config':
  49. prefenc = locale.getpreferredencoding()
  50. print "graph_vlabel Users"
  51. print "graph_args --base 1000"
  52. print "graph_title", title
  53. print "graph_category", categ
  54. for mumble in get_running_instances():
  55. print "srv%d.label %s" % ( mumble.id, mumble.name.replace('#', '').encode(prefenc, "replace") )
  56. if mumble.connecturl:
  57. print "srv%d.info %s" % ( mumble.id, mumble.connecturl )
  58. if mumble.users:
  59. print "srv%d.warning %d" % ( mumble.id, int( mumble.users * warn ) )
  60. print "srv%d.critical %d" % ( mumble.id, int( mumble.users * crit ) )
  61. elif sys.argv[-1] == 'autoconf':
  62. if Mumble.objects.count() == 0:
  63. print "no (no servers configured)"
  64. else:
  65. # check if connecting works
  66. try:
  67. for mumble in get_running_instances():
  68. mumble.ctl
  69. except Exception, instance:
  70. print "no (can't connect to server %s: %s)" % ( mumble.name, instance )
  71. else:
  72. print "yes"
  73. else:
  74. for mumble in get_running_instances():
  75. print "srv%d.value %d" % ( mumble.id, len( mumble.ctl.getPlayers( mumble.srvid ) ) )