Ejemplo n.º 1
0
    def find_all_events_for_ip(self,
                               addr,
                               start_date=0,
                               include_archives=False):
        """
            Retrieve all events (archived ones too) for an ip address and newer
            than `start_date`.

            :param str addr: IP address to find
            :param int start_date: Timestamp the events must be retrieved from
            :param bool include_archives: Do the results must also include archives?
            :rtype: array
            :return: An array containing all attached events.
        """
        if not start_date:
            start_date = utils.get_a_month_ago_date()

        doc = self._ip_collection.find_one({'ip': addr})
        if doc:
            events = [
                event for event in doc['events']
                if event['timestamp'] >= start_date
            ]
        else:
            events = []

        if include_archives:
            archived_events = self._find_archived_events(addr, start_date)
            events.extend(archived_events)

        return events
Ejemplo n.º 2
0
    def find_all_events_for_ip(self, addr, start_date=0, include_archives=False):
        """
            Retrieve all events (archived ones too) for an ip address and newer
            than `start_date`.

            :param str addr: IP address to find
            :param int start_date: Timestamp the events must be retrieved from
            :param bool include_archives: Do the results must also include archives?
            :rtype: array
            :return: An array containing all attached events.
        """
        if not start_date:
            start_date = utils.get_a_month_ago_date()

        doc = self._ip_collection.find_one({'ip': addr})
        if doc:
            events = [event for event in doc['events'] if event['timestamp'] >= start_date]
        else:
            events = []

        if include_archives:
            archived_events = self._find_archived_events(addr, start_date)
            events.extend(archived_events)

        return events
Ejemplo n.º 3
0
    def test_a_month_ago(self):
        now = datetime.now().date()

        if now.month == 1:
            expected = int(time.mktime(now.replace(month=12, year=now.year - 1).timetuple()))
        else:
            expected = int(time.mktime(now.replace(month=now.month - 1).timetuple()))

        self.assertEquals(expected, utils.get_a_month_ago_date())
Ejemplo n.º 4
0
    def test_a_month_ago(self):
        now = datetime.now().date()

        if now.month == 1:
            expected = int(
                time.mktime(
                    now.replace(month=12, year=now.year - 1).timetuple()))
        else:
            expected = int(
                time.mktime(now.replace(month=now.month - 1).timetuple()))

        self.assertEqual(expected, utils.get_a_month_ago_date())
Ejemplo n.º 5
0
import hashlib
import random
import time
import ssl

import pymongo
from bson.code import Code
from config import secrets
from utils import utils
from utils.logger import LOGGER

IP_COLLECTION = 'iptable'
RAW_COLLECTION = 'rawfiles'
ARCHIVE_COLLECTION = 'archives'
TOPTEN_COLLECTION = 'top10'
A_MONTH_AGO = utils.get_a_month_ago_date()
TOP_LIMIT = 10


class Mongo(object):
    """
        This class is designed to provide everything needed to deal with MongoDB
        and to handle the needs of this app such as pushing new document or
        querying existing documents. In other words, this class is a typical
        data access object.
    """
    def __init__(self):
        """
            Constructor that only aims to init members and random numbers
            generator.
        """
Ejemplo n.º 6
0
import pymongo
from bson.code import Code
from config import settings
from utils import utils
from utils.logger import LOGGER


COLLECTION_PREFIX = "dev_" if settings.MONGODB['is_dev'] else ""

IP_COLLECTION = COLLECTION_PREFIX + 'iptable'
RAW_COLLECTION = COLLECTION_PREFIX + 'rawfiles'
ARCHIVE_COLLECTION = COLLECTION_PREFIX + 'archives'
TOPTEN_COLLECTION = COLLECTION_PREFIX + 'top10'
SPAMHAUS_COLLECTION = COLLECTION_PREFIX + 'spamhaus'

A_MONTH_AGO = utils.get_a_month_ago_date()

TOP_LIMIT = 10


class Mongo(object):
    """
        This class is designed to provide everything needed to dial with mongo
        and to handle the needs of this app such as pushing new document or
        querying existing documents. In other words, this class is a typical
        data access object.
    """

    def __init__(self):
        """
            Constructor that only aims to init members and random numbers