download multiple device configs


Anyone know of or have a scipt to download multiple device configurations at once? I'm thinking of writing a script that will identify resources within a group and then download their configurations for a specific configsource instance. I can't be the first one to want this though so thought I'd check here.


16 replies

Userlevel 6
Badge +11

https://github.com/willingminds/lmapi-scripts

See lm-get-configs and the run-lm-get-configs wrapper.  There are a fair number of workarounds in the main script due to various problems with module behavior.  I am currently battling an apparent API bug where the query we use (basically, sort in reverse by version and provide the first result) triggers a bizarre "too many predicates" error. Sent that back to dev when they wanted to wash their hands of it because our API code is in Perl and is "unsupported".

To use the API module, you need a .lmapi file in the caller's home directly with one set of credentials per portal in YAML.  For example:

---
companies:
    willingminds:
        access_id: '****'
        access_key: '****'

The wrapper runs the script and checks into git -- not necessary, but we want to track changes and have post-commit hooks to get email reports on what changed.  This was the original reason we wrote it, but it is also super helpful to be able to scan all configs at once with grep or with template-validation tools, etc.

Just to be sure, you're not talking about downloading from the device to LM. You're talking about downloading from LM to your laptop.  I thought the first until I saw @mnagel's response.

Userlevel 6
Badge +11
3 hours ago, Stuart Weenig said:

Just to be sure, you're not talking about downloading from the device to LM. You're talking about downloading from LM to your laptop.  I thought the first until I saw @mnagel's response.

You may be right, I just could not see how that would make sense given the way LM does it or why it would be useful :).

@Stuart Weenig Correct, download a collection of configs from LM to a local device.

@mnagel Thank for the link. However, I am going to be a choosy beggar since I am useless with perl. I decided to go ahead and write something in python and will link it here if it turns out to be any good.

I put this together.

https://github.com/peteperreault/lm

Script is getGroupConfigs. It's working for Cisco and Palo Alto devices, potentially only a subset of each. I'm sure there are additional devices that can be added as well as additional functionality. @Stuart Weenig You'll recognize some bits from connectwise_manage. You know what they say, imitation (and outright thievery) is the sincerest form of flattery. ?

Haha, those are really nicely written functions, aren't they. ?

On 8/12/2020 at 1:21 PM, pperreault said:

I put this together.

https://github.com/peteperreault/lm

Script is getGroupConfigs. It's working for Cisco and Palo Alto devices, potentially only a subset of each. I'm sure there are additional devices that can be added as well as additional functionality. @Stuart Weenig You'll recognize some bits from connectwise_manage. You know what they say, imitation (and outright thievery) is the sincerest form of flattery. ?

 

Hi @pperreault

I am new to scripting so trying to get my head around this. We are in the same boat where we have download configs for multiple devices, how to go about utilising this script ? 

Let me know.

Thank you

@Herin, this script downloads the configs from LM after the ConfigSource downloads the config from the device. Just wanting to make sure you are trying to do that. The python script has built in help, so if you run it with the `--help` argument, it should show you everything you need. The only thing that may not be described is that you put your credentials into a json file. This json file is similar to how i do it here.

Thanks @Stuart Weenig @pperreault got the script working though i am not sure why it is downloading configs for 50 devices only. I dont see any limit in the script. Is there something i am missing here.

Appreciate if you can give some pointer.

Worked it out. By default a list of 50 stored config results will be returned. Had to update the Get Devices queryParams= '?size=1000&offset=0'

On 6/25/2021 at 4:25 AM, Herin said:

 

Hi @pperreault

I am new to scripting so trying to get my head around this. We are in the same boat where we have download configs for multiple devices, how to go about utilising this script ? 

Let me know.

Thank you

Thanks for the script, could you please help me with Jason file template to pass the credentials required to authenticate?

Appreciate your help . 

On 8/12/2020 at 8:51 AM, pperreault said:

I put this together.

https://github.com/peteperreault/lm

Script is getGroupConfigs. It's working for Cisco and Palo Alto devices, potentially only a subset of each. I'm sure there are additional devices that can be added as well as additional functionality. @Stuart Weenig You'll recognize some bits from connectwise_manage. You know what they say, imitation (and outright thievery) is the sincerest form of flattery. ?

Thanks for the script, could you please help me with Jason file template to pass the credentials required to authenticate?

Appreciate your help . 

Userlevel 7
Badge +17

Should look something like this:

{
	"lm_id": "HKLASUEKGYAKGJASJ",
	"lm_key": "1383270q9845092834759823409762",
	"lm_company": "yourportalname"
}
Userlevel 6
Badge +11

It is not JSON, it is YAML.  Example:

---
companies:
    PORTALNAME:
        access_id: 'ACCESS-ID'
        access_key: 'ACCESS-KEY'

I probably should sync up to our current version -- we've had to add exceptions regularly to keep from being inundated with fake changes due to inadequate error handling in the LM code.  Wish we could just integrate Oxidized sometimes.  At least there if problems are found, people generally fix them.

Userlevel 6
Badge +11
Just now, mnagel said:

It is not JSON, it is YAML.  Example:

---
companies:
    PORTALNAME:
        access_id: 'ACCESS-ID'
        access_key: 'ACCESS-KEY'

I probably should sync up to our current version -- we've had to add exceptions regularly to keep from being inundated with fake changes due to inadequate error handling in the LM code.  Wish we could just integrate Oxidized sometimes.  At least there if problems are found, people generally fix them.

Oops, sorry -- was thinking this was a reference to my script for some reason... :).

Userlevel 7
Badge +17
1 minute ago, mnagel said:

It is not JSON, it is YAML.  Example:

 

Are you sure?

keyFileJson = json.loads(fileText)
AccessId = keyFileJson['lm_id']
AccessKey = keyFileJson['lm_key']
Company = keyFileJson['lm_company']

 

Reply