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.

95 lines
3.0 KiB

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