Community discussions

MikroTik App
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

If statment in function

Mon Oct 02, 2023 12:39 pm

Good Morning everyone.

Goal: use an specific OID in a function according to Device.Type in dude functions.

Problem: I can pull the [device.type] correctly but when I check it in a if statement i get "Parse Failed". So I know my code is probably not correct.

My Code: if(device_property("Type")) = "Mimosa" ,oid("iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0")

This basically should be a function that checks if a device.type (My custom type I have setup in dude) is equal to set string value. If they match then return a OID value.

Any help PLEASE, I have lookded everywhere with no luck.
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

Re: If statment in function

Mon Oct 02, 2023 12:50 pm

I have also tried to see if string_size wont work either but it does not.

What I tried: if(string_size(device_property("Type"))) = string_size("Mimosa"),oid("iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0"),"")
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: If statment in function

Mon Oct 02, 2023 12:50 pm

not tested code

if(device_property("Type")) = "Mimosa" ,oid("iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0")
=>
if ( device_property("Type") = "Mimosa", oid("iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0"), "" )

if(string_size(device_property("Type"))) = string_size("Mimosa"),oid("iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0"),"")
=>
if ( string_size(device_property("Type")) = string_size("Mimosa"), oid("iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0"), "" )
Last edited by rextended on Mon Oct 02, 2023 12:53 pm, edited 1 time in total.
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

Re: If statment in function

Mon Oct 02, 2023 12:53 pm

Hi Rextended

your code doesnt seem to work either.
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

Re: If statment in function

Mon Oct 02, 2023 12:54 pm

Rex that last one WORKED
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: If statment in function

Mon Oct 02, 2023 12:54 pm

not tested code
It just for put on evidence the wrong place of the ")"
Last edited by rextended on Mon Oct 02, 2023 12:55 pm, edited 1 time in total.
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

Re: If statment in function

Mon Oct 02, 2023 12:55 pm

Im going to try and see if it works on all my others and I will revert back with my findings.

Thank you SO much!
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

Re: If statment in function

Mon Oct 02, 2023 1:07 pm

Rextended,

For my Mikrotik devices I get error " Expected end of command (Line 1 Column 14)

My Code: if ( device_property("Type") = "MikroTik", ros_command(":put /system resource get board-name"), "")
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

Re: If statment in function

Mon Oct 02, 2023 2:15 pm

My nested IF seems to be wrong. I cant find the syntax for this :c

Code:

if ( device_property("Type") = "Ubiquity", oid("2.840.10036.3.1.2.1.3.5"), ""),
if ( device_property("Type") = "MikroTik", ros_command(":put /system resource get board-name"), ""),
if ( device_property("Type") = "Mimosa", oid("iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0"), ""),
if ( device_property("Type") = "BDcom", "",
"Fix ME",)
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

Re: If statment in function

Mon Oct 02, 2023 2:43 pm

Updated code:

if ( device_property("Type") = "Ubiquity", oid("2.840.10036.3.1.2.1.3.5"), "","")
if ( device_property("Type") = "MikroTik", ros_command(":put [/system resource get board-name]"), "","")
if ( device_property("Type") = "Mimosa", oid("iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0"), "","")
if ( device_property("Type") = "BDcom", "", "")
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

Re: If statment in function

Mon Oct 02, 2023 2:51 pm

in the nested IF:

There is a problem with matching device.type..........

If I used the mimosa OID line, it gets used for all devices no matter the if condition??/ im confused why it does this.
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

Re: If statment in function

Mon Oct 02, 2023 3:00 pm

I have Also tried this:

if ( device_property("Type") = "MikroTik", ros_command(":put [/system resource get board-name]"), if ( device_property("Type") = "Mimosa", oid("iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0"), if ( device_property("Type") = "Ubiquity", oid("2.840.10036.3.1.2.1.3.5"), if ( device_property("Type") = "BDcom", 0))))
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

Re: If statment in function

Mon Oct 02, 2023 3:02 pm

Ok this code only pulls the 1st if statement but if it the condition does not match it does not fall to the else statement?

if ( device_property("Type") = "MikroTik", ros_command(":put [/system resource get board-name]"),
if ( device_property("Type") = "Mimosa", oid("iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0"),
if ( device_property("Type") = "Ubiquity", oid("2.840.10036.3.1.2.1.3.5"),
if ( device_property("Type") = "BDcom", "",""))))
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

Re: If statment in function

Tue Oct 03, 2023 2:37 pm

Hi,

I dont know why this if is still not working. ive tried so much.

Code:

if ( device_property("Type") = 0, ros_command(":put [/system resource get board-name]"),
if ( device_property("Type") = 1, oid("iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0"),
if ( device_property("Type") = 2, oid("2.840.10036.3.1.2.1.3.5"),"")))
Screenshot 2023-10-03 133535.png
You do not have the required permissions to view the files attached to this post.
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

Re: If statment in function

Thu Oct 05, 2023 1:40 pm

Bump of shame
 
Byron
just joined
Topic Author
Posts: 20
Joined: Sun Jan 09, 2022 6:46 pm

Re: If statment in function

Mon Oct 09, 2023 9:47 am

So the IF function is bugged according to MikroTik support.

Need to see what work around I can get instead.

Who is online

Users browsing this forum: No registered users and 1 guest