mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
commit
05791827a9
3 changed files with 77 additions and 16 deletions
|
@ -396,6 +396,10 @@ monitor:
|
||||||
full: --memory
|
full: --memory
|
||||||
help: Check Memory
|
help: Check Memory
|
||||||
action: store_true
|
action: store_true
|
||||||
|
-s:
|
||||||
|
full: --swap
|
||||||
|
help: Check Swap
|
||||||
|
action: store_true
|
||||||
-c:
|
-c:
|
||||||
full: --cpu
|
full: --cpu
|
||||||
help: Check CPU
|
help: Check CPU
|
||||||
|
@ -436,7 +440,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
|
||||||
|
|
22
process.yml
Normal file
22
process.yml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
apache2:
|
||||||
|
status: service
|
||||||
|
bind9:
|
||||||
|
status: service
|
||||||
|
dovecot:
|
||||||
|
status: service
|
||||||
|
postfix:
|
||||||
|
status: service
|
||||||
|
mysql:
|
||||||
|
status: service
|
||||||
|
glances:
|
||||||
|
status: service
|
||||||
|
tahoe-lafs:
|
||||||
|
status: ps aux | grep tahoe |grep -v grep
|
||||||
|
ssh:
|
||||||
|
status: service
|
||||||
|
metronome:
|
||||||
|
status: metronomectl status
|
||||||
|
samba:
|
||||||
|
status: service
|
||||||
|
slapd:
|
||||||
|
status: service
|
|
@ -29,9 +29,31 @@ 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
|
||||||
|
import socket
|
||||||
|
import fcntl
|
||||||
|
import struct
|
||||||
|
if not __debug__:
|
||||||
|
import traceback
|
||||||
|
|
||||||
s = xmlrpclib.ServerProxy('http://127.0.0.1:61209')
|
s = xmlrpclib.ServerProxy('http://127.0.0.1:61209')
|
||||||
|
|
||||||
|
def get_ip_address(ifname):
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
return socket.inet_ntoa(fcntl.ioctl(
|
||||||
|
s.fileno(),
|
||||||
|
0x8915, # SIOCGIFADDR
|
||||||
|
struct.pack('256s', ifname[:15])
|
||||||
|
)[20:24])
|
||||||
|
|
||||||
def bytes2human(n):
|
def bytes2human(n):
|
||||||
symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
|
symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
|
||||||
prefix = {}
|
prefix = {}
|
||||||
|
@ -74,19 +96,24 @@ def process_stop(args):
|
||||||
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')
|
processes = yaml.load(f)
|
||||||
if output == 0:
|
|
||||||
output = os.system('/usr/lib/nagios/plugins/check_tcp -H ' + ip + ' -p' + args + ' > /dev/null')
|
result = {}
|
||||||
if output == 0:
|
for process, commands in processes.items():
|
||||||
return { 'Port' : args + " " + _("is open") }
|
if commands['status'] == 'service':
|
||||||
|
cmd = "service " + process + " status"
|
||||||
else:
|
else:
|
||||||
return { 'Warning' : args + " " + _("is closed in your box") }
|
cmd = commands['status']
|
||||||
else:
|
|
||||||
raise YunoHostError(1, args + " " + _("is closed") )
|
|
||||||
|
|
||||||
|
if os.system(cmd + " > /dev/null 2>&1") == 0:
|
||||||
|
result.update({ process : _('Running') })
|
||||||
|
else:
|
||||||
|
result.update({ process : _('Down') })
|
||||||
|
|
||||||
def monitor_info(memory=False, cpu=False, disk=False, ifconfig=False, uptime=False, public=False):
|
return { 'Status' : result }
|
||||||
|
|
||||||
|
def monitor_info(memory=False, swap=False, cpu=False, disk=False, ifconfig=False, uptime=False, public=False):
|
||||||
"""
|
"""
|
||||||
Check System
|
Check System
|
||||||
|
|
||||||
|
@ -96,22 +123,30 @@ def monitor_info(memory=False, cpu=False, disk=False, ifconfig=False, uptime=Fal
|
||||||
public -- Show IP public
|
public -- Show IP public
|
||||||
cpu -- Check CPU
|
cpu -- Check CPU
|
||||||
memory -- Check Memory
|
memory -- Check Memory
|
||||||
|
swap -- Check Swap
|
||||||
ifconfig -- Show Ip and MAC Adress
|
ifconfig -- Show Ip and MAC Adress
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if memory:
|
if memory:
|
||||||
return json.loads(s.getMem())
|
return json.loads(s.getMem())
|
||||||
|
|
||||||
|
if swap:
|
||||||
|
return json.loads(s.getMemSwap())
|
||||||
|
|
||||||
elif cpu:
|
elif cpu:
|
||||||
return json.loads(s.getLoad())
|
return json.loads(s.getLoad())
|
||||||
|
|
||||||
elif ifconfig:
|
elif ifconfig:
|
||||||
# TODO: c'est pas ifconfig ça ;)
|
|
||||||
result = {}
|
result = {}
|
||||||
for k, fs in enumerate(json.loads(s.getNetwork())):
|
for k, fs in enumerate(json.loads(s.getNetwork())):
|
||||||
interface = fs['interface_name']
|
interface = fs['interface_name']
|
||||||
del fs['interface_name']
|
if interface != "lo":
|
||||||
result[interface] = fs
|
ip = get_ip_address(str(interface))
|
||||||
|
del fs['interface_name']
|
||||||
|
result[ip] = fs
|
||||||
|
else:
|
||||||
|
del fs['interface_name']
|
||||||
|
result[interface] = fs
|
||||||
return result
|
return result
|
||||||
|
|
||||||
elif disk:
|
elif disk:
|
||||||
|
@ -137,7 +172,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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue