Пример #1
0
 def test_serialize_in_sync_with_deserialize(self):
     ty = ObjectRefType.Host
     ident = "node1"
     ref = ObjectRef.deserialize(ObjectRef(ty, ident).serialize())
     assert ref.object_type == ty
     assert ref.ident == ident
     assert ref.labels == {}
Пример #2
0
 def test_serialize_in_sync_with_deserialize_with_labels(self):
     ty = ObjectRefType.Host
     ident = "node1"
     labels = {"abc": "123"}
     ref = ObjectRef.deserialize(ObjectRef(ty, ident, labels).serialize())
     assert ref.object_type == ty
     assert ref.ident == ident
     assert ref.labels == labels
Пример #3
0
    def _object_ref_from_linkinfo(self, linkinfo: str) -> Optional[ObjectRef]:
        if ':' not in linkinfo:
            return None

        folder_path, host_name = linkinfo.split(':', 1)
        if not host_name:
            return ObjectRef(ObjectRefType.Folder, folder_path)
        return ObjectRef(ObjectRefType.Host, host_name)
Пример #4
0
def test__migrate_pre_2_0_audit_log(tmp_path, old_audit_log, new_path):
    uc = update_config.UpdateConfig(cmk.utils.log.logger, argparse.Namespace())

    assert not new_path.exists()
    assert old_audit_log.exists()

    uc._migrate_pre_2_0_audit_log()

    assert new_path.exists()
    assert not old_audit_log.exists()

    # Now try to parse the migrated log with the new logic
    store = AuditLogStore(new_path)
    assert store.read() == [
        AuditLogStore.Entry(
            time=1604991356,
            object_ref=None,
            user_id='cmkadmin',
            action='liveproxyd-activate',
            text='Activating changes of Livestatus Proxy configuration',
            diff_text=None),
        AuditLogStore.Entry(
            time=1604991356,
            object_ref=None,
            user_id='cmkadmin',
            action='liveproxyd-activate',
            text='Activating changes of Livestatus Proxy configuration',
            diff_text=None),
        AuditLogStore.Entry(time=1604992040,
                            object_ref=ObjectRef(ObjectRefType.Host, "heute2"),
                            user_id='cmkadmin',
                            action='create-host',
                            text='Created new host heute2.',
                            diff_text=None),
        AuditLogStore.Entry(time=1604992159,
                            object_ref=ObjectRef(ObjectRefType.Host, "heute2"),
                            user_id='cmkadmin',
                            action='delete-host',
                            text='Deleted host heute2',
                            diff_text=None),
        AuditLogStore.Entry(time=1604992163,
                            object_ref=ObjectRef(ObjectRefType.Host, "heute1"),
                            user_id='cmkadmin',
                            action='create-host',
                            text='Created new host heute1.',
                            diff_text=None),
        AuditLogStore.Entry(time=1604992166,
                            object_ref=ObjectRef(ObjectRefType.Host,
                                                 "heute12"),
                            user_id='cmkadmin',
                            action='create-host',
                            text='Created new host heute12.',
                            diff_text=None),
    ]
Пример #5
0
 def test_serialize(self):
     ty = ObjectRefType.Host
     ident = "node1"
     assert ObjectRef(ty, ident).serialize() == {
         'ident': 'node1',
         'object_type': 'Host'
     }
Пример #6
0
 def test_serialize(self):
     ty = ObjectRefType.Host
     ident = "node1"
     assert ObjectRef(ty, ident).serialize() == {
         "ident": "node1",
         "object_type": "Host"
     }
Пример #7
0
 def object_ref(self) -> ObjectRef:
     return ObjectRef(
         ObjectRefType.Rule,
         self.id,
         {
             "ruleset": self.ruleset.name,
         },
     )
Пример #8
0
 def fixture_entry(self):
     return {
         'id': 'd60ca3d4-7201-4a89-b66f-2f156192cad2',
         'action_name': 'create-host',
         'text': 'Created new host node1.',
         'object': ObjectRef(ObjectRefType.Host, "node1"),
         'user_id': 'cmkadmin',
         'domains': ['check_mk'],
         'time': 1605461248.786142,
         'need_sync': True,
         'need_restart': True,
     }
Пример #9
0
 def test_serialization_with_labels(self):
     ty = ObjectRefType.Host
     ident = "node1"
     assert ObjectRef(ty, ident, {
         "a": "b"
     }).serialize() == {
         'ident': 'node1',
         'object_type': 'Host',
         'labels': {
             'a': 'b'
         }
     }
Пример #10
0
 def test_serialization_with_labels(self):
     ty = ObjectRefType.Host
     ident = "node1"
     assert ObjectRef(ty, ident, {
         "a": "b"
     }).serialize() == {
         "ident": "node1",
         "object_type": "Host",
         "labels": {
             "a": "b"
         },
     }
Пример #11
0
 def fixture_entry(self):
     return {
         "id": "d60ca3d4-7201-4a89-b66f-2f156192cad2",
         "action_name": "create-host",
         "text": "Created new host node1.",
         "object": ObjectRef(ObjectRefType.Host, "node1"),
         "user_id": "cmkadmin",
         "domains": ["check_mk"],
         "time": 1605461248.786142,
         "need_sync": True,
         "need_restart": True,
     }
Пример #12
0
    def test_read_pre_20_host_change(self, store, old_type, ref_type):
        with store._path.open("wb") as f:
            f.write(
                repr({
                    'id': 'd60ca3d4-7201-4a89-b66f-2f156192cad2',
                    'action_name': 'create-host',
                    'text': 'Created new host node1.',
                    'object': (old_type, 'node1'),
                    'user_id': 'cmkadmin',
                    'domains': ['check_mk'],
                    'time': 1605461248.786142,
                    'need_sync': True,
                    'need_restart': True,
                }).encode("utf-8") + b"\0")

        assert store.read()[0]["object"] == ObjectRef(ref_type, 'node1')
Пример #13
0
    def test_read_pre_20_host_change(self, store, old_type, ref_type):
        with store._path.open("wb") as f:
            f.write(
                repr({
                    "id": "d60ca3d4-7201-4a89-b66f-2f156192cad2",
                    "action_name": "create-host",
                    "text": "Created new host node1.",
                    "object": (old_type, "node1"),
                    "user_id": "cmkadmin",
                    "domains": ["check_mk"],
                    "time": 1605461248.786142,
                    "need_sync": True,
                    "need_restart": True,
                }).encode("utf-8") + b"\0")

        assert store.read()[0]["object"] == ObjectRef(ref_type, "node1")
Пример #14
0
 def test_serialize_represented_as_native_types(self):
     serialized = ObjectRef(ObjectRefType.Host, "h1").serialize()
     as_text = repr(serialized)
     assert ast.literal_eval(as_text) == serialized
Пример #15
0
 def object_ref(self) -> ObjectRef:
     return ObjectRef(ObjectRefType.Ruleset, self.name)
Пример #16
0
def make_user_object_ref(user_id: UserId) -> ObjectRef:
    return ObjectRef(ObjectRefType.User, str(user_id))
Пример #17
0
def test__migrate_pre_2_0_audit_log(
    uc: update_config.UpdateConfig,
    old_audit_log: Path,
    new_path: Path,
) -> None:
    assert not new_path.exists()
    assert old_audit_log.exists()

    uc._migrate_pre_2_0_audit_log()

    assert new_path.exists()
    assert not old_audit_log.exists()

    # Now try to parse the migrated log with the new logic
    log_store = AuditLogStore(new_path)
    assert log_store.read() == [
        AuditLogStore.Entry(
            time=1604991356,
            object_ref=None,
            user_id="cmkadmin",
            action="liveproxyd-activate",
            text="Activating changes of Livestatus Proxy configuration",
            diff_text=None,
        ),
        AuditLogStore.Entry(
            time=1604991356,
            object_ref=None,
            user_id="cmkadmin",
            action="liveproxyd-activate",
            text="Activating changes of Livestatus Proxy configuration",
            diff_text=None,
        ),
        AuditLogStore.Entry(
            time=1604992040,
            object_ref=ObjectRef(ObjectRefType.Host, "heute2"),
            user_id="cmkadmin",
            action="create-host",
            text="Created new host heute2.",
            diff_text=None,
        ),
        AuditLogStore.Entry(
            time=1604992159,
            object_ref=ObjectRef(ObjectRefType.Host, "heute2"),
            user_id="cmkadmin",
            action="delete-host",
            text="Deleted host heute2",
            diff_text=None,
        ),
        AuditLogStore.Entry(
            time=1604992163,
            object_ref=ObjectRef(ObjectRefType.Host, "heute1"),
            user_id="cmkadmin",
            action="create-host",
            text="Created new host heute1.",
            diff_text=None,
        ),
        AuditLogStore.Entry(
            time=1604992166,
            object_ref=ObjectRef(ObjectRefType.Host, "heute12"),
            user_id="cmkadmin",
            action="create-host",
            text="Created new host heute12.",
            diff_text=None,
        ),
    ]
Пример #18
0
 def object_ref(self) -> ObjectRef:
     return ObjectRef(ObjectRefType.Rule, "|".join([self.ruleset.name, self.id]))