2018-03-29 22:37:28 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2018-11-27 11:03:18 +01:00
|
|
|
try:
|
|
|
|
import simplejson as json
|
|
|
|
except ImportError:
|
|
|
|
import json
|
2018-03-29 22:37:28 +02:00
|
|
|
|
|
|
|
from redis import StrictRedis
|
2018-11-14 17:07:30 +01:00
|
|
|
from .libs.helpers import get_socket_path, get_ipasn
|
2018-03-29 22:37:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Monitor():
|
|
|
|
|
|
|
|
def __init__(self):
|
2018-04-05 14:36:01 +02:00
|
|
|
self.intake = StrictRedis(unix_socket_path=get_socket_path('intake'), db=0, decode_responses=True)
|
|
|
|
self.sanitize = StrictRedis(unix_socket_path=get_socket_path('prepare'), db=0, decode_responses=True)
|
2018-11-14 17:07:30 +01:00
|
|
|
self.cache = StrictRedis(unix_socket_path=get_socket_path('cache'), db=1, decode_responses=True)
|
|
|
|
self.ipasn = get_ipasn()
|
2018-03-29 22:37:28 +02:00
|
|
|
|
|
|
|
def get_values(self):
|
|
|
|
ips_in_intake = self.intake.scard('intake')
|
|
|
|
ready_to_insert = self.sanitize.scard('to_insert')
|
2018-11-26 14:57:58 +01:00
|
|
|
ipasn_meta = self.ipasn.meta()
|
|
|
|
if len(ipasn_meta['cached_dates']['caida']['v4']['cached']) > 15:
|
|
|
|
ipasn_meta['cached_dates']['caida']['v4']['cached'] = 'Too many entries'
|
|
|
|
if len(ipasn_meta['cached_dates']['caida']['v6']['cached']) > 15:
|
|
|
|
ipasn_meta['cached_dates']['caida']['v6']['cached'] = 'Too many entries'
|
2018-11-14 17:07:30 +01:00
|
|
|
return json.dumps({'Non-parsed IPs': ips_in_intake, 'Parsed IPs': ready_to_insert,
|
2018-11-26 14:57:58 +01:00
|
|
|
'running': self.cache.hgetall('running'), 'IPASN History': ipasn_meta},
|
2018-11-14 17:07:30 +01:00
|
|
|
indent=2)
|