Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poudriere: add -q to quite the results and a bit of cleanup #538

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions snmp/poudriere
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@ poudriere - LibreNMS JSON style SNMP extend for monitoring Poudriere

=head1 VERSION

0.2.0
0.3.0

=head1 SYNOPSIS

poudriere [B<-w>] [B<-b>] [B<-o> <cache base>] [B<-a>] [B<-z>]
poudriere B<-w> [B<-o> <cache base>] [B<-a>] [B<-z>] [B<-q>]

poudriere [<-b>] [B<-a>] [B<-z>]

poudriere --help|-h

poudriere --version|-v

=head1 SNMPD CONFIG

extend poudriere /etc/snmp/extends/poudriere -b
extend poudriere /usr/local/etc/snmp/poudriere -b -a -z

or if using cron...

# cron
4/5 * * * * root /usr/local/etc/snmp/poudriere -b -a -z -q

# snmpd.conf
extend poudriere cat /var/cache/poudriere.json.snmp

=head1 FLAGS
Expand All @@ -30,13 +36,17 @@ or if using cron...

Include `poudriere status -a` as .data.history .

=head2 -w
=head2 -b

Write the results out.
Encapsulate the result in GZip+Base64 if -w is not used.

=head2 -b
=head2 -q

Print out the compressed data if GZip+Base64 is smaller.
If -w is specified, do not print the results to stdout.

=head2 -w

Write the results out.

=head2 -z

Expand Down Expand Up @@ -126,10 +136,12 @@ my $version;
my $help;
my $history;
my $zero_non_build;
my $if_write_be_quiet;
GetOptions(
a => \$history,
'o=s' => \$cache_base,
w => \$write,
q => \$if_write_be_quiet,
b => \$compress,
z => \$zero_non_build,
v => \$version,
Expand Down Expand Up @@ -306,8 +318,8 @@ if ( $? == 0 ) {
$found->{IGNORE} = 0;
$found->{FETCH} = 0;
$found->{REMAIN} = 0;
$found->{TIME} = 0;
}
$found->{TIME} = 0;
} ## end if ( $zero_non_build && $found->{STATUS} !~...)

if ( $found->{STATUS} ne 'done' ) {
$data->{not_done} = 1;
Expand Down Expand Up @@ -393,7 +405,7 @@ if ( $? == 0 ) {
eval {
$ps
= decode_json(
`ps -o 'jid %cpu %mem rss cow dsiz etimes inblk jobc majflt minflt msgrcv msgsnd nivcsw nlwp nsigs nswap nvcsw oublk ssiz systime time tsiz usertime' --libxo json -J $jails_string`
`ps -o 'jid %cpu %mem rss cow dsiz etimes inblk jobc majflt minflt msgrcv msgsnd nivcsw nlwp nsigs nswap nvcsw oublk ssiz systime time tsiz usertime' --libxo json -J $jails_string 2> /dev/null`
);
};
if ($@) {
Expand Down Expand Up @@ -503,16 +515,9 @@ if ($write) {
$compressed =~ s/\n//g;
$compressed = $compressed . "\n";
my $print_compressed = 0;
if ( length($compressed) > length($raw_json) ) {
write_file( $cache_base . '.snmp', $raw_json );
} else {
write_file( $cache_base . '.snmp', $compressed );
$print_compressed = 1;
}
write_file( $cache_base . '.snmp', $compressed );

if ( $compress && $print_compressed ) {
print $compressed;
} else {
if ( !$if_write_be_quiet ) {
print $raw_json;
}
} else {
Expand All @@ -527,10 +532,5 @@ if ($write) {
my $compressed = encode_base64($compressed_string);
$compressed =~ s/\n//g;
$compressed = $compressed . "\n";
my $print_compressed = 0;
if ( length($compressed) > length($raw_json) ) {
print $raw_json;
} else {
print $compressed;
}
print $compressed;
} ## end else [ if ($write) ]
Loading