Skip to content

Commit bb4064a

Browse files
committed
Initial Version.
1 parent 0d815ec commit bb4064a

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

Management-Utilities/FSxN-Report/Generate-FSxN-Report.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def generateHTMLReport(region):
249249
htmlBody += f"<b>Name:</b> {name}<br>\n"
250250
htmlBody += f"<b>Region:</b> {region}<br>\n"
251251
htmlBody += f"<b>Availability:</b> {ontapConfig['DeploymentType']}<br>\n"
252-
htmlBody += f"<b>Provised Performance Tier Storage:</b> {fsxn['StorageCapacity']}GB<br>\n"
252+
htmlBody += f"<b>Provisioned Performance Tier Storage:</b> {fsxn['StorageCapacity']}GB<br>\n"
253253
htmlBody += f"<b>Used Performance Tier Storage:</b> {fileSystemUsedCapacity}<br>\n"
254254
htmlBody += f"<b>Percent Used Performance Tier:</b> {percentUsed}<br>\n"
255255
htmlBody += "</td></tr>\n"
@@ -277,7 +277,7 @@ def generateHTMLReport(region):
277277
htmlBody += f'<td align="right" style="{tableCellStyle}">{ontapConfig["VolumeStyle"]}</td><td align="right" style="{tableCellStyle}">{securityStyle}</td>\n'
278278
htmlBody += f'<td align="right" style="{tableCellStyle}">{int(volumeCapacity/1024/1024)}</td><td align="right" style="{tableCellStyle}">{volumePercentUsed}</td>\n'
279279
htmlBody += f'<td align="right" style="{tableCellStyle}">{int(volumeFilesCapacity)}</td><td align="right" style="{tableCellStyle}">{volumeFilesPercentUsed}</td></tr>\n'
280-
htmlBody += '<tr><td style="{tableCellStyle}"> </td></tr>\n'
280+
htmlBody += f'<tr><td style="{tableCellStyle}"> </td></tr>\n'
281281
htmlBody += "</table>\n"
282282
htmlBody += "<br><br>\n"
283283

@@ -314,7 +314,7 @@ def generateTextReport(region):
314314
fileSystemUsedCapacity = 'N/A'
315315
percentUsed = 'N/A'
316316
textReport += f"{indent}Used Capacity: {fileSystemUsedCapacity}\n"
317-
textReport += f"{indent}Percent Capacity Used: {percentUsed}%\n"
317+
textReport += f"{indent}Percent Capacity Used: {percentUsed}\n"
318318

319319
textReport += f"{indent}Storage Virtual Machines:\n"
320320
for svm in svms:
@@ -355,7 +355,7 @@ def generateTextReport(region):
355355
################################################################################
356356
# This function is used to email the report.
357357
################################################################################
358-
def emailReport(report, fromAddress, toAddress):
358+
def emailReport(report, fromAddress, toAddress, reportType):
359359

360360
sesClient = boto3.client('ses')
361361
sesClient.send_email(
@@ -366,7 +366,7 @@ def emailReport(report, fromAddress, toAddress):
366366
},
367367
Message= {
368368
'Body': {
369-
'Html': {
369+
reportType: {
370370
'Data': report,
371371
}
372372
},
@@ -414,9 +414,19 @@ def getConfig():
414414
# set REPORT_TYPE appropriately.
415415
if config['TEXT_REPORT'] != None and config['REPORT_TYPE'] is None:
416416
if config['TEXT_REPORT'].lower() == 'true':
417-
config['REPORT_TYPE'] = "text"
417+
config['REPORT_TYPE'] = "Text"
418418
else:
419-
config['REPORT_TYPE'] = "html"
419+
config['REPORT_TYPE'] = "Html"
420+
#
421+
# Since the API is case sensitive, make sure the REPORT_TYPE is set to
422+
# either 'Text' or 'Html'.
423+
if config['REPORT_TYPE'] is not None:
424+
if config['REPORT_TYPE'].lower() == 'text':
425+
config['REPORT_TYPE'] = 'Text'
426+
else:
427+
config['REPORT_TYPE'] = 'Html'
428+
else:
429+
config['REPORT_TYPE'] = 'Html'
420430

421431
################################################################################
422432
################################################################################
@@ -459,7 +469,7 @@ def lambda_handler(event, context):
459469
report = ""
460470
#
461471
# For an HTML report, just want the HTML start and end data once for all the regions.
462-
if config['REPORT_TYPE'] != "text":
472+
if config['REPORT_TYPE'].lower() != "text":
463473
currentReport = "<!DOCTYPE html>\n<html>\n"
464474
currentReport += "<head>\n<title>FSxN Report</title>\n"
465475
currentReport += "</head>\n<body>\n"
@@ -471,7 +481,7 @@ def lambda_handler(event, context):
471481
getFSxNInfo(region)
472482
#
473483
# Generate the report.
474-
if config['REPORT_TYPE'] == 'text':
484+
if config['REPORT_TYPE'].lower() == 'text':
475485
currentReport = generateTextReport(region)
476486
else: # Default to an HTML report.
477487
currentReport += generateHTMLReport(region)
@@ -480,21 +490,21 @@ def lambda_handler(event, context):
480490
raise Exception(f"Report for region {region} exceeds maximum email size of {maxEmailSize} characters.")
481491

482492
if len(report) + len(currentReport) > maxEmailSize:
483-
emailReport(report, config['FROM_ADDRESS'], config['TO_ADDRESS'])
493+
emailReport(report, config['FROM_ADDRESS'], config['TO_ADDRESS'], config['REPORT_TYPE'])
484494
report = currentReport
485495
currentReport = ""
486496
else:
487497
report += currentReport
488498
currentReport = ""
489499

490-
if config['REPORT_TYPE'] != 'text':
500+
if config['REPORT_TYPE'].lower() != 'text':
491501
report += "</body></html>\n"
492502
#
493503
# Email the report.
494504
if config['TO_ADDRESS'] is None or config['FROM_ADDRESS'] is None:
495505
print(report)
496506
else:
497-
emailReport(report, config['FROM_ADDRESS'], config['TO_ADDRESS'])
507+
emailReport(report, config['FROM_ADDRESS'], config['TO_ADDRESS'], config['REPORT_TYPE'])
498508

499509
################################################################################
500510
################################################################################

Management-Utilities/FSxN-Report/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ following environment variables can be set to control the behavior of the progra
1616
- `REPORT_TYPE`: The type of report to generate. Can be either `html` or `text`. Defaults to `html`.
1717

1818
If you want the program to run on a regular basis, and send you an email with the report, it is
19-
recommedned to deploy it as a Lambda function with an EventBridge rule to trigger it on a schedule (e.g. daily, weekly, montly, etc.).
19+
recommended to deploy it as a Lambda function with an EventBridge rule to trigger it on a schedule (e.g. daily, weekly, monthly, etc.).
2020

2121
## Deployment
2222
To ease with the deployment, a CloudFormation template has been provided. It will:
@@ -52,7 +52,7 @@ If you want to create your own role, here are the minimum permissions required:
5252
|---|:---:|---|
5353
|`fsx:describe_file_systems`| `*` | Needed to list all FSx for ONTAP file systems in the account. |
5454
|`fsx:describe_volumes`| `*` | Needed to list all volumes in the account. |
55-
|`fsx:describe_stroage_virtual_machines`| `*` | Needed to list all volumes and SVMs in the account. |
55+
|`fsx:describe_storage_virtual_machines`| `*` | Needed to list all volumes and SVMs in the account. |
5656
|`cw:get_metric_data`| `*` | Needed to get the metrics for the file systems. |
5757
|`ec2:describe_region`| `*` | Needed to list all AWS regions. |
5858
|`ses:send_email`| `arn:aws:ses:${AWS_REGION}:${AWS_ACCOUNT}:identity/${EMAIL_ADDRESS}`<br>`arn:aws:ses:${AWS_REGION}:${AWS_ACCOUNT}:configuration-set/${EMAIL_ADDRESS}`| Recommend just using `*` for the email addresses, otherwise you'll need a resource line for each `To` and `From` email address. |

Management-Utilities/FSxN-Report/cloudformation.yaml

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ Resources:
445445
htmlBody += f"<b>Name:</b> {name}<br>\n"
446446
htmlBody += f"<b>Region:</b> {region}<br>\n"
447447
htmlBody += f"<b>Availability:</b> {ontapConfig['DeploymentType']}<br>\n"
448-
htmlBody += f"<b>Provised Performance Tier Storage:</b> {fsxn['StorageCapacity']}GB<br>\n"
448+
htmlBody += f"<b>Provisioned Performance Tier Storage:</b> {fsxn['StorageCapacity']}GB<br>\n"
449449
htmlBody += f"<b>Used Performance Tier Storage:</b> {fileSystemUsedCapacity}<br>\n"
450450
htmlBody += f"<b>Percent Used Performance Tier:</b> {percentUsed}<br>\n"
451451
htmlBody += "</td></tr>\n"
@@ -473,7 +473,7 @@ Resources:
473473
htmlBody += f'<td align="right" style="{tableCellStyle}">{ontapConfig["VolumeStyle"]}</td><td align="right" style="{tableCellStyle}">{securityStyle}</td>\n'
474474
htmlBody += f'<td align="right" style="{tableCellStyle}">{int(volumeCapacity/1024/1024)}</td><td align="right" style="{tableCellStyle}">{volumePercentUsed}</td>\n'
475475
htmlBody += f'<td align="right" style="{tableCellStyle}">{int(volumeFilesCapacity)}</td><td align="right" style="{tableCellStyle}">{volumeFilesPercentUsed}</td></tr>\n'
476-
htmlBody += '<tr><td style="{tableCellStyle}"> </td></tr>\n'
476+
htmlBody += f'<tr><td style="{tableCellStyle}"> </td></tr>\n'
477477
htmlBody += "</table>\n"
478478
htmlBody += "<br><br>\n"
479479
@@ -510,7 +510,7 @@ Resources:
510510
fileSystemUsedCapacity = 'N/A'
511511
percentUsed = 'N/A'
512512
textReport += f"{indent}Used Capacity: {fileSystemUsedCapacity}\n"
513-
textReport += f"{indent}Percent Capacity Used: {percentUsed}%\n"
513+
textReport += f"{indent}Percent Capacity Used: {percentUsed}\n"
514514
515515
textReport += f"{indent}Storage Virtual Machines:\n"
516516
for svm in svms:
@@ -551,7 +551,7 @@ Resources:
551551
################################################################################
552552
# This function is used to email the report.
553553
################################################################################
554-
def emailReport(report, fromAddress, toAddress):
554+
def emailReport(report, fromAddress, toAddress, reportType):
555555
556556
sesClient = boto3.client('ses')
557557
sesClient.send_email(
@@ -562,7 +562,7 @@ Resources:
562562
},
563563
Message= {
564564
'Body': {
565-
'Html': {
565+
reportType: {
566566
'Data': report,
567567
}
568568
},
@@ -610,9 +610,19 @@ Resources:
610610
# set REPORT_TYPE appropriately.
611611
if config['TEXT_REPORT'] != None and config['REPORT_TYPE'] is None:
612612
if config['TEXT_REPORT'].lower() == 'true':
613-
config['REPORT_TYPE'] = "text"
613+
config['REPORT_TYPE'] = "Text"
614614
else:
615-
config['REPORT_TYPE'] = "html"
615+
config['REPORT_TYPE'] = "Html"
616+
#
617+
# Since the API is case sensitive, make sure the REPORT_TYPE is set to
618+
# either 'Text' or 'Html'.
619+
if config['REPORT_TYPE'] is not None:
620+
if config['REPORT_TYPE'].lower() == 'text':
621+
config['REPORT_TYPE'] = 'Text'
622+
else:
623+
config['REPORT_TYPE'] = 'Html'
624+
else:
625+
config['REPORT_TYPE'] = 'Html'
616626
617627
################################################################################
618628
################################################################################
@@ -655,7 +665,7 @@ Resources:
655665
report = ""
656666
#
657667
# For an HTML report, just want the HTML start and end data once for all the regions.
658-
if config['REPORT_TYPE'] != "text":
668+
if config['REPORT_TYPE'].lower() != "text":
659669
currentReport = "<!DOCTYPE html>\n<html>\n"
660670
currentReport += "<head>\n<title>FSxN Report</title>\n"
661671
currentReport += "</head>\n<body>\n"
@@ -667,7 +677,7 @@ Resources:
667677
getFSxNInfo(region)
668678
#
669679
# Generate the report.
670-
if config['REPORT_TYPE'] == 'text':
680+
if config['REPORT_TYPE'].lower() == 'text':
671681
currentReport = generateTextReport(region)
672682
else: # Default to an HTML report.
673683
currentReport += generateHTMLReport(region)
@@ -676,21 +686,21 @@ Resources:
676686
raise Exception(f"Report for region {region} exceeds maximum email size of {maxEmailSize} characters.")
677687
678688
if len(report) + len(currentReport) > maxEmailSize:
679-
emailReport(report, config['FROM_ADDRESS'], config['TO_ADDRESS'])
689+
emailReport(report, config['FROM_ADDRESS'], config['TO_ADDRESS'], config['REPORT_TYPE'])
680690
report = currentReport
681691
currentReport = ""
682692
else:
683693
report += currentReport
684694
currentReport = ""
685695
686-
if config['REPORT_TYPE'] != 'text':
696+
if config['REPORT_TYPE'].lower() != 'text':
687697
report += "</body></html>\n"
688698
#
689699
# Email the report.
690700
if config['TO_ADDRESS'] is None or config['FROM_ADDRESS'] is None:
691701
print(report)
692702
else:
693-
emailReport(report, config['FROM_ADDRESS'], config['TO_ADDRESS'])
703+
emailReport(report, config['FROM_ADDRESS'], config['TO_ADDRESS'], config['REPORT_TYPE'])
694704
695705
################################################################################
696706
################################################################################

0 commit comments

Comments
 (0)