Community discussions

MikroTik App
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Health readings with v7

Tue Nov 16, 2021 3:39 pm

The health menu (/system/health/) has been restructured. I am reworking a script ("Notify about health state") to work with RouterOS v7 but I do not have devices with all the sensors around. Can you share your output, especially if it contains more than temperature (type=C) or voltage (type=V)? Thanks!
 
bruins0437
newbie
Posts: 33
Joined: Thu Jul 13, 2017 4:30 am
Location: New Hampshire

Re: Health readings with v7

Tue Nov 16, 2021 4:08 pm

This is from my Cloud Core CCR1072.
[admin@NHSHITFW001] > / system health print;
Columns: NAME, VALUE, TYPE
 #  NAME                VALUE  TYPE
 0  power-consumption   50.7   W   
 1  cpu-temperature     40     C   
 2  fan1-speed          4931   RPM 
 3  fan2-speed          5060   RPM 
 4  fan3-speed          4986   RPM 
 5  fan4-speed          5099   RPM 
 6  board-temperature1  27     C   
 7  board-temperature2  25     C   
 8  psu1-voltage        12.1   V   
 9  psu2-voltage        12.1   V   
10  psu1-current        0.3    A   
11  psu2-current        3.9    A   
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Health readings with v7

Tue Nov 16, 2021 4:57 pm

Great, thanks a lot!

I know other devices do have just PSU state (not voltage). Can anybody give an example for these?
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 723
Joined: Tue Dec 17, 2019 1:08 pm

Re: Health readings with v7

Tue Nov 16, 2021 9:32 pm

Guten Abend,


# nov/16/2021 20:31:46 by RouterOS 7.1rc6
# model = CRS328-24P-4S+

/ system health print;
# NAME VALUE TYPE
0 power-consumption 14.2 W
1 cpu-temperature 50 C
2 fan1-speed 2565 RPM
3 fan2-speed 2790 RPM
4 fan3-speed 2145 RPM
5 fan4-speed 2250 RPM
6 board-temperature1 29 C
7 psu1-voltage 26.2 V
8 psu2-voltage 52.3 V
9 psu1-current 0 A
10 psu2-current 0.2 A
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Health readings with v7

Fri Nov 19, 2021 10:46 am

Thanks a lot, much appreciated!

Still missing output with a psu state... Anybody else?
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 723
Joined: Tue Dec 17, 2019 1:08 pm

Re: Health readings with v7

Sat Nov 20, 2021 3:30 am

PSU-State ?
Do you know which models have this output ?
Dual Power supplies Devices?
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Health readings with v7

Sun Nov 21, 2021 3:35 pm

I know that the rack version of CCR1009 has the states for PSUs. I own one, but it runs stable RouterOS in production.

Looks like bigger CCRs have voltage sensors for both PSUs, but no state (see above).
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 723
Joined: Tue Dec 17, 2019 1:08 pm

Re: Health readings with v7

Sun Nov 21, 2021 8:56 pm

Same Problem here...
CCR1009 are all in production use.

Not sure, but i think updating them to V7 is punishable by death :lol:
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Sun Nov 21, 2021 10:02 pm

Interesting Information.

Can some post output of:
 :put [/system health get]
This would then give me a better naming of the variables (to use with Splunk)
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 723
Joined: Tue Dec 17, 2019 1:08 pm

Re: Health readings with v7

Sun Nov 21, 2021 10:04 pm

# nov/16/2021 20:31:46 by RouterOS 7.1rc6
# model = CRS328-24P-4S+

[/system health print as-value]

.id=*10;name=power-consumption;type=W;value=8.9;.id=*11;name=cpu-temperature;type=C;value=54;.id=*1b59;name=fan1-speed;type=RPM;value=0;.id=*1b5a;name=fan2-speed;type=RPM;value=0;.id=*1b5b;name=fan3-speed;type=RPM;value=0;.id=*1b5c;name=fan4-speed;type
=RPM;value=0;.id=*1bbd;name=board-temperature1;type=C;value=30;.id=*1c21;name=psu1-voltage;type=V;value=26.2;.id=*1c22;name=psu2-voltage;type=V;value=52.3;.id=*1c85;name=psu1-current;type=A;value=0;.id=*1c86;name=psu2-current;type=A;value=0.1
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Sun Nov 21, 2021 10:29 pm

Thanks, can you also try:
:put [/system health get]
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 723
Joined: Tue Dec 17, 2019 1:08 pm

Re: Health readings with v7

Sun Nov 21, 2021 10:55 pm

Doesn't seam to work on ROS7
You do not have the required permissions to view the files attached to this post.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Mon Nov 22, 2021 12:02 am

Strange, try:

It works on my CHR router:
[@M-71rc6] > :put [/system/health/get]
state=disabled;state-after-reboot=enabled
Try add all the /
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 723
Joined: Tue Dec 17, 2019 1:08 pm

Re: Health readings with v7

Mon Nov 22, 2021 12:09 am

Result from your Script (:foreach id in=[/system health find] do=....)


.id=*10;name=power-consumption;type=W;value=9.6
.id=*11;name=cpu-temperature;type=C;value=54
.id=*1b59;name=fan1-speed;type=RPM;value=0
.id=*1b5a;name=fan2-speed;type=RPM;value=0
.id=*1b5b;name=fan3-speed;type=RPM;value=0
.id=*1b5c;name=fan4-speed;type=RPM;value=0
.id=*1bbd;name=board-temperature1;type=C;value=30
.id=*1c21;name=psu1-voltage;type=V;value=26.2
.id=*1c22;name=psu2-voltage;type=V;value=52.3
.id=*1c85;name=psu1-current;type=A;value=0
.id=*1c86;name=psu2-current;type=A;value=0.1
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 723
Joined: Tue Dec 17, 2019 1:08 pm

Re: Health readings with v7

Mon Nov 22, 2021 12:13 am

Result of :put [/system/health/get]
You do not have the required permissions to view the files attached to this post.
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 723
Joined: Tue Dec 17, 2019 1:08 pm

Re: Health readings with v7

Mon Nov 22, 2021 12:23 am

It's seams to be a ROS7 problem...

I upgrade the Swich back to ROS version 6.48.5
The Command :put [/system health get] works normally ..
You do not have the required permissions to view the files attached to this post.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Mon Nov 22, 2021 8:12 am

Can you post a support ticket to Mikrotik about this.
What I also see in 6.x I have to devide voltage by 10. But if you look at your post for v7, it give correct voltage:
.id=*1c22;name=psu2-voltage;type=V;value=52.3
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Health readings with v7

Mon Nov 22, 2021 10:52 am

No need to open a support ticket, this is the new intended behavior.

At first I struggled myself, but it makes sense: Every sensor is no longer a property but an item. Think of other items, the sensors behave the same now - try with something like ip addresses.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Mon Nov 22, 2021 11:04 am

Why do I not get the same on my test setup?

On my 7.1 RC 6 CHR router I do get the old format:
  MMM      MMM  III  KKK  KKK  RRR  RRR   OOOOOO      TTT     I

  MikroTik RouterOS 7.1rc6 (c) 1999-2021       https://www.mikr

[xxx@M-71rc6] > :put [/system/health/get]
state=disabled;state-after-reboot=enabled
[xxx@M-71rc6] > 
Also can some other post output of (7.x router):
:foreach id in=[/system/health/find] do={:put [/system/health/get $id]}
I do only get error on the find command on 7.1 RC6 CHR router.
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Health readings with v7

Mon Nov 22, 2021 11:23 am

CHR should behave the same. If it does not that is an issue I guess.
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 723
Joined: Tue Dec 17, 2019 1:08 pm

Re: Health readings with v7

Mon Nov 22, 2021 5:20 pm

Mikrotik-Device : CRS112-8P-4S


-------------------------------------------------------
MikroTik RouterOS 6.48.4 (CRS112-8P-4S)

[admin@MikroTik] > :put [/system health get]
psu1-voltage=275;psu2-voltage=484;temperature=45

[admin@MikroTik] > /system health print
temperature: 45C
psu1-voltage: 27.5V
psu2-voltage: 48.4V
-------------------------------------------------------


-------------------------------------------------------
MikroTik RouterOS 6.49.1 (CRS112-8P-4S)

[admin@MikroTik] > :put [/system health get]
psu1-voltage=275;psu2-voltage=484;temperature=45

[admin@MikroTik] > /system health print
temperature: 45C
psu1-voltage: 27.5V
psu2-voltage: 48.4V
-------------------------------------------------------

-------------------------------------------------------
MikroTik RouterOS 7.1rc6 (CRS112-8P-4S)


[admin@MikroTik] > /system health print
Columns: NAME, VALUE, TYPE
# NAME VALUE TYPE
0 temperature 46 C
1 psu1-voltage 27.5 V
2 psu2-voltage 48.4 V

[admin@MikroTik] > :put [/system health get]
**** NOT Working ****

[admin@MikroTik] > :foreach id in=[/system/health/find] do={:put [/system/health/get $id]}
.id=*e;name=temperature;type=C;value=46
.id=*1c21;name=psu1-voltage;type=V;value=27.5
.id=*1c22;name=psu2-voltage;type=V;value=48.4

-------------------------------------------------------
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 723
Joined: Tue Dec 17, 2019 1:08 pm

Re: Health readings with v7

Mon Nov 22, 2021 5:21 pm

Mikrotik-Device : hEX S


-------------------------------------------------------
MikroTik RouterOS 6.48.5 (hEX S)


[admin@MikroTik] > :put [/system health get]
temperature=60;voltage=477

[admin@MikroTik] > /system health print
voltage: 47.7V
temperature: 60C

-------------------------------------------------------



-------------------------------------------------------
MikroTik RouterOS 6.49.1 (hEX S)


[admin@MikroTik] > :put [/system health get]
temperature=61;voltage=477


[admin@MikroTik] > /system health print
voltage: 47.7V
temperature: 61C

-------------------------------------------------------



-------------------------------------------------------
MikroTik RouterOS 7.1rc6 (hEX S)


[admin@MikroTik] > /system health print
Columns: NAME, VALUE, TYPE
# NAME VALUE TYPE
0 voltage 0.5 V

**** Missing Temp & false Voltage ****

[admin@MikroTik] > :put [/system health get]
**** NOT Working ****

[admin@MikroTik] > :foreach id in=[/system/health/find] do={:put [/system/health/get $id]}
.id=*d;name=voltage;type=V;value=0.5

-------------------------------------------------------
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 723
Joined: Tue Dec 17, 2019 1:08 pm

Re: Health readings with v7

Mon Nov 22, 2021 5:38 pm

Mikrotik-Device : hEX

-------------------------------------------------------
MikroTik RouterOS 6.48.5 (hEX)


[admin@MikroTik] > :put [/system health get]
temperature=42;voltage=273


[admin@MikroTik] > /system health print
voltage: 27.3V
temperature: 42C

-------------------------------------------------------

-------------------------------------------------------
MikroTik RouterOS 6.49.1 (hEX)


[admin@MikroTik] > :put [/system health get]
temperature=41;voltage=273


[admin@MikroTik] > /system health print
voltage: 27.3V
temperature: 42C

-------------------------------------------------------

-------------------------------------------------------
MikroTik RouterOS 7.1rc6 (hEX)


[admin@Mikrotik] > /system health print
Columns: NAME, VALUE, TYPE
# NAME VALUE TYPE
0 voltage 0.5 V

**** Missing Temp & false Voltage ****

[admin@MikroTik] > :put [/system health get]
**** NOT Working ****

[admin@MikroTik] > :foreach id in=[/system/health/find] do={:put [/system/health/get $id]}
.id=*d;name=voltage;type=V;value=0.5

-------------------------------------------------------
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Mon Nov 22, 2021 7:26 pm

Can someone else with v7+ RouterOS test what of the two command below gives output.
:put [/system health get]
:foreach id in=[/system/health/find] do={:put [/system/health/get $id]}
It will be hard (not impossible) to make a script when same version of RouterOS need two different script, depending on hardware.
 
User avatar
deadkat
Frequent Visitor
Frequent Visitor
Posts: 57
Joined: Sun Nov 15, 2020 11:14 pm
Location: Alabama, USA

Re: Health readings with v7

Tue Nov 23, 2021 6:02 pm

From my RB4011, running RC6, output looks like this:
[admin@RouterOS] > :put [/system health get]
number: 0
.id=*d;name=voltage;type=V;value=24.1
[admin@RouterOS] > :foreach id in=[/system/health/find] do={:put [/system/health/get $id]}
.id=*d;name=voltage;type=V;value=24.1
.id=*e;name=temperature;type=C;value=36
[admin@RouterOS] > :put [/system health get num=0]
.id=*d;name=voltage;type=V;value=24.1
[admin@RouterOS] > 


edit:
for eworm:
[admin@RouterOS] > /system/health/print
Columns: NAME, VALUE, TYPE
#  NAME         VALUE  TYPE
0  voltage      24.1   V   
1  temperature  36     C   
[admin@RouterOS] > 
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Tue Nov 23, 2021 6:43 pm

From my RB4011, running RC6, output looks like this:
Strange that you do not get temperature from:
put [/system health get]
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Health readings with v7

Tue Nov 23, 2021 9:50 pm

From my RB4011, running RC6, output looks like this:
Strange that you do not get temperature from:
put [/system health get]
He answered the interactive prompt with "0", so this is correct.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Tue Nov 23, 2021 10:23 pm

Did not see that :)
So
:put [/system health get]
in his case does not give any output without adding an id.

Hope that MT fixes this so that all system works equal on same OS version.
My CHR 7.1rc6 does not work with the find:
:foreach id in=[/system/health/find] do={:put [/system/health/get $id]}
bad command name find (line 1 column 33)
And this command does not work on 6.x at all, so need som on-error in the script.
Output are also different so Splunk need to be modded to accept different output. ARG

Tested 7.1rc6 on an SXT 5HPnD, there new method works.
:foreach id in=[/system/health/find] do={:put [/system/health/get $id]}
.id=*d;name=voltage;type=V;value=24
.id=*e;name=temperature;type=C;value=37
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Tue Nov 23, 2021 11:31 pm

Then we have a solution that works on both version without testing for RouteOS version.
: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"
	}
}
Script test the new method first, and if that fails, it will run the old version.
Now the work on Splunk have to be done with handling two different output.
Last edited by Jotne on Wed Nov 24, 2021 6:12 pm, edited 1 time in total.
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 723
Joined: Tue Dec 17, 2019 1:08 pm

Re: Health readings with v7

Wed Nov 24, 2021 12:16 am

@Jotne,
do you still need help with testing ?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Wed Nov 24, 2021 12:13 pm

No, thank you
Did setup a box with RuterOS 7.1rc6.
Terminal is very slow, so something is wrong.
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Health readings with v7

Wed Nov 24, 2021 12:35 pm

The terminal is indeed veeeeeeeeeeery slow. I assume that Mikrotik still have debug/test flag active that slows it that much down.
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Health readings with v7

Wed Dec 08, 2021 4:58 pm

Now that RouterOS v7 has a stable branch it should spread a lot more.
Anybody around with a rack mount CCR1009 who can provide the output?
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Health readings with v7  [SOLVED]

Fri Dec 10, 2021 4:12 pm

Answering myself...
[admin@MikroTik] > /system/health/print 
Columns: NAME, VALUE, TYPE
#  NAME               VALUE  TYPE
0  voltage            15.2   V   
1  temperature        34     C   
2  power-consumption  11.5   W   
3  cpu-temperature    54     C   
4  current            0.7    A   
5  fan1-speed         5693   RPM 
6  psu1-state         ok         
7  psu2-state         ok
The type for psu-state is an empty string... 🤪

MikroTik, is that expected?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Fri Dec 10, 2021 5:53 pm

It would (for me and Splunk prosjekt) be interesting to see different type of health output.

Can all with 7.1 on different type of Routers pot output and system info of
{
:put [/system/routerboard/get model]
:foreach id in=[/system health find] do={
	:local health "$[/system health get $id]"
	:put "$health"
}
}
My test router:
SXT 5HPnD r2
.id=*d;name=voltage;type=V;value=12.2
.id=*e;name=temperature;type=C;value=16
Large routers would give more Information.
 
User avatar
deadkat
Frequent Visitor
Frequent Visitor
Posts: 57
Joined: Sun Nov 15, 2020 11:14 pm
Location: Alabama, USA

Re: Health readings with v7

Fri Dec 10, 2021 6:17 pm

RouterBOARD 3011UiAS
.id=*d;name=voltage;type=V;value=27.8
.id=*e;name=temperature;type=C;value=22
RB4011iGS+
.id=*d;name=voltage;type=V;value=24.5
.id=*e;name=temperature;type=C;value=29
RB4011iGS+5HacQ2HnD
.id=*d;name=voltage;type=V;value=24.4
.id=*e;name=temperature;type=C;value=27
CRS226-24G-2S+
.id=*d;name=voltage;type=V;value=24.9
.id=*e;name=temperature;type=C;value=23
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Health readings with v7

Sat Dec 11, 2021 12:47 am

CCR1009-7G-1C-1S+
.id=*d;name=voltage;type=V;value=15.2
.id=*e;name=temperature;type=C;value=34
.id=*10;name=power-consumption;type=W;value=11.5
.id=*11;name=cpu-temperature;type=C;value=54
.id=*12;name=current;type=A;value=0.7
.id=*1b59;name=fan1-speed;type=RPM;value=5713
.id=*1ce9;name=psu1-state;type=;value=ok
.id=*1cea;name=psu2-state;type=;value=ok
CRS328-24P-4S+
.id=*10;name=power-consumption;type=W;value=47.2
.id=*11;name=cpu-temperature;type=C;value=58
.id=*1b59;name=fan1-speed;type=RPM;value=405
.id=*1b5a;name=fan2-speed;type=RPM;value=795
.id=*1bbd;name=board-temperature1;type=C;value=32
.id=*1c21;name=psu1-voltage;type=V;value=25.6
.id=*1c22;name=psu2-voltage;type=V;value=51.1
.id=*1c85;name=psu1-current;type=A;value=0.7
.id=*1c86;name=psu2-current;type=A;value=0.5
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Sat Dec 11, 2021 11:22 am

Some PSU give only OK (and not OK I guess)
Other PSU gives Ampere and Volt.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Sat Dec 11, 2021 4:44 pm

Anyone know what this shows when a PSU is bad?
.id=*1ce9;name=psu1-state;type=;value=ok
Edit:
It may be "fail" as show in this post:
viewtopic.php?t=141553
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Health readings with v7

Thu Dec 16, 2021 10:28 pm

Yes, it's "fail":
.id=*d;name=voltage;type=V;value=24.2
.id=*e;name=temperature;type=C;value=34
.id=*10;name=power-consumption;type=W;value=24.9
.id=*11;name=cpu-temperature;type=C;value=57
.id=*12;name=current;type=A;value=1
.id=*1b59;name=fan1-speed;type=RPM;value=6573
.id=*1ce9;name=psu1-state;type=;value=ok
.id=*1cea;name=psu2-state;type=;value=fail
 
User avatar
stewartpe
just joined
Posts: 15
Joined: Wed Dec 12, 2007 7:49 pm

Re: Health readings with v7

Fri Jun 17, 2022 8:00 pm

Using Values In v7 Scripts
The next step is to extract a value to use in a script. Here's an example of monitoring psu2-voltage to detect a low battery condition:
1. Determine item number with /system/health/print.
Image
2. Create a script. Let's call it "battery". Policy read, reboot, write, test.
# Set to item number you want to read.
:local health "$[/system health get 3]"
# Extract "value" from the array.
:local volts ($health->"value")
# Verify that you're getting the result you want. Comment out the next line when you're satisfied.
:log info message=$volts
# Set the voltage threshold here.
:if ($volts < 24.0) do={
:log warning "Battery Low $volts V"
# Send an email or a text to yourself. Text to AT&T cellphones: yournumber@txt.att.net
/tool e-mail send to="yourname@yourdomain.com" body="Router52 Battery Low $volts V"
}
Image
3. Create a schedule. Let's call it "battery". Policy read, reboot, write, test.
Interval: 1 hour
On event: battery
Image
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Mon Jun 20, 2022 12:23 pm

You should never use internal ID in script. They changes all the time.

Some like this should do.
:local health [/system health get [find name="psu2-voltage"]]
 
User avatar
panisk0
newbie
Posts: 25
Joined: Sun Mar 06, 2016 10:36 pm
Location: Cracow
Contact:

Re: Health readings with v7

Tue Aug 23, 2022 10:30 pm

RB5009UG+S+ v7.4

v6 code
:put [/system health get temperature]

v7 code
:put ([/system health get 0]->"value")
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Wed Aug 24, 2022 8:52 am

Here is the script I do use in MikroTik App for Splunk to get health reading for bot v6 and v7. This gets all health settings.
: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"
	}
}
I could have used a test for RouterOS version and selected correct part to run.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Health readings with v7

Thu Aug 25, 2022 2:59 pm

Tested on RuterOS v6.48.6 / v7.2.1, on this way do not give any errors on script on both v6 and v7, without use on-error.
Not tested on CHR
{
    :local ros [:pick [/system resource get version] 0 1]

    :if ($ros = "7") do={
        :put ([/system health get [find where name="cpu-temperature"]]->"value")
    } else={
        :put ([/system health print as-value]->"temperature")
    }
}
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Health readings with v7

Thu Aug 25, 2022 9:47 pm

CHR fails.
{...     :local ros [:pick [/system resource get version] 0 1]
{...                                                          
{...     :if ($ros = "7") do={
{{...         :put ([/system health get [find where name="cpu-temperature"]]->"value")
{{...     } else={                                                                    
{{...         :put ([/system health print as-value]->"temperature")
{{...     }                                                        
{... }
bad command name find (line 5 column 36)
I do use this to take care of CHR and other devices without health:
:if (!([/system health get]~"(state=disabled|^\$)")) do={
hEX 7.2.3 does not work:
 {
{...     :local ros [:pick [/system resource get version] 0 1]
{...                                                          
{...     :if ($ros = "7") do={
{{...         :put ([/system health get [find where name="cpu-temperature"]]->"value")
{{...     } else={                                                                    
{{...         :put ([/system health print as-value]->"temperature")
{{...     }                                                        
{... }
no such item
This :if ($ros = "7") do={ may by change to :if ($ros > "6") do={ to handle RouterOS 8.x etc :)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Health readings with v7

Fri Aug 26, 2022 10:44 am

For sure, if any 8.x exist on future, the syntax is changed again... :roll:
 
deanz
just joined
Posts: 1
Joined: Mon Feb 10, 2020 5:38 pm

Re: Health readings with v7

Thu Oct 27, 2022 9:43 am

my script to send temperature over telegram:
#---- send temperature to telegram if > 60C
:local temperatura [/system/health get [find name=cpu-temperature] value]
#or
#:local temperatura [/system/health get [find name=temperature] value]
#:local volts [/system/health get [find name=voltage] value]
#...
:local emessage ""
:global sendCPUTemperature
#:log warning $temperatura;
##
{
 #create variable
  :if ($sendCPUTemperature<0) do={
    :global sendCPUTemperature 0
    }
  #check temp limit
    :if ($temperatura>60 && $sendCPUTemperature=0) do={
      :set emessage "Temp CPU HIGH: $temperatura C"
      :global telegramMessage $emessage
      #system script run SendToTelegram
      :log warning $emessage;
      :global sendCPUTemperature 1
      :delay 3;
    } 
    # send on telegram only when the temperature drop 
    :if ($temperatura<60 && $sendCPUTemperature=1) do={
      :set emessage "Temp CPU OK: $temperatura C"
      :log warning $emessage;
      :global sendCPUTemperature 0
      :global telegramMessage $emessage
      /system script run SendToTelegram
      :delay 3;  
    }
}
script for telegram - name:"SendToTelegram":
:global telegramMessage
:local botid
:local chatid

:local CurDate [/system clock get date] 
:local CurTime [/system clock get time] 
:local CurIdent [/system identity get name] 

set botid "xxxxxxxxx:yourbootidcode"
set chatid "xxxxxxxxx"

if ($telegramMessage != "") do={
   /tool fetch url="https://api.telegram.org/bot$botid/sendmessage?chat_id=-$chatid&text=$telegramMessage %0A >>>$CurIdent" \
   keep-result=no
set telegramMessage ""
}
 
dima1002
Member Candidate
Member Candidate
Posts: 160
Joined: Fri Jan 26, 2018 8:40 pm

Re: Health readings with v7

Mon Dec 12, 2022 7:22 am

does this also work with whatsapp or pushover?
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 11383
Joined: Thu Mar 03, 2016 10:23 pm

Re: Health readings with v7

Mon Dec 12, 2022 12:20 pm

As long as you have a simple "API" call which can be used to push message ... telegram has a pretty simple "API", everything is encoded into URL.
 
Keybet
just joined
Posts: 2
Joined: Sun Sep 22, 2019 5:23 am

Re: Health readings with v7

Thu Nov 23, 2023 12:47 pm

/system health
# Version7.xx
:local psu1voltage ([/system health get [find where name="psu1-voltage"]]->"value")
:if ($psu1voltage < 23) do={
:log info "Sending email alert..."
/tool e-mail send server=x.x.x.x to=alerts@yyyyyyy.net subject=([/system identity get name] . " - Low Voltage Alert") from="noc@yyyyyyy.net" body=("Low voltage alert. Current voltage is: " . $psu1voltage)
} else={
:log info "Voltage is ok."
}


my simple code to log psu1 voltage and send an email alert when below 23V
set email tool accordingly.

Who is online

Users browsing this forum: NxtGen [Bot], Semrush [Bot] and 22 guests