From ae4ead27243cc59754c33394579efc5e164c180f Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 11 Jan 2021 16:29:49 +0100 Subject: [PATCH] minor fixes --- apps/lync/2013/mssql/mode/lyncusers.pm | 39 +++++++++++++------------- apps/pfsense/snmp/mode/packetstats.pm | 6 ++-- apps/pfsense/snmp/mode/pfinterfaces.pm | 33 +++++++++++++--------- apps/pfsense/snmp/mode/runtime.pm | 9 +++--- apps/pfsense/snmp/plugin.pm | 2 +- 5 files changed, 47 insertions(+), 42 deletions(-) diff --git a/apps/lync/2013/mssql/mode/lyncusers.pm b/apps/lync/2013/mssql/mode/lyncusers.pm index 5726e4512..0d60ba175 100644 --- a/apps/lync/2013/mssql/mode/lyncusers.pm +++ b/apps/lync/2013/mssql/mode/lyncusers.pm @@ -28,32 +28,32 @@ use warnings; sub prefix_user_output { my ($self, %options) = @_; - return "'" . $options{instance_value}->{display} . "' "; + return "'Frontend' "; } sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'users', type => 1, cb_prefix_output => 'prefix_user_output', message_multiple => 'User counts are OK' }, + { name => 'users', type => 0, cb_prefix_output => 'prefix_user_output' } ]; $self->{maps_counters}->{users} = [ { label => 'total', nlabel => 'users.total.count', set => { key_values => [ { name => 'total' } ], - output_template => '%d Total users', + output_template => '%d total users', perfdatas => [ { label => 'total_users', template => '%d', - unit => 'users', min => 0, label_extra_instance => 0 } + unit => 'users', min => 0 } ] } }, { label => 'unique', nlabel => 'users.unique.count', set => { key_values => [ { name => 'unique' } ], - output_template => '%d Unique users', + output_template => '%d unique users', perfdatas => [ { label => 'unique_users', template => '%d', - unit => 'users', min => 0, label_extra_instance => 0 } + unit => 'users', min => 0 } ] } } @@ -67,26 +67,27 @@ sub new { $options{options}->add_options(arguments => { }); - + return $self; } sub manage_selection { my ($self, %options) = @_; - # $options{sql} = sqlmode object - $self->{sql} = $options{sql}; - $self->{sql}->connect(); - $self->{sql}->query(query => q{Select count(*) as totalonline, - count(distinct UserAtHost) as totalunique - From rtcdyn.dbo.RegistrarEndpoint RE - Inner Join - rtc.dbo.Resource R on R.ResourceId = RE.OwnerId - Inner Join - rtcdyn.dbo.Registrar Reg on Reg.RegistrarId = RE.PrimaryRegistrarClusterId}); + $options{sql}->connect(); + $options{sql}->query(query => q{ + Select + count(*) as totalonline, + count(distinct UserAtHost) as totalunique + From rtcdyn.dbo.RegistrarEndpoint RE + Inner Join + rtc.dbo.Resource R on R.ResourceId = RE.OwnerId + Inner Join + rtcdyn.dbo.Registrar Reg on Reg.RegistrarId = RE.PrimaryRegistrarClusterId + }); - my ($total_online, $total_unique) = $self->{sql}->fetchrow_array(); - $self->{users}{total} = { total => $total_online, unique => $total_unique, display => 'Frontend' }; + my ($total_online, $total_unique) = $options{sql}->fetchrow_array(); + $self->{users} = { total => $total_online, unique => $total_unique }; } diff --git a/apps/pfsense/snmp/mode/packetstats.pm b/apps/pfsense/snmp/mode/packetstats.pm index fdf98ad99..2db6d4fa1 100644 --- a/apps/pfsense/snmp/mode/packetstats.pm +++ b/apps/pfsense/snmp/mode/packetstats.pm @@ -30,7 +30,7 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0, message_separator => ' - ' }, + { name => 'global', type => 0, message_separator => ' - ' } ]; $self->{maps_counters}->{global} = [ @@ -98,7 +98,7 @@ sub new { sub manage_selection { my ($self, %options) = @_; - + if ($options{snmp}->is_snmpv1()) { $self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1."); $self->{output}->option_exit(); @@ -109,7 +109,7 @@ sub manage_selection { pfCounterFragment => '.1.3.6.1.4.1.12325.1.200.1.2.3.0', pfCounterShort => '.1.3.6.1.4.1.12325.1.200.1.2.4.0', pfCounterNormalize => '.1.3.6.1.4.1.12325.1.200.1.2.5.0', - pfCounterMemDrop => '.1.3.6.1.4.1.12325.1.200.1.2.6.0', + pfCounterMemDrop => '.1.3.6.1.4.1.12325.1.200.1.2.6.0' ); my $snmp_result = $options{snmp}->get_leef(oids => [values %oids], nothing_quit => 1); $self->{global} = {}; diff --git a/apps/pfsense/snmp/mode/pfinterfaces.pm b/apps/pfsense/snmp/mode/pfinterfaces.pm index 4b0f9fbfd..29af00b31 100644 --- a/apps/pfsense/snmp/mode/pfinterfaces.pm +++ b/apps/pfsense/snmp/mode/pfinterfaces.pm @@ -34,7 +34,7 @@ sub set_counters { ]; $self->{maps_counters}->{pfint} = [ - { label => 'traffic-in-pass', nlabel => 'pass.traffic.in.bitspersecond', set => { + { label => 'traffic-in-pass', nlabel => 'pfinterface.pass.traffic.in.bitspersecond', set => { key_values => [ { name => 'pfInterfacesIf4BytesInPass', per_second => 1 }, { name => 'display' } ], output_change_bytes => 2, output_template => 'Traffic In Pass : %s %s/s', @@ -44,7 +44,7 @@ sub set_counters { ] } }, - { label => 'traffic-out-pass', nlabel => 'pass.traffic.out.bitspersecond', set => { + { label => 'traffic-out-pass', nlabel => 'pfinterface.pass.traffic.out.bitspersecond', set => { key_values => [ { name => 'pfInterfacesIf4BytesOutPass', per_second => 1 }, { name => 'display' } ], output_change_bytes => 2, output_template => 'Traffic Out Pass : %s %s/s', @@ -54,7 +54,7 @@ sub set_counters { ] } }, - { label => 'traffic-in-block', nlabel => 'block.traffic.in.bitspersecond', set => { + { label => 'traffic-in-block', nlabel => 'pfinterface.block.traffic.in.bitspersecond', set => { key_values => [ { name => 'pfInterfacesIf4BytesInBlock', per_second => 1 }, { name => 'display' } ], output_change_bytes => 2, output_template => 'Traffic In Block : %s %s/s', @@ -64,7 +64,7 @@ sub set_counters { ] } }, - { label => 'traffic-out-block', nlabel => 'block.traffic.out.bitspersecond', set => { + { label => 'traffic-out-block', nlabel => 'pfinterface.block.traffic.out.bitspersecond', set => { key_values => [ { name => 'pfInterfacesIf4BytesOutBlock', per_second => 1 }, { name => 'display' } ], output_change_bytes => 2, output_template => 'Traffic Out Block : %s %s/s', @@ -100,17 +100,18 @@ my $mapping = { pfInterfacesIf4BytesInPass => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.7' }, pfInterfacesIf4BytesInBlock => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.8' }, pfInterfacesIf4BytesOutPass => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.9' }, - pfInterfacesIf4BytesOutBlock => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.10' }, + pfInterfacesIf4BytesOutBlock => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.10' } }; sub manage_selection { my ($self, %options) = @_; - + if ($options{snmp}->is_snmpv1()) { $self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1."); $self->{output}->option_exit(); } my $snmp_result = $options{snmp}->get_table(oid => $oid_pfInterfacesIfDescr, nothing_quit => 1); + $self->{pfint} = {}; foreach my $oid (keys %{$snmp_result}) { $oid =~ /^$oid_pfInterfacesIfDescr\.(.*)$/; @@ -122,16 +123,20 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping pfInterface '" . $name . "'.", debug => 1); next; } - + $self->{pfint}->{$instance} = { display => $name }; } - $options{snmp}->load(oids => [$mapping->{pfInterfacesIf4BytesInPass}->{oid}, $mapping->{pfInterfacesIf4BytesOutPass}->{oid}, - $mapping->{pfInterfacesIf4BytesInBlock}->{oid}, $mapping->{pfInterfacesIf4BytesOutBlock}->{oid}, + $options{snmp}->load( + oids => [ + $mapping->{pfInterfacesIf4BytesInPass}->{oid}, $mapping->{pfInterfacesIf4BytesOutPass}->{oid}, + $mapping->{pfInterfacesIf4BytesInBlock}->{oid}, $mapping->{pfInterfacesIf4BytesOutBlock}->{oid}, ], - instances => [keys %{$self->{pfint}}], instance_regexp => '^(.*)$'); + instances => [keys %{$self->{pfint}}], + instance_regexp => '^(.*)$' + ); $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); - + foreach my $instance (keys %{$self->{pfint}}) { my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); @@ -139,13 +144,13 @@ sub manage_selection { $self->{pfint}->{$instance}->{$_} = $result->{$_} * 8; } } - + if (scalar(keys %{$self->{pfint}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No pfInterface found."); $self->{output}->option_exit(); } - - $self->{cache_name} = "pfsense_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + + $self->{cache_name} = 'pfsense_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); } diff --git a/apps/pfsense/snmp/mode/runtime.pm b/apps/pfsense/snmp/mode/runtime.pm index 11d4d00f0..b4f52ae9f 100644 --- a/apps/pfsense/snmp/mode/runtime.pm +++ b/apps/pfsense/snmp/mode/runtime.pm @@ -32,11 +32,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); return $self; } diff --git a/apps/pfsense/snmp/plugin.pm b/apps/pfsense/snmp/plugin.pm index 58c9ec5db..929fd2fc6 100644 --- a/apps/pfsense/snmp/plugin.pm +++ b/apps/pfsense/snmp/plugin.pm @@ -34,7 +34,7 @@ sub new { 'list-pfinterfaces' => 'apps::pfsense::snmp::mode::listpfinterfaces', 'packet-stats' => 'apps::pfsense::snmp::mode::packetstats', 'pfinterfaces' => 'apps::pfsense::snmp::mode::pfinterfaces', - 'runtime' => 'apps::pfsense::snmp::mode::runtime' + 'runtime' => 'apps::pfsense::snmp::mode::runtime' }; return $self;