Skip to content

Commit

Permalink
enhance import from anyware and config file
Browse files Browse the repository at this point in the history
  • Loading branch information
agn-7 committed Jan 31, 2022
1 parent 6346b6c commit 45c0a39
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
5 changes: 4 additions & 1 deletion snmp_collector/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python

from event_loop import run
try:
from event_loop import run
except:
from .event_loop import run

__author__ = 'aGn'
__copyright__ = "Copyright 2018, Planet Earth"
Expand Down
5 changes: 4 additions & 1 deletion snmp_collector/collect/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from pysnmp.hlapi.asyncio import *
from colored_print import ColoredPrint

from response.response import Response
try:
from snmp_collector.response.response import Response
except:
from response.response import Response

log = ColoredPrint()

Expand Down
16 changes: 12 additions & 4 deletions snmp_collector/event_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@

from pysnmp.error import PySnmpError
from pysnmp.hlapi.asyncio import *
from colored_print import ColoredPrint

from read_conf.read_configuration import get_config
from collect.collector import SNMPReader
from utility.utility import Utility
try:
from snmp_collector.read_conf.read_configuration import get_config
from snmp_collector.collect.collector import SNMPReader
from snmp_collector.utility.utility import Utility
except:
from read_conf.read_configuration import get_config
from collect.collector import SNMPReader
from utility.utility import Utility

log = ColoredPrint()

__author__ = 'aGn'
__copyright__ = "Copyright 2018, Planet Earth"
Expand Down Expand Up @@ -208,7 +216,7 @@ def run_forever(self):

else:
time.sleep(5)
print("Waiting for SNMP configuration ...")
log.info("Waiting for SNMP configuration ...")


def run():
Expand Down
12 changes: 10 additions & 2 deletions snmp_collector/read_conf/read_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@

from pprint import pprint
from pysnmp.hlapi.asyncio import *
from colored_print import ColoredPrint

from utility.utility import MWT
try:
from snmp_collector.utility.utility import MWT
except:
from utility.utility import MWT

log = ColoredPrint()

__author__ = 'aGn'
__copyright__ = "Copyright 2018, Planet Earth"
Expand Down Expand Up @@ -84,6 +90,8 @@ def get_config():
config_path = 'config.json'
elif os.path.exists("./config/config.json"):
config_path = './config/config.json'
elif os.path.exists("./snmp_collector/config/config.json"):
config_path = './snmp_collector/config/config.json'
else:
raise ValueError("Cannot find a config file!")

Expand All @@ -95,7 +103,7 @@ def get_config():
pprint(configs)

except (KeyError, IOError, FileNotFoundError, Exception) as exc:
print(exc)
log.err(exc)

return configs

Expand Down
8 changes: 7 additions & 1 deletion snmp_collector/utility/utility.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import time
import os

from colored_print import ColoredPrint

log = ColoredPrint()

__author__ = 'aGn'
__copyright__ = "Copyright 2018, Planet Earth"

Expand All @@ -20,14 +24,16 @@ def is_config_exist():
config_path = os.environ['CONFIG_PATH']
elif os.path.exists('./config/' + path):
config_path = './config/' + path
elif os.path.exists('./snmp_collector/config/' + path):
config_path = './snmp_collector/config/' + path
elif os.path.exists(path):
config_path = path
elif os.path.exists("../" + path):
config_path = "../" + path
elif os.path.exists("../../" + path):
config_path = "../../" + path
else:
print("Cannot find a config file!")
log.err("Cannot find a config file!")

if config_path is not None:
stamp = os.stat(config_path).st_mtime
Expand Down

0 comments on commit 45c0a39

Please sign in to comment.