| 1 | package SNMP::Extension::PassPersist; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use parent qw< Class::Accessor >; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use IO::Pipe; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use IO::Select; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use List::MoreUtils qw< any >; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use Storable qw< nfreeze thaw >; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use Sys::Syslog; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | ▶ | no strict "vars"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | $VERSION = '0.07'; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | use constant HAVE_SORT_KEY_OID | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 7 | => eval "use Sort::Key::OID 0.04 qw<oidsort>; 1" ? 1 : 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # early initialisations -------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | my @attributes = qw< | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | backend_collect | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | backend_fork | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | backend_init | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | backend_pipe | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | heap | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | idle_count | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | input | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | oid_tree | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | sorted_entries | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | output | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | refresh | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | dispatch | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | >; | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 7 | __PACKAGE__->mk_accessors(@attributes); | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # constants -------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 7 | ▶ | use constant SNMP_NONE => "NONE"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 7 | ▶ | use constant SNMP_PING => "PING"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 7 | ▶ | use constant SNMP_PONG => "PONG"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 7 | ▶ | use constant SNMP_GET => "get"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 7 | ▶ | use constant SNMP_GETNEXT => "getnext"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 7 | ▶ | use constant SNMP_SET => "set"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 7 | ▶ | use constant SNMP_NOT_WRITABLE => "not-writable"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | ▶ | use constant SNMP_WRONG_TYPE => "wrong-type"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 7 | ▶ | use constant SNMP_WRONG_LENGTH => "wrong-length"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 7 | ▶ | use constant SNMP_WRONG_VALUE => "wrong-value"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 7 | ▶ | use constant SNMP_INCONSISTENT_VALUE => "inconsistent-value"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # global variables ------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 7 | my %snmp_ext_type = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | counter => "counter", | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | counter64 => "counter64", | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | gauge => "gauge", | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | integer => "integer", | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ipaddr => "ipaddress", | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ipaddress => "ipaddress", | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | netaddr => "ipaddress", | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | objectid => "objectid", | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | octetstr => "string", | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # opaque => "opaque", | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | string => "string", | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | timeticks => "timeticks", | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # new() | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # --- | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 17 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 17 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 17 | my %attrs; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 17 | my $ref = ref $args[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # see how arguments were passed | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 17 | ▶ | if ($ref and $ref eq "HASH") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ref and $ref eq "HASH"
MC/DC100%2/2
$ref and $ref eq "HASH"
$ref
$ref eq "HASH"
Truth table100%3/3
A and B
A= $refB= $ref eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | %attrs = %{$args[0]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 15 | ▶ | croak "error: Don't know how to handle \L$ref reference" if $ref; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 12 | ▶ | croak "error: Odd number of arguments" if @args % 2 == 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 10 | %attrs = @args; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # filter out unknown attributes | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 12 | my %known_attr; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 12 | @known_attr{@attributes} = (1) x @attributes; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 12 | ▶ | !$known_attr{$_} && delete $attrs{$_} for keys %attrs; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # check that code attributes are coderefs | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 12 | for my $code_attr (qw<backend_init backend_collect>) { | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | croak "error: Attribute $code_attr must be a code reference" | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 22 | ▶ | if defined $attrs{$code_attr} and ref $attrs{$code_attr} ne "CODE"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $attrs{$code_attr} and ref $attrs{$code_attr} ne "CODE"
MC/DC100%2/2
defined $attrs{$code_attr} and ref $attrs{$code_attr} ne "CODE"
defined $attrs{$code_attr}
ref $attrs{$code_attr} ne "CODE"
Truth table100%3/3
A and B
A= defined $attrs{$code_attr}B= ref $attrs{$code_attr} ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # default values | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | %attrs = ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | ▶ | backend_collect => sub {}, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | backend_fork => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | ▶ | backend_init => sub {}, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 10 | heap => {}, | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | input => \*STDIN, | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | output => \*STDOUT, | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | oid_tree => {}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | sorted_entries => [], | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | idle_count => 5, | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | refresh => 10, | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | dispatch => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | lc(SNMP_PING) => { nargs => 0, code => \&ping }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | lc(SNMP_GET) => { nargs => 1, code => \&get_oid }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | lc(SNMP_GETNEXT) => { nargs => 1, code => \&getnext_oid }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | lc(SNMP_SET) => { nargs => 2, code => \&set_oid }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | %attrs, | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # create the object with Class::Accessor | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 10 | my $self = $class->SUPER::new(\%attrs); | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 10 | return $self | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # run() | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # --- | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=28 SCAR=45.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # process command-line arguments | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | Getopt::Long::Configure(qw<no_auto_abbrev no_ignore_case>); | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | 4 | ▶ | GetOptions(\my %options, qw<get|g=s getnext|n=s set|s=s>) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | or croak "fatal: An error occured while processing runtime arguments"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 4 | ▶ | my $name = $::COMMAND || basename($0); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$main::COMMAND || basename($0)
MC/DC0%0/2
$main::COMMAND || basename($0)
$main::COMMAND
basename($0)
Truth table33%1/3
A || B
A= $main::COMMANDB= basename($0)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 4 | openlog($name, "ndelay,pid", "local0"); | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | my ($mode_pass, $mode_passpersist); | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | my $backend_fork = $self->backend_fork; | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # determine the run mode | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 4 | ▶ | if (any { defined $options{$_} } "get", "getnext", "set") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | $mode_pass = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | $mode_passpersist = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | $mode_pass = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | 3 | $mode_passpersist = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # execute the init and collect callback once, except in the case | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # where the backend run in a separate process | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 4 | ▶ | unless ($mode_passpersist and $backend_fork) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mode_passpersist and $backend_fork
MC/DC0%0/2
$mode_passpersist and $backend_fork
$mode_passpersist
$backend_fork
Truth table66%2/3
A and B
A= $mode_passpersistB= $backend_fork
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # initialise the backend | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 4 | ▶ | eval { $self->backend_init->($self); 1 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | or croak "fatal: An error occurred while executing the backend " | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ."initialisation callback: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # collect the information | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 3 | ▶ | eval { $self->backend_collect->($self); 1 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | or croak "fatal: An error occurred while executing the backend " | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | ."collecting callback: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # Net-SNMP "pass" mode | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | ▶ | if ($mode_pass) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | for my $op (qw<get getnext set>) { | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 3 | ▶ | if ($options{$op}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | my @args = split /,/, $options{$op}; | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | my $coderef = $self->dispatch->{$op}{code}; | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | my @result = $coderef->($self, @args); | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | $self->output->print(join "\n", @result, ""); | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # Net-SNMP "pass_persist" mode | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | my $needed = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | my $delay = $self->refresh; | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | my $counter = $self->idle_count; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | my ($pipe, $child); | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # if the backend is to be run in a separate process, | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # create a pipe and fork | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | if ($backend_fork) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $pipe = IO::Pipe->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $self->backend_pipe($pipe); | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $child = fork; | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $msg = "fatal: can't fork: $!"; | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | syslog err => $msg and die $msg | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
defined $child || syslog('err', $msg) && die($msg)
syslog("err", $msg) and die $msg
MC/DC0%0/2
defined $child || syslog('err', $msg) && die($msg)
defined $child
syslog("err", $msg)
Truth table0%0/3
A || B
A= defined $childB= syslog("err", $msg)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | unless defined $child; | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # child setup is handled in run_backend_loop() | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | goto &run_backend_loop if $child == 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # parent setup | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $pipe->reader; # declare this end of the pipe as the reader | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $pipe->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | my $io = IO::Select->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | $io->add($self->input); | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | $self->output->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | ▶ | if ($backend_fork) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $io->add($pipe); | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | $SIG{CHLD} = sub { $io->remove($pipe); waitpid($child, 0); }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # main loop | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | ▶ | while ($needed and $counter > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$needed and $counter > 0
MC/DC50%1/2
$needed and $counter > 0
$needed
$counter > 0
Truth table66%2/3
A and B
A= $neededB= $counter > 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 2 | my $start_time = time; | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # wait for some input data | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 2 | my @ready = $io->can_read($delay); | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 2 | for my $fh (@ready) { | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | # handle input data from netsnmpd | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | ▶ | if ($fh == $self->input) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | ▶ | if (my $cmd = <$fh>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | $self->process_cmd(lc($cmd), $fh); | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | 1 | $counter = $self->idle_count; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | $needed = 0 | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # handle input data from the backend process | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | ▶ | if ($backend_fork and $fh == $pipe) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$backend_fork and $fh == $pipe
MC/DC0%0/2
$backend_fork and $fh == $pipe
$backend_fork
$fh == $pipe
Truth table33%1/3
A and B
A= $backend_forkB= $fh == $pipe
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 7 | ▶ | use bytes; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # read a first chunk from the child | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $fh->sysread(my $buffer, 20); | |||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | last unless length $buffer; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # extract the header | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my $headline= substr($buffer, 0, index($buffer, "\n")+1, ""); | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | chomp $headline; | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my %header = map { split /=/, $_, 2 } split /\|/, $headline; | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # read the date in Storable format | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $length = $header{length}; | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $fh->sysread(my $freezed, $length); | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $freezed = $buffer.$freezed; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # decode the freezed data | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my $struct = thaw($freezed); | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $self->add_oid_tree($struct); | |||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | $delay = $delay - (time() - $start_time); | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | ▶ | if ($delay <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | if (not $backend_fork) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # collect information when the timeout has expired | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | eval { $self->backend_collect->($self); 1 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | or croak "fatal: An error occurred while executing " | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | ."the backend collecting callback: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # reset delay | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $delay = $self->refresh; | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $counter--; | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | ▶ | if ($backend_fork) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | kill TERM => $child; | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | kill KILL => $child; | |||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | waitpid($child, 0); | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # run_backend_loop() | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # ---------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | sub run_backend_loop { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_backend_loop: not called CC=3 SCAR=22.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my $pipe = $self->backend_pipe; | |||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $pipe->writer; # declare this end of the pipe as the writer | |||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $pipe->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # execute the initialisation callback | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | eval { $self->backend_init->($self); 1 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | or croak "fatal: An error occurred while executing the backend " | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | ."initialisation callback: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my $start_time = time; | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # execute the collect callback | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | eval { $self->backend_collect->($self); 1 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | or croak "fatal: An error occurred while executing the backend " | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | ."collecting callback: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # freeze the OID tree using Storable | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 7 | ▶ | use bytes; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my $freezed = nfreeze($self->oid_tree); | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $length = length $freezed; | |||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my $output = "length=$length\n$freezed"; | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # send it to the parent via the pipe | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $pipe->syswrite($output); | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | select(undef, undef, undef, .000_001); | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # wait before next execution | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my $delay = $self->refresh() - (time() - $start_time); | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | sleep $delay; | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # add_oid_entry() | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # ------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | ▶ | sub add_oid_entry { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_oid_entry: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 2 | my ($self, $oid, $type, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 2 | ▶ | croak "error: Unknown type '$type'" unless exists $snmp_ext_type{$type}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 2 | $self->oid_tree->{$oid} = [$type => $value]; | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # need to resort | ||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | @{$self->sorted_entries} = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 2 | return 1 | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # add_oid_tree() | ||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # ------------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | sub add_oid_tree { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_oid_tree: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my ($self, $new_tree) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | croak "error: Unknown type" | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | if any { !$snmp_ext_type{$_->[0]} } values %$new_tree; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $oid_tree = $self->oid_tree; | |||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | @{$oid_tree}{keys %$new_tree} = values %$new_tree; | |||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # need to resort | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | @{$self->sorted_entries} = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | return 1 | |||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # dump_oid_tree() | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | # ------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | sub dump_oid_tree { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_oid_tree: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $oid_tree = $self->oid_tree; | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | my $output = $self->output; | |||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | for my $oid (sort by_oid keys %$oid_tree) { | |||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my ($type, $value) = @{ $oid_tree->{$oid} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $output->print("$oid ($type) = $value\n"); | |||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # ping() | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # ---- | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | sub ping { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ping: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | return SNMP_PONG | |||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # get_oid() | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | # ------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 2 | ▶ | sub get_oid { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_oid: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 2 | my ($self, $req_oid) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 2 | my $oid_tree = $self->oid_tree; | |||||||||||||||||||||||||||||||||||||||||||||
| 397 | 2 | my @result = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 2 | ▶ | if ($oid_tree->{$req_oid}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 2 | my ($type, $value) = @{ $oid_tree->{$req_oid} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 401 | 2 | @result = ($req_oid, $type, $value); | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | @result = (SNMP_NONE) | |||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | return @result | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 2 | } | |||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # getnext_oid() | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # ----------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | sub getnext_oid { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getnext_oid: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | my ($self, $req_oid) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | my $next_oid = $self->fetch_next_entry($req_oid) | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->fetch_next_entry($req_oid) || $self->fetch_first_entry
MC/DC0%0/2
$self->fetch_next_entry($req_oid) || $self->fetch_first_entry
$self->fetch_next_entry($req_oid)
$self->fetch_first_entry
Truth table0%0/3
A || B
A= $self->fetch_next_entry($req_oid)B= $self->fetch_first_entry
| |||||||||||||||||||||||||||||||||||||||||||||||
| 418 | || $self->fetch_first_entry(); | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | return $self->get_oid($next_oid) | |||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # set_oid() | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # ------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | sub set_oid { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_oid: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my ($self, $req_oid, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | return SNMP_NOT_WRITABLE | |||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # process_cmd() | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # ----------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # Process and dispatch Net-SNMP commands when in pass_persist mode. | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 1 | ▶ | sub process_cmd { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_cmd: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 1 | my ($self, $cmd, $fh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 440 | 1 | my @result = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 1 | chomp $cmd; | |||||||||||||||||||||||||||||||||||||||||||||
| 443 | 1 | my $dispatch = $self->dispatch; | |||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | ▶ | if (exists $dispatch->{$cmd}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # read the command arguments | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 1 | my @args = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | 1 | my $n = $dispatch->{$cmd}{nargs}; | |||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 1 | ▶ | while ($n-- > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | chomp(my $arg = <$fh>); | |||||||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | push @args, $arg; | |||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # call the command handler | ||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 1 | my $coderef = $dispatch->{$cmd}{code}; | |||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | @result = $coderef->($self, @args); | |||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | @result = SNMP_NONE; | |||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||
| 464 | # output the result | ||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 1 | $self->output->print(join "\n", @result, ""); | |||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | # fetch_next_entry() | ||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # ---------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | sub fetch_next_entry { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_next_entry: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | my ($self, $req_oid) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my $entries = $self->sorted_entries; | |||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | if (!@$entries) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 478 | @$entries = HAVE_SORT_KEY_OID | ||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ? oidsort(keys %{ $self->oid_tree }) | |||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | : sort by_oid keys %{ $self->oid_tree }; | |||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # find the index of the current entry | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | my $curr_entry_idx = -1; | |||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | for my $i (0..$#$entries) { | |||||||||||||||||||||||||||||||||||||||||||||
| 487 | # exact match of the requested entry | ||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | $curr_entry_idx = $i and last if $entries->[$i] eq $req_oid; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$entries->[$i] eq $req_oid && (($curr_entry_idx = $i) && (last))
$curr_entry_idx = $i and last
MC/DC0%0/2
$entries->[$i] eq $req_oid && (($curr_entry_idx = $i) && (last))
$entries->[$i] eq $req_oid
$curr_entry_idx = $i
Truth table0%0/3
A && B
A= $entries->[$i] eq $req_oidB= $curr_entry_idx = $i
| |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # prefix match of the requested entry | ||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | $curr_entry_idx = $i - 1 and last | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/8
$curr_entry_idx == -1 && index($entries->[$i], $req_oid) != -1 && (($curr_entry_idx = $i - 1) && (last))
$curr_entry_idx == -1 and index($entries->[$i], $req_oid) != -1
$curr_entry_idx = $i - 1 and last
MC/DC0%0/3
$curr_entry_idx == -1 && index($entries->[$i], $req_oid) != -1 && (($curr_entry_idx = $i - 1) && (last))
$curr_entry_idx == -1
index($entries->[$i], $req_oid) != -1
$curr_entry_idx = $i - 1
Truth table0%0/4
A and B && C
A= $curr_entry_idx == -1B= index($entries->[$i], $req_oid) != -1C= $curr_entry_idx = $i - 1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 492 | if $curr_entry_idx == -1 and index($entries->[$i], $req_oid) >= 0; | ||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||
| 495 | # get the next entry if it exists, otherwise none | ||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | my $next_entry_oid = $entries->[$curr_entry_idx + 1] || SNMP_NONE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$entries[$curr_entry_idx + 1] || 'NONE'
MC/DC0%0/1
$$entries[$curr_entry_idx + 1] || 'NONE'
$$entries[$curr_entry_idx + 1]
Truth table0%0/2
A
A= $$entries[$curr_entry_idx + 1]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | return $next_entry_oid | |||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||
| 502 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 503 | # fetch_first_entry() | ||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # ----------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | sub fetch_first_entry { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_first_entry: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | my $entries = $self->sorted_entries; | |||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | if (!@$entries) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 511 | @$entries = HAVE_SORT_KEY_OID | ||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ? oidsort(keys %{ $self->oid_tree }) | |||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | : sort by_oid keys %{ $self->oid_tree }; | |||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | my $first_entry_oid = $entries->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | return $first_entry_oid | |||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||
| 521 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 522 | # by_oid() | ||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # ------ | ||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # sort() sub-function, for sorting by OID | ||||||||||||||||||||||||||||||||||||||||||||||
| 525 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | sub by_oid ($$) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
by_oid: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | my (undef, @a) = split /\./, $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | my (undef, @b) = split /\./, $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | my $v = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | $v ||= $a[$_] <=> $b[$_] for 0 .. $#a; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$v ||= $a[$_] <=> $b[$_]
MC/DC0%0/2
$v ||= $a[$_] <=> $b[$_]
$v
$a[$_] <=> $b[$_]
Truth table0%0/3
A ||= B
A= $vB= $a[$_] <=> $b[$_]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | return $v | |||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 7 | __PACKAGE__ | |||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||
| 537 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||