def add_sensor_alert(self,
                         node_id: int,
                         sensor_id: int,
                         state: int,
                         optional_data: Optional[Dict[str, Any]],
                         change_state: bool,
                         has_latest_data: bool,
                         data_type: int,
                         sensor_data: Any,
                         logger: logging.Logger = None) -> bool:

        sensor_alert = SensorAlert()
        sensor_alert.nodeId = node_id
        sensor_alert.sensorId = sensor_id
        sensor_alert.state = state
        sensor_alert.changeState = change_state
        sensor_alert.hasLatestData = has_latest_data
        sensor_alert.dataType = data_type
        sensor_alert.sensorData = sensor_data

        sensor_alert.hasOptionalData = False
        sensor_alert.optionalData = optional_data
        if optional_data:
            sensor_alert.hasOptionalData = True

        self._sensor_alerts.append(sensor_alert)
        return True
Example #2
0
    def _create_instrumentation_dummy(self) -> Instrumentation:
        alert_level = AlertLevel()
        alert_level.level = 1
        alert_level.name = "Instrumentation Alert Level"
        alert_level.triggerAlertTriggered = True
        alert_level.triggerAlertNormal = True
        alert_level.instrumentation_cmd = "dummy.py"
        alert_level.instrumentation_timeout = 10

        sensor_alert = SensorAlert()
        sensor_alert.nodeId = 2
        sensor_alert.sensorId = 3
        sensor_alert.description = "Instrumentation Sensor Alert"
        sensor_alert.timeReceived = 1337
        sensor_alert.alertDelay = 20
        sensor_alert.state = 1
        sensor_alert.hasOptionalData = True
        sensor_alert.optionalData = {"key1": "value1", "key2": "value2"}
        sensor_alert.changeState = False
        sensor_alert.alertLevels = [1]
        sensor_alert.triggeredAlertLevels = [1]
        sensor_alert.hasLatestData = False
        sensor_alert.dataType = SensorDataType.NONE
        sensor_alert.sensorData = None

        logger = logging.getLogger("Instrumentation Test Case")

        return Instrumentation(alert_level, sensor_alert, logger)
Example #3
0
    def addSensorAlert(self,
                       nodeId: int,
                       sensorId: int,
                       state: int,
                       dataJson: str,
                       changeState: bool,
                       hasLatestData: bool,
                       dataType: int,
                       sensorData: Any,
                       logger: logging.Logger = None) -> bool:

        sensor_alert = SensorAlert()
        sensor_alert.nodeId = nodeId
        sensor_alert.sensorId = sensorId
        sensor_alert.state = state
        sensor_alert.changeState = changeState
        sensor_alert.hasLatestData = hasLatestData
        sensor_alert.dataType = dataType
        sensor_alert.sensorData = sensorData
        if dataJson == "":
            sensor_alert.hasOptionalData = False
        else:
            sensor_alert.hasOptionalData = True
            sensor_alert.optionalData = json.loads(dataJson)

        self._sensor_alerts.append(sensor_alert)
        return True
Example #4
0
    def test_process_output_invalid_data_type(self):
        """
        Tests an invalid data type output processing of an instrumentation script.
        """
        instrumentation = self._create_instrumentation_dummy()
        sensor_alert = instrumentation._sensor_alert

        invalid_sensor_alert = SensorAlert().deepcopy(sensor_alert)
        invalid_sensor_alert.dataType = SensorDataType.INT
        invalid_sensor_alert.sensorData = 1

        # Test instrumentation script output processing.
        was_success, new_sensor_alert = instrumentation._process_output(
            json.dumps(invalid_sensor_alert.convert_to_dict()))
        self.assertFalse(was_success)
        self.assertIsNone(new_sensor_alert)