-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from mfreeman451/feat/snmp_poller_cmd
Feat/snmp poller cmd
- Loading branch information
Showing
15 changed files
with
270 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/mfreeman451/serviceradar/pkg/checker/snmp" | ||
"github.com/mfreeman451/serviceradar/pkg/config" | ||
"github.com/mfreeman451/serviceradar/pkg/grpc" | ||
"github.com/mfreeman451/serviceradar/pkg/lifecycle" | ||
"github.com/mfreeman451/serviceradar/proto" | ||
) | ||
|
||
var ( | ||
errFailedToLoadConfig = fmt.Errorf("failed to load config") | ||
) | ||
|
||
func main() { | ||
if err := run(); err != nil { | ||
log.Fatalf("Fatal error: %v", err) | ||
} | ||
} | ||
|
||
func run() error { | ||
log.Printf("Starting SNMP checker...") | ||
|
||
// Parse command line flags | ||
configPath := flag.String("config", "/etc/serviceradar/checkers/snmp.json", "Path to config file") | ||
flag.Parse() | ||
|
||
// Load and validate configuration using shared config package | ||
var cfg snmp.Config | ||
if err := config.LoadAndValidate(*configPath, &cfg); err != nil { | ||
return fmt.Errorf("%w: %w", errFailedToLoadConfig, err) | ||
} | ||
|
||
// Create SNMP service | ||
service, err := snmp.NewSNMPService(&cfg) | ||
if err != nil { | ||
return fmt.Errorf("failed to create SNMP service: %w", err) | ||
} | ||
|
||
// Create and register block service | ||
snmpAgentService := snmp.NewSNMPPollerService(&snmp.Poller{Config: cfg}) | ||
|
||
// Create gRPC service registrar | ||
registerServices := func(s *grpc.Server) error { | ||
// Register agent service | ||
proto.RegisterAgentServiceServer(s.GetGRPCServer(), snmpAgentService) | ||
|
||
return nil | ||
} | ||
|
||
// Create and configure service options | ||
opts := lifecycle.ServerOptions{ | ||
ListenAddr: cfg.ListenAddr, | ||
Service: &snmpService{service: service}, | ||
RegisterGRPCServices: []lifecycle.GRPCServiceRegistrar{registerServices}, | ||
EnableHealthCheck: true, | ||
Security: cfg.Security, | ||
} | ||
|
||
// Run service with lifecycle management | ||
if err := lifecycle.RunServer(context.Background(), &opts); err != nil { | ||
return fmt.Errorf("server error: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// snmpService wraps the SNMPService to implement lifecycle.Service | ||
type snmpService struct { | ||
service *snmp.SNMPService | ||
} | ||
|
||
func (s *snmpService) Start(ctx context.Context) error { | ||
log.Printf("Starting SNMP service...") | ||
return s.service.Start(ctx) | ||
} | ||
|
||
func (s *snmpService) Stop(ctx context.Context) error { | ||
log.Printf("Stopping SNMP service...") | ||
return s.service.Stop() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ | |
VERSION=${VERSION:-1.0.16} | ||
|
||
|
||
./setup-deb-poller.sh | ||
./setup-deb-dusk-checker.sh | ||
./setup-deb-agent.sh | ||
|
||
scp ../release-artifacts/serviceradar-poller_${VERSION}.deb [email protected]:~/ | ||
scp ../release-artifacts/serviceradar-agent_${VERSION}.deb [email protected]:~/ | ||
scp ../release-artifacts/serviceradar-dusk-checker_${VERSION}.deb [email protected]:~/ | ||
./scripts/setup-deb-poller.sh | ||
./scripts/setup-deb-dusk-checker.sh | ||
./scripts/setup-deb-agent.sh | ||
./scripts/setup-deb-snmp-checker.sh | ||
|
||
scp ./release-artifacts/serviceradar-poller_${VERSION}.deb [email protected]:~/ | ||
scp ./release-artifacts/serviceradar-agent_${VERSION}.deb [email protected]:~/ | ||
scp ./release-artifacts/serviceradar-dusk-checker_${VERSION}.deb [email protected]:~/ | ||
scp ./release-artifacts/serviceradar-snmp-checker_${VERSION}.deb [email protected]:~/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.