Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Contract/DashboardApiInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Contract;

use BytesCommerce\ZabbixApi\Provisioning\Dto\DashboardSpec;
use BytesCommerce\ZabbixApi\Provisioning\Dto\HostInfo;
use BytesCommerce\ZabbixApi\Provisioning\Dto\ZabbixDashboard;
use BytesCommerce\ZabbixApi\Provisioning\ValueObject\DashboardId;
use BytesCommerce\ZabbixApi\Provisioning\ValueObject\ManagedKey;

interface DashboardApiInterface
{
public function findByManagedKey(ManagedKey $key, string $applicationName): ?ZabbixDashboard;

public function create(DashboardSpec $spec): DashboardId;

public function update(DashboardId $id, DashboardSpec $spec): void;

public function get(DashboardId $id): ZabbixDashboard;

public function findHostById(string $hostId): ?HostInfo;

public function findHostByName(string $hostName): ?HostInfo;
}
16 changes: 16 additions & 0 deletions src/Contract/DashboardProvisionerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Contract;

use BytesCommerce\ZabbixApi\Provisioning\Dto\ProvisioningResult;

interface DashboardProvisionerInterface
{
public function provisionForHost(
string $hostIdentifier,
string $dashboardName = 'ops_overview',
bool $dryRun = false,
): ProvisioningResult;
}
12 changes: 12 additions & 0 deletions src/Contract/DefinitionLoaderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Contract;

interface DefinitionLoaderInterface
{
public function load(string $name): array;

public function exists(string $name): bool;
}
16 changes: 16 additions & 0 deletions src/Contract/EntityExclusionProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Contract;

use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

#[AutoconfigureTag('zabbix.entity_exclusion_provider')]
interface EntityExclusionProviderInterface
{
/**
* @return list<class-string>
*/
public function getExcludedEntityClasses(): array;
}
16 changes: 16 additions & 0 deletions src/Contract/ExceptionExclusionProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Contract;

use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

#[AutoconfigureTag('zabbix.exception_exclusion_provider')]
interface ExceptionExclusionProviderInterface
{
/**
* @return list<class-string<\Throwable>>
*/
public function getExcludedExceptionClasses(): array;
}
20 changes: 20 additions & 0 deletions src/Contract/ItemDefinitionProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Contract;

interface ItemDefinitionProviderInterface
{
public function getAllItemDefinitions(): array;

public function getFullItemKey(string $suffix): string;

public function getHostId(): ?string;

public function setHostId(string $hostId): void;

public function getItemIdForKey(string $key): ?string;

public function setItemId(string $key, string $itemId): void;
}
16 changes: 16 additions & 0 deletions src/Contract/RouteExclusionProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Contract;

use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

#[AutoconfigureTag('zabbix.route_exclusion_provider')]
interface RouteExclusionProviderInterface
{
/**
* @return list<string>
*/
public function getExcludedRoutes(): array;
}
12 changes: 12 additions & 0 deletions src/Contract/ZabbixClientWithApiKeyInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Contract;

use BytesCommerce\ZabbixApi\Enums\ZabbixAction;

interface ZabbixClientWithApiKeyInterface
{
public function call(ZabbixAction $action, array $params = []): mixed;
}
14 changes: 14 additions & 0 deletions src/Contract/ZabbixClientWrapperInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Contract;

use BytesCommerce\ZabbixApi\Enums\ZabbixAction;

interface ZabbixClientWrapperInterface
{
public function call(ZabbixAction $action, array $params = []): mixed;

public function getClient(): ZabbixClientWithApiKeyInterface;
}
24 changes: 24 additions & 0 deletions src/Contract/ZabbixNamingProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Contract;

interface ZabbixNamingProviderInterface
{
public function getAppName(): string;

public function getHostName(): string;

public function getCleanHostName(): string;

public function getHostGroup(): string;

public function getDashboardName(): string;

public function getDashboardPrefix(): string;

public function getItemKey(string $suffix): string;

public function getEnvLabel(): string;
}
12 changes: 12 additions & 0 deletions src/Contract/ZabbixSenderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Contract;

interface ZabbixSenderInterface
{
public function pushNumeric(string $key, float|int $value, int $clock, array $tags, string $correlationId): void;

public function pushEvent(string $key, array $payload, int $clock, string $correlationId): void;
}
14 changes: 14 additions & 0 deletions src/Contract/ZabbixSetupInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Contract;

interface ZabbixSetupInterface
{
public function ensureFast(): void;

public function ensureAll(): void;

public function ensureHost(): string;
}
25 changes: 21 additions & 4 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,41 @@ public function getConfigTreeBuilder(): TreeBuilder
->children()
->scalarNode('base_uri')
->isRequired()
->cannotBeEmpty()
->info('Zabbix API endpoint URL, e.g. https://zabbix.example.com/api_jsonrpc.php')
->defaultValue('%env(ZABBIX_API_URL)%')
->info('Base URI for Zabbix API')
->end()
->scalarNode('api_token')
->defaultNull()
->info('Zabbix API token for token-based authentication (alternative to username/password)')
->end()
->scalarNode('username')
->defaultNull()
->info('Zabbix username for login-based authentication')
->info('Username for Zabbix authentication')
->end()
->scalarNode('password')
->defaultNull()
->info('Zabbix password for login-based authentication')
->defaultNull()
->end()
->integerNode('auth_ttl')
->defaultValue(3600)
->min(60)
->info('Authentication TTL in seconds')
->end()
->scalarNode('app_name')
->defaultValue('%env(APP_NAME)%')
->info('Application name for monitoring')
->end()
->scalarNode('host_group')
->defaultValue('Application Servers')
->info('Default Zabbix host group')
->end()
->scalarNode('dashboard_config_path')
->defaultValue('%kernel.project_dir%/config/zabbix/dashboards')
->info('Path to dashboard configuration files')
->end()
->booleanNode('setup_enabled')
->defaultFalse()
->info('Enable Zabbix setup commands')
->info('Authentication token cache TTL in seconds (minimum 60)')
->end()
->end();
Expand Down
13 changes: 6 additions & 7 deletions src/DependencyInjection/ZabbixApiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ final class ZabbixApiExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yaml');

$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

Expand All @@ -24,10 +21,12 @@ public function load(array $configs, ContainerBuilder $container): void
$container->setParameter('zabbix_api.username', $config['username']);
$container->setParameter('zabbix_api.password', $config['password']);
$container->setParameter('zabbix_api.auth_ttl', $config['auth_ttl']);
}
$container->setParameter('zabbix_api.app_name', $config['app_name']);
$container->setParameter('zabbix_api.host_group', $config['host_group']);
$container->setParameter('zabbix_api.dashboard_config_path', $config['dashboard_config_path']);
$container->setParameter('zabbix_api.setup_enabled', $config['setup_enabled']);

public function getConfiguration(array $config, ContainerBuilder $container): ?Configuration
{
return new Configuration();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yaml');
}
}
15 changes: 15 additions & 0 deletions src/Message/EnsureZabbixSetupMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Message;

use Symfony\Component\Messenger\Attribute\AsMessage;

#[AsMessage('async')]
final readonly class EnsureZabbixSetupMessage
{
public function __construct(public bool $force = false)
{
}
}
19 changes: 19 additions & 0 deletions src/Message/PushEventMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Message;

use Symfony\Component\Messenger\Attribute\AsMessage;

#[AsMessage('async')]
final readonly class PushEventMessage
{
public function __construct(
public string $key,
public array $payload,
public ?int $clock = null,
public string $correlationId = '',
) {
}
}
20 changes: 20 additions & 0 deletions src/Message/PushMetricMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Message;

use Symfony\Component\Messenger\Attribute\AsMessage;

#[AsMessage('async')]
final readonly class PushMetricMessage
{
public function __construct(
public string $key,
public float|int $value,
public ?int $clock = null,
public array $tags = [],
public string $correlationId = '',
) {
}
}
22 changes: 22 additions & 0 deletions src/Messenger/Handler/EnsureZabbixSetupHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Messenger\Handler;

use BytesCommerce\ZabbixApi\Contract\ZabbixSetupInterface;
use BytesCommerce\ZabbixApi\Message\EnsureZabbixSetupMessage;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
final readonly class EnsureZabbixSetupHandler
{
public function __construct(private ZabbixSetupInterface $setup)
{
}

public function __invoke(EnsureZabbixSetupMessage $message): void
{
$this->setup->ensureAll();
}
}
28 changes: 28 additions & 0 deletions src/Messenger/Handler/PushEventHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace BytesCommerce\ZabbixApi\Messenger\Handler;

use BytesCommerce\ZabbixApi\Contract\ZabbixSenderInterface;
use BytesCommerce\ZabbixApi\Message\PushEventMessage;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
final readonly class PushEventHandler
{
public function __construct(
private ZabbixSenderInterface $sender,
) {
}

public function __invoke(PushEventMessage $message): void
{
$this->sender->pushEvent(
key: $message->key,
payload: $message->payload,
clock: $message->clock ?? time(),
correlationId: $message->correlationId,
);
}
}
Loading
Loading