diff --git a/snmp/poudriere b/snmp/poudriere index b413fc895..36244c4f5 100755 --- a/snmp/poudriere +++ b/snmp/poudriere @@ -1,4 +1,4 @@ -#!/usr/bin/env perl +#!/usr/local/bin/perl =head1 NAME @@ -6,7 +6,7 @@ poudriere - LibreNMS JSON style SNMP extend for monitoring Poudriere =head1 VERSION -0.0.1 +0.1.0 =head1 SYNOPSIS @@ -45,6 +45,12 @@ meaning it will be written out to the two locations. The later is for use with returning data for SNMP. Will be compressed if possible. +=head1 REQUIREMENTS + + p5-File-Slurp + p5-MIME-Base64 + p5-JSON + =cut use strict; @@ -55,6 +61,7 @@ use MIME::Base64; use IO::Compress::Gzip qw(gzip $GzipError); use Pod::Usage; use JSON; +use Cwd 'abs_path'; sub time_to_seconds { my $time = $_[0]; @@ -66,13 +73,23 @@ sub time_to_seconds { if ( $time =~ /^0\:[0-9]+\.[0-9]+$/ ) { $time =~ s/^0\://; return $time; - } elsif ( $time =~ /^[0-9]+\:[0-9]+\.[0-9]+$/ ) { + } elsif ( $time =~ /^[0-9]+\:[0-9]+\.[0-9]+$/ + || $time =~ /^[0-9]+\:[0-9]+$/ ) + { my $minutes = $time; $minutes =~ s/\:.*//; $time =~ s/.*\://; $time = ( $minutes * 60 ) + $time; return $time; - } elsif ( $time =~ /^[0-9]+D\:[0-9]+\:[0-9]+\.[0-9]+$/ ) { + } elsif ( $time =~ /^[0-9]+\:[0-9]+\:[0-9]+\.[0-9]+$/ + || $time =~ /^[0-9]+\:[0-9]+\:[0-9]+$/ ) + { + my ( $hours, $minutes, $seconds ) = split( /:/, $time ); + $time = ( $hours * 3600 ) + ( $minutes * 60 ) + $seconds; + return $time; + } elsif ( $time =~ /^[0-9]+D\:[0-9]+\:[0-9]+\.[0-9]+$/ + || $time =~ /^[0-9]+D\:[0-9]+\:[0-9]+$/ ) + { my $days = $time; $days =~ s/D\:.*$//; my $minutes = $time; @@ -80,7 +97,7 @@ sub time_to_seconds { $minutes =~ s/\:.*//; $time = ( $days * 86400 ) + ( $minutes * 60 ) + $time; return $time; - } + } ## end elsif ( $time =~ /^[0-9]+D\:[0-9]+\:[0-9]+\.[0-9]+$/...) # return 0 for anything unknown return 0; @@ -162,7 +179,8 @@ my $data = { 'check-sanity' => 0, 'pkg-depends' => 0, 'fetch-depends' => 0, - 'fetch checksum' => 0, + 'fetch' => 0, + 'checksum' => 0, 'extract-depends' => 0, 'extract' => 0, 'patch-depends' => 0, @@ -174,6 +192,12 @@ my $data = { 'run-depends' => 0, 'stage' => 0, 'package' => 0, + 'package_size_all' => 0, + 'package_size_latest' => 0, + 'package_size_building' => 0, + 'log_size_latest' => 0, + 'log_size_done' => 0, + 'log_size_per_package' => 0, }, jailANDportsANDset => {} }; @@ -195,10 +219,10 @@ my @poudriere_stats = ( 'QUEUE', 'BUILT', 'FAIL', 'SKIP', 'IGNORE', 'FETCH', 'RE ### ### -my $status_raw = `poudriere -N status -f 2> /dev/null`; +my $status_raw = `poudriere -N status -f -l 2> /dev/null`; if ( $? == 0 ) { $data->{status} = $status_raw; - $data->{build_info} = `poudriere -N status -f -b 2>&1`; + $data->{build_info} = `poudriere -N status -f -b -l 2>&1`; my @status_split = split( /\n/, $status_raw ); my $status_split_int = 1; @@ -235,7 +259,8 @@ if ( $? == 0 ) { 'check-sanity' => 0, 'pkg-depends' => 0, 'fetch-depends' => 0, - 'fetch checksum' => 0, + 'fetch' => 0, + 'checksum' => 0, 'extract-depends' => 0, 'extract' => 0, 'patch-depends' => 0, @@ -247,6 +272,12 @@ if ( $? == 0 ) { 'run-depends' => 0, 'stage' => 0, 'package' => 0, + 'package_size_all' => 0, + 'package_size_latest' => 0, + 'package_size_building' => 0, + 'log_size_latest' => 0, + 'log_size_done' => 0, + 'log_size_per_package' => 0, }; ( $found->{SET}, $found->{PORTS}, $found->{JAIL}, $found->{BUILD}, $found->{STATUS}, @@ -265,11 +296,52 @@ if ( $? == 0 ) { $jailANDportsANDset = $found->{JAIL} . '-' . $found->{PORTS} . '-' . $found->{SET}; } + $found->{packages_dir_all} = $found->{LOGS} . '/../../../../packages/' . $jailANDportsANDset . '/All'; + $found->{packages_dir_latest} = $found->{LOGS} . '/../../../../packages/' . $jailANDportsANDset . '/Latest'; + $found->{packages_dir_building} + = $found->{LOGS} . '/../../../../packages/' . $jailANDportsANDset . '/.building'; + $found->{logs_dir_latest} = $found->{LOGS} . '/logs'; + $found->{logs_dir_done} = $found->{LOGS} . '/../latest-done/logs'; + $found->{logs_dir_per_package} = $found->{LOGS} . '/../latest-per-pkg/'; + my %dir_size_stats = ( + 'logs_dir_per_package' => 'log_size_per_package', + 'logs_dir_done' => 'log_size_done', + 'logs_dir_latest' => 'log_size_latest', + 'packages_dir_building' => 'package_size_building', + 'packages_dir_latest' => 'package_size_latest', + 'packages_dir_all' => 'package_size_all', + ); + + foreach my $item ( keys(%dir_size_stats) ) { + eval { + if ( defined( $found->{$item} ) ) { + $found->{$item} = abs_path( $found->{$item} ); + if ( defined( $found->{$item} ) ) { + if ( -d $found->{$item} ) { + my @files = read_dir( $found->{$item} ); + foreach my $to_stat (@files) { + if ( -f $found->{$item} . '/' . $to_stat ) { + my ( + $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, + $size, $atime, $mtime, $ctime, $blksize, $blocks + ) = stat( $found->{$item} . '/' . $to_stat ); + $found->{ $dir_size_stats{$item} } += $size; + } + } + $data->{stats}{ $dir_size_stats{$item} } = $found->{ $dir_size_stats{$item} }; + } ## end if ( -d $found->{$item} ) + } ## end if ( defined( $found->{$item} ) ) + } ## end if ( defined( $found->{$item} ) ) + }; + } ## end foreach my $item ( keys(%dir_size_stats) ) + foreach my $item (@poudriere_stats) { if ( $item eq 'TIME' ) { $found->{$item} = time_to_seconds( $found->{$item} ); } - $data->{stats}{$item} += $found->{$item}; + if ( $item =~ /^\d+$/ ) { + $data->{stats}{$item} += $found->{$item}; + } } ## @@ -367,13 +439,13 @@ if ( $? == 0 ) { } elsif ( $line =~ /[\ \t]package[\ \t]/ ) { $type = 'package'; } - if (defined($type)) { + if ( defined($type) ) { $data->{stats}{$type}++; - if (defined($data->{jailANDportsANDset}{$current_section})) { + if ( defined( $data->{jailANDportsANDset}{$current_section} ) ) { $data->{jailANDportsANDset}{$current_section}{$type}++; } } - } ## end elsif ( $line =~ /^\[[0-9]+\].*\/.*\|.*-.*\:/) + } ## end elsif ( $line =~ /^\[.*\].*\:.*\|.*\:/ ) } ## end foreach my $line (@build_info_split) } else { $to_return->{error} = 1;