mirror of
https://github.com/librenms/librenms-agent.git
synced 2024-05-09 09:54:52 +00:00
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
#Copyright (c) 2018, Zane C. Bowers-Hadley
|
#Copyright (c) 2019, Zane C. Bowers-Hadley
|
||||||
#All rights reserved.
|
#All rights reserved.
|
||||||
#
|
#
|
||||||
#Redistribution and use in source and binary forms, with or without modification,
|
#Redistribution and use in source and binary forms, with or without modification,
|
||||||
@ -91,7 +91,7 @@ use Parse::Netstat qw(parse_netstat);
|
|||||||
|
|
||||||
$Getopt::Std::STANDARD_HELP_VERSION = 1;
|
$Getopt::Std::STANDARD_HELP_VERSION = 1;
|
||||||
sub main::VERSION_MESSAGE {
|
sub main::VERSION_MESSAGE {
|
||||||
print "Port Activity SNMP stats extend 0.0.0\n";
|
print "Port Activity SNMP stats extend 0.0.1\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub main::HELP_MESSAGE {
|
sub main::HELP_MESSAGE {
|
||||||
@ -218,6 +218,7 @@ my @protos_array=split(/\,/, $opts{p});
|
|||||||
|
|
||||||
#holds the various protocol hashes
|
#holds the various protocol hashes
|
||||||
my %protos;
|
my %protos;
|
||||||
|
my %proto_lookup;
|
||||||
|
|
||||||
#make sure each one specificied is defined and build the hash that will be returned
|
#make sure each one specificied is defined and build the hash that will be returned
|
||||||
my $protos_array_int=0;
|
my $protos_array_int=0;
|
||||||
@ -235,26 +236,16 @@ while ( defined( $protos_array[$protos_array_int] ) ){
|
|||||||
exit 4;
|
exit 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$proto_lookup{ $port } = $protos_array [$protos_array_int ];
|
||||||
|
|
||||||
$protos_array_int++;
|
$protos_array_int++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $netstat='netstat -n';
|
||||||
|
|
||||||
my $os=$^O;
|
my $os=$^O;
|
||||||
|
|
||||||
my $netstat;
|
my $res = parse_netstat(output => join("", `$netstat`), flavor=>$os, udp=>0, unix=>0);
|
||||||
|
|
||||||
#make sure this is a supported OS
|
|
||||||
if ( $os eq 'freebsd' ){
|
|
||||||
$netstat='netstat -S -p tcp'
|
|
||||||
}elsif( $os eq 'linux' ){
|
|
||||||
$netstat='netstat -n'
|
|
||||||
}else{
|
|
||||||
$to_return{errorString}=$os.' is not a supported OS as of currently';
|
|
||||||
$to_return{error}=3;
|
|
||||||
return_json(\%to_return, $opts{P});
|
|
||||||
exit 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $res = parse_netstat(output => join("", `$netstat`), flavor=>$os);
|
|
||||||
|
|
||||||
#check to make sure that it was able to parse the output
|
#check to make sure that it was able to parse the output
|
||||||
if (
|
if (
|
||||||
@ -273,7 +264,9 @@ while ( defined( $res->[2]{'active_conns'}[$active_conns_int] ) ){
|
|||||||
my $conn=$res->[2]{active_conns}[$active_conns_int];
|
my $conn=$res->[2]{active_conns}[$active_conns_int];
|
||||||
|
|
||||||
#we only care about TCP currently
|
#we only care about TCP currently
|
||||||
if ( $conn->{proto} =~ /^[Tt][Cc][Pp]/ ){
|
if ( defined( $conn->{proto} ) &&
|
||||||
|
( $conn->{proto} =~ /^[Tt][Cc][Pp]/ )
|
||||||
|
){
|
||||||
$protos_array_int=0;
|
$protos_array_int=0;
|
||||||
my $service;
|
my $service;
|
||||||
while(
|
while(
|
||||||
@ -282,8 +275,8 @@ while ( defined( $res->[2]{'active_conns'}[$active_conns_int] ) ){
|
|||||||
){
|
){
|
||||||
#check if this matches either ports
|
#check if this matches either ports
|
||||||
if (
|
if (
|
||||||
( $protos_array[ $protos_array_int ] eq $conn->{'local_port'} ) ||
|
( defined($proto_lookup{ $conn->{'local_port'} }) ) ||
|
||||||
( $protos_array[ $protos_array_int ] eq $conn->{'foreign_port'} )
|
( defined($proto_lookup{ $conn->{'foreign_port'} }) )
|
||||||
){
|
){
|
||||||
$service=$protos_array[ $protos_array_int ];
|
$service=$protos_array[ $protos_array_int ];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user