AwsInspector\Command\CloudwatchLogs\ShowLogGroupsCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $groupPattern = $input->getArgument('group');
        if (empty($groupPattern)) {
            $groupPattern = '.*';
        }
        $cloudwatchLogsClient = \AwsInspector\SdkFactory::getClient('cloudwatchlogs');
        /* @var $cloudwatchLogsClient \Aws\CloudWatchLogs\CloudWatchLogsClient */
        $table = new Table($output);
        $table->setHeaders(['Name', 'Retention [days]', 'Size [MB]']);
        $totalBytes = 0;
        $nextToken = null;
        do {
            $params = ['limit' => 50];
            if ($nextToken) {
                $params['nextToken'] = $nextToken;
            }
            $result = $cloudwatchLogsClient->describeLogGroups($params);
            foreach ($result->get('logGroups') as $logGroup) {
                $name = $logGroup['logGroupName'];
                if (preg_match('/' . $groupPattern . '/', $name)) {
                    $table->addRow([$logGroup['logGroupName'], isset($logGroup['retentionInDays']) ? $logGroup['retentionInDays'] : 'Never', round($logGroup['storedBytes'] / (1024 * 1024))]);
                    $totalBytes += $logGroup['storedBytes'];
                }
            }
            $nextToken = $result->get("nextToken");
        } while ($nextToken);
        $table->render();
        $output->writeln('Total size: ' . $this->formatBytes($totalBytes));
    }