moved file check into statcollect function only if results are true

This commit is contained in:
Marc Mance
2024-06-06 14:50:24 -04:00
parent 9c24ca5a56
commit 0bdc036f01
4 changed files with 32 additions and 32 deletions

View File

@@ -36,6 +36,14 @@ def runZpoolIostat():
# Check the return code (0 for success)
if result.returncode == 0:
# Check if the file exists
if not os.path.exists(filename):
# Create the file in write mode ('w') if it doesn't exist
with open(filename, "w", newline="") as csvfile:
csv_writer = csv.writer(csvfile)
# Write the header row (optional)
csv_writer.writerow(headerRow)
# Access the captured output as a string
output = result.stdout
@@ -73,14 +81,6 @@ def runZpoolIostat():
poolname = lineData[0]
filename = poolname + "-zio.csv"
# Check if the file exists
if not os.path.exists(filename):
# Create the file in write mode ('w') if it doesn't exist
with open(filename, "w", newline="") as csvfile:
csv_writer = csv.writer(csvfile)
# Write the header row (optional)
csv_writer.writerow(headerRow)
# Now open the file in append mode ('a')
with open(filename, "a", newline="") as csvfile:
csv_writer = csv.writer(csvfile)