diff --git a/lib/python/logger.py b/lib/python/logger.py index 54c2db6..0e9016a 100755 --- a/lib/python/logger.py +++ b/lib/python/logger.py @@ -42,12 +42,12 @@ class log(object): except Exception as e: # Make this non-fatal since we also log to journal for systemd? raise e - self.systemd() + self.chkSystemd() self.journald() self.Logger.setLevel(self.loglvls[self.loglvl]) self.log_handlers() - def systemd(self): + def chkSystemd(self): # Add journald support if we're on systemd. # We probably are since we're most likely on Arch, but we don't want to # make assumptions. diff --git a/ref/python.tips_tricks_and_dirty_hacks b/ref/python.tips_tricks_and_dirty_hacks index 9847aef..00c4a23 100644 --- a/ref/python.tips_tricks_and_dirty_hacks +++ b/ref/python.tips_tricks_and_dirty_hacks @@ -170,3 +170,33 @@ os.setegid(my_gid) os.setgroups(my_grps) os.umask(old_umask) subprocess.run(['touch', '/tmp/parenttest']) + +############################################################################### + + +Getting remote sshd version + +stdlib: +---- +import socket + +try: + sock = socket.socket() + sock.settimeout(10) + sock.connect(('cylon', 22)) + version = sock.recv(64).decode('utf-8').strip() + # version is a string like "SSH-2.0-OpenSSH_7.9" + sock.close() +except Exception as e: + # Obviously you can specify multiple exceptions to catch. + raise RuntimeError(e) +---- + +paramiko (does not require auth): +---- +import paramiko + +t = paramiko.Transport(('cylon', 22)) +t.connect() +t.remote_version +---- diff --git a/storage/backups/borg/backup.py b/storage/backups/borg/backup.py index 03c0751..dda9654 100755 --- a/storage/backups/borg/backup.py +++ b/storage/backups/borg/backup.py @@ -83,7 +83,10 @@ class Backup(object): if self.args['verbose']: handlers.append(logging.StreamHandler()) if has_systemd: - h = journal.JournalHandler() + try: + h = journal.JournalHandler() + except AttributeError: + h = journal.JournaldLogHandler() h.setFormatter(_journalfmt) h.setLevel(loglvls[self.args['loglevel']]) self.logger.addHandler(h)