Update collect to take input with specified format - #130
Conversation
e59ee6e to
92bdb3b
Compare
synackd
left a comment
There was a problem hiding this comment.
Testing with real BMCs.
Scanning:
$ ./magellan scan --subnet 172.16.0.0/24 -l info -i -F json --insecure
{"level":"warn","error":"RegisterFlagCompletionFunc: flag 'format' does not exist","time":"2026-05-14T13:45:41-06:00","message":"failed to register completion function"}
[
{
"host": "https://172.16.0.105",
"port": 443,
"protocol": "tcp",
"state": true,
"timestamp": "2026-05-14T13:45:41.948173759-06:00",
"service_type": "Redfish"
},
{
"host": "https://172.16.0.104",
"port": 443,
"protocol": "tcp",
"state": true,
"timestamp": "2026-05-14T13:45:41.947999177-06:00",
"service_type": "Redfish"
},
{
"host": "https://172.16.0.102",
"port": 443,
"protocol": "tcp",
"state": true,
"timestamp": "2026-05-14T13:45:41.947644981-06:00",
"service_type": "Redfish"
},
{
"host": "https://172.16.0.101",
"port": 443,
"protocol": "tcp",
"state": true,
"timestamp": "2026-05-14T13:45:41.947476248-06:00",
"service_type": "Redfish"
},
{
"host": "https://172.16.0.103",
"port": 443,
"protocol": "tcp",
"state": true,
"timestamp": "2026-05-14T13:45:41.947691662-06:00",
"service_type": "Redfish"
},
{
"host": "https://172.16.0.199",
"port": 443,
"protocol": "tcp",
"state": true,
"timestamp": "2026-05-14T13:45:41.948031377-06:00",
"service_type": "Redfish"
},
{
"host": "https://172.16.0.198",
"port": 443,
"protocol": "tcp",
"state": true,
"timestamp": "2026-05-14T13:45:41.947765703-06:00",
"service_type": "Redfish"
}
]
Scanning piping to collect:
$ ./magellan scan --subnet 172.16.0.0/24 -l info -i -F json --insecure | ./magellan collect -f json --show-output -i
{"level":"warn","error":"RegisterFlagCompletionFunc: flag 'format' does not exist","time":"2026-05-14T13:46:07-06:00","message":"failed to register completion function"}
{"level":"warn","error":"RegisterFlagCompletionFunc: flag 'format' does not exist","time":"2026-05-14T13:46:07-06:00","message":"failed to register completion function"}
{"level":"error","error":"no file found","time":"2026-05-14T13:46:07-06:00","caller":"/opt/shared/magellan/cmd/collect.go:61","message":"failed to get scanned results from cache"}
{"level":"error","error":"no assets found","time":"2026-05-14T13:46:07-06:00","caller":"/opt/shared/magellan/cmd/collect.go:178","message":"failed to collect data"}
null
I think this may be happening because the This is where the check happens: And here is where the flag default is set: I can run it by setting ./magellan scan --subnet 172.16.0.0/24 -l info -i -F json | ./magellan collect -f json --show-output -i --cache "" -l debug |
cbe75b6 to
7b1e8d4
Compare
|
@synackd It should be working now. I had to add some missing logic back to This is the command I'm using to test currently: ./magellan scan --subnet 172.16.0.0/24 -l info -i -F json | ./magellan collect -f json --show-output -i --cache "" -l debug |
|
That command line worked for me. What if we added a check to see that stdin was open and, if so, used that instead of a cache unless explicitly told to do so? |
collect take input with specified formatcollect take input with specified format
collect take input with specified formatcollect to take input with specified format
@davidallendj Just wanted to check in again with this to see if this was something we wanted to add in this PR. |
Yes, I think we should. I just haven't gotten back around to add it. If you already have it implemented though, feel free to push to this branch and we can get this merged. |
|
Understood. I didn't attempt it in order to avoid possibly duplicating your work. All yours. 🙂 |
|
@synackd seems to have approved. Is that true? |
|
I believe we are waiting for @davidallendj to implement this:
|
|
Sorry this took so long. It was taking a minute to get some of the behaviors correct, but both of these cases should work like expected and ./magellan scan --subnet 172.18.0.0/24 -l info -i --port 5000
./magellan collect -f json --show-output -i -l debug./magellan scan --subnet 172.18.0.0/24 -l info -i -F json --port 5000 | ./magellan collect -f json --show-output -i -l debug |
f817c9a to
98aa0e6
Compare
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: Polly Labs <pollychen.lab@gmail.com> Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
98aa0e6 to
1a4a3f2
Compare
|
Just tested again with:
These all worked as expected. |
synackd
left a comment
There was a problem hiding this comment.
One possible code fix and several documentation updates.
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
synackd
left a comment
There was a problem hiding this comment.
I retested all of the mentioned test cases and they worked as expected. However, I found an error when testing YAML with piping commands. There is some other weird behavior I found as well as well as some small documentation updates that are needed.
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
synackd
left a comment
There was a problem hiding this comment.
Looks like most things are fixed, but found one more potential issue. I think after that and #130 (comment) we should be good. Will test after changes are pushed.
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
synackd
left a comment
There was a problem hiding this comment.
Mainly one code fix with some more documentation fixes.
| } else { | ||
| // input should be a valid JSON | ||
| var ( | ||
| data JSONArray | ||
| input = []byte(arg) | ||
| err error | ||
| ) | ||
| if !json.Valid(input) { | ||
| log.Error().Msgf("argument %d not a valid JSON", i) | ||
| continue | ||
| } | ||
| err = json.Unmarshal(input, &data) | ||
| if err != nil { | ||
| log.Error().Err(err).Msgf("failed to unmarshal input for argument %d", i) | ||
| } | ||
| return data | ||
| } | ||
| } |
There was a problem hiding this comment.
This should use format.UnmarshalData() instead of the JSON unmarshaller so inline YAML data passed with -d/--data will honor -f yaml, e.g:
} else {
// input should be valid data in the selected input format
var (
data JSONArray
input = []byte(arg)
err error
)
err = format.UnmarshalData(input, &data, inputFormat)
if err != nil {
log.Error().Err(err).Msgf("failed to unmarshal %s input for argument %d", inputFormat, i)
}
return data
}| magellan scan --subnet 10.0.0.0/16 -i | ||
|
|
||
| // same as above example but output is in JSON without caching | ||
| magellan scan --subnet 10.0.0.0/16 -i -f json --disable-cache |
| magellan send -d @inventory.json https://smd.openchami.cluster | ||
|
|
||
| // send data from multiple files (must specify -f/--format if not JSON) | ||
| // send data from multiple files (must specify -F/--output-format if not JSON) |
| // assumes subnet without CIDR has a subnet-mask of 255.255.0.0++ | ||
| // assumes subnet without CIDR has a subnet-mask of 255.255.0.0 |
There was a problem hiding this comment.
We'll want to keep the ++ otherwise the command will be on the same line as the comment.
| magellan scan --subnet 10.0.0.0/16 -i | ||
|
|
||
| // same as above example but output is in JSON without caching | ||
| magellan scan --subnet 10.0.0.0/16 -i -f json --disable-cache |
There was a problem hiding this comment.
Shouldn't this use -F since we are outputting?
| sendCmd.Flags().StringArrayVarP(&sendDataArgs, "data", "d", []string{}, "Set the data to send to specified host (prepend @ for files)") | ||
| sendCmd.Flags().VarP(&sendInputFormat, "format", "F", "Set the default data input format (json|yaml) can be overridden by file extension") | ||
| sendCmd.Flags().BoolVarP(&forceUpdate, "force-update", "f", false, "Set flag to force update data sent to SMD") | ||
| sendCmd.Flags().VarP(&sendInputFormat, "input-format", "f", "Set the default data input format (json|yaml) can be overridden by file extension") |
There was a problem hiding this comment.
Line 131 in 9ac3ace
-F -> -f to match this flag
Signed-off-by: David Allen <davidallendj@gmail.com>
Pull Request Template
Thank you for your contribution! Please ensure the following before submitting:
Checklist
make test(or equivalent) locally and all tests passgit commit -s) with my real name and email<filename>.licensesidecarLICENSES/directoryDescription
This PR changes the
collectcommand to take JSON or YAML as input from thescancommand. This allows for the entire discovery process to be completed as a single command without hitting the file system.Examples:
Fixes #128
Type of Change
For more info, see Contributing Guidelines.