From d85517268ba1784554412a30abd3c291a5bef2dd Mon Sep 17 00:00:00 2001 From: Fanch Date: Fri, 17 Oct 2025 16:11:30 +0200 Subject: [PATCH] pahekoldap --- bin/checkPahekoLdap.py | 22 ++++++++++++++++++++-- bin/lib/ssh.py | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 bin/lib/ssh.py diff --git a/bin/checkPahekoLdap.py b/bin/checkPahekoLdap.py index 91574a1..360f448 100755 --- a/bin/checkPahekoLdap.py +++ b/bin/checkPahekoLdap.py @@ -4,6 +4,7 @@ import sys from lib.paheko import Paheko from lib.ldap import Ldap +from lib.ssh import Ssh paheko = Paheko() categorie_membres = paheko.get_categorie_id("Membres") @@ -78,6 +79,18 @@ def test_mails_orga(paheko_entry): return res +def test_server_location(paheko_entry): + # Vérifie que le serveur est bien renseigné. + is_orga = paheko_entry["admin_orga"].strip("'") == "Oui" + if is_orga: + serveur_prod = paheko_entry["serveur_prod"] + if not serveur_prod: + return False + directory = f"/kaz/dockers/{paheko_entry['nom_orga']}-orga" + with Ssh(serveur_prod) as ssh: + return ssh.check_return_code(f"ls {directory}") == 0 + return True + with Ldap() as ldap: try: not_in_ldap = [] @@ -86,6 +99,7 @@ with Ldap() as ldap: quota = [] services = [] mails_orgas = [] + servers_locations = [] for membre in membres: ldap_entry = ldap.get_email(membre["email"]) if ldap_entry: @@ -108,6 +122,9 @@ with Ldap() as ldap: suffix = '\n '.join(mails_orga) mails_orgas.append(f"{membre['email']}:\n {suffix}") + if not test_server_location(membre): + servers_locations.append(f"{membre['email']}, pas trouvé sur {membre['serveur_prod']}") + else: not_in_ldap.append(f"{membre['email']} / id : {membre['id']}") except Exception as e: @@ -129,10 +146,9 @@ with Ldap() as ldap: print("Mails dans paheko mais pas dans le LDAP :") print("\n".join(not_in_ldap)) -print("Mails dans lda LDAP mais pas dans paheko :") +print("Mails dans le LDAP mais pas dans paheko :") print("\n".join(not_in_paheko)) - print("\nMails de secours pas ok dans le LDAP :") print("\n".join(mail_secours)) @@ -145,3 +161,5 @@ print("\n".join(quota)) print("\nMails d'orga dans paheko mais manquant dans le LDAP :") print("\n".join(mails_orgas)) +print("\nOrgas pas trouvées sur le serveur renseigné dans paheko :") +print("\n".join(servers_locations)) \ No newline at end of file diff --git a/bin/lib/ssh.py b/bin/lib/ssh.py new file mode 100644 index 0000000..0e597f0 --- /dev/null +++ b/bin/lib/ssh.py @@ -0,0 +1,24 @@ +import paramiko + +class Ssh: + def __init__(self, server, username="root"): + self.ssh_connection = None + self.server = server + self.username = username + + def __enter__(self): + self.ssh_connection = paramiko.SSHClient() + self.ssh_connection.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + self.ssh_connection.connect(self.server, port=2201, username=self.username) + return self + + def __exit__(self, tp, e, traceback): + self.ssh_connection.close() + + def check_output(self, command): + ssh_stdin, ssh_stdout, ssh_stderr = self.ssh_connection.exec_command(command) + return ssh_stdout.read().decode() + + def check_return_code(self, command): + ssh_stdin, ssh_stdout, ssh_stderr = self.ssh_connection.exec_command(command) + return ssh_stdout.channel.recv_exit_status() \ No newline at end of file