[enh] Add MX check + Refactoring

This commit is contained in:
Adrien Beudin 2015-04-10 14:29:55 +00:00
parent 2c453b4996
commit c31ddef8b6
3 changed files with 33 additions and 3 deletions

View file

@ -679,6 +679,12 @@ monitor:
action: append_const
const: infos
dest: units
-c:
full: --check
help: Check network configuration
action: append_const
const: check
dest: units
-H:
full: --human-readable
help: Print sizes in human readable format

View file

@ -33,6 +33,7 @@ import xmlrpclib
import os.path
import errno
import os
import dns.resolver
import cPickle as pickle
from urllib import urlopen
from datetime import datetime, timedelta
@ -160,7 +161,7 @@ def monitor_network(units=None, human_readable=False):
smtp_check = m18n.n('network_check_smtp_ko')
if units is None:
units = ['usage', 'infos']
units = ['check', 'usage', 'infos']
# Get network devices and their addresses
devices = {}
@ -173,7 +174,30 @@ def monitor_network(units=None, human_readable=False):
# Retrieve monitoring for unit(s)
for u in units:
if u == 'usage':
if u == 'check':
result[u] = {}
with open('/etc/yunohost/current_host', 'r') as f:
domain = f.readline().rstrip()
cmd_check_smtp = os.system('/bin/nc -z -w1 yunohost.org 25')
if cmd_check_smtp == 0:
smtp_check = m18n.n('network_check_smtp_ok')
else:
smtp_check = m18n.n('network_check_smtp_ko')
try:
answers = dns.resolver.query(domain,'MX')
mx_check = {}
i = 0
for server in answers:
mx_check[i] = server
i = i + 1
except:
mx_check = m18n.n('network_check_mx_ko')
result[u] = {
'smtp_check': smtp_check,
'mx_check': mx_check
}
elif u == 'usage':
result[u] = {}
for i in json.loads(glances.getNetwork()):
iname = i['interface_name']
@ -210,7 +234,6 @@ def monitor_network(units=None, human_readable=False):
'public_ip': p_ip,
'local_ip': l_ip,
'gateway': gateway,
'smtp_check' : smtp_check
}
else:
raise MoulinetteError(errno.EINVAL, m18n.n('unit_unknown', u))

View file

@ -118,6 +118,7 @@
"network_check_smtp_ok" : "Outbound mail (SMTP port 25) is not blocked",
"network_check_smtp_ko" : "Outbound mail (SMTP port 25) seems to be blocked by your network",
"network_check_mx_ko" : "DNS MX record is not set",
"ldap_initialized" : "LDAP successfully initialized",
"admin_password_change_failed" : "Unable to change password",