-
Notifications
You must be signed in to change notification settings - Fork 302
enh(network::paloalto::api) Add host discovery to handle Panorama #6188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
scresto31
wants to merge
11
commits into
develop
Choose a base branch
from
CTOR-2278-plugin-network-paloalto-api-add-host-discovery-to-handle-panorama
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b9787f1
Add panorama-firewall-discovery mode
scresto31 fb5c911
Update plugin
scresto31 ff72ec9
Update
scresto31 c712020
Update
scresto31 584a63c
Update
scresto31 4789bdb
Merge branch 'develop' into CTOR-2278-plugin-network-paloalto-api-add…
scresto31 b5b9431
Merge branch 'develop' into CTOR-2278-plugin-network-paloalto-api-add…
scresto31 f546a88
FIx tests
scresto31 a501502
Update tests
scresto31 8178cb0
Update plugin
scresto31 24dc013
Update after review
scresto31 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
src/network/paloalto/api/mode/panoramafirewalldiscovery.pm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| # | ||
| # Copyright 2026-Present Centreon (http://www.centreon.com/) | ||
| # | ||
| # Centreon is a full-fledged industry-strength solution that meets | ||
| # the needs in IT infrastructure and application monitoring for | ||
| # service performance. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| package network::paloalto::api::mode::panoramafirewalldiscovery; | ||
|
|
||
| use base qw(centreon::plugins::mode); | ||
|
|
||
| use strict; | ||
| use warnings; | ||
|
|
||
| use centreon::plugins::misc qw/json_encode is_excluded/; | ||
|
|
||
| sub new { | ||
| my ($class, %options) = @_; | ||
| my $self = $class->SUPER::new(package => __PACKAGE__, %options); | ||
| bless $self, $class; | ||
|
|
||
| $options{options}->add_options(arguments => { | ||
| "prettify" => { name => 'prettify' }, | ||
| 'only-connected' => { name => 'only_connected' }, | ||
| 'include-name:s' => { name => 'include_name', default => '' }, | ||
| 'exclude-name:s' => { name => 'exclude_name', default => '' }, | ||
| 'include-model:s' => { name => 'include_model', default => '' }, | ||
| 'exclude-model:s' => { name => 'exclude_model', default => '' }, | ||
| 'include-ip-address:s' => { name => 'include_ip_address', default => '' }, | ||
| 'exclude-ip-address:s' => { name => 'exclude_ip_address', default => '' } | ||
| }); | ||
|
|
||
| return $self; | ||
| } | ||
|
|
||
| sub check_options { | ||
| my ($self, %options) = @_; | ||
| $self->SUPER::init(%options); | ||
| } | ||
|
|
||
| sub manage_selection { | ||
| my ($self, %options) = @_; | ||
|
|
||
| $self->{output}->option_exit( short_msg => "The --target parameter is not allowed in this mode." ) | ||
| if $options{custom}->{target}; | ||
|
|
||
| my $filter = $self->{option_results}->{only_connected} ? 'connected' : 'all'; | ||
| my $result = $self->{instances} = $options{custom}->request_api( | ||
| type => 'op', | ||
| cmd => "<show><devices><$filter></$filter></devices></show>", | ||
| ForceArray => [ 'entry' ] | ||
| ); | ||
|
|
||
| $self->{devices} = [ ]; | ||
|
|
||
| return unless $result && ref $result->{devices}->{entry} eq 'ARRAY'; | ||
|
|
||
| foreach my $device (@{$result->{devices}->{entry}}) { | ||
| next unless $device->{serial}; | ||
|
|
||
| my $item = { | ||
| Serial => $device->{serial}, | ||
| Name => $device->{name} // '', | ||
| HostName => $device->{hostname} // '', | ||
| Connected => $device->{connected} // '', | ||
| Model => $device->{model} // '', | ||
| IpAddress => $device->{'ip-address'} // '', | ||
| }; | ||
|
|
||
| next if is_excluded($item->{Name}, $self->{option_results}->{include_name}, $self->{option_results}->{exclude_name}, output => $self->{output}) || | ||
| is_excluded($item->{Model}, $self->{option_results}->{include_model}, $self->{option_results}->{exclude_model}, output => $self->{output}) || | ||
| is_excluded($item->{IpAddress}, $self->{option_results}->{include_ip_address}, $self->{option_results}->{exclude_ip_address}, output => $self->{output}); | ||
|
|
||
| push @{$self->{devices}}, $item; | ||
| } | ||
| } | ||
|
|
||
| sub run { | ||
| my ($self, %options) = @_; | ||
|
|
||
| my $disco_stats; | ||
|
|
||
| $disco_stats->{start_time} = time(); | ||
|
|
||
| $self->manage_selection(%options); | ||
|
|
||
| $disco_stats->{end_time} = time(); | ||
| $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; | ||
| $disco_stats->{discovered_items} = @{$self->{devices}}; | ||
| $disco_stats->{results} = $self->{devices}; | ||
|
|
||
| my $encoded_data = json_encode($disco_stats, | ||
| prettify => $self->{option_results}->{prettify}, | ||
| errstr => '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'); | ||
|
|
||
| $self->{output}->output_add(short_msg => $encoded_data); | ||
| $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); | ||
| $self->{output}->exit(); | ||
| } | ||
| 1; | ||
|
|
||
| __END__ | ||
|
|
||
| =head1 MODE | ||
|
|
||
| Discover firewalls managed by Panorama. | ||
|
|
||
| =over 8 | ||
|
|
||
| =item B<--only-connected> | ||
|
|
||
| Display only connected firewalls. | ||
|
|
||
| =item B<--include-name> | ||
|
|
||
| Filter firewall by name (can be a regex). | ||
|
|
||
| =item B<--exclude-name> | ||
|
|
||
| Exclude firewall by name (can be a regex). | ||
|
|
||
| =item B<--include-model> | ||
|
|
||
| Filter firewall by model (can be a regex). | ||
|
|
||
| =item B<--exclude-model> | ||
|
|
||
| Exclude firewall by model (can be a regex). | ||
|
|
||
| =item B<--include-ip-address> | ||
|
|
||
| Filter firewall by IP address (can be a regex). | ||
|
|
||
| =item B<--exclude-ip-address> | ||
|
|
||
| Exclude firewall IP by address (can be a regex). | ||
|
|
||
| =item B<--prettify> | ||
|
|
||
| Prettify JSON output. | ||
|
|
||
| =back | ||
|
|
||
| =cut |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -386,4 +386,4 @@ | |
| ], | ||
| "data": [], | ||
| "callbacks": [] | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.