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.

84 lines
2.7 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 *
  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. mm = Mumble.objects.filter( booted = True ).order_by( "id" );
  40. if sys.argv[-1] == 'config':
  41. print "graph_vlabel Users"
  42. print "graph_args --base 1000"
  43. print "graph_title", title
  44. print "graph_category", categ
  45. for mumble in mm:
  46. print "srv%d.label %s" % ( mumble.id, mumble.name.replace( '#', '' ) );
  47. print "srv%d.info %s" % ( mumble.id, mumble.connecturl );
  48. if mumble.users:
  49. print "srv%d.warning %d" % ( mumble.id, int( mumble.users * warn ) );
  50. print "srv%d.critical %d" % ( mumble.id, int( mumble.users * crit ) );
  51. elif sys.argv[-1] == 'autoconf':
  52. if mm.count() == 0:
  53. print "no (no servers configured)";
  54. else:
  55. # check if connecting works
  56. try:
  57. for mumble in mm:
  58. mumble.getCtl();
  59. except Exception, instance:
  60. print "no (can't connect to server %s: %s)" % ( mumble.name, instance );
  61. else:
  62. print "yes";
  63. else:
  64. for mumble in mm:
  65. print "srv%d.value %d" % ( mumble.id, len( mumble.ctl.getPlayers( mumble.srvid ) ) );