-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: boilerplate * feat: register udptraceroute * chore: fix nits * fix: unit tests breaking * Merge from main * refactor: validation logic * review: implement changes requested by @lvlcn-t * review: implement changes requested by @puffitos * chore: add target to logger * chore: remove testcase type Signed-off-by: Niklas Treml <[email protected]> * chore: rename shadowed variable Signed-off-by: Niklas Treml <[email protected]> * fix: validate ip correctly Signed-off-by: Niklas Treml <[email protected]> * docs: add docs for config Signed-off-by: Niklas Treml <[email protected]> * chore: log error instead of err Signed-off-by: Niklas Treml <[email protected]> * docs: update readme to include traceroute Signed-off-by: Niklas Treml <[email protected]> * docs: capabilities Signed-off-by: Niklas Treml <[email protected]> * docs: document target * chore: remove duplicate debug log Signed-off-by: Niklas Treml <[email protected]> --------- Signed-off-by: Niklas Treml <[email protected]>
- Loading branch information
1 parent
1d5f0ed
commit ec1fc82
Showing
10 changed files
with
487 additions
and
9 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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package traceroute | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"net/url" | ||
"time" | ||
|
||
"github.com/caas-team/sparrow/pkg/checks" | ||
) | ||
|
||
// Config is the configuration for the traceroute check | ||
type Config struct { | ||
// Targets is a list of targets to traceroute to | ||
Targets []Target `json:"targets" yaml:"targets" mapstructure:"targets"` | ||
// Retries is the number of times to retry the traceroute for a target, if it fails | ||
Retries int `json:"retries" yaml:"retries" mapstructure:"retries"` | ||
// MaxHops is the maximum number of hops to try before giving up | ||
MaxHops int `json:"maxHops" yaml:"maxHops" mapstructure:"maxHops"` | ||
// Interval is the time to wait between check iterations | ||
Interval time.Duration `json:"interval" yaml:"interval" mapstructure:"interval"` | ||
// Timeout is the maximum time to wait for a response from a hop | ||
Timeout time.Duration `json:"timeout" yaml:"timeout" mapstructure:"timeout"` | ||
} | ||
|
||
func (c *Config) For() string { | ||
return CheckName | ||
} | ||
|
||
func (c *Config) Validate() error { | ||
if c.Timeout <= 0 { | ||
return checks.ErrInvalidConfig{CheckName: CheckName, Field: "traceroute.timeout", Reason: "must be greater than 0"} | ||
} | ||
if c.Interval <= 0 { | ||
return checks.ErrInvalidConfig{CheckName: CheckName, Field: "traceroute.interval", Reason: "must be greater than 0"} | ||
} | ||
|
||
for i, t := range c.Targets { | ||
ip := net.ParseIP(t.Addr) | ||
|
||
if ip != nil { | ||
continue | ||
} | ||
|
||
_, err := url.Parse(t.Addr) | ||
if err != nil && ip == nil { | ||
return checks.ErrInvalidConfig{CheckName: CheckName, Field: fmt.Sprintf("traceroute.targets[%d].addr", i), Reason: "invalid url or ip"} | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.