Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Internal backend for utilization reports, alerts and interface for Cablecast Reflect Customers.

Notifications You must be signed in to change notification settings

drraccoony/Cablecast-ReflectUtilization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cablecast-ReflectUtilization

Internal backend for ultiization reports, alerts and interface for Cablecast Reflect Customers.

For this, I am using PHP alongside the AWS PHP SDK w/ "home directory" Credential Profile & MySQL for housing data locally for histroical reporting.

DataModel

Getting the data

Running AWS CLI command aws ce get-cost-and-usage --time-period Start=2020-05-01,End=2020-06-01 --granularity MONTHLY --metrics "BlendedCost" --group-by Type=TAG,Key=NetsuiteID returns all customers with the "NetsuiteID" tag. This can be adapted to the PHP SDK for AWS by running:

  $startdate = date("Y-m-j", strtotime( '-2 days' ));
  $enddate = date("Y-m-j", strtotime( '-1 days' ));
  $data = $client->getCostAndUsage([
      'TimePeriod' => [
          'End' => $enddate,
          'Start' => $startdate,
        ],
      'Granularity' => 'MONTHLY',
      'Metrics' => ['BlendedCost','UsageQuantity'],
      'GroupBy' => [
        [
        'Type' => 'TAG',
        'Key' => 'NetsuiteID']
      ]
    ]);

More information on the syntax and parameters here.

Installing / Getting started

Can't imagine this'll be useful for anyone outside our org. But just incase:

  1. Clone repo to a webserver of your choice with MySQL and php extensions
  2. Create database called reflect_usage and import customer_usage.sql
  3. Rename db_connect.php.default to db_connect.php
  4. Define db username and password in db_connect.php
  5. Setup AWS Credentials.

Tasks / Objectives

  • Create project & setup AWS PHP SDK
  • Setup credendial storage for AWS SDK
  • Use proper function to pull costUsage
    • Write costUsage json to database
    • Setup get_usage.php to be a 4am CRON job
  • Create "Customers" table
    • Tie customers to UsageReports
  • (Partially) Generate reports
  • Generate email alerts

Links

About

Internal backend for utilization reports, alerts and interface for Cablecast Reflect Customers.

Topics

Resources

Stars

Watchers

Forks

Languages