master
brent s 3 years ago
parent a89a6ec94b
commit 7eee1c4658
  1. 4
      lib/python/logger.py
  2. 30
      ref/python.tips_tricks_and_dirty_hacks
  3. 5
      storage/backups/borg/backup.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.

@ -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
----

@ -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)

Loading…
Cancel
Save