From 157b7fdc590d1aef3f69545d6937edb0f33f374d Mon Sep 17 00:00:00 2001 From: Konvergenzradius <53154948+Konvergenzradius@users.noreply.github.com> Date: Mon, 27 Apr 2020 01:01:16 +0200 Subject: [PATCH 1/2] Fix bugs --- sshalert.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sshalert.py b/sshalert.py index 45d677d..a41ed25 100755 --- a/sshalert.py +++ b/sshalert.py @@ -41,11 +41,11 @@ def process_log_entry(logline): Check a logline and see if it matches the content we care about. """ # If it's a local sudo exec - if all(x in logline for x in ["sudo", "COMMAND"]: + if all(x in logline for x in ["sudo", "COMMAND"]): send_sms(logline) # If it's an SSH login - elif all(x in logline for x in ["ssh", "Accepted"]: + elif all(x in logline for x in ["ssh", "Accepted"]): send_sms(logline) return From 5c2ee2e7b46a8670dec6eb3071791a1ae554591f Mon Sep 17 00:00:00 2001 From: Konvergenzradius <53154948+Konvergenzradius@users.noreply.github.com> Date: Mon, 27 Apr 2020 01:02:21 +0200 Subject: [PATCH 2/2] Be PEP 8 compliant --- sshalert.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sshalert.py b/sshalert.py index a41ed25..4cf6d66 100755 --- a/sshalert.py +++ b/sshalert.py @@ -15,7 +15,8 @@ nexmo_key = os.getenv("NEXMO_KEY") nexmo_secret = os.getenv("NEXMO_SECRET") except: - logging.critical("ERROR: Have you exported all required environment variables? (TARGET_PHONE_NUMBER, NEXMO_KEY, NEXMO_SECRET)") + logging.critical( + "ERROR: Have you exported all required environment variables? (TARGET_PHONE_NUMBER, NEXMO_KEY, NEXMO_SECRET)") exit(1) # Initialize the nexmo client @@ -26,7 +27,8 @@ def poll_logfile(filename): """ Polls a logfile for sudo commands or ssh logins. """ - f = subprocess.Popen(["tail", "-F", "-n", "0", filename], encoding="utf8", stdout=subprocess.PIPE, stderr=subprocess.PIPE) + f = subprocess.Popen(["tail", "-F", "-n", "0", filename], encoding="utf8", stdout=subprocess.PIPE, + stderr=subprocess.PIPE) p = select.poll() p.register(f.stdout) @@ -43,7 +45,7 @@ def process_log_entry(logline): # If it's a local sudo exec if all(x in logline for x in ["sudo", "COMMAND"]): send_sms(logline) - + # If it's an SSH login elif all(x in logline for x in ["ssh", "Accepted"]): send_sms(logline)