diff --git a/app/Elasticsearch/LifetimePolicy/LifetimePolicyCommand.php b/app/Elasticsearch/LifetimePolicy/LifetimePolicyCommand.php new file mode 100644 index 0000000..b0423e6 --- /dev/null +++ b/app/Elasticsearch/LifetimePolicy/LifetimePolicyCommand.php @@ -0,0 +1,41 @@ +client = $client; + } + + + public function configure() + { + $this->setName('elasticsearch:lifetime-policy:enable'); + } + + + public function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output): int + { + $lifetimePolicyFile = \Nette\Utils\FileSystem::read(__DIR__ . '/lifetime_policy.json'); + $this->client->ilm()->putLifecycle([ + 'policy' => self::LIFETIME_POLICY_NAME, + 'body' => $lifetimePolicyFile + ] + ); + $output->writeln('Lifetime policy \'' . self::LIFETIME_POLICY_NAME . '\' added.'); + + + return 0; + } + +} diff --git a/app/Elasticsearch/LifetimePolicy/create_index.json b/app/Elasticsearch/LifetimePolicy/create_index.json new file mode 100644 index 0000000..357059b --- /dev/null +++ b/app/Elasticsearch/LifetimePolicy/create_index.json @@ -0,0 +1,7 @@ +{ + "aliases": { + "test-alias":{ + "is_write_index": true + } + } +} diff --git a/app/Elasticsearch/LifetimePolicy/index_template.json b/app/Elasticsearch/LifetimePolicy/index_template.json new file mode 100644 index 0000000..749d1cf --- /dev/null +++ b/app/Elasticsearch/LifetimePolicy/index_template.json @@ -0,0 +1,11 @@ +{ + "index_patterns": ["monitoring-*"], + "template": { + "settings": { + "number_of_shards": 1, + "number_of_replicas": 1, + "index.lifecycle.name": "my_policy", + "index.lifecycle.rollover_alias": "test-alias" + } + } +} diff --git a/app/Elasticsearch/LifetimePolicy/lifetime_policy.json b/app/Elasticsearch/LifetimePolicy/lifetime_policy.json new file mode 100644 index 0000000..78a6810 --- /dev/null +++ b/app/Elasticsearch/LifetimePolicy/lifetime_policy.json @@ -0,0 +1,19 @@ +{ + "policy": { + "phases": { + "hot": { + "actions": { + "rollover": { + "max_age": "7d" + } + } + }, + "delete": { + "min_age": "8d", + "actions": { + "delete": {} + } + } + } + } +} diff --git a/app/config/config.neon b/app/config/config.neon index abbcde5..b72461b 100644 --- a/app/config/config.neon +++ b/app/config/config.neon @@ -455,6 +455,11 @@ services: arguments: isAllowed: %github.allow% + - + factory: \Pd\Monitoring\Elasticsearch\LifetimePolicy\LifetimePolicyCommand + tags: + - kdyby.console.command + decorator: Nette\Application\UI\Control: