Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Без нарушений

Code Block
#!/bin/bash
get_token() {
token=`curl -k -s -X POST -H "Content-Type: application/json" -d '{"username":"'$wnamlogin'","password":"'$wnampassword'"}'  https://$wnam_address/api/2.0/authenticate | jq -r .access_token`
echo $token > /tmp/token


STATUS="100" 
wnamlogin="admin"
wnampassword="admin"
wnam_address="172.16.133.12"
if [ ! -f /tmp/token ]; then
	get_token
fi
access_token=`cat /tmp/token`
status=`curl -s -kw "%{http_code}" -sk -X POST -H "Content-Type: application/json" -H "Authorization: Bearer "$access_token -d '"{"username":"'$wnamlogin'","password":"'$wnampassword'"}' \"hostname\":\"$1\",\"ARM_IP\":\"$2\",\"ARM_MAC\":\"$3\",\"status\":\"$STATUS\"}" https://$wnam_address/api/2.0/authenticate | jq -r .access_token`
curlsakura_state`
if [ "$status" -eq 401 ]; then
get_token
access_token=`cat /tmp/token`
curl -s -k -X POST -H "Content-Type: application/json" -H "Authorization: Bearer "$access_token -d "{\"hostname\":\"$1\",\"ARM_IP\":\"$2\",\"ARM_MAC\":\"$3\",\"status\":\"$STATUS\"}" https://$wnam_address/api/2.0/sakura_state 
fi

Критическое

Code Block
#!/bin/bash
get_token() {
token=`curl -k -s -X POST -H "Content-Type: application/json" -d '{"username":"'$wnamlogin'","password":"'$wnampassword'"}'  https://$wnam_address/api/2.0/authenticate | jq -r .access_token`
echo $token > /tmp/token
} 

STATUS="1" 
wnamlogin="admin"
wnampassword="admin"
wnam_address="172.16.133.12"
if [ ! -f /tmp/token ]; then
	get_token
fi
access_token=`cat /tmp/token`
status=`curl -s -kw "%{http_code}" -sk -X POST -H "Content-Type: application/json" -H "Authorization: Bearer "$access_token -d '{"username":"'$wnamlogin'","password":"'$wnampassword'"}'  "{\"hostname\":\"$1\",\"ARM_IP\":\"$2\",\"ARM_MAC\":\"$3\",\"status\":\"$STATUS\"}" https://$wnam_address/api/2.0/authenticate | jq -r .access_token`
curlsakura_state`
if [ "$status" -eq 401 ]; then
get_token
access_token=`cat /tmp/token`
curl -s -k -X POST -H "Content-Type: application/json" -H "Authorization: Bearer "$access_token -d "{\"hostname\":\"$1\",\"ARM_IP\":\"$2\",\"ARM_MAC\":\"$3\",\"status\":\"$STATUS\"}" https://$wnam_address/api/2.0/sakura_state 
fi

офлайн

Code Block
#!/bin/bash
get_token() {
token=`curl -k -s -X POST -H "Content-Type: application/json" -d '{"username":"'$wnamlogin'","password":"'$wnampassword'"}'  https://$wnam_address/api/2.0/authenticate | jq -r .access_token`
echo $token > /tmp/token


STATUS="0" 
wnamlogin="admin"
wnampassword="admin"
wnam_address="172.16.133.12"
if [ ! -f /tmp/token ]; then
	get_token
fi
access_token=`cat /tmp/token``
status=`curl -ks -w "%{http_code}" -sk -X POST -H "Content-Type: application/json" -H "Authorization: Bearer "$access_token -d '"{"username":"'$wnamlogin'","password":"'$wnampassword'"}' \"hostname\":\"$1\",\"ARM_IP\":\"$2\",\"ARM_MAC\":\"$3\",\"status\":\"$STATUS\"}" https://$wnam_address/api/2.0/authenticate | jq -r .access_token`
curlsakura_state`
if [ "$status" -eq 401 ]; then
get_token
access_token=`cat /tmp/token`
curl -s -k -X POST -H "Content-Type: application/json" -H "Authorization: Bearer "$access_token -d "{\"hostname\":\"$1\",\"ARM_IP\":\"$2\",\"ARM_MAC\":\"$3\",\"status\":\"$STATUS\"}" https://$wnam_address/api/2.0/sakura_state 
fi

В скрпиптах нужно поменять адрес сервера WNAM и реквизиты доступа к нему. 

...