Add Tryton and NMAP checks.
This commit is contained in:
parent
10e333f9db
commit
02189f20e5
|
@ -1,8 +1,11 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
from trytond.pool import PoolMeta
|
||||
import subprocess
|
||||
import json
|
||||
import nmap
|
||||
from jsonrpclib import Server as ServerProxy
|
||||
from trytond.pool import PoolMeta
|
||||
|
||||
import pingparser
|
||||
|
||||
__all__ = ['CheckPlan']
|
||||
|
@ -46,3 +49,73 @@ class CheckPlan:
|
|||
'float_value': result['avgping']
|
||||
})
|
||||
return res
|
||||
|
||||
def check_tryton(self):
|
||||
urls = self.get_attribute('tryton_urls')
|
||||
urls = urls.split()
|
||||
res = []
|
||||
for url in urls:
|
||||
server = ServerProxy(url, verbose=0)
|
||||
try:
|
||||
databases = server.common.db.list(None, None)
|
||||
except Exception, e:
|
||||
res.append({
|
||||
'result': 'tryton_status',
|
||||
'char_value': 'Error',
|
||||
'label': url,
|
||||
'payload': json.dumps({
|
||||
'exception': str(e),
|
||||
})
|
||||
})
|
||||
continue
|
||||
res.append({
|
||||
'result': 'tryton_status',
|
||||
'char_value': 'OK',
|
||||
'label': url,
|
||||
'payload': json.dumps({
|
||||
'list': databases,
|
||||
})
|
||||
})
|
||||
return res
|
||||
|
||||
def check_open_ports(self):
|
||||
'''
|
||||
Expected structure in ports attribute:
|
||||
|
||||
protocol:port
|
||||
|
||||
Example:
|
||||
|
||||
TCP:22
|
||||
TCP:8000
|
||||
'''
|
||||
ip = self.get_attribute('ip')
|
||||
valid_entries = set()
|
||||
entries = [x.strip() for x in self.get_attribute('open_ports').split()]
|
||||
for entry in entries:
|
||||
if len(entry.split(':')) != 2:
|
||||
continue
|
||||
protocol, port = entry.split(':')
|
||||
valid_entries.add((protocol.upper(), int(port)))
|
||||
|
||||
scanner = nmap.PortScanner()
|
||||
#scanner.scan(ip, '1-65535')
|
||||
scanner.scan(ip, '25-25')
|
||||
# Get ip from scanner as user may have given a URL
|
||||
# but scanner results are indexed with ip
|
||||
ip = scanner.all_hosts()[0]
|
||||
entries = set()
|
||||
for protocol in scanner[ip].all_protocols():
|
||||
for port in scanner[ip][protocol].keys():
|
||||
if protocol.upper() in ('TCP', 'UDP'):
|
||||
entries.add((protocol.upper(), port))
|
||||
value = 'OK'
|
||||
if entries - valid_entries:
|
||||
value = 'Error'
|
||||
return [{
|
||||
'result': 'open_ports_status',
|
||||
'char_value': value,
|
||||
'payload': json.dumps({
|
||||
'invalid_ports': list(entries - valid_entries),
|
||||
})
|
||||
}]
|
||||
|
|
|
@ -23,5 +23,25 @@
|
|||
<field name="type">float</field>
|
||||
<field name="uom" ref="uom_millisecond"/>
|
||||
</record>
|
||||
|
||||
<record model="monitoring.check.type" id="check_tryton">
|
||||
<field name="name">Tryton</field>
|
||||
<field name="internal_name">check_tryton</field>
|
||||
</record>
|
||||
<record model="monitoring.result.type" id="result_tryton_status">
|
||||
<field name="name">Tryton Status</field>
|
||||
<field name="internal_name">tryton_status</field>
|
||||
<field name="type">char</field>
|
||||
</record>
|
||||
|
||||
<record model="monitoring.check.type" id="check_open_ports">
|
||||
<field name="name">NMAP Open Ports</field>
|
||||
<field name="internal_name">check_open_ports</field>
|
||||
</record>
|
||||
<record model="monitoring.result.type" id="result_open_ports">
|
||||
<field name="name">NMAP Open Ports Status</field>
|
||||
<field name="internal_name">open_ports_status</field>
|
||||
<field name="type">char</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
Loading…
Reference in New Issue