Scripting

Hi,

Does anyone know if it is possible to call API commands from the inbuilt scheduler.

IN simple terms what I am trying to achieve is a HTTP POST. The reason behind this is to be able to send on an interval, say every 60 minutes variables to a web server and log the results.

The reason for doing it router side rather than server side, is that some of our devices site on ‘internal corporate networks’ and we cannot get external access inbound to the devices.

I have achieved what I want using the ‘/tools email’ command, but i’d prefer a HTTP post.

Many Thanks,

Alex

It is not possible to call api commands from scheduler.

You can forward port from the gateway to internal router and then connect to the router from your server.

Hi,

These are situations where we cannot get a port forwarded inbound. Hence the need for having something that is sent from the routerboard to a http / https server.

Regards,

Alex

Try this:

/tool fetch mode=http host=<server> src-path=("/path/to/page?router=" . [/system identity get name] . "&var1=" . $var1 . "&var2=" . $var2 . "&var3=" . $var3 ....")

It uses HTTP GET not POST, so server will have to handle it as a get request.
Also, you’ll have to format variables with url encoding to be interpreted by server properly.

EDIT: fixed typos

Alternate solution would be to run up a MetaRouter or KVM guest and run whatever you want on those, which would give you more flexibility.

The wiki has info detailing how to do each:
http://wiki.mikrotik.com/wiki/Manual:Metarouter#Building_your_own_OpenWRT_image (installing an OpenWRT image as a MetaRouter)
http://wiki.mikrotik.com/wiki/Manual:KVM