minor fixes

This commit is contained in:
garnier-quentin 2021-01-11 16:29:49 +01:00
parent b52296c995
commit ae4ead2724
5 changed files with 47 additions and 42 deletions

View File

@ -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 };
}

View File

@ -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} = {};

View File

@ -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'));
}

View File

@ -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;
}

View File

@ -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;