Example #1
0
    def __init__(self):
        """Construct Alexa API."""
        self._log = log()
        self.isLogined = False

        self._log.info("Starting Alexa cloud service parser...")

        self.login()
Example #2
0
    def __init__(self, access_token):
        """Construct Smartthings API."""
        self._log = log()

        self.access_token = access_token
        self.timezones = {}

        self.isLogined = False
        self.check_login()
Example #3
0
    def __init__(self, path):
        """Construct onhub class."""
        import parsers.onhub.diagnosticreport_pb2 as diagnostic
        import parsers.onhub.models as models

        self._log = log()

        self._log.info("Starting Onhub diagnostic report parser...")

        dr = diagnostic.DiagnosticReport()

        try:
            dr.ParseFromString(open(path, 'rb').read())
            self.report = self.generate_report(dr)

            # set stations
            _stations = self.report['infoJSON']['_apState']['_stations']
            self.stations = []

            for station in _stations:
                if station['_connected']:
                    ip_address = station['_ipAddresses'][0]
                else:
                    ip_address = ''

                mac_address = self.search_macaddr(station['_id'])

                self.stations.append(
                    models.Station(station['_dhcpHostname'], station['_id'],
                                   station['_lastSeenSecondsSinceEpoch'],
                                   station['_connected'], station['_guest'],
                                   ip_address, mac_address))

            # set commands
            _commands = self.report['commandOutput']
            self.commands = []

            for command in _commands:
                self.commands.append(
                    models.Command(command['command'], command['output']))

            self.settings = []

            self.settings.append(
                models.Settings('generateTime', self.report['unixTime']))

        except IOError:
            self._log.error("Unable to read diagnostic report", exc_info=True)
        except:
            self._log.error("Unable to parse report", exc_info=True)
Example #4
0
    def __init__(self, path):
        """Construct packet class."""
        self._log = log()

        import parsers.packet.models as models

        self._log.info("Reading {} packet file.".format(path))
        try:
            self.pcapfile = FileCapture(path, display_filter='coap or xmpp or mqtt')
        except:
            self.log.error("Unable to read {} packet file".format(path),
                           exc_info=True)
        self.packets = []

        for packet in self.pcapfile:
            time = int(float(packet.frame_info.time_epoch))
            src_macaddr = packet.eth.src
            dst_macaddr = packet.eth.dst

            protocol = packet.highest_layer

            src_ipaddr = packet.ip.src
            dst_ipaddr = packet.ip.dst

            if protocol == "COAP":
                src_port = packet.udp.srcport
                dst_port = packet.udp.dstport
                message = self.parse_coap(packet.coap)

            elif protocol == "XMPP":
                src_port = packet.tcp.srcport
                dst_port = packet.tcp.dstport
                message = self.parse_xmpp(packet.xmpp)

            elif protocol == "MQTT":
                src_port = packet.tcp.srcport
                dst_port = packet.tcp.dstport
                message = self.parse_mqtt(packet.mqtt)

            self.packets.append(models.Packet(
                time, src_macaddr, dst_macaddr, src_ipaddr, src_port,
                dst_ipaddr, dst_port, protocol, message
            ))

        self.pcapfile.close()
Example #5
0
from parsers.log import log
from util.dbsession import session

import json

conf = ConfigParser()
conf.read('config.ini')

REDIS_URL = 'redis://{}:{}/{}'.format(conf['redis']['host'],
                                      conf['redis']['port'],
                                      conf['redis']['db'])

app = Celery('tasks', broker=REDIS_URL, backend=REDIS_URL)

logger = log()

logger.info("Starting Celery tasks - backend: {}".format(REDIS_URL))


@signals.setup_logging.connect
def setup_celery_logging(**kwargs):
    """Disable celery default logging."""
    pass


def get_packet(path):
    """Get packet information from tcpdump file."""
    logger.debug("Get packet information from {}".format(path))
    packet = Packet(path)