ldap_netdb: Add -v option to cron job and skip localhost
This commit is contained in:
parent
8ca459430c
commit
533b48204f
1 changed files with 12 additions and 2 deletions
|
@ -115,14 +115,18 @@ def parse_objectclass(data):
|
|||
return objclass
|
||||
|
||||
|
||||
def main():
|
||||
def main(verbose):
|
||||
requests.packages.urllib3.disable_warnings(SubjectAltNameWarning)
|
||||
syslog.openlog(
|
||||
sys.argv[0].split("/")[-1], logoption=syslog.LOG_PID, facility=syslog.LOG_DAEMON
|
||||
)
|
||||
(conn, basedn) = ldap_connect()
|
||||
for (hostname, mtime) in get_hostlist():
|
||||
if hostname in ("localhost"):
|
||||
continue
|
||||
dn = f"cn={hostname},ou=Hosts,{basedn}"
|
||||
if verbose:
|
||||
print(f"Processing entry {dn}")
|
||||
result = conn.search(
|
||||
search_base=dn,
|
||||
search_scope=ldap3.BASE,
|
||||
|
@ -162,6 +166,12 @@ def main():
|
|||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
verbose = False
|
||||
if len(sys.argv) > 1:
|
||||
if sys.argv[1] == "-v":
|
||||
verbose = True
|
||||
else:
|
||||
print(f"Usage: {sys.argv[0]} [-v]", file=sys.stderr)
|
||||
main(verbose)
|
||||
except KeyboardInterrupt:
|
||||
sys.exit(1)
|
||||
|
|
Loading…
Add table
Reference in a new issue