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.
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
[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
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?
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… ![]()
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”.
Thanks Gents, we underestimate the value of a forum like this. It is an incredible resource to have access to. ![]()
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.
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.
is not possible to be sure the OID is the same, both on script than on fake bridge or similar
I spent a few years with this dilemma of how to query via SNMP some global variables generated by custom scripts with indicators that I would like to display in The Dude and in other monitoring systems like Zabbix.
In fact, it is possible to do this using remote execution of scripts via snmp and returning their values, but this did not really please me, as the OID for the same script on different routers could be different, as the scripts are executed by their indexes and not by their names.
This makes configuration in the monitoring system very difficult, but worse than that, a wrong configuration could simply cause another script to be executed in place of the one that only had the function of returning information, which is really very bad.
Using a fake disabled bridge to look for its name that could be changed by the script to the content of the variable was one of the ways I saw other members suggested.
This approach solves the problem of executing an inappropriate script, but does not solve the issue of the OID being different between different routers.
The solution I found that solved my problem was to use the “system note” function, which is a space where you can create a complete text with several lines and you can consult it by OID (“1.3.6.1.4.1. 14988.1.1.7.5.0”).
So just create a script that brings together all the variables you want to use and writes them to the “system note”, putting this script to run through the scheduler from time to time as needed.
:global LinkAtivo
:global PercentLossPrincipal
:global MPLoss
:global PercentLossBackup
:global MBLoss
system note set note="Link: $LinkAtivo
Perda Prin: $PercentLossPrincipal
Media Prin: $MPLoss
Perda Back: $PercentLossBackup
Media Back: $MBLoss"
It is possible to consult it with the read-only public community, the OID will always be the same regardless of the router, we do not run the risk of executing a script by mistake and it is possible to store a lot of information in this field.
root@Syslog:~# snmpget -v1 -cpublic 10.100.203.1 1.3.6.1.4.1.14988.1.1.7.5.0
iso.3.6.1.4.1.14988.1.1.7.5.0 = STRING: "Link: PRINCIPAL
Perda Prin: 0
Media Prin: 0
Perda Back: 0
Media Back: 0"
On the monitoring side, simply create functions to filter with regular expressions and extract only the variable you want for that specific query.
And “Voilá” we have it resolved.