Strange behavior of method in API
-
I made a script in python to populate a network, in which I condigure the name, IP, snmp port, snmp community and so.
In class org.netxms.client.NXCObjectModificationData, when using the method void setSnmpVersion(int snmpVersion), I noticed the following:
- If I pass number 1 as a paramether to the method, it configures as version 2c;
- If I pass number 2 as a paramether to the method, it configures as version 1.
Is this supposed to happen? Because of that, in my script I wrote this to configure correctly:
if objectSnmpVersion == "V1":
objectSnmpVersion = 2
elif objectSnmpVersion == "V2C":
objectSnmpVersion = 1
elif objectSnmpVersion == "V3":
objectSnmpVersion = 3
md.setSnmpVersion(objectSnmpVersion)
but didnt' like it... ??? -
-
Hi!
SNMP version constants are a bit illogical (for historical reasons). They are following:
0 = SNMP v1
1 = SNMP v2
3 = SNMP v32 is an invalid value, so it falls back to v1 (as any invalid value will do). You can use constants from AbstractNode class:
AbstractNode.SNMP_VERSION_1, AbstractNode.SNMP_VERSION_2C, AbstractNode.SNMP_VERSION_3
Best regards,
Victor -
I have attached the script here.
I'm sorry, but all my comments are written in portuguese so here goes a little explanation about the code:In the beggining of the script it's defined the name of the container in which the nodes will be created. It checks if there already is a container with that name and if there isn't we create it. In any case we get the ID of the container of that name.
Then, it opens an archive named input.csv with reading option and mark its delimiter as ';'.
This archive has the following format:NAMEORIP;10.106.7.252;COMMUNITY;0rqu1dea;SNMPPORT;161;SNMPVERSION;V2C;SEEDNAME;a-rg-fcc-arq-001-araraquara;ACCESSMODE;ICMPSNMP;ADDRESSFORMAT;AUTOADDRESS;
NAMEORIP;10.11.133.170;COMMUNITY;0rqu1dea;SNMPPORT;161;SNMPVERSION;V2C;SEEDNAME;a-rg-fcc-ula-085-cadministrativo;ACCESSMODE;ICMPSNMP;ADDRESSFORMAT;AUTOADDRESS;
NAMEORIP;10.224.0.110;SNMPPORT;161;SNMPVERSION;V2C;SEEDNAME;a-rg-fcc-ula-301-image-01;ACCESSMODE;ICMPONLY;ADDRESSFORMAT;AUTOADDRESS;;;
NAMEORIP;10.5.1.132;COMMUNITY;0rqu1dea;SNMPPORT;161;SNMPVERSION;V2C;SEEDNAME;a-rg-fcc-bet-511-guaruja;ACCESSMODE;ICMPSNMP;ADDRESSFORMAT;AUTOADDRESS;
NAMEORIP;10.5.1.134;SNMPPORT;161;SNMPVERSION;V2C;SEEDNAME;a-rg-fcc-bhe-010-liberdade;ACCESSMODE;ICMPONLY;ADDRESSFORMAT;AUTOADDRESS;;;Above there are some lines of the archive. It's in this format because this is how it was exported by our running network management system (yeah I know it looks ugly!). As you can see, not all collumns are filled for all lines, and the names in upercase letters represent what parameter comes next, so we "treat" this in the if-chain by reading 2 collumns at a time and checking what that collumn represents. We save the data collected in variables.
Then it's the creation part:
First it checks if an object with that name already exists. If so, it doesn't create it. If not, it calls the methods of classes NXCObjectCreationData and NXCObjectModificationData and create it with the parameters got from the archive.Sorry about my not-so-good english, hope I made it clear! ;D
If you have any questions about anything feel free to ask me, I'll be glad to explain!Regards,
Jhúlia Graziella
-
@victor said in Strange behavior of method in API:
Hi!
SNMP version constants are a bit illogical (for historical reasons). They are following:
0 = SNMP v1
1 = SNMP v2
3 = SNMP v32 is an invalid value, so it falls back to v1 (as any invalid value will do). You can use constants from AbstractNode class:
AbstractNode.SNMP_VERSION_1, AbstractNode.SNMP_VERSION_2C, AbstractNode.SNMP_VERSION_3
Best regards,
VictorOh, okay! Thank you very much!
I'll correct it. -
Btw, is it intended to create all nodes with SNMP access disabled?
Best regards,
Victor -
In this situation yes, because we won't monitore this nodes using SNMP, but I made this way so the script can be reused to populate the rest of the nodes!
Thank you,
Jhúlia Graziella
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login