Skip to content

Update collect take input with specified format#130

Open
davidallendj wants to merge 11 commits into
mainfrom
allend/collect-json-input
Open

Update collect take input with specified format#130
davidallendj wants to merge 11 commits into
mainfrom
allend/collect-json-input

Conversation

@davidallendj
Copy link
Copy Markdown
Collaborator

@davidallendj davidallendj commented Apr 6, 2026

Pull Request Template

Thank you for your contribution! Please ensure the following before submitting:

Checklist

  • My code follows the style guidelines of this project
  • I have added/updated comments where needed
  • I have added tests that prove my fix is effective or my feature works
  • I have run make test (or equivalent) locally and all tests pass
  • DCO Sign-off: All commits are signed off (git commit -s) with my real name and email
  • [] REUSE Compliance:
    • Each new/modified source file has SPDX copyright and license headers
    • Any non-commentable files include a <filename>.license sidecar
    • All referenced licenses are present in the LICENSES/ directory

Description

This PR changes the collect command to take JSON or YAML as input from the scan command. This allows for the entire discovery process to be completed as a single command without hitting the file system.

Examples:

# scan -> collect
magellan scan --subnet 172.18.0.0/24 --port 5000 -l info -i -F json | magellan collect -f json --show-output -i

# scan -> collect -> send
magellan scan --subnet 172.18.0.0/24 --port 5000 -l info -i -F json | magellan collect -f json --show-output -i | magellan send https://smd.example.com

# collect -> send
magellan collect pdu x3000m0 x3000m1 -u admin -p password | magellan send https://smd.example.com

Fixes #128

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

For more info, see Contributing Guidelines.

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>
@davidallendj davidallendj force-pushed the allend/collect-json-input branch from e59ee6e to 92bdb3b Compare April 6, 2026 22:24
Signed-off-by: David Allen <davidallendj@gmail.com>
Copy link
Copy Markdown
Contributor

@synackd synackd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread cmd/collect.go
@@ -9,16 +9,20 @@ import (
"github.com/OpenCHAMI/magellan/internal/cache/sqlite"
"github.com/OpenCHAMI/magellan/internal/format"
magellan "github.com/OpenCHAMI/magellan/pkg"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we haven't added linting to Magellan yet, we definitely should. Internal imports should go after other package imports. I suspect this needs to be done in other files as well, so it can be addressed in a subsequent PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Allow collect to take JSON or YAML as input

2 participants