forked from IntegralDefense/velocloud_logs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvelocloud_logs.py
43 lines (33 loc) · 1.18 KB
/
velocloud_logs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import logging
from api.base import VelocloudEnterpriseApi
from api.logging import setup_logger
from settings import LOGS_TO_PULL, SCRIPT_LOG_FILE, TIME_FILE
def read_time_from_file():
""" Read the last run's end CTIME string """
try:
with open(TIME_FILE, "r") as rf:
time_string = rf.read().strip()
except FileNotFoundError:
logging.error(
"File {} not found when reading latest time stamp.".format(TIME_FILE)
)
return None
else:
logging.info("Read {} from {}".format(time_string, TIME_FILE))
return time_string
def write_time_to_file(time_string):
""" Write the last run's time to file """
with open(TIME_FILE, "w+") as wf:
wf.write(time_string)
def main():
logging.info("Starting main function.")
api = VelocloudEnterpriseApi()
start_time = read_time_from_file()
logging.info("Velocloud API object created.")
logging.info("About to get the following log types: {}".format(LOGS_TO_PULL))
[api.get_logs(type_=log_type, start=start_time) for log_type in LOGS_TO_PULL]
write_time_to_file(api.last_time)
if __name__ == "__main__":
setup_logger()
main()
exit()