Merge branch 'ent-8914-bug-plugintools' into 'develop'

Added controls for avoid undefined vars

See merge request artica/pandorafms!4854
This commit is contained in:
Daniel Rodriguez 2022-05-17 14:29:23 +00:00
commit 7a9bc44604
1 changed files with 84 additions and 64 deletions

View File

@ -2207,12 +2207,26 @@ sub snmp_get {
};
}
if (!defined $snmp->{version}) {
return {
'error' => "Only SNMP 1 2 2c and 3 are supported."
};
} elsif (!defined $snmp->{host}) {
return {
'error' => "Destination host must be defined."
};
} elsif (!defined $snmp->{oid}) {
return {
'error' => "OID must be defined"
};
} else {
$snmp->{extra} = '' unless defined $snmp->{extra};
$snmp->{context} = '' unless defined $snmp->{context};
$snmp->{community} = 'public' unless defined $snmp->{community};
if ( defined ($snmp->{version} )
&& (($snmp->{version} eq "1")
if (($snmp->{version} eq "1")
|| ($snmp->{version} eq "2")
|| ($snmp->{version} eq "2c"))) {
|| ($snmp->{version} eq "2c")) {
if (defined $snmp->{port}){
$cmd = "snmpget -r $retries -t $timeout $snmp->{extra} -On -v $snmp->{version} -c $snmp->{community} $snmp->{host}:$snmp->{port} $snmp->{oid}";
@ -2223,7 +2237,11 @@ sub snmp_get {
}
elsif ( defined ($snmp->{version} )
&& ($snmp->{version} eq "3") ) { # SNMP v3
&& ($snmp->{version} eq "3") ) {
$snmp->{securityLevel} = '' unless defined $snmp->{securityLevel};
# SNMP v3
# Authentication required
# $securityLevel = (noAuthNoPriv|authNoPriv|authPriv);
@ -2267,12 +2285,14 @@ sub snmp_get {
$cmd = "snmpget -r $retries -t $timeout $snmp->{extra} -On -v $snmp->{version} -n \"$snmp->{context}\" -u $snmp->{securityName} -l $snmp->{securityLevel} -a $snmp->{authProtocol} -A $snmp->{authKey} -x $snmp->{privProtocol} -X $snmp->{privKey} $snmp->{host} $snmp->{oid}";
}
}
}
else {
return {
error => "Only SNMP 1 2 2c and 3 are supported."
'error' => "Security Level not defined."
};
}
}
}
#print STDERR "Launched: $cmd\n";
my $result = `$cmd`;
if ($? != 0) {