コード例 #1
0
    def test_update_alert(self):
        """
        Test Alert object updating.
        """
        system_data = self._create_system_data()

        # Create changes that should be copied to the stored object.
        new_alerts = []
        for i in range(len(self.alerts)):
            temp_alert = ManagerObjAlert().deepcopy(self.alerts[i])
            temp_alert.description = "new_alert_" + str(i + 1)
            temp_alert.clientAlertId = i
            # We started the alert levels in our test data with level 1.
            temp_alert.alertLevels = [(i % len(self.alert_levels)) + 1]
            new_alerts.append(temp_alert)

        for i in range(len(new_alerts)):

            # Update store with new object data.
            temp_alert = new_alerts[i]
            system_data.update_alert(temp_alert)

            gt_storage = []
            for j in range(i + 1):
                gt_storage.append(new_alerts[j])
            for j in range(i + 1, len(new_alerts)):
                gt_storage.append(self.alerts[j])

            stored_alerts = system_data.get_alerts_list()
            compare_alerts_content(self, gt_storage, stored_alerts)
コード例 #2
0
    def test_update_alert(self):
        """
        Tests updating of alerts in the database.
        """
        config_logging(logging.ERROR)

        storage = self._init_database()

        system_data = self._create_system_data()
        self._create_objects(storage, system_data)

        # Update local objects.
        ctr = 0
        for alert in system_data.get_alerts_list():
            temp_alert = ManagerObjAlert().deepcopy(alert)
            temp_alert.description = "new_alert_" + str(ctr + 1)
            temp_alert.clientAlertId = ctr
            # We started the alert levels in our test data with level 1.
            temp_alert.alertLevels = [
                (ctr % len(system_data.get_alert_levels_list())) + 1
            ]
            system_data.update_alert(temp_alert)
            ctr += 1

        # Update database objects.
        storage._open_connection()
        for alert in system_data.get_alerts_list():
            storage._update_alert(alert)
        storage._conn.commit()

        storage._system_data = SystemData()
        storage.synchronize_database_to_system_data()

        compare_alerts_content(self, system_data.get_alerts_list(),
                               storage._system_data.get_alerts_list())
コード例 #3
0
    def _invalid_alert_level_missing(self, system_data: SystemData):
        # Test non-existing alert level.
        node = ManagerObjNode()
        node.nodeId = 1
        node.hostname = "hostname_1"
        node.nodeType = "alert"
        node.instance = "instance_1"
        node.connected = 1
        node.version = 1.0
        node.rev = 0
        node.username = "******"
        node.persistent = 1
        system_data.update_node(node)

        alert = ManagerObjAlert()
        alert.nodeId = 1
        alert.alertId = 1
        alert.clientAlertId = 1
        alert.alertLevels = [99]
        alert.description = "alert_1"
        is_exception = False
        try:
            system_data.update_alert(alert)
        except ValueError:
            is_exception = True
        if not is_exception:
            self.fail("Exception because of wrong node type expected.")
コード例 #4
0
 def _invalid_node_missing(self, system_data: SystemData):
     # Test non-existing node.
     alert = ManagerObjAlert()
     alert.nodeId = 99
     alert.alertId = 1
     alert.clientAlertId = 1
     alert.alertLevels = []
     alert.description = "alert_1"
     is_exception = False
     try:
         system_data.update_alert(alert)
     except ValueError:
         is_exception = True
     if not is_exception:
         self.fail("Exception because of non-existing node expected.")
コード例 #5
0
    def test_update(self):
        """
        Tests updating of system information in the database.
        """
        config_logging(logging.ERROR)

        storage = self._init_database()

        # Create database objects.
        system_data = self._create_system_data()
        storage.update_server_information(0, system_data.get_options_list(),
                                          system_data.get_nodes_list(),
                                          system_data.get_sensors_list(),
                                          system_data.get_alerts_list(),
                                          system_data.get_managers_list(),
                                          system_data.get_alert_levels_list(),
                                          [])

        # Update local objects.
        ctr = 0
        for option in system_data.get_options_list():
            temp_option = ManagerObjOption().deepcopy(option)
            temp_option.value = float(ctr)
            system_data.update_option(temp_option)
            ctr += 1

        for alert_level in system_data.get_alert_levels_list():
            temp_alert_level = ManagerObjAlertLevel().deepcopy(alert_level)
            temp_alert_level.name = "new_alert_level_" + str(ctr + 1)
            temp_alert_level.triggerAlways = (ctr % 2)
            temp_alert_level.instrumentation_active = (ctr % 2) == 0

            if temp_alert_level.instrumentation_active:
                temp_alert_level.instrumentation_cmd = "alert_level_instrumentation_" + str(
                    ctr + 1)
                temp_alert_level.instrumentation_timeout = 123 + ctr

            system_data.update_alert_level(temp_alert_level)
            ctr += 1

        for node in system_data.get_nodes_list():
            temp_node = ManagerObjNode().deepcopy(node)
            temp_node.hostname = "new_hostname_" + str(ctr + 1)
            temp_node.nodeType = ["alert", "manager", "sensor",
                                  "server"][ctr % 4]
            temp_node.instance = "new_instance_" + str(ctr + 1)
            temp_node.connected = (ctr % 2)
            temp_node.version = float(5 + ctr)
            temp_node.rev = ctr
            temp_node.username = "******" + str(ctr + 1)
            temp_node.persistent = (ctr % 2)
            system_data.update_node(temp_node)
            ctr += 1

        for alert in system_data.get_alerts_list():
            temp_alert = ManagerObjAlert().deepcopy(alert)
            temp_alert.description = "new_alert_" + str(ctr + 1)
            temp_alert.remoteAlertId = ctr
            # We started the alert levels in our test data with level 1.
            temp_alert.alertLevels = [
                (ctr % len(system_data.get_alert_levels_list())) + 1
            ]
            system_data.update_alert(temp_alert)
            ctr += 1

        for manager in system_data.get_managers_list():
            temp_manager = ManagerObjManager().deepcopy(manager)
            temp_manager.description = "new_manager_" + str(ctr + 1)
            system_data.update_manager(temp_manager)
            ctr += 1

        for sensor in system_data.get_sensors_list():
            temp_sensor = ManagerObjSensor().deepcopy(sensor)
            temp_sensor.description = "new_sensor_" + str(ctr + 1)
            temp_sensor.remoteSensorId = ctr
            temp_sensor.alertDelay = ctr + 10
            temp_sensor.lastStateUpdated = ctr + 10
            temp_sensor.state = ctr % 2
            temp_sensor.dataType = SensorDataType.INT
            temp_sensor.data = ctr
            # We started the alert levels in our test data with level 1.
            temp_sensor.alertLevels = [
                (ctr % len(system_data.get_alert_levels_list())) + 1
            ]
            system_data.update_sensor(temp_sensor)
            ctr += 1

        # Update database objects.
        storage.update_server_information(0, system_data.get_options_list(),
                                          system_data.get_nodes_list(),
                                          system_data.get_sensors_list(),
                                          system_data.get_alerts_list(),
                                          system_data.get_managers_list(),
                                          system_data.get_alert_levels_list(),
                                          [])

        storage._system_data = SystemData()
        storage.synchronize_database_to_system_data()

        compare_nodes_content(self, system_data.get_nodes_list(),
                              storage._system_data.get_nodes_list())
        compare_alerts_content(self, system_data.get_alerts_list(),
                               storage._system_data.get_alerts_list())
        compare_managers_content(self, system_data.get_managers_list(),
                                 storage._system_data.get_managers_list())
        compare_sensors_content(self, system_data.get_sensors_list(),
                                storage._system_data.get_sensors_list())
        compare_alert_levels_content(
            self, system_data.get_alert_levels_list(),
            storage._system_data.get_alert_levels_list())
コード例 #6
0
    def _create_alerts(self,
                       system_data: Optional[SystemData] = None) -> SystemData:

        if system_data is None:
            system_data = self._create_alert_levels()

        node = ManagerObjNode()
        node.nodeId = 1
        node.hostname = "hostname_1"
        node.nodeType = "alert"
        node.instance = "instance_1"
        node.connected = 1
        node.version = 1.0
        node.rev = 0
        node.username = "******"
        node.persistent = 1
        self.nodes.append(node)
        system_data.update_node(ManagerObjNode().deepcopy(node))

        alert = ManagerObjAlert()
        alert.nodeId = 1
        alert.alertId = 2
        alert.remoteAlertId = 0
        alert.alertLevels = [1]
        alert.description = "alert_1"
        self.alerts.append(alert)
        system_data.update_alert(ManagerObjAlert().deepcopy(alert))

        node = ManagerObjNode()
        node.nodeId = 2
        node.hostname = "hostname_2"
        node.nodeType = "alert"
        node.instance = "instance_2"
        node.connected = 1
        node.version = 1.0
        node.rev = 0
        node.username = "******"
        node.persistent = 1
        self.nodes.append(node)
        system_data.update_node(ManagerObjNode().deepcopy(node))

        alert = ManagerObjAlert()
        alert.nodeId = 2
        alert.alertId = 1
        alert.remoteAlertId = 3
        alert.alertLevels = [2]
        alert.description = "alert_2"
        self.alerts.append(alert)
        system_data.update_alert(ManagerObjAlert().deepcopy(alert))

        node = ManagerObjNode()
        node.nodeId = 3
        node.hostname = "hostname_3"
        node.nodeType = "alert"
        node.instance = "instance_3"
        node.connected = 1
        node.version = 1.0
        node.rev = 0
        node.username = "******"
        node.persistent = 1
        self.nodes.append(node)
        system_data.update_node(ManagerObjNode().deepcopy(node))

        alert = ManagerObjAlert()
        alert.nodeId = 3
        alert.alertId = 3
        alert.remoteAlertId = 1
        alert.alertLevels = [1, 2]
        alert.description = "alert_3"
        self.alerts.append(alert)
        system_data.update_alert(ManagerObjAlert().deepcopy(alert))

        return system_data