Community discussions

MikroTik App
 
Puffer
just joined
Topic Author
Posts: 24
Joined: Mon Mar 08, 2010 2:09 pm

Remote read global variable

Sat Apr 09, 2022 5:05 am

Has anyone been able to read a global variable using a remote server ?
I have a modified system voltage variable on the RB and would like to read it from a remote Zabbix instance.
First prize would be a snmp get OID for global variables.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Remote read global variable

Sat Apr 09, 2022 12:24 pm

put the value in the name of one fake bridge...
/interface bridge
add comment="used just for read remotely the valiable-value" name=variable-value
and find the right OID for that entry

console code

[rex@net] > /interface print oid where comment="used just for read remotely the valiable-value"
Flags: D - dynamic, X - disabled, R - running, S - slave 
 0  R  ;;; used just for read remotely the valiable-value
       name=.1.3.6.1.2.1.2.2.1.2.14 actual-mtu=.1.3.6.1.2.1.2.2.1.4.14 mac-address=.1.3.6.1.2.1.2.2.1.6.14 admin-status=.1.3.6.1.2.1.2.2.1.7.14
       oper-status=.1.3.6.1.2.1.2.2.1.8.14 bytes-in=.1.3.6.1.2.1.31.1.1.1.6.14 packets-in=.1.3.6.1.2.1.31.1.1.1.7.14
       discards-in=.1.3.6.1.2.1.2.2.1.13.14 errors-in=.1.3.6.1.2.1.2.2.1.14.14 bytes-out=.1.3.6.1.2.1.31.1.1.1.10.14
       packets-out=.1.3.6.1.2.1.31.1.1.1.11.14 discards-out=.1.3.6.1.2.1.2.2.1.19.14 errors-out=.1.3.6.1.2.1.2.2.1.20.14
name=.1.3.6.1.2.1.2.2.1.2.14
and you can read remotely the value...

For set the value inside the (remote) script simply:
/interface bridge set [find where comment="used just for read remotely the valiable-value"] name=$globalvar
 
fragtion
Member Candidate
Member Candidate
Posts: 259
Joined: Fri Nov 13, 2009 10:08 pm
Location: Johannesburg, South Africa

Re: Remote read global variable

Sat Apr 09, 2022 12:50 pm

put the value in the name of one fake bridge...
Cool trick. Will this have any impact on CPU/firewall performance however? Maybe there's (should be!) a better way to do this than having to create a whole bridge just for a single variable?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Remote read global variable

Sat Apr 09, 2022 12:54 pm

do not count, but you think so, just disable the bridge....

you can do this with all remote-oid-readable things, not just for bridge... :lol:
 
pe1chl
Forum Guru
Forum Guru
Posts: 10215
Joined: Mon Jun 08, 2015 12:09 pm

Re: Remote read global variable

Sat Apr 09, 2022 2:19 pm

There is a capability to setup scripts that you can run from an SNMP object... see:
https://wiki.mikrotik.com/wiki/Manual:SNMP#Run_Script
When you have a script that outputs something you can run that script and read that output via SNMP.
This requires that you setup a community with write permission, it does not work on the default "public".
 
Puffer
just joined
Topic Author
Posts: 24
Joined: Mon Mar 08, 2010 2:09 pm

Re: Remote read global variable

Sat Apr 09, 2022 4:22 pm

Thanks Gents, we underestimate the value of a forum like this. It is an incredible resource to have access to. :D
 
Puffer
just joined
Topic Author
Posts: 24
Joined: Mon Mar 08, 2010 2:09 pm

Re: Remote read global variable

Mon Apr 11, 2022 10:51 am

There is a capability to setup scripts that you can run from an SNMP object... see:
https://wiki.mikrotik.com/wiki/Manual:SNMP#Run_Script
When you have a script that outputs something you can run that script and read that output via SNMP.
This requires that you setup a community with write permission, it does not work on the default "public".
I understand the script OID is dynamically assigned. Is there any way of ensuring that a script will always get the same OID, ie can the required output script be put first so it will "always" get the same OID. (1.3.6.1.4.1.14988.1.1.18.1.1.2.1) I want to deploy the same script to several routers and use one Zabbix template for all, just changing the IP.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10215
Joined: Mon Jun 08, 2015 12:09 pm

Re: Remote read global variable

Mon Apr 11, 2022 10:56 am

That is not how you are supposed to use SNMP. OIDs ending in indexes can never assumed to be static nor can they assumed to be predictable!
When Zabbix assumes that, it is broken. It should be able to first enumerate a list to find the proper index to use based on searching for a name.
(you are not the first to fall into this trap)
In practice, the index will probably be the sequence in which you created the scripts, and it will not change. But, it could change on reboot.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Remote read global variable

Mon Apr 11, 2022 11:01 am

is not possible to be sure the OID is the same, both on script than on fake bridge or similar

Who is online

Users browsing this forum: 4l4R1 and 18 guests