Skip to content

Commit

Permalink
Add csv/json export support for parents and children tab
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Dec 5, 2024
1 parent 22603ba commit 74bb945
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
8 changes: 6 additions & 2 deletions application/controllers/HostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function servicesAction(): \Generator
$this->setAutorefreshInterval(10);
}

public function parentsAction(): void
public function parentsAction(): \Generator
{
$nodesQuery = $this->fetchNodes(true);

Expand Down Expand Up @@ -275,6 +275,8 @@ public function parentsAction(): void

$nodesQuery->filter($filter);

yield $this->export($nodesQuery);

$this->addControl($paginationControl);
$this->addControl($sortControl);
$this->addControl($limitControl);
Expand All @@ -293,7 +295,7 @@ public function parentsAction(): void
$this->setAutorefreshInterval(10);
}

public function childrenAction(): void
public function childrenAction(): \Generator
{
$nodesQuery = $this->fetchNodes();

Expand Down Expand Up @@ -337,6 +339,8 @@ public function childrenAction(): void

$nodesQuery->filter($filter);

yield $this->export($nodesQuery);

$this->addControl($paginationControl);
$this->addControl($sortControl);
$this->addControl($limitControl);
Expand Down
8 changes: 6 additions & 2 deletions application/controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function indexAction(): void
$this->setAutorefreshInterval(10);
}

public function parentsAction(): void
public function parentsAction(): \Generator
{
$nodesQuery = $this->fetchNodes(true);

Expand Down Expand Up @@ -142,6 +142,8 @@ public function parentsAction(): void

$nodesQuery->filter($filter);

yield $this->export($nodesQuery);

$this->addControl($paginationControl);
$this->addControl($sortControl);
$this->addControl($limitControl);
Expand All @@ -160,7 +162,7 @@ public function parentsAction(): void
$this->setAutorefreshInterval(10);
}

public function childrenAction(): void
public function childrenAction(): \Generator
{
$nodesQuery = $this->fetchNodes();

Expand Down Expand Up @@ -205,6 +207,8 @@ public function childrenAction(): void

$nodesQuery->filter($filter);

yield $this->export($nodesQuery);

$this->addControl($paginationControl);
$this->addControl($sortControl);
$this->addControl($limitControl);
Expand Down
4 changes: 3 additions & 1 deletion library/Icingadb/Data/CsvResultSetUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DateTime;
use DateTimeZone;
use Icinga\Module\Icingadb\Model\DependencyNode;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Icingadb\Model\Service;
use ipl\Orm\Model;
Expand Down Expand Up @@ -67,7 +68,8 @@ protected function extractKeysAndValues(Model $model, string $path = ''): array

public static function stream(Query $query): void
{
if ($query->getModel() instanceof Host || $query->getModel() instanceof Service) {
$model = $query->getModel();
if ($model instanceof Host || $model instanceof Service || $model instanceof DependencyNode) {
$query->setResultSetClass(VolatileCsvResults::class);
} else {
$query->setResultSetClass(__CLASS__);
Expand Down
4 changes: 3 additions & 1 deletion library/Icingadb/Data/JsonResultSetUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DateTime;
use DateTimeZone;
use Icinga\Module\Icingadb\Model\DependencyNode;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Icingadb\Model\Service;
use Icinga\Util\Json;
Expand Down Expand Up @@ -61,7 +62,8 @@ protected function createObject(Model $model): array

public static function stream(Query $query): void
{
if ($query->getModel() instanceof Host || $query->getModel() instanceof Service) {
$model = $query->getModel();
if ($model instanceof Host || $model instanceof Service || $model instanceof DependencyNode) {
$query->setResultSetClass(VolatileJsonResults::class);
} else {
$query->setResultSetClass(__CLASS__);
Expand Down

0 comments on commit 74bb945

Please sign in to comment.