Thursday, March 28, 2019

Palo Alto Perl Module

Hi all,

​

I am currently working on a Perl module for the Palo Alto API. As it now has a reasonable amount of functionality and has been tested I think it's ready for public consumption. You can find it on [metacpan](https://metacpan.org/pod/Device::Firewall::PaloAlto) or on [github](https://github.com/gregfoletta/Device-Firewall-PaloAlto).

​

I am fully aware that most people in the networking space are using Python rather than Perl, and frankly I am not interested in zealotry. What I have done however is write this module not only to be used in Perl scripts or modules, but to be used straight from the command line.

​

The API replies can be in some unfriendly formats. I clean these up, place put them in modules, then allow the output of JSON representations of these straight to STDOUT. You can then use the `jq` command line utility to quickly search or transform these structured replies.

Here's an example of using the module from a bash shell to quickly check which interfaces are up. The username, password and URI of the firewall are read from environment variables if not specified:

perl -MDevice::Firewall::PaloAlto -E 'Device::Firewall::PaloAlto->new(verify_hostname => 0)->auth->op->interfaces->to_json' | \
jq '.[] | select(.state == "up") | .name'

"tunnel"

"loopback.1"

"vlan.32"

"tunnel.2"

"loopback.2"

"ethernet1/2"

"loopback"

"vlan"

"loopback.4"

"loopback.3"

"ethernet1/1"

"tunnel.1"

​

Feel free to reach out with any suggestions or queries.



No comments:

Post a Comment