Scrape production data from POCloud to push to accounting servers
Send daily reports of Meshify Data via AWS functions.
Reports will be generated on a schedule by AWS Lambda, a serverless, event-driven computing platform. Each report will contain all devices of a specified type that the user has been granted access to in Meshify. If a user has access to multiple device types and is configured to receive reports for multiple device types, the user will receive one report for each device type. The Lambda function will mark in red any data that is more than 24 hours old in order to denote devices that have not updated. Values reported are the latest values at the time of report generation (12:00 GMT / 07:00 CST by default).
If you would like to run the reports locally without the AWS Lambda Function, refer to README-local.md
This section will show you how to configure the S3 Bucket within AWS. It assumes a strong knowledge of AWS platforms.
Populating channel config files tells the Lambda function which devices to prepare reports for and which channels to include data from. Devices will not be recognized unless they have both a Channel Config file and a To file.
Prepare a file named devicetype_channels.json where “devicetype” is the Meshify name for the devicetype.
touch <devicetype>_channels.json
In the text editor of your choice, develop a JSON list of objects that contains properties “meshify_name” and “vanity_name”.
[
{
"meshify_name": "<channel name in meshify>",
"vanity_name": "<vanity name for report header>"
},
{
"meshify_name": "<another channel name in meshify>",
"vanity_name": "<another vanity name for report header>"
},
]
Upload this file to the “channel_config” folder in the S3 Bucket.
Populating To files tells the Lambda function which devices to prepare reports for and whom to send the reports for each company. Devices will not be recognized unless they have both a Channel Config file and a To file.
Prepare a file named devicetype_to.json where “devicetype” is the Meshify name for the devicetype.
touch <devicetype>_to.json
In the text editor of your choice, develop a JSON object that contains properties of the format below. CompanyA and CompanyB should be replaced by the full name of the company as recorded in Meshify.
{
"CompanyA": [
"person@email.com",
"place@email.com"
],
"CompanyB": [
"person@email.com",
"thing@email.com"
]
}
Upload this file to the “to_files” folder in the S3 Bucket.
Clone this repository and open it
git clone https://github.com/Henry-Pump/POCloud-Email-Reports.git
cd POCloud-Email-Reports
Setup a Python Virtual environment and activate the environment
python3 -m venv env
source env/bin/activate
Install necessary python packages in the virtual environment.
pip install requests tzlocal xlsxwriter
Create a folder for deploying the lambda function
Shell
mkdir -p deploy
To build the lambda file automatically, allow execution permissions on the build script and execute it. To build manually, examine the build_lambda.sh file and execute commands at your own peril.
chmod +x build_lambda.sh
./build_lambda.sh
You should now have a file named lambda.zip in the main directory of the repo. This is the file to upload into your Lambda function.
This section will show you how to configure the Lambda function within AWS. It assumes a strong knowledge of AWS platforms.
Configure a new CloudWatch event with the schedule expression:
cron(0 12 * * ? *)
This will schedule the event to be triggered at 12:00 PM GMT (7:00 AM CST) every day of the week.