Today I wrote a little nagios plugin to check the state of murmurd (popular mumble server) because the ones out there don't seem to do the job (at least I couldn't make them).
requirements:
-dbus
-murmurd running with dbus interface
-python-dbus bindings
-nagios ;)
define a new command in /etc/nagios/objects/commands.cfg (at least under gentoo that's where to do it):
# murmur (Mumble)
define command{
command_name check_murmur
command_line $USER1$/check_murmur.py $ARG1$ $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$ $ARG7$ 2>/dev/null
}
define the service in i.e. /etc/nagios/objects/localhost.cfg:
define service{
use local-service
host_name example.org
service_description Mumble murmurd
check_command check_murmur!servernum!minusers!maxusers!minchannels!maxchannels!minbans!maxbans
}
where servernum starts with 1
all minumums are disabled when <= 0
all maximums except bans are disabled when <= 0
maxbans is disabled when <= -1
now paste the script below in /usr/lib/nagios/plugins/check_murmur.py (you may have to put it in a different directory, but the filename should be the same).
Good luck and have fun :)
#!/usr/bin/python
import sys
import dbus
servernum = '1'
minusers = 0
maxusers = 0
minchannels = 0
maxchannels = 0
minbans = 0
maxbans = -1
warning = False
reportstr = ""
warningstr = ""
if(len(sys.argv) == 1 or sys.argv[1] == '-h' or sys.argv[1] == '--help'):
print 'usage: ' + sys.argv[0] + ' <server number> <minusers> <maxusers> <minchannels> <maxchannels> <minbans> <maxbans>'
print 'minimus: <= 0: disabled (except maxbans, only disabled for <= -1); maximums: <= 0 disabled; server numbers start with 1!'
sys.exit()
servernum = sys.argv[1]
if(int(sys.argv[2]) > 0):
minusers = int(sys.argv[2])
if(int(sys.argv[3]) > 0):
maxusers = int(sys.argv[3])
if(int(sys.argv[4]) > 0):
minchannels = int(sys.argv[4])
if(int(sys.argv[5]) > 0):
maxchannels = int(sys.argv[5])
if(int(sys.argv[6]) > 0):
minbans = int(sys.argv[6])
if(int(sys.argv[7]) > -1):
maxbans = int(sys.argv[7])
bus = dbus.SystemBus()
server = bus.get_object('net.sourceforge.mumble.murmur', '/'+str(servernum))
try:
players = server.getPlayers()
except dbus.exceptions.DBusException:
print "Critical: No connection via dbus. If dbus is up this service is probably down."
sys.exit(2) #Crit
channels = server.getChannels()
bans = server.getBans()
reportstr += "users: " + str(len(players)) + ", channels: " + str(len(channels)) + ", bans: " + str(len(bans))
if(minusers > 0):
if(minusers > len(players)):
warning = True
warningstr += " <less than " + str(minusers) + " users>"
if(maxusers > 0):
if(maxusers < len(players)):
warning = True
warningstr += " <more than " + str(maxusers) + " users>"
if(minchannels > 0):
if(minchannels > len(channels)):
warning = True
warningstr += " <less than " + str(minchannels) + " channels>"
if(maxchannels > 0):
if(maxchannels < len(channels)):
warning = True
warningstr += " <more than " + str(maxchannels) + " channels>"
if(minbans > 0):
if(minbans > len(bans)):
warning = True
warningstr += " <less than " + str(minbans) + " bans>"
if(maxbans > -1):
if(maxbans < len(bans)):
warning = True
warningstr +=" <more than " + str(maxbans) + " bans>"
if(warning):
reportstr = "WARNING: " + reportstr + ", warnings:" + warningstr
else:
reportstr = "OK: " + reportstr
print reportstr
if(warning):
sys.exit(1)
else:
sys.exit()
UPDATE: The plugin got accepted at nagios exchange.