I have a Centos 6.4 and i'm checking the functionality of the deamon through the command snmpwalk -v 2c -c public localhost OID.
Now if i use the script in this doc everything is working and my custom (i made it) MIB is clean and the result is ok.
But i want more so i did this:
#!/usr/bin/perl
use NetSNMP::agent (':all');
use NetSNMP::ASN qw(ASN_OCTET_STR ASN_INTEGER);
#$string_value = qx{/tmp/readabilityChk};
#print $string_value;
#&hello_handler();
sub hello_handler {
my ($handler, $registration_info, $request_info, $requests) = @_;
my $request;
#my $string_value = "cipolline";
my $integer_value = "8675309";
my $string_value = `/tmp/readabilityChk`;
for($request = $requests; $request; $request = $request->next()) {
my $oid = $request->getOID();
if ($request_info->getMode() == MODE_GET) {
if ($oid == new NetSNMP::OID(".1.3.6.1.4.1.2021.150.1.1.3")) {
$request->setValue(ASN_OCTET_STR, $string_value);
}
elsif ($oid == new NetSNMP::OID(".1.3.6.1.4.1.2021.150.1.1.100")) {
$request->setValue(ASN_INTEGER, $integer_value);
}
} elsif ($request_info->getMode() == MODE_GETNEXT) {
if ($oid == new NetSNMP::OID(".1.3.6.1.4.1.150.2021.1.1.3")) {
$request->setOID(".1.3.6.1.4.1.2021.150.1.1.100");
$request->setValue(ASN_INTEGER, $integer_value);
}
elsif ($oid < new NetSNMP::OID(".1.3.6.1.4.1.2021.150.1.1.3")) {
$request->setOID(".1.3.6.1.4.1.2021.150.1.1.3");
$request->setValue(ASN_OCTET_STR, $string_value);
}
elsif ($oid < new NetSNMP::OID(".1.3.6.1.4.1.2021.150.1.1.100")) {
$request->setOID(".1.3.6.1.4.1.2021.150.1.1.100");
$request->setValue(ASN_INTEGER, $integer_value);
}
}
}
}
my $agent = new NetSNMP::agent();
$agent->register("hello_world", ".1.3.6.1.4.1.2021.150",
\&hello_handler);`
THE PROBLEM is that the snmpwalk give: UCD-CUSTOM-MIB::custom = STRING: or now UCD-CUSTOM-MIB::custom = No more variables left in this MIB View (It is past the end of the MIB tree)
in the log i have this: Non-string value passed to setValue with ASN_OCTET_STR/ASN_BIT_STR: type was 0
I think the problem is the type of the var that is (mysteriously) not a string. but i can't really find out how to fix it.
please help me T_T
The problem was that /tmp/ directory wasn't a executable location for SELinux, so no scripts could have run from there. The pratical solution is to turn off SELinux or move the .sh in a proper directory (like libexec)