Skip to content

Commit

Permalink
migrate: Enhance logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Nov 10, 2023
1 parent ccc6ca3 commit 00dce34
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions application/clicommands/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public function navigationAction(): void
$rc = 0;
$directories = file_exists($preferencesPath) ? new DirectoryIterator($preferencesPath) : [];

$anythingChanged = false;

/** @var string $directory */
foreach ($directories as $directory) {
/** @var string $username */
Expand All @@ -87,14 +89,15 @@ public function navigationAction(): void

if (! $menuItems->isEmpty()) {
$menuUpdated = $this->transformNavigationItems($menuItems, $username, $rc);
$anythingChanged |= $menuUpdated;
}

if (! $icingadbHostActions->isEmpty()) {
$this->transformNavigationItems($icingadbHostActions, $username, $rc);
$anythingChanged |= $this->transformNavigationItems($icingadbHostActions, $username, $rc);
}

if (! $icingadbServiceActions->isEmpty()) {
$this->transformNavigationItems(
$anythingChanged |= $this->transformNavigationItems(
$icingadbServiceActions,
$username,
$rc
Expand All @@ -106,10 +109,11 @@ public function navigationAction(): void

if (! $menuItems->isEmpty()) {
$menuUpdated = $this->migrateNavigationItems($menuItems, $username, $directory . '/menu.ini', $rc);
$anythingChanged |= $menuUpdated;
}

if (! $hostActions->isEmpty()) {
$this->migrateNavigationItems(
$anythingChanged |= $this->migrateNavigationItems(
$hostActions,
$username,
$directory . '/icingadb-host-actions.ini',
Expand All @@ -118,7 +122,7 @@ public function navigationAction(): void
}

if (! $serviceActions->isEmpty()) {
$this->migrateNavigationItems(
$anythingChanged |= $this->migrateNavigationItems(
$serviceActions,
$username,
$directory . '/icingadb-service-actions.ini',
Expand All @@ -142,33 +146,35 @@ public function navigationAction(): void
$menuUpdated = false;
$originalMenuItems = $this->readFromIni($sharedNavigation . '/menu.ini', $rc);

Logger::info('Transforming legacy wildcard filters of existing shared Icinga DB Web');
Logger::info('Transforming legacy wildcard filters of existing shared Icinga DB Web navigation items');

if (! $menuItems->isEmpty()) {
$menuUpdated = $this->transformNavigationItems($menuItems, $user, $rc);
$anythingChanged |= $menuUpdated;
}

if (! $icingadbHostActions->isEmpty()) {
$this->transformNavigationItems($icingadbHostActions, $user, $rc);
$anythingChanged |= $this->transformNavigationItems($icingadbHostActions, $user, $rc);
}

if (! $icingadbServiceActions->isEmpty()) {
$this->transformNavigationItems(
$anythingChanged |= $this->transformNavigationItems(
$icingadbServiceActions,
$user,
$rc
);
}

if (! $this->skipMigration) {
Logger::info('Migrating shared monitoring navigation items to the Icinga DB Web actions');
Logger::info('Migrating shared monitoring navigation items to the Icinga DB Web items');

if (! $menuItems->isEmpty()) {
$menuUpdated = $this->migrateNavigationItems($menuItems, $user, $sharedNavigation . '/menu.ini', $rc);
$anythingChanged |= $menuUpdated;
}

if (! $hostActions->isEmpty()) {
$this->migrateNavigationItems(
$anythingChanged |= $this->migrateNavigationItems(
$hostActions,
$user,
$sharedNavigation . '/icingadb-host-actions.ini',
Expand All @@ -177,7 +183,7 @@ public function navigationAction(): void
}

if (! $serviceActions->isEmpty()) {
$this->migrateNavigationItems(
$anythingChanged |= $this->migrateNavigationItems(
$serviceActions,
$user,
$sharedNavigation . '/icingadb-service-actions.ini',
Expand All @@ -200,7 +206,9 @@ public function navigationAction(): void
exit($rc);
}

if ($this->skipMigration) {
if (! $anythingChanged) {
Logger::info('Nothing to do');
} elseif ($this->skipMigration) {
Logger::info('Successfully transformed all icingadb navigation item filters');
} else {
Logger::info('Successfully migrated all monitoring navigation items');
Expand Down Expand Up @@ -446,6 +454,8 @@ public function dashboardAction(): void
$rc = 0;
$directories = new DirectoryIterator($dashboardsPath);

$anythingChanged = false;

/** @var string $directory */
foreach ($directories as $directory) {
/** @var string $userName */
Expand Down Expand Up @@ -505,6 +515,10 @@ public function dashboardAction(): void
$this->createBackupIni("$directory/dashboard", $backupConfig);
}

if ($changed) {
$anythingChanged = true;
}

try {
$dashboardsConfig->saveIni();
} catch (NotWritableError $error) {
Expand All @@ -523,7 +537,9 @@ public function dashboardAction(): void
exit($rc);
}

if ($this->skipMigration) {
if (! $anythingChanged) {
Logger::info('Nothing to do');
} elseif ($this->skipMigration) {
Logger::info('Successfully transformed all icingadb dashboards');
} else {
Logger::info('Successfully migrated dashboards for all the matched users');
Expand Down

0 comments on commit 00dce34

Please sign in to comment.