snmp

Started by jamesof, May 11, 2013, 02:36:29 PM

Previous topic - Next topic

jamesof

i have this is in config->scripting library
script name : test

sub main()
{
   return ret = SNMPSet("2c", .1.3.6.1.2.1.25.1.6.0, 10);
if (!ret)
{
    trace(1,"SNMPSet failed");
    return -1;
}

}

and when trying to execute it from console it says
error : script test not found .
what should i do?
and is it enough for snmp set? isn't it necessary to install net-snmp?

Victor Kirhenshtein

Your script has syntax error, and so it not compiles. Because of that you got "script not found" message (not very meaningful in this case, I agree). Besides that, it has other errors. First of all, you have to create SNMP transport object for node you want to query, and then use it in SNMPGet function. Below is an example of script which can be run from server's debug console to get SNMP object ID from node passed as parameter:


if ($1 == null)
{
   println "Please specify node name as parameter";
   return 3;
}

transport = CreateSNMPTransport(FindObject($1));    // Create SNMP transport for node
if (transport == null)
{
    println "Failed to create SNMP transport, exit";
    return 1;
}

value = SNMPGetValue(transport, ".1.3.6.1.2.1.1.1.0");
if (value == null)
{
    println "Failed to issue SNMP GET request";
    return 2;
}
else
{
    println "System description: " . value;
    return 0;
}


Example of running this script on my test server attached.

Best regards,
Victor

jamesof

#2
thanks
but i want to set an object such as  .1.3.6.1.2.1.25.1.5.0
is this wrong?

if ($1 == null)
{
   println "Please specify node name as parameter";
   return 3;
}
println $1;
transport = CreateSNMPTransport(FindObject($1));   
if (transport == null)
{
    println "Failed to create SNMP transport, exit";
    return 1;
}

ret = SNMPSet(transport, ".1.3.6.1.2.1.25.1.5.0", 4);
if (!ret)
{
   println "failed";
    trace(1,"SNMPSet failed");
    return -1;
}

Victor Kirhenshtein

Hi!

Script looks correct. But are you sure that .1.3.6.1.2.1.25.1.5.0 is writeable, and that community string set in NetXMS allows read/write access?

Best regards,
Victor