Skip to content

Commit 53929aa

Browse files
committed
Initial Version
1 parent 4a1afd9 commit 53929aa

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
# Copyright (c) NetApp, Inc.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
name: "Update Cloudformation Template"
6+
7+
on:
8+
pull_request:
9+
paths:
10+
- 'Management-Utilities/FSxN-Report/Generate-FSxN-Report.py'
11+
push:
12+
paths:
13+
- 'Management-Utilities/FSxN-Report/Generate-FSxN-Report.py'
14+
branches:
15+
- main
16+
17+
jobs:
18+
update-Cloudformation-Template:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
# Give the default GITHUB_TOKEN write permission to commit and push the
22+
# added or changed files to the repository.
23+
contents: write
24+
25+
steps:
26+
- name: Checkout pull request
27+
uses: actions/checkout@v4
28+
with:
29+
ref: ${{ github.event.pull_request.head.ref }}
30+
31+
- name: Update the Cloudformation Template
32+
shell: bash
33+
working-directory: Management-Utilities/FSxN-Report
34+
run: ./update_fsxn_report_CF_template
35+
36+
- name: Commit the changes
37+
uses: stefanzweifel/git-auto-commit-action@v5

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424

2525
import boto3
2626
from botocore.config import Config
27-
import json
2827
from datetime import datetime, timedelta
29-
import argparse
3028
import os
3129

3230
################################################################################
@@ -59,13 +57,13 @@ def getFSxNInfo(region):
5957
for fsxn in fsxnData['FileSystems']:
6058
if fsxn['FileSystemType'] == 'ONTAP':
6159
fsxns.append(fsxn)
62-
next = fsxnData.get('NextToken')
63-
while next:
60+
nextToken = fsxnData.get('NextToken')
61+
while nextToken:
6462
fsxnData = fsxClient.describe_file_systems(NextToken=next)
6563
for fsxn in fsxnData['FileSystems']:
6664
if fsxn['FileSystemType'] == 'ONTAP':
6765
fsxns.append(fsxn)
68-
next = fsxnData.get('NextToken')
66+
nextToken = fsxnData.get('NextToken')
6967
#
7068
# Retrieve all the FSxN usage information
7169
fsxnUsageInfo = {}
@@ -360,7 +358,7 @@ def generateTextReport(region):
360358
def emailReport(report, fromAddress, toAddress):
361359

362360
sesClient = boto3.client('ses')
363-
response = sesClient.send_email(
361+
sesClient.send_email(
364362
Destination={
365363
'ToAddresses': [
366364
toAddress
@@ -482,7 +480,7 @@ def lambda_handler(event, context):
482480
raise Exception(f"Report for region {region} exceeds maximum email size of {maxEmailSize} characters.")
483481

484482
if len(report) + len(currentReport) > maxEmailSize:
485-
emailReport(report, fromAddress, toAddress)
483+
emailReport(report, config['FROM_ADDRESS'], config['TO_ADDRESS'])
486484
report = currentReport
487485
currentReport = ""
488486
else:

Management-Utilities/FSxN-Report/cloudformation.yaml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Resources:
8181
Properties:
8282
Description: "Event rule to trigger the FSxN Report Lambda function."
8383
Name: !Sub "FSxN_Report-${AWS::StackName}"
84-
ScheduleExpression: "cron(0 0 * * ? *)" # Every day at midnight UTC
84+
ScheduleExpression: "cron(0 0 * * ? *)"
8585
State: "ENABLED"
8686
Targets:
8787
- Arn: !GetAtt LambdaFunction.Arn
@@ -93,7 +93,7 @@ Resources:
9393
Properties:
9494
Description: "Event rule to trigger the FSxN Report Lambda function."
9595
Name: !Sub "FSxN_Report-${AWS::StackName}"
96-
ScheduleExpression: "cron(0 0 ? * 2 *)" # Every Monday at midnight UTC
96+
ScheduleExpression: "cron(0 0 ? * 2 *)"
9797
State: "ENABLED"
9898
Targets:
9999
- Arn: !GetAtt LambdaFunction.Arn
@@ -105,7 +105,7 @@ Resources:
105105
Properties:
106106
Description: "Event rule to trigger the FSxN Report Lambda function."
107107
Name: !Sub "FSxN_Report-${AWS::StackName}"
108-
ScheduleExpression: "cron(0 0 1 * ? *)" # Every month on the first day at midnight UTC
108+
ScheduleExpression: "cron(0 0 1 * ? *)"
109109
State: "ENABLED"
110110
Targets:
111111
- Arn: !GetAtt LambdaFunction.Arn
@@ -183,7 +183,7 @@ Resources:
183183
PackageType: "Zip"
184184
Runtime: "python3.13"
185185
Handler: "index.lambda_handler"
186-
Timeout: 300 # 5 minutes
186+
Timeout: 300
187187
Environment:
188188
Variables:
189189
TO_ADDRESS: !Ref emailTo
@@ -220,9 +220,7 @@ Resources:
220220
221221
import boto3
222222
from botocore.config import Config
223-
import json
224223
from datetime import datetime, timedelta
225-
import argparse
226224
import os
227225
228226
################################################################################
@@ -255,13 +253,13 @@ Resources:
255253
for fsxn in fsxnData['FileSystems']:
256254
if fsxn['FileSystemType'] == 'ONTAP':
257255
fsxns.append(fsxn)
258-
next = fsxnData.get('NextToken')
259-
while next:
256+
nextToken = fsxnData.get('NextToken')
257+
while nextToken:
260258
fsxnData = fsxClient.describe_file_systems(NextToken=next)
261259
for fsxn in fsxnData['FileSystems']:
262260
if fsxn['FileSystemType'] == 'ONTAP':
263261
fsxns.append(fsxn)
264-
next = fsxnData.get('NextToken')
262+
nextToken = fsxnData.get('NextToken')
265263
#
266264
# Retrieve all the FSxN usage information
267265
fsxnUsageInfo = {}
@@ -556,7 +554,7 @@ Resources:
556554
def emailReport(report, fromAddress, toAddress):
557555
558556
sesClient = boto3.client('ses')
559-
response = sesClient.send_email(
557+
sesClient.send_email(
560558
Destination={
561559
'ToAddresses': [
562560
toAddress
@@ -678,7 +676,7 @@ Resources:
678676
raise Exception(f"Report for region {region} exceeds maximum email size of {maxEmailSize} characters.")
679677
680678
if len(report) + len(currentReport) > maxEmailSize:
681-
emailReport(report, fromAddress, toAddress)
679+
emailReport(report, config['FROM_ADDRESS'], config['TO_ADDRESS'])
682680
report = currentReport
683681
currentReport = ""
684682
else:

0 commit comments

Comments
 (0)