feat(16-04): add Collector interface and RouterOSCollector
- Define Collector interface with Collect(ctx, dev, pub) error signature - Implement RouterOSCollector as thin wrapper delegating to PollDevice - Add compile-time interface assertion for RouterOSCollector Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
19
poller/internal/poller/collector.go
Normal file
19
poller/internal/poller/collector.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package poller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/staack/the-other-dude/poller/internal/bus"
|
||||||
|
"github.com/staack/the-other-dude/poller/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Collector defines the contract for device-type-specific data collection.
|
||||||
|
// Each device type (RouterOS, SNMP) implements this interface.
|
||||||
|
// The Scheduler dispatches to the appropriate Collector based on device_type.
|
||||||
|
type Collector interface {
|
||||||
|
// Collect performs one complete poll cycle for a device.
|
||||||
|
// It handles lock acquisition, credential decryption, connection,
|
||||||
|
// data collection, and event publishing.
|
||||||
|
// Returns ErrDeviceOffline if the device cannot be reached.
|
||||||
|
Collect(ctx context.Context, dev store.Device, pub *bus.Publisher) error
|
||||||
|
}
|
||||||
48
poller/internal/poller/routeros_collector.go
Normal file
48
poller/internal/poller/routeros_collector.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package poller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/bsm/redislock"
|
||||||
|
|
||||||
|
"github.com/staack/the-other-dude/poller/internal/bus"
|
||||||
|
"github.com/staack/the-other-dude/poller/internal/store"
|
||||||
|
"github.com/staack/the-other-dude/poller/internal/vault"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RouterOSCollector implements Collector for MikroTik RouterOS devices.
|
||||||
|
// It wraps the existing PollDevice logic, preserving identical behavior.
|
||||||
|
type RouterOSCollector struct {
|
||||||
|
locker *redislock.Client
|
||||||
|
credentialCache *vault.CredentialCache
|
||||||
|
connTimeout time.Duration
|
||||||
|
cmdTimeout time.Duration
|
||||||
|
lockTTL time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRouterOSCollector creates a RouterOSCollector with the given dependencies.
|
||||||
|
func NewRouterOSCollector(
|
||||||
|
locker *redislock.Client,
|
||||||
|
credentialCache *vault.CredentialCache,
|
||||||
|
connTimeout time.Duration,
|
||||||
|
cmdTimeout time.Duration,
|
||||||
|
lockTTL time.Duration,
|
||||||
|
) *RouterOSCollector {
|
||||||
|
return &RouterOSCollector{
|
||||||
|
locker: locker,
|
||||||
|
credentialCache: credentialCache,
|
||||||
|
connTimeout: connTimeout,
|
||||||
|
cmdTimeout: cmdTimeout,
|
||||||
|
lockTTL: lockTTL,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect performs one RouterOS poll cycle. This is a thin wrapper around
|
||||||
|
// PollDevice -- all business logic remains in worker.go unchanged.
|
||||||
|
func (c *RouterOSCollector) Collect(ctx context.Context, dev store.Device, pub *bus.Publisher) error {
|
||||||
|
return PollDevice(ctx, dev, c.locker, pub, c.credentialCache, c.connTimeout, c.cmdTimeout, c.lockTTL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compile-time interface assertion.
|
||||||
|
var _ Collector = (*RouterOSCollector)(nil)
|
||||||
Reference in New Issue
Block a user