no, internal scripting language cannot do that for you. you either have to use Expect scripting language since ssh and telnet is more interactive interface and it is not possible do SNMP queries from within the RouterOS.
if you have some linux host in your network then you can set up it to monitor devices using the Dude or already named expect script.
There’s also API… it’s the most reliable way to do this in fact (using stuff like Expect will produce odd results if the shell UI changes a little; with API, if stuff changes in an incompatible way, you’ll know, and could potentially deal with it).
yes, completely forgot to mention API as a way to communicate with the router. That should be considered the safest way how to communicate with the router as devs also have promised to not to make changes to protocol itself, however commands may change along with the CLI changes.