Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
the_rock
Legend
Legend
Jump to solution

Exporting large group of IPs into a file from mgmt_cli

Hey guys,

Apologies if this may sound like a really silly question, but Im trying to figure out if Im doing this right. To make a long story short, I imported customer's config into my lab and trying to see if I can export large group with about 5000 IPs into csv format file via cli, but not having much luck so far. Below is command I ran:

mgmt_cli show group name "Block" > block.csv

It seems like it did take it and after I logged in, its just "sitting" there for 20 mins and file size is not moving at all.

If someone could confirm if this is correct, would be awesome.

Tx as always.

Andy

0 Kudos
1 Solution

Accepted Solutions
the_rock
Legend
Legend

My colleague, who is Linux GENIUS (everyone says that about him), helped me figure it out. Anyway, creds are just my lab, so you get an idea 🙂

He will also send me info how he converted the file to fit into when you try import hosts into another mgmt.

mgmt_cli show group -u admin -p 'maxwe!!' name "Block" > blockips.csv --format json

Command to import the file:

mgmt_cli add host --batch block.csv

 

Example (it HAS TO look like something below)

 

#cat test.csv

 

 

name,ip-address

obj1,192.168.1.1

 

Btw, here is example how to get right file format that can be used right away to add via mgmt_cli:

 

example for hosts, but you get an idea for ranges or subnets:

 

mgmt_cli -r true show-group name "Block" --format json | jq '.members[] | [.name, ."ipv4-address"] | @csv' -r >> ip_block_test.csv

 

--->To add address-range via API:

mgmt_cli add address-range --batch address-ranges_full.csv

 

#cat address-ranges_full.csv

name,ip-address-first,ip-address-last

range1,10.0.0.0,10.0.0.100

 

---> To add a network via API:

mgmt_cli add network --batch networks.csv

 

#cat networks.csv

name,subnet,subnet-mask

network1,10.10.10.0,255.255.255.0

network2,20.20.20.0,255.255.255.0

network3,30.30.30.0,255.255.255.0

 

---> To add a host 

mgmt_cli add host --batch test.csv

 

#cat test.csv

name,ip-address

obj1,192.168.1.1

 

Hope this saves a headache for whoever has to do this in the future 🙂

 

Andy

 

View solution in original post

0 Kudos
7 Replies
Nüüül
Advisor

Hi Andy,

did you try to execute it without redirecting to a file?

what exactly do you want/need to achieve? 

as output would be like this:

Click to Expand
- uid: "ff7ae4dc-9f1e-4c1e-af2b-217a6834083c"
name: "net_auto_feed_zoom-221.122.64.0-24"
type: "network"
domain:
uid: "41e821a0-3720-11e3-aa6e-0800200c9fde"
name: "SMC User"
domain-type: "domain"
subnet4: "221.122.64.0"
mask-length4: 24
subnet-mask: "255.255.255.0"
icon: "NetworkObjects/network"
color: "blue"

 when having so much objects, maybe using async-response would help

 

Click to Expand
mgmt_cli --session-id sid --format json show group async-response true name groupname ( maybe some jq magic like| jq .tasks[0] and so on) > out.txt

 

0 Kudos
the_rock
Legend
Legend

Hey @Nüüül 

Tx a lot for responding, appreciated! Yes, without redirecting to a file, works fine, but reason why I need a file is because we are trying to get right CSV file that can be imported into S1C portal for the customer, but only TAC can do it, since there is no regular ssh access.

Andy

0 Kudos
Nüüül
Advisor

OK, i would go with the web API - exporting all the objects and reimporting them to smart1cloud. As web API should still be there (another argument necessary "context" if i remember correctly)

 

 

0 Kudos
the_rock
Legend
Legend

Do you have an example? I tried exporting from smart console, but does NOT let you export only single group, even from object explorer : - (

Andy

0 Kudos
Nüüül
Advisor

how urgent is this? can send you something tomorrow if thats ok?

0 Kudos
the_rock
Legend
Legend

Its not urgent, no rush. Im just trying to see if I can get this exported from the lab, but so far, no luck.

Andy

0 Kudos
the_rock
Legend
Legend

My colleague, who is Linux GENIUS (everyone says that about him), helped me figure it out. Anyway, creds are just my lab, so you get an idea 🙂

He will also send me info how he converted the file to fit into when you try import hosts into another mgmt.

mgmt_cli show group -u admin -p 'maxwe!!' name "Block" > blockips.csv --format json

Command to import the file:

mgmt_cli add host --batch block.csv

 

Example (it HAS TO look like something below)

 

#cat test.csv

 

 

name,ip-address

obj1,192.168.1.1

 

Btw, here is example how to get right file format that can be used right away to add via mgmt_cli:

 

example for hosts, but you get an idea for ranges or subnets:

 

mgmt_cli -r true show-group name "Block" --format json | jq '.members[] | [.name, ."ipv4-address"] | @csv' -r >> ip_block_test.csv

 

--->To add address-range via API:

mgmt_cli add address-range --batch address-ranges_full.csv

 

#cat address-ranges_full.csv

name,ip-address-first,ip-address-last

range1,10.0.0.0,10.0.0.100

 

---> To add a network via API:

mgmt_cli add network --batch networks.csv

 

#cat networks.csv

name,subnet,subnet-mask

network1,10.10.10.0,255.255.255.0

network2,20.20.20.0,255.255.255.0

network3,30.30.30.0,255.255.255.0

 

---> To add a host 

mgmt_cli add host --batch test.csv

 

#cat test.csv

name,ip-address

obj1,192.168.1.1

 

Hope this saves a headache for whoever has to do this in the future 🙂

 

Andy

 

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events