Introducing SOC Insights for BloxOne Threat Defense: Boost your SOC efficiency with AI-driven insights to eliminate manual work and accelerate investigation and response times. Read the blog announcement here.

API & Integration, DevOps,NetOps,SecOps

Reply

func:nextavailableip wapi in a script

New Member
Posts: 5
5082     0

When i run this command in command line with $field1 and $field2 define

 

curl -s -k -u XXX:XXX -H "Content-Type: application/json" -X POST "https://hostname/wapi/v2.7/record:host" -d '{"ipv4addrs":[{"ipv4addr":"func:nextavailableip:'"$field2"'"}],"name":"'$field1'"}' this works and i am able to add a host with next available ip

 

 

when i run it in a bash script which reads in a field1 and field2 from a csv  

 

while read field1 field2 

do

  curl -s -k -u xxx:xxx -H "Content-Type: application/json" -X POST "https://hostname/wapi/v2.7/record:host" -d '{"ipv4addrs":[{"ipv4addr":"func:nextavailableip:'"$field2"'"}],"name":"'$field1'"}'

 

done < DNS_HOST_record.csv

 

 

i get this error 

 

{ "Error": "AdmConProtoError: JSON Decoding: Invalid control character at: line 1 column 62 (char 62)",

  "code": "Client.Ibap.Proto.JSONDecoding",

  "text": "JSON Decoding: Invalid control character at: line 1 column 62 (char 62)"

}

 

 

my DNS_HOST_record.csv file is consist of this file

 

host123.bladblah.net,192.168.1.0/24

host345.bladblah.net,192.168.1.0/24

 

not sure what i'm doing wrong here?

Re: func:nextavailableip wapi in a script

Adviser
Posts: 181
5082     0

Hi,

 

I don't see a problem with your script. I tried it out on my system. It works fine. You can verify how you are passing the arguments to the script. I've attached the screenshots of how I tested it.

image07.PNGimage08.PNG

Hope this helps,

Krishna

Re: func:nextavailableip wapi in a script

New Member
Posts: 5
5082     0

So i am not sure why i'm getting the json errors using the same script commands.

Re: func:nextavailableip wapi in a script

New Member
Posts: 5
5083     0

BTW i have my IFS defined as 

 

IFS=$IFS     # Always keep the original IFS!

IFS=","      # Now set it to what we want the "read" loop to use

Re: func:nextavailableip wapi in a script

[ Edited ]
New Member
Posts: 5
5083     0

Screen Shot 2018-11-09 at 8.46.03 AM.png

 

using the curl command works

 

putting the same curl command in my bash script fails

 

Screen Shot 2018-11-09 at 8.46.18 AM.png   

 

 

#!/bin/bash

# Beginning of common script header section

# First we go ahead and create a log directory where we will log our output..."

clear

logdir="logs"

now=`date '+%Y_%m_%d_at_%H_%M'`

today=`date '+%Y_%m_%d'`

logfile="hostadd_$now.log"

echo "$now HostRecordAdd version 1.0 dated Nov 7, 2018 by Andy Wu"

if [ -d $logdir ]

then

    echo "$now Log Directory already exists..." | tee -a $logdir/$logfile

else

    mkdir $logdir

fi

 

touch $logdir/$logfile

echo "$now Beginning script execution...." | tee -a $logdir/$logfile

 

# End of common script header section

 

echo | tee -a $logdir/$logfile

 

#IFS=$IFS     # Always keep the original IFS!

#IFS=","      # Now set it to what we want the "read" loop to use

echo | tee -a $logdir/$logfile

while read field1 field2 

do

  curl -s -k -u xxx:xxx -H "Content-Type: application/json" -X POST "https://10.29.12.192/wapi/v2.9/record:host" -d '{"ipv4addrs":[{"ipv4addr":"func:nextavailableip:'"$field2"'"}],"name":"'$field1'"}'

  echo

  echo $field1

  echo $field2

done < DNS_HOST_record.csv

 

Re: func:nextavailableip wapi in a script

New Member
Posts: 5
5083     0

found the issue for some reason vi the csv file added some control characters to the file.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You