Community discussions

MikroTik App
 
kispalsz
just joined
Topic Author
Posts: 5
Joined: Sun Jul 30, 2023 9:41 pm

V6 v7 universal health report to local/global variable list

Mon Sep 04, 2023 8:32 pm

Please help! I always get stuck.

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]";
 
kispalsz
just joined
Topic Author
Posts: 5
Joined: Sun Jul 30, 2023 9:41 pm

Re: V6 v7 universal health report to local/global variable list

Tue Sep 05, 2023 10:16 am

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"
}
Output:
09:09:10 script,info Value_1: 23.9
09:09:10 script,info Value_2:
09:09:10 script,info Value_3 : 31
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?

Thanks.

Please help! I always get stuck.

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]";
 
drpioneer
just joined
Posts: 10
Joined: Mon Nov 01, 2021 8:33 am

Re: V6 v7 universal health report to local/global variable list

Fri Nov 17, 2023 7:58 am