Changed db.path flag to cache

This commit is contained in:
David J. Allen 2024-05-10 14:54:34 -06:00
parent 24cbae6570
commit f4540ea4ce
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
5 changed files with 13 additions and 13 deletions

View file

@ -83,7 +83,7 @@ Available Commands:
Flags:
--access-token string set the access token
-c, --config string set the config file path
--db.path string set the probe storage path (default "/tmp/magellan/magellan.db")
--cache string set the probe storage path (default "/tmp/magellan/magellan.db")
-h, --help help for magellan
--threads int set the number of threads (default -1)
--timeout int set the timeout (default 30)
@ -101,7 +101,7 @@ There are three main commands to use with the tool: `scan`, `list`, and `collect
--subnet 172.16.0.0 \
--subnet-mask 255.255.255.0 \
--format json \
--db.path data/assets.db --port 443
--cache data/assets.db --port 443
```
This will scan the `172.16.0.0` subnet returning the host and port that return a response and store the results in a local cache with at the `data/assets.db` path. Additional flags can be set such as `--host` to add more hosts to scan not included on the subnet, `--timeout` to set how long to wait for a response from the BMC node, or `--concurrency` to set the number of requests to make concurrently. Setting the `--format=json` will format the output in JSON. Try using `./magellan help scan` for a complete set of options this subcommand.
@ -109,7 +109,7 @@ This will scan the `172.16.0.0` subnet returning the host and port that return a
To inspect the cache, use the `list` command. Make sure to point to the same database used before:
```bash
./magellan list --db.path data/assets.db --format json
./magellan list --cache data/assets.db --format json
```
This will print a list of node info found and stored from the scan. Like the `scan` subcommand, the output format can be set using the `--format` flag.
@ -118,7 +118,7 @@ Finally, set the `MAGELLAN_ACCESS_TOKEN`run the `collect` command to query the n
```bash
./magellan collect \
--db.path data/assets.db \
--cache data/assets.db \
--timeout 5 \
--user admin \
--pass password \
@ -130,7 +130,7 @@ Finally, set the `MAGELLAN_ACCESS_TOKEN`run the `collect` command to query the n
This uses the info stored in cache to request information about each BMC node if possible. Like with the scan, the time to wait for a response can be set with the `--timeout` flag as well. This command also requires the `--user` and `--pass` flags to be set if access the Redfish service requires basic authentication. Additionally, it may be necessary to set the `--host` and `--port` flags for `magellan` to find the SMD API (not the root API endpoint "/hsm/v2"). The output of the `collect` can be saved by using the `--output`
Note: If the `db.path` flag is not set, `magellan` will use "/tmp/$USER/magellan.db" by default.
Note: If the `cache` flag is not set, `magellan` will use "/tmp/$USER/magellan.db" by default.
### Getting an Access Token (WIP)

View file

@ -26,7 +26,7 @@ var collectCmd = &cobra.Command{
l := log.NewLogger(logrus.New(), logrus.DebugLevel)
// get probe states stored in db from scan
probeStates, err := sqlite.GetProbeResults(dbpath)
probeStates, err := sqlite.GetProbeResults(cachePath)
if err != nil {
l.Log.Errorf("failed toget states: %v", err)
}

View file

@ -15,7 +15,7 @@ var listCmd = &cobra.Command{
Use: "list",
Short: "List information from scan",
Run: func(cmd *cobra.Command, args []string) {
probeResults, err := sqlite.GetProbeResults(dbpath)
probeResults, err := sqlite.GetProbeResults(cachePath)
if err != nil {
logrus.Errorf("failed toget probe results: %v\n", err)
}

View file

@ -24,7 +24,7 @@ var (
cacertPath string
username string
password string
dbpath string
cachePath string
outputPath string
configPath string
verbose bool
@ -83,13 +83,13 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "", "set the config file path")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "set output verbosity")
rootCmd.PersistentFlags().StringVar(&accessToken, "access-token", "", "set the access token")
rootCmd.PersistentFlags().StringVar(&dbpath, "db.path", fmt.Sprintf("/tmp/%smagellan/magellan.db", currentUser.Username+"/"), "set the probe storage path")
rootCmd.PersistentFlags().StringVar(&cachePath, "cache", fmt.Sprintf("/tmp/%smagellan/magellan.db", currentUser.Username+"/"), "set the scanning result cache path")
// bind viper config flags with cobra
viper.BindPFlag("concurrency", rootCmd.Flags().Lookup("concurrency"))
viper.BindPFlag("timeout", rootCmd.Flags().Lookup("timeout"))
viper.BindPFlag("verbose", rootCmd.Flags().Lookup("verbose"))
viper.BindPFlag("db.path", rootCmd.Flags().Lookup("db.path"))
viper.BindPFlag("cache", rootCmd.Flags().Lookup("cache"))
viper.BindPFlags(rootCmd.Flags())
}
@ -104,7 +104,7 @@ func SetDefaults() {
viper.SetDefault("timeout", 30)
viper.SetDefault("config", "")
viper.SetDefault("verbose", false)
viper.SetDefault("db.path", "/tmp/magellan/magellan.db")
viper.SetDefault("cache", "/tmp/magellan/magellan.db")
viper.SetDefault("scan.hosts", []string{})
viper.SetDefault("scan.ports", []int{})
viper.SetDefault("scan.subnets", []string{})

View file

@ -82,12 +82,12 @@ var scanCmd = &cobra.Command{
}
// make the dbpath dir if needed
err := os.MkdirAll(path.Dir(dbpath), 0766)
err := os.MkdirAll(path.Dir(cachePath), 0766)
if err != nil {
fmt.Printf("failed tomake database directory: %v", err)
}
sqlite.InsertProbeResults(dbpath, &probeStates)
sqlite.InsertProbeResults(cachePath, &probeStates)
},
}