From 1a08a88b9e0a69467478dd7558868d50b029ff15 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Sat, 8 Jul 2023 09:56:07 +1000 Subject: [PATCH] docs/debug --- .github/ISSUE_TEMPLATE/i-have-an-issue.md | 4 +-- pialert/mac_vendor.py | 31 +++++++++++++++-------- pialert/scanners/arpscan.py | 5 ++-- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/i-have-an-issue.md b/.github/ISSUE_TEMPLATE/i-have-an-issue.md index 34b1a38c..88cc1ead 100755 --- a/.github/ISSUE_TEMPLATE/i-have-an-issue.md +++ b/.github/ISSUE_TEMPLATE/i-have-an-issue.md @@ -19,7 +19,7 @@ assignees: '' paste_here ``` -## Paste your `docker-compose.yml` and `.env` (remove personal info)** +## Paste your `docker-compose.yml` and `.env` (remove personal info) `docker-compose.yml` @@ -29,8 +29,6 @@ paste_here `.env` - - ``` paste_here ``` diff --git a/pialert/mac_vendor.py b/pialert/mac_vendor.py index 35359ba8..aa576039 100755 --- a/pialert/mac_vendor.py +++ b/pialert/mac_vendor.py @@ -1,5 +1,6 @@ import subprocess +import conf from const import pialertPath, vendorsDB from helper import timeNow, updateState @@ -22,13 +23,18 @@ def update_devices_MAC_vendors (db, pArg = ''): mylog('verbose', [' Updating vendors DB (iab & oui)']) update_args = ['sh', pialertPath + '/update_vendors.sh', pArg] - try: + # Execute command + if conf.LOG_LEVEL == 'debug': # try runnning a subprocess update_output = subprocess.check_output (update_args) - except subprocess.CalledProcessError as e: - # An error occured, handle it - mylog('none', [' FAILED: Updating vendors DB, set LOG_LEVEL=debug for more info']) - mylog('none', [e.output]) + else: + try: + # try runnning a subprocess safely + update_output = subprocess.check_output (update_args) + except subprocess.CalledProcessError as e: + # An error occured, handle it + mylog('none', [' FAILED: Updating vendors DB, set LOG_LEVEL=debug for more info']) + mylog('none', [e.output]) # Initialize variables recordsToUpdate = [] @@ -82,14 +88,19 @@ def query_MAC_vendor (pMAC): # Search vendor in HW Vendors DB mac = mac[0:6] grep_args = ['grep', '-i', mac, vendorsDB] + # Execute command - try: + if conf.LOG_LEVEL == 'debug': # try runnning a subprocess grep_output = subprocess.check_output (grep_args) - except subprocess.CalledProcessError as e: - # An error occured, handle it - mylog('none', ["[Mac Vendor Check] Error: ", e.output]) - grep_output = " There was an error, check logs for details" + else: + try: + # try runnning a subprocess + grep_output = subprocess.check_output (grep_args) + except subprocess.CalledProcessError as e: + # An error occured, handle it + mylog('none', ["[Mac Vendor Check] Error: ", e.output]) + grep_output = " There was an error, check logs for details" # Return Vendor vendor = grep_output[7:] diff --git a/pialert/scanners/arpscan.py b/pialert/scanners/arpscan.py index dfb4261e..42a9c502 100755 --- a/pialert/scanners/arpscan.py +++ b/pialert/scanners/arpscan.py @@ -62,9 +62,10 @@ def execute_arpscan_on_interface (interface): result = subprocess.check_output (arpscan_args, universal_newlines=True) except subprocess.CalledProcessError as e: # An error occured, handle it - error_type = type(e).__name__ # Capture the error type - + error_type = type(e).__name__ # Capture the error type + mylog('none', [f'[ARP Scan] Error type : {error_type}']) + mylog('none', [f'[ARP Scan] Set LOG_LEVEL=debug for more details']) mylog('none', [f'[ARP Scan] Error output: {e.output}']) result = ""