File: //lib/check_mk_agent/need_sudo/mtu.py
#!/usr/bin/python
'''
Envia um pacote de ping com mais de 1500 bytes e checa se foi fragmentado
'''
import os
import random
import subprocess
import ConfigParser
config_file = "/etc/locaweb/monitoring/plugins.conf"
if os.path.isfile(config_file):
config = ConfigParser.ConfigParser()
config.read(config_file)
blacklist = config.get("mtu", "blacklist").split()
else:
blacklist = []
def main():
''' Funcao principal '''
# Pega um ponto de montagem nfs aleatorio para fazer o teste
nfs = []
for line in [ line.strip().split() for line in open("/etc/mtab").readlines() ]:
if line[2] == 'nfs' and line[0] not in blacklist:
nfs.append(line[0].split(":")[0])
if len(nfs) == 0:
print "0 Check_MTU status=0 OK - no NFS mount found"
return
nfs = random.choice(nfs)
# testa o ping naquele ponto de montagem nfs
p = subprocess.Popen(
['ping', '-w', '3', '-c', '1', '-s', '2000', '-M', 'do', nfs],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True)
retcode = p.wait()
if retcode == 0:
print "0 Check_MTU status=0 OK - %s" % nfs
elif retcode == 2:
print "1 Check_MTU status=1 WARNING - %s, check ping permissions" % nfs
else:
print "2 Check_MTU status=2 CRITICAL - %s" % nfs
return
if __name__ == '__main__':
main()