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.

89 lines
2.9 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. from django.conf import settings
  34. from mumble.models import MumbleServer, Mumble
  35. warn = getattr( settings, "MUNIN_WARNING", 0.80 )
  36. crit = getattr( settings, "MUNIN_CRITICAL", 0.95 )
  37. title = getattr( settings, "MUNIN_TITLE", "Mumble Users" )
  38. categ = getattr( settings, "MUNIN_CATEGORY", "network" )
  39. def get_running_instances():
  40. for server in MumbleServer.objects.all():
  41. runinst = server.ctl.getBootedServers()
  42. for inst in server.mumble_set.filter( srvid__in=runinst ):
  43. yield inst
  44. if sys.argv[-1] == 'config':
  45. print "graph_vlabel Users"
  46. print "graph_args --base 1000"
  47. print "graph_title", title
  48. print "graph_category", categ
  49. for mumble in get_running_instances():
  50. print "srv%d.label %s" % ( mumble.id, mumble.name.replace( '#', '' ) );
  51. print "srv%d.info %s" % ( mumble.id, mumble.connecturl );
  52. if mumble.users:
  53. print "srv%d.warning %d" % ( mumble.id, int( mumble.users * warn ) );
  54. print "srv%d.critical %d" % ( mumble.id, int( mumble.users * crit ) );
  55. elif sys.argv[-1] == 'autoconf':
  56. if Mumble.objects.count() == 0:
  57. print "no (no servers configured)";
  58. else:
  59. # check if connecting works
  60. try:
  61. for mumble in get_running_instances():
  62. mumble.ctl
  63. except Exception, instance:
  64. print "no (can't connect to server %s: %s)" % ( mumble.name, instance );
  65. else:
  66. print "yes";
  67. else:
  68. for mumble in get_running_instances():
  69. print "srv%d.value %d" % ( mumble.id, len( mumble.ctl.getPlayers( mumble.srvid ) ) );