change yunohost check process

This commit is contained in:
root 2013-10-01 10:02:22 +02:00
parent bf65f93f8e
commit 85f2706ea6
2 changed files with 26 additions and 11 deletions

View file

@ -436,7 +436,7 @@ monitor:
-c: -c:
full: --check full: --check
help: Check process help: Check process
metavar: PORT action: store_true
-i: -i:
full: --info full: --info
help: Process info help: Process info

View file

@ -29,6 +29,17 @@ import psutil
from urllib import urlopen from urllib import urlopen
from datetime import datetime, timedelta from datetime import datetime, timedelta
from yunohost import YunoHostError, win_msg, colorize, validate, get_required_args from yunohost import YunoHostError, win_msg, colorize, validate, get_required_args
import os
import sys
try:
import yaml
except ImportError:
sys.stderr.write('Error: Yunohost CLI Require yaml lib\n')
sys.stderr.write('apt-get install python-yaml\n')
sys.exit(1)
import json
if not __debug__:
import traceback
s = xmlrpclib.ServerProxy('http://127.0.0.1:61209') s = xmlrpclib.ServerProxy('http://127.0.0.1:61209')
@ -73,17 +84,21 @@ def process_stop(args):
else: else:
raise YunoHostError(1, 'Stop : ' + args.title() + " " + _("failure")) raise YunoHostError(1, 'Stop : ' + args.title() + " " + _("failure"))
def process_check(args): def process_check(args):
ip = public()['Public IP'] with open('process.yml', 'r') as f:
output = os.system('/usr/lib/nagios/plugins/check_tcp -H localhost -p' + args + ' > /dev/null') process = yaml.load(f)
if output == 0:
output = os.system('/usr/lib/nagios/plugins/check_tcp -H ' + ip + ' -p' + args + ' > /dev/null') for i in process:
if output == 0: cmd = process[i]['command']
return { 'Port' : args + " " + _("is open") } if cmd == 'service':
status = os.system("service " + i + " status")
else: else:
return { 'Warning' : args + " " + _("is closed in your box") } status = os.system(cmd)
if status == 0:
return { i + " " + _("is up") }
else: else:
raise YunoHostError(1, args + " " + _("is closed") ) raise YunoHostError(1, i + " " + _("is down") )
def monitor_info(memory=False, cpu=False, disk=False, ifconfig=False, uptime=False, public=False): def monitor_info(memory=False, cpu=False, disk=False, ifconfig=False, uptime=False, public=False):
@ -137,7 +152,7 @@ def monitor_info(memory=False, cpu=False, disk=False, ifconfig=False, uptime=Fal
else: else:
raise YunoHostError(1, _('No arguments provided')) raise YunoHostError(1, _('No arguments provided'))
def monitor_process(enable=None, disable=None, start=None, stop=None, check=None, info=False): def monitor_process(enable=None, disable=None, start=None, stop=None, check=False, info=False):
""" """
Check Process Check Process