mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Merge pull request #20 from davidallendj/optimization
Fixed `magellan` running much slow when using Docker container
This commit is contained in:
commit
97bfcada06
3 changed files with 63 additions and 86 deletions
|
|
@ -11,6 +11,8 @@ THREADS="1"
|
||||||
TIMEOUT="30"
|
TIMEOUT="30"
|
||||||
ARGS=""
|
ARGS=""
|
||||||
FORCE_UPDATE=false
|
FORCE_UPDATE=false
|
||||||
|
SCAN_PARAMS=""
|
||||||
|
COLLECT_PARAMS=""
|
||||||
|
|
||||||
|
|
||||||
function build(){
|
function build(){
|
||||||
|
|
@ -19,11 +21,11 @@ function build(){
|
||||||
|
|
||||||
function scan() {
|
function scan() {
|
||||||
# ./magellan scan --subnet 172.16.0.0 --port 443
|
# ./magellan scan --subnet 172.16.0.0 --port 443
|
||||||
${EXE} scan \
|
${EXE} scan ${SCAN_PARAMS}
|
||||||
--subnet ${SUBNETS} \
|
# --subnet ${SUBNETS} \
|
||||||
--port ${PORTS} \
|
# --port ${PORTS} \
|
||||||
--timeout ${TIMEOUT} \
|
# --timeout ${TIMEOUT} \
|
||||||
--threads ${THREADS}
|
# --threads ${THREADS}
|
||||||
}
|
}
|
||||||
|
|
||||||
function list(){
|
function list(){
|
||||||
|
|
@ -33,20 +35,30 @@ function list(){
|
||||||
|
|
||||||
function collect() {
|
function collect() {
|
||||||
# ./magellan collect --user admin --pass password
|
# ./magellan collect --user admin --pass password
|
||||||
${EXE} collect \
|
${EXE} collect ${COLLECT_PARAMS}
|
||||||
--user ${USER} \
|
# --user ${USER} \
|
||||||
--pass ${PASS} \
|
# --pass ${PASS} \
|
||||||
--timeout ${TIMEOUT} \
|
# --timeout ${TIMEOUT} \
|
||||||
--threads ${THREADS} \
|
# --threads ${THREADS} \
|
||||||
--host ${SMD_HOST} \
|
# --host ${SMD_HOST} \
|
||||||
--port ${SMD_PORT} \
|
# --port ${SMD_PORT} \
|
||||||
--force-update ${FORCE_UPDATE}
|
# --force-update ${FORCE_UPDATE}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# parse incoming arguments to set variables
|
# parse incoming arguments to set variables
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
|
--scan)
|
||||||
|
SCAN_PARAMS="$2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--collect)
|
||||||
|
COLLECT_PARAMS="$2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--subnet)
|
--subnet)
|
||||||
SUBNETS="$2"
|
SUBNETS="$2"
|
||||||
shift # past argument
|
shift # past argument
|
||||||
|
|
@ -100,15 +112,6 @@ done
|
||||||
|
|
||||||
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
|
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
|
||||||
|
|
||||||
echo "SMD host = ${SMD_HOST}"
|
|
||||||
echo "SMD port = ${SMD_PORT}"
|
|
||||||
echo "subnets = ${SUBNETS}"
|
|
||||||
echo "ports = ${PORTS}"
|
|
||||||
echo "user = ${USER}"
|
|
||||||
echo "threads = ${THREADS}"
|
|
||||||
echo "timeout = ${TIMEOUT}"
|
|
||||||
echo "pass = ..."
|
|
||||||
|
|
||||||
if [[ -n $1 ]]; then
|
if [[ -n $1 ]]; then
|
||||||
echo "Last line of file specified as non-opt/last argument:"
|
echo "Last line of file specified as non-opt/last argument:"
|
||||||
tail -1 "$1"
|
tail -1 "$1"
|
||||||
|
|
@ -116,3 +119,8 @@ fi
|
||||||
|
|
||||||
scan
|
scan
|
||||||
collect
|
collect
|
||||||
|
|
||||||
|
# run with docker
|
||||||
|
# docker run magellan:latest magellan.sh \
|
||||||
|
# --scan "--subnet 127.16.0.0 --port 443" \
|
||||||
|
# --collect "--user admin --pass password --timeout 300 --threads 1 --smd-host host --smd-port port"
|
||||||
|
|
@ -53,7 +53,7 @@ func AddRedfishEndpoint(data []byte, headers map[string]string) error {
|
||||||
if res != nil {
|
if res != nil {
|
||||||
statusOk := res.StatusCode >= 200 && res.StatusCode < 300
|
statusOk := res.StatusCode >= 200 && res.StatusCode < 300
|
||||||
if !statusOk {
|
if !statusOk {
|
||||||
return fmt.Errorf("could not add redfish endpoint")
|
return fmt.Errorf("returned status code %d when adding endpoint", res.StatusCode)
|
||||||
}
|
}
|
||||||
fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body))
|
fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,16 +122,8 @@ func CollectAll(probeStates *[]ScannedResult, l *log.Logger, q *QueryParams) err
|
||||||
done := make(chan struct{}, q.Threads+1)
|
done := make(chan struct{}, q.Threads+1)
|
||||||
chanProbeState := make(chan ScannedResult, q.Threads+1)
|
chanProbeState := make(chan ScannedResult, q.Threads+1)
|
||||||
|
|
||||||
// generate custom xnames for bmcs
|
|
||||||
node := xnames.Node{
|
|
||||||
Cabinet: 1000,
|
|
||||||
Chassis: 1,
|
|
||||||
ComputeModule: 7,
|
|
||||||
NodeBMC: -1,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// collect bmc information asynchronously
|
// collect bmc information asynchronously
|
||||||
|
var offset = 0
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(q.Threads)
|
wg.Add(q.Threads)
|
||||||
for i := 0; i < q.Threads; i++ {
|
for i := 0; i < q.Threads; i++ {
|
||||||
|
|
@ -145,12 +137,19 @@ func CollectAll(probeStates *[]ScannedResult, l *log.Logger, q *QueryParams) err
|
||||||
q.Host = ps.Host
|
q.Host = ps.Host
|
||||||
q.Port = ps.Port
|
q.Port = ps.Port
|
||||||
|
|
||||||
node.NodeBMC += 1
|
// generate custom xnames for bmcs
|
||||||
|
node := xnames.Node{
|
||||||
bmclibClient, err := NewClient(l, q)
|
Cabinet: 1000,
|
||||||
if err != nil {
|
Chassis: 1,
|
||||||
l.Log.Errorf("could not make client: %v", err)
|
ComputeModule: 7,
|
||||||
|
NodeBMC: offset,
|
||||||
}
|
}
|
||||||
|
offset += 1
|
||||||
|
|
||||||
|
// bmclibClient, err := NewClient(l, q)
|
||||||
|
// if err != nil {
|
||||||
|
// l.Log.Errorf("could not make client: %v", err)
|
||||||
|
// }
|
||||||
|
|
||||||
gofishClient, err := connectGofish(q)
|
gofishClient, err := connectGofish(q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -173,14 +172,14 @@ func CollectAll(probeStates *[]ScannedResult, l *log.Logger, q *QueryParams) err
|
||||||
var rm map[string]json.RawMessage
|
var rm map[string]json.RawMessage
|
||||||
|
|
||||||
// inventories
|
// inventories
|
||||||
if bmclibClient != nil {
|
// if bmclibClient != nil {
|
||||||
inventory, err := CollectInventory(bmclibClient, q)
|
// inventory, err := CollectInventory(bmclibClient, q)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
l.Log.Errorf("could not query inventory (%v:%v): %v", q.Host, q.Port, err)
|
// l.Log.Errorf("could not query inventory (%v:%v): %v", q.Host, q.Port, err)
|
||||||
}
|
// }
|
||||||
json.Unmarshal(inventory, &rm)
|
// json.Unmarshal(inventory, &rm)
|
||||||
data["Inventory"] = rm["Inventory"]
|
// data["Inventory"] = rm["Inventory"]
|
||||||
}
|
// }
|
||||||
|
|
||||||
// chassis
|
// chassis
|
||||||
if gofishClient != nil {
|
if gofishClient != nil {
|
||||||
|
|
@ -211,25 +210,29 @@ func CollectAll(probeStates *[]ScannedResult, l *log.Logger, q *QueryParams) err
|
||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
headers["Content-Type"] = "application/json"
|
headers["Content-Type"] = "application/json"
|
||||||
|
|
||||||
b, err := json.MarshalIndent(data, "", " ")
|
body, err := json.MarshalIndent(data, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Log.Errorf("could not marshal JSON: %v", err)
|
l.Log.Errorf("could not marshal JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if q.Verbose {
|
||||||
|
fmt.Printf("%v\n", string(body))
|
||||||
|
}
|
||||||
|
|
||||||
// write JSON data to file
|
// write JSON data to file
|
||||||
err = os.WriteFile(path.Clean(outputPath + "/" + q.Host + ".json"), b, os.ModePerm)
|
err = os.WriteFile(path.Clean(outputPath + "/" + q.Host + ".json"), body, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Log.Errorf("could not write data to file: %v", err)
|
l.Log.Errorf("could not write data to file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// add all endpoints to smd
|
// add all endpoints to smd
|
||||||
err = smd.AddRedfishEndpoint(b, headers)
|
err = smd.AddRedfishEndpoint(body, headers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Log.Error(err)
|
l.Log.Error(err)
|
||||||
|
|
||||||
// try updating instead
|
// try updating instead
|
||||||
if q.ForceUpdate {
|
if q.ForceUpdate {
|
||||||
err = smd.UpdateRedfishEndpoint(data["ID"].(string), b, headers)
|
err = smd.UpdateRedfishEndpoint(data["ID"].(string), body, headers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Log.Error(err)
|
l.Log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
@ -296,9 +299,6 @@ func CollectMetadata(client *bmclib.Client, q *QueryParams) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if q.Verbose {
|
|
||||||
fmt.Printf("Metadata: %v\n", string(b))
|
|
||||||
}
|
|
||||||
ctxCancel()
|
ctxCancel()
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
@ -328,9 +328,6 @@ func CollectInventory(client *bmclib.Client, q *QueryParams) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if q.Verbose {
|
|
||||||
fmt.Printf("%v\n", string(b))
|
|
||||||
}
|
|
||||||
ctxCancel()
|
ctxCancel()
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
@ -358,9 +355,6 @@ func CollectPowerState(client *bmclib.Client, q *QueryParams) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if q.Verbose {
|
|
||||||
fmt.Printf("%v\n", string(b))
|
|
||||||
}
|
|
||||||
ctxCancel()
|
ctxCancel()
|
||||||
return b, nil
|
return b, nil
|
||||||
|
|
||||||
|
|
@ -392,11 +386,7 @@ func CollectUsers(client *bmclib.Client, q *QueryParams) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// return b, nil
|
|
||||||
ctxCancel()
|
ctxCancel()
|
||||||
if q.Verbose {
|
|
||||||
fmt.Printf("%v\n", string(b))
|
|
||||||
}
|
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -406,9 +396,6 @@ func CollectBios(client *bmclib.Client, q *QueryParams) ([]byte, error) {
|
||||||
// return nil, fmt.Errorf("could not make query: %v", err)
|
// return nil, fmt.Errorf("could not make query: %v", err)
|
||||||
// }
|
// }
|
||||||
b, err := makeRequest(client, client.GetBiosConfiguration, q.Timeout)
|
b, err := makeRequest(client, client.GetBiosConfiguration, q.Timeout)
|
||||||
if q.Verbose {
|
|
||||||
fmt.Printf("%v\n", string(b))
|
|
||||||
}
|
|
||||||
return b, err
|
return b, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -437,9 +424,6 @@ func CollectEthernetInterfaces(c *gofish.APIClient, q *QueryParams, systemID str
|
||||||
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if q.Verbose {
|
|
||||||
// fmt.Printf("%v\n", string(b))
|
|
||||||
// }
|
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -455,9 +439,6 @@ func CollectChassis(c *gofish.APIClient, q *QueryParams) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if q.Verbose {
|
|
||||||
fmt.Printf("%v\n", string(b))
|
|
||||||
}
|
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -483,9 +464,6 @@ func CollectStorage(c *gofish.APIClient, q *QueryParams) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if q.Verbose {
|
|
||||||
fmt.Printf("%v\n", string(b))
|
|
||||||
}
|
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -516,9 +494,6 @@ func CollectSystems(c *gofish.APIClient, q *QueryParams) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if q.Verbose {
|
|
||||||
fmt.Printf("%v\n", string(b))
|
|
||||||
}
|
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -534,9 +509,6 @@ func CollectRegisteries(c *gofish.APIClient, q *QueryParams) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if q.Verbose {
|
|
||||||
fmt.Printf("%v\n", string(b))
|
|
||||||
}
|
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -577,9 +549,6 @@ func CollectProcessors(q *QueryParams) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if q.Verbose {
|
|
||||||
fmt.Printf("%v\n", string(b))
|
|
||||||
}
|
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue