mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Merge pull request #5 from YunoHost/dev_beudbeud
add public ip , enable and disable process, check port
This commit is contained in:
commit
2c6e45abac
2 changed files with 56 additions and 13 deletions
|
@ -379,28 +379,37 @@ monitor:
|
||||||
action: store_true
|
action: store_true
|
||||||
-i:
|
-i:
|
||||||
full: --ifconfig
|
full: --ifconfig
|
||||||
help: Ifconfig
|
help: Show Ip and MAC Adress
|
||||||
action: store_true
|
action: store_true
|
||||||
-u:
|
-u:
|
||||||
full: --uptime
|
full: --uptime
|
||||||
help: Show Uptime
|
help: Show Uptime
|
||||||
action: store_true
|
action: store_true
|
||||||
|
-p:
|
||||||
|
full: --public
|
||||||
|
help: Show IP public
|
||||||
|
action: store_true
|
||||||
process:
|
process:
|
||||||
action_help: Check Process
|
action_help: Check Process
|
||||||
arguments:
|
arguments:
|
||||||
-e:
|
-e:
|
||||||
full: --enable
|
full: --enable
|
||||||
help: Enable process
|
help: Enable process
|
||||||
|
metavar: PROCESS
|
||||||
-d:
|
-d:
|
||||||
full: --disable
|
full: --disable
|
||||||
help: Disable process
|
help: Disable process
|
||||||
|
metavar: PROCESS
|
||||||
--start:
|
--start:
|
||||||
help: Start process
|
help: Start process
|
||||||
|
metavar: PROCESS
|
||||||
--stop:
|
--stop:
|
||||||
help: Stop process
|
help: Stop process
|
||||||
|
metavar: PROCESS
|
||||||
-c:
|
-c:
|
||||||
full: --check
|
full: --check
|
||||||
help: Check process
|
help: Check process
|
||||||
|
metavar: PORT
|
||||||
-i:
|
-i:
|
||||||
full: --info
|
full: --info
|
||||||
help: Process info
|
help: Process info
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from urllib import urlopen
|
||||||
try:
|
try:
|
||||||
import psutil
|
import psutil
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -59,6 +60,13 @@ def uptime():
|
||||||
uptime = (str(datetime.now() - datetime.fromtimestamp(psutil.BOOT_TIME)).split('.')[0])
|
uptime = (str(datetime.now() - datetime.fromtimestamp(psutil.BOOT_TIME)).split('.')[0])
|
||||||
return { _("Uptime") : uptime }
|
return { _("Uptime") : uptime }
|
||||||
|
|
||||||
|
def public():
|
||||||
|
try:
|
||||||
|
ip = str(urlopen('http://ip.yunohost.org').read())
|
||||||
|
except:
|
||||||
|
raise YunoHostError(1, "No connection" )
|
||||||
|
return { _("Public IP"): ip }
|
||||||
|
|
||||||
def processcount():
|
def processcount():
|
||||||
processcount = {'total': 0, 'running': 0, 'sleeping': 0}
|
processcount = {'total': 0, 'running': 0, 'sleeping': 0}
|
||||||
process_all = [proc for proc in psutil.process_iter()]
|
process_all = [proc for proc in psutil.process_iter()]
|
||||||
|
@ -90,27 +98,46 @@ def processcount():
|
||||||
return { _("Total") : str(processcount['total']), _("Running") : str(processcount['running']), _("Sleeping") : str(processcount['sleeping']) }
|
return { _("Total") : str(processcount['total']), _("Running") : str(processcount['running']), _("Sleeping") : str(processcount['sleeping']) }
|
||||||
|
|
||||||
def process_enable(args):
|
def process_enable(args):
|
||||||
print 'process_enable'
|
output = subprocess.Popen(['update-rc.d', args, 'defaults'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
if output.wait() == 0:
|
||||||
|
resultat = process_start(args)
|
||||||
|
return resultat
|
||||||
|
else:
|
||||||
|
raise YunoHostError(1, _('Enable ' + agrs + ' failure'))
|
||||||
|
|
||||||
def process_disable(args):
|
def process_disable(args):
|
||||||
print 'process disable'
|
output = subprocess.Popen(['update-rc.d', args, 'remove'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
if output.wait() == 0:
|
||||||
|
resultat = process_stop(args)
|
||||||
|
return resultat
|
||||||
|
else:
|
||||||
|
raise YunoHostError(1, _('Disable ' + agrs + ' failure'))
|
||||||
|
|
||||||
def process_start(args):
|
def process_start(args):
|
||||||
output = subprocess.Popen(['service', args, 'start'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
output = subprocess.Popen(['service', args, 'start'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
if output.wait() == 0:
|
if output.wait() == 0:
|
||||||
return { _('Start') + " " + args : "OK" }
|
return { args.title() + " " + _('Start') : "OK" }
|
||||||
else:
|
else:
|
||||||
raise YunoHostError(1, _('Start failure'))
|
raise YunoHostError(1, _('Start ' + args + ' failure'))
|
||||||
|
|
||||||
def process_stop(args):
|
def process_stop(args):
|
||||||
output = subprocess.Popen(['service', args, 'stop'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
output = subprocess.Popen(['service', args, 'stop'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
if output.wait() == 0:
|
if output.wait() == 0:
|
||||||
return { _('Stop') + " " + args : "OK" }
|
return { args.title() + " " + _('Stop') : "OK" }
|
||||||
else:
|
else:
|
||||||
raise YunoHostError(1, _('Start failure'))
|
raise YunoHostError(1, _('Stop ' + args + ' failure'))
|
||||||
|
|
||||||
def process_check(args):
|
def process_check(args):
|
||||||
print 'process_check'
|
ip = public()['Public IP']
|
||||||
|
output = os.system('/usr/lib/nagios/plugins/check_tcp -H localhost -p' + args + ' > /dev/null')
|
||||||
|
if output == 0:
|
||||||
|
output = os.system('/usr/lib/nagios/plugins/check_tcp -H ' + ip + ' -p' + args + ' > /dev/null')
|
||||||
|
if output == 0:
|
||||||
|
return { _("Port") + " " + args : _("is open") }
|
||||||
|
else:
|
||||||
|
raise YunoHostError(1, "Port " + args + " is closed in your box" )
|
||||||
|
else:
|
||||||
|
raise YunoHostError(1, args + " is closed" )
|
||||||
|
|
||||||
|
|
||||||
def monitor_info(args):
|
def monitor_info(args):
|
||||||
|
@ -129,19 +156,26 @@ def monitor_info(args):
|
||||||
elif args['uptime']:
|
elif args['uptime']:
|
||||||
resultat = uptime()
|
resultat = uptime()
|
||||||
return resultat
|
return resultat
|
||||||
|
elif args['public']:
|
||||||
|
resultat = public()
|
||||||
|
return resultat
|
||||||
|
|
||||||
def monitor_process(args):
|
def monitor_process(args):
|
||||||
if args['enable']:
|
if args['enable']:
|
||||||
process_enable(args['enable'])
|
resultat = process_enable(args['enable'])
|
||||||
|
return resultat
|
||||||
elif args['disable']:
|
elif args['disable']:
|
||||||
process_disable(args['disable'])
|
resultat = process_disable(args['disable'])
|
||||||
|
return resultat
|
||||||
elif args['start']:
|
elif args['start']:
|
||||||
resultat = process_start(args['start'])
|
resultat = process_start(args['start'])
|
||||||
return resultat
|
return resultat
|
||||||
elif args['stop']:
|
elif args['stop']:
|
||||||
process_stop(args['stop'])
|
resultat = process_stop(args['stop'])
|
||||||
|
return resultat
|
||||||
elif args['check']:
|
elif args['check']:
|
||||||
process_check(args['check'])
|
resultat = process_check(args['check'])
|
||||||
|
return resultat
|
||||||
elif args['info']:
|
elif args['info']:
|
||||||
resultat = processcount()
|
resultat = processcount()
|
||||||
return resultat
|
return resultat
|
||||||
|
|
Loading…
Add table
Reference in a new issue