Exemple #1
0
    def __init__(self,
                 trace_path: str,
                 config_path: str,
                 debug: bool = False,
                 db_path: str = None):
        self._trace: Trace = Trace()
        self._start_time: float
        self._trace.load_file(trace_path)
        self._debug: bool = debug
        self._cfg: SchedulerConfig = self.load_config(config_path)
        self._client: mqtt.Client = mqtt.Client(self._cfg.name)
        if not self._debug:
            self.configure_client()
        self._engine: sched.scheduler = sched.scheduler(
            self.scheduler_time, self.scheduler_sleep)
        if os.path.exists(self._cfg.log_path) and not self._cfg.overwrite_log:
            raise FileExistsError(
                "Log file already exists and no overwrite configured")

        # SQL session
        self.session = create_sessions(self._cfg.db_path)

        # Intruder module
        self.intruder: IntruderHub = IntruderHub(self._cfg.name,
                                                 self._client,
                                                 db_path=db_path)

        # Connect to broker
        if not self._debug:
            self.connect()
Exemple #2
0
def profile(maxIter: int):
    app = pg.QtGui.QApplication(sys.argv)
    app.setApplicationName("Plotter - Profiling")
    session = create_sessions(cfg.db_path)
    plots_win = PlotsWindow(session, maxIter, True, app)
    sett_win = SettingsWindow(plots_win)
    sys.exit(app.exec_())
Exemple #3
0
def main():
    pg.setConfigOptions(background=cfg.themes["light"]["background"],
                        foreground=cfg.themes["light"]["axis"])
    app = pg.QtGui.QApplication(sys.argv)
    app.setApplicationName("Plotter")
    session = create_sessions(cfg.db_path)
    plots_win: PlotsWindow = PlotsWindow(session)
    sett_win: SettingsWindow = SettingsWindow(plots_win)
    sys.exit(app.exec_())
Exemple #4
0
    def __init__(self):
        self.nodes: Dict[str, Dict[str, SensorJSON]] = {}
        self.node_ids: Dict[str, int] = {}
        self.sensor_ids: Dict[str] = {}

        # MQTT client
        self.client: mqtt.Client = mqtt.Client(cfg.client_name)
        self.client.tls_set(ca_certs=cfg.ca_cert,
                            certfile=cfg.certfile,
                            keyfile=cfg.keyfile)
        self.client.on_connect = self.on_connect
        self.client.on_message = self.on_message
        self.client.on_log = self.on_log

        # SQL session
        self.session = create_sessions(cfg.db_path)
        self.transactions_counter: int = 0
        self.max_transaction_counter: int = 50
    def __init__(self, name: str = "mqtt_intruder_1", client: mqtt.Client = None, debug: bool = False, db_path: str = None):
        self.name: str = name
        if db_path is None:
            self.db_path = cfg.db_path
        else:
            self.db_path = db_path
        self.session: Session = create_sessions(self.db_path)
        self.intruder_prefix: str = cfg.topic_prefix
        self.control_topic: str = cfg.topic_prefix + "control"

        self.client: mqtt.Client
        if client is None:
            self.client = mqtt.Client(self.name)
            self.client.on_connect = self.on_connect
            self.client.on_message = self.on_message
            self.client.tls_set(ca_certs=cfg.cafile,
                                certfile=cfg.certfile,
                                keyfile=cfg.keyfile)
        else:
            self.client = client
Exemple #6
0
from typing import List, Tuple, Dict
from operator import itemgetter

from bookkeeper.sql import create_sessions, Node, Sensor, Measurement, Attack

import app_config as cfg

session = create_sessions(cfg.db_path)


def get_node_id(name: str) -> int:
    """Given a node name, returns its ID"""
    node = session.query(Node.id).filter_by(name=name).all()
    if len(node) == 0:
        return 0
    return node[0].id


def get_sensor_id(sensor_name: str, node_name: str) -> int:
    """Given a sensor/node name, returns its ID"""
    node_id = session.query(Node.id).filter_by(name=node_name).all()
    sensor = session.query(Sensor.id).filter_by(name=sensor_name,
                                                node_id=node_id[0].id).all()
    if len(sensor) == 0:
        return 0
    return sensor[0].id


def get_data_tuples(node_name: str,
                    sensor_name: str) -> List[Tuple[float, float]]:
    """Returns the list of all data points for the given node/sensor"""