| 1 | # |
| 2 | # Copyright (C) 2020 FreeIPA Contributors see COPYING for license |
| 3 | # |
| 4 | |
| 5 | import loggingscip-python python python-stdlib 3.11 logging/__init__: |
| 6 | import rescip-python python python-stdlib 3.11 re/__init__: |
| 7 | from urllib.parsescip-python python python-stdlib 3.11 `urllib.parse`/__init__: import urlparse |
| 8 | |
| 9 | from ipahealthcheck.ds.pluginscip-python python ipahealthcheck 0.16 `ipahealthcheck.ds.plugin`/__init__: import DSPluginscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.plugin`/DSPlugin#, registryscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.plugin`/registry. |
| 10 | from ipahealthcheck.core.pluginscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.plugin`/__init__: import Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result# |
| 11 | from ipahealthcheck.core.pluginscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.plugin`/__init__: import durationscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/duration(). |
| 12 | from ipahealthcheck.corescip-python python ipahealthcheck 0.16 `ipahealthcheck.core`/__init__: import constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__: |
| 13 | |
| 14 | from ipalibscip-python python ipahealthcheck 0.16 ipalib/__init__: import api, errors |
| 15 | from ipapython.dnscip-python python ipahealthcheck 0.16 `ipapython.dn`/__init__: import DN |
| 16 | |
| 17 | loggerscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/logger. = loggingscip-python python python-stdlib 3.11 logging/__init__:.getLoggerscip-python python python-stdlib 3.11 logging/getLogger().() |
| 18 | |
| 19 | |
| 20 | @registryscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.plugin`/registry. |
| 21 | class RUVCheckscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#(DSPluginscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.plugin`/DSPlugin#): |
| 22 | """ |
| 23 | Provide the main and dogtag RUV. |
| 24 | |
| 25 | Local analysis is not possible since it requires collecting the |
| 26 | RUV from all masters and healthcheck is limited to only talking |
| 27 | to itself. |
| 28 | """ |
| 29 | requiresscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#requires. = ('dirsrv',) |
| 30 | |
| 31 | def get_ruvscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#get_ruv().(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#get_ruv().(self), dnscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#get_ruv().(dn)): |
| 32 | """Identify the RUV for a suffix on this master""" |
| 33 | try: |
| 34 | entry = selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#get_ruv().(self).connscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.plugin`/DSPlugin#conn..get_entry(dnscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#get_ruv().(dn)) |
| 35 | except Exceptionscip-python python python-stdlib 3.11 builtins/Exception#: |
| 36 | return None |
| 37 | else: |
| 38 | return entry.single_value.get('nsDS5ReplicaID') |
| 39 | |
| 40 | @durationscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/duration(). |
| 41 | def checkscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#check().(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#check().(self)): |
| 42 | ruv = selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#check().(self).get_ruvscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#get_ruv().(DN(('cn', 'replica'), ('cn', api.env.basedn), |
| 43 | ('cn', 'mapping tree'), ('cn', 'config'))) |
| 44 | csruv = selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#check().(self).get_ruvscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#get_ruv().(DN(('cn', 'replica'), ('cn', 'o=ipaca'), |
| 45 | ('cn', 'mapping tree'), ('cn', 'config'))) |
| 46 | |
| 47 | if ruv is not None: |
| 48 | yield Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result#(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#check().(self), constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__:.SUCCESSscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.constants`/SUCCESS., |
| 49 | key=strscip-python python python-stdlib 3.11 builtins/str#(api.env.basedn), |
| 50 | ruv=ruv) |
| 51 | if csruv is not None: |
| 52 | yield Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result#(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/RUVCheck#check().(self), constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__:.SUCCESSscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.constants`/SUCCESS., |
| 53 | key='o=ipaca', |
| 54 | ruv=csruv) |
| 55 | |
| 56 | |
| 57 | @registryscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.plugin`/registry. |
| 58 | class KnownRUVCheckscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#(DSPluginscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.plugin`/DSPlugin#): |
| 59 | """Return all known RUVs. This can be used to identify "dangling" |
| 60 | RUVs, or left-overs from previous replication agreements. |
| 61 | """ |
| 62 | requiresscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#requires. = ('dirsrv',) |
| 63 | |
| 64 | def get_all_ruvsscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#get_all_ruvs().(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#get_all_ruvs().(self), suffixscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#get_all_ruvs().(suffix)): |
| 65 | """Get all known RUVs on this master |
| 66 | |
| 67 | Return the RUV entries as a list of tuples: (hostname, rid) |
| 68 | """ |
| 69 | search_filter = '(&(nsuniqueid=ffffffff-ffffffff-ffffffff-ffffffff)' \ |
| 70 | '(objectclass=nstombstone))' |
| 71 | try: |
| 72 | entries = selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#get_all_ruvs().(self).connscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.plugin`/DSPlugin#conn..get_entries( |
| 73 | suffixscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#get_all_ruvs().(suffix), selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#get_all_ruvs().(self).connscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.plugin`/DSPlugin#conn..SCOPE_SUBTREE, search_filter, |
| 74 | ['nsds50ruv']) |
| 75 | except errors.NotFound: |
| 76 | loggerscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/logger..debugscip-python python python-stdlib 3.11 logging/Logger#debug().("No RUV records found.") |
| 77 | return [] |
| 78 | # raise NoRUVsFound("No RUV records found.") |
| 79 | |
| 80 | servers = [] |
| 81 | for e in entries: |
| 82 | for ruv in e['nsds50ruv']: |
| 83 | if ruv.startswith('{replicageneration'): |
| 84 | continue |
| 85 | data = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().( |
| 86 | r'\{replica (\d+) (ldap://.*:\d+)\}(\s+\w+\s+\w*){0,1}', |
| 87 | ruv |
| 88 | ) |
| 89 | if data: |
| 90 | rid = data.groupscip-python python python-stdlib 3.11 re/Match#group().(1) |
| 91 | ( |
| 92 | _scheme, netloc, _path, _params, _query, _fragment |
| 93 | ) = urlparse(data.groupscip-python python python-stdlib 3.11 re/Match#group().(2)) |
| 94 | servers.appendscip-python python python-stdlib 3.11 builtins/list#append().((rescip-python python python-stdlib 3.11 re/__init__:.subscip-python python python-stdlib 3.11 re/sub().(r':\d+', '', netloc), rid)) |
| 95 | else: |
| 96 | loggerscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/logger..debugscip-python python python-stdlib 3.11 logging/Logger#debug().("Unable to decode RUV: %s", ruv) |
| 97 | |
| 98 | return servers |
| 99 | |
| 100 | @durationscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/duration(). |
| 101 | def checkscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#check().(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#check().(self)): |
| 102 | |
| 103 | ruvs = selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#check().(self).get_all_ruvsscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#get_all_ruvs().(api.env.basedn) |
| 104 | csruvs = selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#check().(self).get_all_ruvsscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#get_all_ruvs().(DN('o=ipaca')) |
| 105 | |
| 106 | if ruvs: |
| 107 | yield Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result#(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#check().(self), constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__:.SUCCESSscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.constants`/SUCCESS., |
| 108 | key='ruvs_' + strscip-python python python-stdlib 3.11 builtins/str#(api.env.basedn), |
| 109 | suffix=strscip-python python python-stdlib 3.11 builtins/str#(api.env.basedn), |
| 110 | ruvs=ruvs) |
| 111 | |
| 112 | if csruvs: |
| 113 | yield Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result#(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.ds.ruv`/KnownRUVCheck#check().(self), constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__:.SUCCESSscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.constants`/SUCCESS., |
| 114 | key='ruvs_o=ipaca', |
| 115 | suffix='o=ipaca', |
| 116 | ruvs=csruvs) |