Nvidia-Onyx-Ivo

From Cheatsheet
Jump to navigationJump to search


This page was written and contributed by Ivo Palli.

General

NVIDIA Onyx Management Console

SSH

ssh user@10.0.99.12
show what-just-happened
quit

REST API

cat << EOF | curl -kSsLX POST -d @- -c cookies.txt "https://10.0.99.12/admin/launch?script=rh&template=json-request&action=json-login" > result.json
{
 "username": "user",
 "password": "top_secret",
 "cmd": "show what-just-happened"
}
EOF

Getting logs, bash script

#!/bin/bash

TMP="/tmp/switches.tmp"
USER="user"
PASS="top_secret"

SW1="10.0.99.12"
SW2="10.0.99.13"
SW3="10.0.99.14"
SW4="10.0.99.15"

function get_logs
{
URL="https://$1/admin/launch?script=rh&template=json-request&action=json-login"

rm -f "${TMP}"

# Get data
cat << EOF | curl -kSsLX POST -d @- "${URL}" > "${TMP}"
{
 "username": "${USER}",
 "password": "${PASS}",
 "cmd": "show what-just-happened"
}
EOF

# Check if login went ok
if [ "$(jq -r ".status" "${TMP}")" \!= "OK" ]; then
  echo "Login failed on $1"
  exit
fi

# First sort the output numerically, change it from an object to an array, convert it to TSV
cat /tmp/switches.tmp | \
  jq '.data[0] | to_entries | sort_by(.key|tonumber) | reduce .[] as $entry ({}; . + { ($entry.key): $entry.value } )' | \
  jq '[.[][]]' | \
  jq -s -r '.[] |
    ([.[] | keys_unsorted[]] |
    reduce .[] as $item ([]; if any(.[]; . == $item) then . else . + [$item] end)) as $keys |
    $keys, (.[] | [.[$keys[]] | if . == null or . == "" then "-" else . end  ]) | @tsv'

rm -f "${TMP}"
}

for x in $SW1 $SW2 $SW3 $SW4; do
  get_logs $x > logs_$x
done

Links