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));
}