I know Jotne’s health report solution, which also works for Mikrotik routerOs v6 and V7.
:do {
New version
:foreach id in=[/system health find] do={
:local health “$[/system health get $id]”
:set ( “$health”->“script” ) “health”
:log info message=“$health”
}
} on-error={
Old version
:if (!([/system health get]~“(state=disabled|^$)”)) do={
:local health “$[/system health get]”
:set ( “$health”->“script” ) “health”
:log info message=“$health”
}
}
My problem is that I want to store the values read by the script in variables.
That is, I want to use a script for both V6 and V7.
How can the output of the above commands be split up and stored in a single variable?
What I’m looking for the solution the most is version 7. Although I know how to ask for all possible values one by one, but if, for example, the PSU1 FAN does not exist, the script stops with an error.
like:
set healthfan1speed “[/system health get value-name=fan1-speed]”;
When I run it like this in V7 routerOS, this is the output, correctly:
{
:local voltage [/system/health get [find where name=voltage] value]
:put $voltage
# :local cputemp [/system/health get [find where name=cpu-temperature] value]
:put $cputemp
:local temp [/system/health get [find where name=temperature] value]
:put $temp
:log info "Value_1: $voltage"
:log info "Value_2: $cputemp"
:log info "Value_3 : $temp"
}
But if I remove the # ( :local cputemp…) , the script doesn’t run.
{
:local voltage [/system/health get [find where name=voltage] value]
:put $voltage
:local cputemp [/system/health get [find where name=cpu-temperature] value]
:put $cputemp
:local temp [/system/health get [find where name=temperature] value]
:put $temp
:log info "Value_1: $voltage"
:log info "Value_2: $cputemp"
:log info "Value_3 : $temp"
}
There is no cpu-temperature health information collection on the device, so it may stop due to an error. How can this error be avoided?