Compare commits

...

18 Commits

5 changed files with 233 additions and 18 deletions

View File

@ -1,4 +1,14 @@
Revision history for Proc-ProcessTable-piddler
0.2.0 2019-09-04/00:00
- Add support for the environ key.
- Add add fifo, a_ignore, and memreglib.
- Documentation cleanup.
- If we don't plan to add something, don't
dedup it.
0.1.0 2019-09-03/05:20
- Add NO_COLOR support.
0.0.0 2019-09-03/04:10
- Initial release.

View File

@ -6,7 +6,7 @@ use Getopt::Long;
use Proc::ProcessTable::piddler;
sub version{
print "piddler v. 0.0.0\n";
print "piddler v. 0.2.0\n";
}
sub help{
@ -17,12 +17,16 @@ sub help{
-v Print the version info.
--version Print the version info.
-a Show a_inodes.
-d Do not dedup.
-f Show FIFOs.
-m Show memory mapped libraries of the REG type.
-n Do not resolve PTR addresses.
-p Do not show pipes.
-r Do not show show VREG / files.
-t Do not show shared libraries.
-u Do not show unix sockets.
--nc Disable color.
-p Show pipes.
-r Show show VREG / files.
-t Show shared libraries.
-u Show unix sockets.
';
}
@ -35,6 +39,10 @@ my $unix=0;
my $vregroot=0;
my $dont_dedup=0;
my $dont_resolv=0;
my $no_color=0;
my $a_inode=0;
my $fifo=0;
my $memreglib=0;
# get the commandline options
Getopt::Long::Configure ('no_ignore_case');
@ -50,6 +58,10 @@ GetOptions(
'r' => \$vregroot,
'd' => \$dont_dedup,
'n' => \$dont_resolv,
'nc' => \$no_color,
'f' => \$fifo,
'a' => \$a_inode,
'm' => \$memreglib,
);
# print the version info if requested
@ -93,6 +105,18 @@ if ( defined( $ENV{PIDDLER_pipe} ) ){
if ( defined( $ENV{PIDDLER_vregroot} ) ){
$vregroot = $vregroot ^ $ENV{PIDDLER_vregroot};
}
# XOR the -m if needed
if ( defined( $ENV{PIDDLER_memreglib} ) ){
$memreglib = $memreglib ^ $ENV{PIDDLER_memreglib};
}
# XOR the -a if needed
if ( defined( $ENV{PIDDLER_a_inode} ) ){
$a_inode = $a_inode ^ $ENV{PIDDLER_a_inode};
}
# XOR the -f if needed
if ( defined( $ENV{PIDDLER_fifo} ) ){
$fifo = $fifo ^ $ENV{PIDDLER_fifo};
}
# XOR the -d if needed
if ( defined( $ENV{PIDDLER_dont_dedup} ) ){
$dont_dedup = $dont_dedup ^ $ENV{PIDDLER_dont_dedup};
@ -101,15 +125,27 @@ if ( defined( $ENV{PIDDLER_dont_dedup} ) ){
if ( defined( $ENV{PIDDLER_dont_resolv} ) ){
$dont_resolv = $dont_resolv ^ $ENV{PIDDLER_dont_resolv};
}
# same for the no color
if ( defined( $ENV{NO_COLOR} ) ){
$no_color = $no_color ^ 1;
}
# disable the color if requested
if ( $no_color ){
$ENV{ANSI_COLORS_DISABLED}=1;
}
my $ppp=Proc::ProcessTable::piddler->new(
{
txt=>$txt,
unix=>$unix,
pipe=>$pipe,
a_inode=>$a_inode,
fifo=>$fifo,
vregroot=>$vregroot,
dont_dedup=>$dont_dedup,
dont_resolv=>$dont_resolv,
memreglib=>$memreglib,
}
);
@ -122,42 +158,74 @@ piddler - Display all process table, open files, and network connections for a P
=head1 SYNOPSIS
piddler [B<-d>] [B<-n>] [B<-p>] [B<-r>] [B<-r>] [B<-t>] [B<-u>]
piddler [B<-a>] [B<-d>] [B<-f>] [B<-m>] [B<-n>] [B<-p>] [B<-r>] [B<-r>] [B<-t>] [B<-u>]
=head1 FLAGS
=head2 -a
Show a_inodes.
=head2 -d
Do not dedup.
=head2 -f
Show FIFOs.
=head2 -m
Show memory mapped libraries of the REG type.
=head2 -n
Do not resolve PTR addresses.
Do not resolve PTR addresses
=head2 --nc
Disable color..
=head2 -p
Do not show pipes.
Show pipes.
=head2 -r
Do not show show VREG / files.
Show show VREG / files.
=head2 -t
Do not show shared libraries.
Show shared libraries.
=head2 -u
Do not show unix sockets.
Show unix sockets.
=head1 ENVIROMENTAL VARIABLES
These are used for XORing the corresponding
flags.
=head2 NO_COLOR
If set to 1, color will be disabled.
=head2 PIDDLER_a_inode
If set to 1, a_inode types will be shown.
=head2 PIDDLER_fifo
If set to 1, FIFOs will not be shown.
=head2 PIDDLER_memreglib
If set to 1, memory mapped libraries with the type REG will be shown.
=head2 PIDDLER_txt
If set to 1, libraries will not be shown.
If set to 1, libraries with the TXT type will not be shown.
=head2 PIDDLER_pipe

View File

@ -16,11 +16,11 @@ Proc::ProcessTable::piddler - Display all process table, open files, and network
=head1 VERSION
Version 0.0.0
Version 0.2.0
=cut
our $VERSION = '0.0.0';
our $VERSION = '0.2.0';
=head1 SYNOPSIS
@ -63,6 +63,12 @@ of options.
=head3 args hash
=head4 a_inode
Print a_inode types.
Defaults to 0, false.
=head4 dont_dedup
Don't dedup the file descriptor list.
@ -86,6 +92,22 @@ Don't resolve PTR addresses.
Defaults to 0, false.
=head4 fifo
Print FIFOs.
Defaults to 0, false.
=head4 memreglib
Prints memory mappaed libraries that show are of type REG.
The following are used to match libraries.
/\.[0-9]+$/
/\.[0-9]+\.[0-9$/
/\.jar/
=head4 pipe
Print pipes.
@ -173,17 +195,22 @@ sub new{
'BRIGHT_MAGENTA',
'BRIGHT_BLUE'
],
environ=>'BRIGHT_MAGENTA',
txt=>0,
pipe=>0,
unix=>0,
vregroot=>0,
dont_dedup=>0,
dont_resolv=>0,
fifo=>0,
a_inode=>0,
memreglib=>0,
};
bless $self;
my @arg_feed=(
'txt', 'pipe', 'unix', 'vregroot', 'dont_dedup', 'dont_resolv'
'txt', 'pipe', 'unix', 'vregroot', 'dont_dedup', 'dont_resolv',
'fifo', 'a_inore', 'memreglib'
);
foreach my $feed ( @arg_feed ){
@ -419,6 +446,13 @@ sub run{
$value=$self->timeString( $proc->{$key} );
}
if ( $key =~ /^environ$/ ){
$value=join( color( $self->{environ} ).', '.color('reset') , @{ $proc->{environ} } );
if ( !defined( $value ) ){
$value='';
}
}
if (
( $key =~ /flt$/ ) &&
( $proc->{$key} eq 0 ) &&
@ -492,6 +526,7 @@ sub run{
my %rw_filehandles;
my %r_filehandles;
my %w_filehandles;
my %mem_filehandles;
my @lines=split(/\n/, $output_raw);
my $line_int=1;
while ( defined( $lines[$line_int] ) ){
@ -522,6 +557,29 @@ sub run{
( $line_split[3] =~ /^[Uu][Nn][Ii][Xx]$/ ) &&
( ! $self->{unix} )
) ||
# fifo... spammy with elasticsearch and the like... only print if asked...
(
( $line_split[3] =~ /^[Ff][Ii][Ff][Oo]$/ ) &&
( ! $self->{fifo} )
) ||
# memory mapped libraries with REG type....
# spammy.... ES tends to have lots of these
(
( $line_split[3] =~ /^[Rr][Ee][Gg]$/ ) &&
(
( $line_split[7] =~ /\.so$/ ) ||
( $line_split[7] =~ /\.so\.[0-9]$/ ) ||
( $line_split[7] =~ /\.so\.[0-9]+\.[0-9]+$/ ) ||
( $line_split[7] =~ /\.so\.[0-9]+\.[0-9]+\.[0-9]+$/ ) ||
( $line_split[7] =~ /\.jar$/ )
) &&
( ! $self->{memreglib} )
) ||
# a_inode... spammy with elasticsearch and the like... only print if asked...
(
( $line_split[3] =~ /^a\_inode$/ ) &&
( ! $self->{a_inode} )
) ||
# vreg /....can by spammy with somethings like firefox
(
( $line_split[3] =~ /^[Vv][Rr][Ee][Gg]$/ ) &&
@ -534,9 +592,13 @@ sub run{
# begin deduping
my $name= color( $self->{file_colors}[5] ).$line_split[7].color( 'reset' );
if ( ! $self->{dont_dedup} ){
if (
( ! $self->{dont_dedup} ) &&
( ! $dont_add )
){
if (
( $line_split[3] =~ /[Vv][Rr][Ee][Gg]/ ) ||
( $line_split[3] =~ /[Rr][Ee][Gg]/ ) ||
( $line_split[3] =~ /[Vv][Dd][Ii][Dd]/ ) ||
( $line_split[3] =~ /[Vv][Cc][Hh][Rr]/ )
) {
@ -568,6 +630,14 @@ sub run{
} else {
$w_filehandles{ $name }++;
}
}elsif (
( $line_split[2] =~ /mem/ )
){
if (! defined( $mem_filehandles{ $name } ) ) {
$mem_filehandles{ $name } = 1;
} else {
$mem_filehandles{ $name }++;
}
}
}
}
@ -592,9 +662,11 @@ sub run{
my %rw_dedup;
my %r_dedup;
my %w_dedup;
my %mem_dedup;
foreach my $line ( @fdata ){
if (
( $line->[1] =~ /[Vv][Rr][Ee][Gg]/ ) ||
( $line->[1] =~ /[Rr][Ee][Gg]/ ) ||
( $line->[1] =~ /[Vv][Dd][Ii][Dd]/ ) ||
( $line->[1] =~ /[Vv][Cc][Hh][Rr]/ )
){
@ -636,6 +708,13 @@ sub run{
}
$w_dedup{ $line->[5] } = 1;
}
}elsif(
( $line->[0] =~ /mem/ )
){
if ($mem_filehandles{ $line->[5] } > 1){
$line->[0]=$line->[0].'+';
}
$mem_dedup{ $line->[5] } = 1;
}
if ( $add_line ){

View File

@ -1,3 +1,61 @@
# Proc-ProcessTable-piddler
# About
Displays information on a pid.
Display all process table, open files, and network connections for a PID.
![piddler](piddler.png)
# Command Line Options
```
-a Show a_inodes.
-d Do not dedup.
-f Show FIFOs.
-m Show memory mapped libraries of the REG type.
-n Do not resolve PTR addresses.
--nc Disable color.
-p Show pipes.
-r Show show VREG / files.
-t Show shared libraries.
-u Show unix sockets.
```
# Enviromental Variables
The enviromental variables below may be set to set the default for the
flag in question.
Unless set to defined ands set to 1, these will default to 0.
| Variable | Description |
| -------- | ---------------- |
| NO_COLOR | If set to 1, color will be disabled. |
| PIDDLER_dont_dedup | If set to 1, duplicate file handles are removed. |
| PIDDLER_dont_resolv | If set to 1, PTR addresses will not be resolved for network connections. |
| PIDDLER_a_inode | If set to 1, a_inode types will be shown. |
| PIDDLER_fifo | If set to 1, FIFOs will not be shown. |
| PIDDLER_memreglib | If set to 1, memory mapped libraries with the type REG will be shown. |
| PIDDLER_pipe | If set to 1, pipes will not be shown. |
| PIDDLER_txt | If set to 1, libraries with the TXT type will not be shown. |
| PIDDLER_unix | If set to 1, unix socket will not be shown. |
| PIDDLER_vregroot | If set to 1, VREG / will not be shown. |
# Installing
## FreeBSD
pkg install perl5 p5-App-cpanminus
cpanm Proc::ProcessTable::piddler
## Linux
### CentOS
yum install cpanm
cpanm Proc::ProcessTable::piddler
### Debian
This has been tested as working on Debian 9 minimal.
apt install perl perl-base perl-modules make cpanminus gcc
cpanm Proc::ProcessTable::piddler

BIN
piddler.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB