|
| 1 | +"""Get monitoring for a firewall device.""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | +import datetime |
| 4 | + |
| 5 | +import click |
| 6 | + |
| 7 | +import SoftLayer |
| 8 | +from SoftLayer.CLI import environment |
| 9 | +from SoftLayer.CLI import formatting |
| 10 | + |
| 11 | + |
| 12 | +@click.command(cls=SoftLayer.CLI.command.SLCommand, ) |
| 13 | +@click.argument('identifier') |
| 14 | +@environment.pass_env |
| 15 | +def cli(env, identifier): |
| 16 | + """Gets bandwidth details for a firewall from the past 30 days.""" |
| 17 | + |
| 18 | + mgr = SoftLayer.FirewallManager(env.client) |
| 19 | + |
| 20 | + _firewall = mgr.get_instance(identifier) |
| 21 | + |
| 22 | + table = formatting.KeyValueTable(['name', 'value']) |
| 23 | + table.align['name'] = 'r' |
| 24 | + table.align['value'] = 'l' |
| 25 | + |
| 26 | + end = datetime.date.today() |
| 27 | + start = end.replace(day=1) |
| 28 | + last_month = start - datetime.timedelta(days=30) |
| 29 | + |
| 30 | + monitoring = mgr.get_summary(_firewall['metricTrackingObject']['id'], |
| 31 | + last_month.strftime('%Y-%m-%d'), end.strftime('%Y-%m-%d')) |
| 32 | + public_out = 0 |
| 33 | + public_in = 0 |
| 34 | + for monitor in monitoring: |
| 35 | + |
| 36 | + if monitor['type'] == 'publicOut_net_octet': |
| 37 | + public_out += monitor['counter'] |
| 38 | + |
| 39 | + if monitor['type'] == 'publicIn_net_octet': |
| 40 | + public_in += monitor['counter'] |
| 41 | + |
| 42 | + table.add_row(['Id', _firewall.get('id')]) |
| 43 | + table.add_row(['Name', _firewall['networkGateway']['name']]) |
| 44 | + table.add_row(['Stard Date', last_month.strftime('%Y-%m-%d')]) |
| 45 | + table.add_row(['End Date', end.strftime('%Y-%m-%d')]) |
| 46 | + table.add_row(['Out', formatting.b_to_gb(public_out)]) |
| 47 | + table.add_row(['In', formatting.b_to_gb(public_in)]) |
| 48 | + table.add_row(['Total', formatting.b_to_gb(public_out + public_in)]) |
| 49 | + table.add_row(['Status', _firewall['networkGateway']['status']['name']]) |
| 50 | + |
| 51 | + env.fout(table) |
0 commit comments