enhance cisco meraki

This commit is contained in:
garnier-quentin 2020-09-30 15:01:30 +02:00
parent b482ee2775
commit 0a30502e91
2 changed files with 42 additions and 3 deletions

View File

@ -137,6 +137,21 @@ sub get_cache_networks {
return $self->{cache_networks}; return $self->{cache_networks};
} }
sub get_organization {
my ($self, %options) = @_;
$self->cache_meraki_entities();
my $organization_id;
if (defined($options{network_id})) {
$organization_id = $self->{cache_networks}->{ $options{network_id} }->{organizationId};
}
my $organization;
$organization = $self->{cache_organizations}->{$organization_id}
if (defined($organization_id) && defined($self->{cache_organizations}->{$organization_id}));
return $organization;
}
sub get_organization_id { sub get_organization_id {
my ($self, %options) = @_; my ($self, %options) = @_;

View File

@ -236,9 +236,11 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-device-name:s' => { name => 'filter_device_name' }, 'filter-device-name:s' => { name => 'filter_device_name' },
'filter-network-id:s' => { name => 'filter_network_id' }, 'filter-network-id:s' => { name => 'filter_network_id' },
'filter-tags:s' => { name => 'filter_tags' } 'filter-organization-name:s' => { name => 'filter_organization_name' },
'filter-organization-id:s' => { name => 'filter_organization_id' },
'filter-tags:s' => { name => 'filter_tags' }
}); });
return $self; return $self;
@ -359,6 +361,8 @@ sub manage_selection {
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_device_name}) ? md5_hex($self->{option_results}->{filter_device_name}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_device_name}) ? md5_hex($self->{option_results}->{filter_device_name}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_network_id}) ? md5_hex($self->{option_results}->{filter_network_id}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_network_id}) ? md5_hex($self->{option_results}->{filter_network_id}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_organization_id}) ? md5_hex($self->{option_results}->{filter_organization_id}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_organization_name}) ? md5_hex($self->{option_results}->{filter_organization_name}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_tags}) ? md5_hex($self->{option_results}->{filter_tags}) : md5_hex('all')); (defined($self->{option_results}->{filter_tags}) ? md5_hex($self->{option_results}->{filter_tags}) : md5_hex('all'));
my $last_timestamp = $self->read_statefile_key(key => 'last_timestamp'); my $last_timestamp = $self->read_statefile_key(key => 'last_timestamp');
my $timespan = 300; my $timespan = 300;
@ -383,6 +387,18 @@ sub manage_selection {
next; next;
} }
my $organization = $options{custom}->get_organization(network_id => $_->{networkId});
if (defined($self->{option_results}->{filter_organization_id}) && $self->{option_results}->{filter_organization_id} ne '' &&
$organization->{id} !~ /$self->{option_results}->{filter_organization_id}/) {
$self->{output}->output_add(long_msg => "skipping device '" . $_->{name} . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_organization_name}) && $self->{option_results}->{filter_organization_name} ne '' &&
$organization->{name} !~ /$self->{option_results}->{filter_organization_name}/) {
$self->{output}->output_add(long_msg => "skipping device '" . $_->{name} . "': no matching filter.", debug => 1);
next;
}
$devices->{ $_->{serial} } = $_->{model}; $devices->{ $_->{serial} } = $_->{model};
} }
@ -476,6 +492,14 @@ Filter devices by name (Can be a regexp).
Filter devices by network id (Can be a regexp). Filter devices by network id (Can be a regexp).
=item B<--filter-organization-id>
Filter devices by organization id (Can be a regexp).
=item B<--filter-organization-name>
Filter devices by organization name (Can be a regexp).
=item B<--filter-tags> =item B<--filter-tags>
Filter devices by tags (Can be a regexp). Filter devices by tags (Can be a regexp).