Skip to content

Commit

Permalink
error handling in case inventory not reachable
Browse files Browse the repository at this point in the history
  • Loading branch information
richardtief committed Dec 17, 2020
1 parent 8506917 commit e054590
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,21 @@ def initialize_collector_by_name(class_name, logger):


def get_targets(inventory):
try:
request = requests.get(url="http://" + os.environ['INVENTORY'] + "/vrops_list")
targets = request.json()
return targets
except requests.exceptions.ConnectionError as e:
logger.critical(f'No connection to {inventory} - Error: {e}')
logger.critical(f'Exit')
sys.exit(0)
# error handling in case inventory is not reachable
attempt = 1
while attempt == 1:
try:
request = requests.get(url="http://" + os.environ['INVENTORY'] + "/vrops_list")
targets = request.json()
return targets
except requests.exceptions.ConnectionError as e:
logger.critical(f'No connection to {inventory} - Error: {e}')
logger.critical(f'Trying again in 5sec.')
time.sleep(5)
attempt += 1
logger.critical(f'{inventory} not reachable')
logger.critical(f'Exit')
sys.exit(0)


if __name__ == '__main__':
Expand Down

0 comments on commit e054590

Please sign in to comment.