File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed
Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ # !/usr/bin/env perl
2+
3+ use MIME::Base64;
4+ use Gzip::Faster;
5+ use Getopt::Long;
6+ use warnings;
7+ use strict;
8+
9+ sub version{
10+ print " lnms_return_optimizer v. 0.0.1\n " ;
11+ }
12+
13+
14+
15+ my $version ;
16+ my $help ;
17+ my $extract ;
18+ my $new_line ;
19+ GetOptions(
20+ ' e' => \$extract ,
21+ ' n' => \$new_line ,
22+ ' h' => \$help ,
23+ ' help' => \$help ,
24+ ' v' => \$version ,
25+ ' version' => \$version ,
26+ );
27+
28+ if ($version ) {
29+ version;
30+ exit ;
31+ }
32+
33+ if ($help ) {
34+ version;
35+
36+ print '
37+ foo | lnms_return_otimizer
38+
39+ -e Operate in extract mode instead.
40+ -n Include newlines with the base64.
41+
42+ -h Print help.
43+ --help Print help.
44+ -v Print version info.
45+ --version Print version info.
46+ ' ;
47+
48+ exit ;
49+ }
50+
51+ my $data = ' ' ;
52+ foreach my $line (<STDIN >) {
53+ $data = $data . $line ;
54+ }
55+
56+ if ($extract ) {
57+ if ($data =~ / ^[A-Za-z0-9\/\+\n ]+\= *\n *$ / ) {
58+ print gunzip(decode_base64($data ));
59+ }else {
60+ print $data ;
61+ }
62+ }else {
63+ # gzip and print encode in base64
64+ # base64 is needed as snmp does not like
65+ my $compressed = encode_base64(gzip($data ));
66+ if (!$new_line ) {
67+ $compressed =~ s /\n // g ;
68+ $compressed = $compressed . " \n " ;
69+ }
70+
71+ # check which is smaller and prints it
72+ if (length ($compressed ) > length ($data )) {
73+ print $data ;
74+ }else {
75+ print $compressed ;
76+ }
77+ }
You can’t perform that action at this time.
0 commit comments