Added ability to store output of collect command

Signed-off-by: David J. Allen <davidallendj@gmail.com>
This commit is contained in:
David Allen 2023-09-18 16:45:15 -06:00
parent 589cc12962
commit 3b9f4e6070
10 changed files with 135 additions and 62 deletions

View file

@ -4,7 +4,7 @@ import (
magellan "github.com/bikeshack/magellan/internal"
"github.com/bikeshack/magellan/internal/api/smd"
"github.com/bikeshack/magellan/internal/db/sqlite"
"github.com/bikeshack/magellan/internal/log"
"github.com/cznic/mathutil"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@ -15,7 +15,7 @@ var collectCmd = &cobra.Command{
Short: "Query information about BMC",
Run: func(cmd *cobra.Command, args []string) {
// make application logger
l := magellan.NewLogger(logrus.New(), logrus.DebugLevel)
l := log.NewLogger(logrus.New(), logrus.DebugLevel)
// get probe states stored in db from scan
probeStates, err := sqlite.GetProbeResults(dbpath)
@ -35,6 +35,7 @@ var collectCmd = &cobra.Command{
Threads: threads,
Verbose: verbose,
WithSecureTLS: withSecureTLS,
OutputPath: outputPath,
}
magellan.CollectInfo(&probeStates, l, q)
@ -52,6 +53,7 @@ func init() {
collectCmd.PersistentFlags().IntVar(&smd.Port, "port", smd.Port, "set the port to the smd API")
collectCmd.PersistentFlags().StringVar(&user, "user", "", "set the BMC user")
collectCmd.PersistentFlags().StringVar(&pass, "pass", "", "set the BMC password")
collectCmd.PersistentFlags().StringVarP(&outputPath, "output", "o", "/tmp/magellan/data/", "set the path to store collection data")
collectCmd.PersistentFlags().StringVar(&preferredDriver, "preferred-driver", "ipmi", "set the preferred driver to use")
collectCmd.PersistentFlags().StringVar(&ipmitoolPath, "ipmitool.path", "/usr/bin/ipmitool", "set the path for ipmitool")
collectCmd.PersistentFlags().BoolVar(&withSecureTLS, "secure-tls", false, "enable secure TLS")

View file

@ -20,6 +20,7 @@ var (
drivers []string
preferredDriver string
ipmitoolPath string
outputPath string
verbose bool
)
@ -51,5 +52,5 @@ func init() {
rootCmd.PersistentFlags().IntVar(&threads, "threads", -1, "set the number of threads")
rootCmd.PersistentFlags().IntVar(&timeout, "timeout", 30, "set the timeout")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", true, "set verbose flag")
rootCmd.PersistentFlags().StringVar(&dbpath, "db.path", "/tmp/magellan.db", "set the probe storage path")
rootCmd.PersistentFlags().StringVar(&dbpath, "db.path", "/tmp/magellan/magellan.db", "set the probe storage path")
}

View file

@ -2,6 +2,8 @@ package cmd
import (
"fmt"
"os"
"path"
magellan "github.com/bikeshack/magellan/internal"
"github.com/bikeshack/magellan/internal/db/sqlite"
@ -46,6 +48,13 @@ var scanCmd = &cobra.Command{
for _, r := range probeStates {
fmt.Printf("%s:%d (%s)\n", r.Host, r.Port, r.Protocol)
}
// make the dbpath dir if needed
err := os.MkdirAll(path.Dir(dbpath), 0766)
if err != nil {
fmt.Printf("could not make database directory: %v", err)
}
sqlite.InsertProbeResults(dbpath, &probeStates)
},
}