Skip to content

Commit 8bc1223

Browse files
committed
Added filepath check
1 parent f32bd73 commit 8bc1223

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

netbox_retrieve.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import configparser
44
import netbox_connection
55

6+
# Get the directory of the current script
7+
script_dir = os.path.dirname(os.path.abspath(__file__))
8+
69
def get_ipam_prefixes(netbox):
710
"""
811
Retrieve all IPAM prefixes from Netbox.
@@ -24,7 +27,6 @@ def write_to_csv(data, filename):
2427
- data (pynetbox.core.query.Request): IPAM prefixes data retrieved from Netbox.
2528
- filename (str): Name of the CSV file to write data to.
2629
"""
27-
script_dir = os.path.dirname(os.path.realpath(__file__)) # Get the directory of the running script
2830
file_path = os.path.join(script_dir, filename) # Construct the full path to the output file
2931
with open(file_path, 'w', newline='') as file:
3032
writer = csv.writer(file)
@@ -38,7 +40,7 @@ def write_to_csv(data, filename):
3840

3941
# Read URL and token from var.ini
4042
config = configparser.ConfigParser()
41-
config.read('var.ini')
43+
config.read(os.path.join(script_dir, 'var.ini'))
4244
url = config['credentials']['url']
4345
token = config['credentials']['token']
4446

0 commit comments

Comments
 (0)