my Script to Beep MB buzzer if pool degraded

SMnasMAN

Contributor
Joined
Dec 2, 2018
Messages
177
i was surprised there is no audible alarm on a pool degrade (ie disk failure). I come from the enterprise / hw raid world and audible alarms are everywhere bc they are the most reliable (vs email or sms alerts) - for the most important alerts (of which, for FN there is no more important alert). I searched pretty hard on google and forums, and could not find anything like this. Depending upon your noise level, it may be hard to hear the buzzer , so do test this (just change DEGRADED to ONLINE in the script). i have 4x sm servers on a rack and was able to hear the buzzer nicely (fans on them ~3k rpm). even when i set 2 of the server to run their fans at 6k rpm , i could still hear it (however at full, 8k rpm fans on 2x servers, i could NOT hear it).

After thinking about it, i think the reason ixSys does not include an audible alarm in freenas is they cant guarantee it will work as users have different MB / hardware (so some wo any buzzer on mb), so they dont want to create a scenario where users expect to hear an alarm (when ixSys is hard pressed to guarantee that an alarm/buzzer will universally work due to users' differentiating hardware). ie on their TrueNAS paid line, there is a blue/red light on the chassis bezel that preforms this function (however they should still have an audible alarm imo). Im not against email alerts, but it should be audable alarm + email alerts. email can be un-reliable, requires LAN+internet (often), and expecting users to look at a 3am email report *every single day* is unseasonably burden sum (depending upon how you freenas is used).

another , even remote/offisite / different room- buzzer solution, would be to use a cheap mikrotik router($20-$50), with a on pcb buzzer (most have them), and then have the FN server send a snmpget request to the mikrotik's IP , which will trigger a script to run on the MT (which will sound the mikrotik's buzzer at various hz / levels). if anyone is interested in this, reply and i can give u all info to do it. you could even have the mt do a short different hz beep if it cant reach the FN box/boxes.

so i made this rough script to every 5min scan zpool status for the word DEGRADED, and if so then keep beeping the motherboard buzzer. I have only tested this on supermicro MB buzzers (tested on X8 , X9 , X10 sm MBs- works and is loud enough over fans) - i am using the standard freebsd method for beeping the bios/mb buzzer : printf "\007" > /dev/ttyv6 , so it should work on other MB types w on-board (or dongle) buzzers. Please lmk if im missing some other terms to grep for, or if there is a better way to do this.

I schedule cron (via gui, for persistence) to run this script every 5min, if it should fire, the alarm sounds for 3min, then 5min later will run again for 3min (until u disable cront task, or pool is not degraded).

1- scp the script to your FN box, or copy paste via vi/ee - (either put on a pool, or i put it on /root/ if you have recent version of FN with /root/ persistance)
2- chmod +x scriptname.sh

3- add gui cront entry for every X minutes. ( i do every 5min , so it keeps repeating till if fix HDD)
(if you want to test if buzzer works on your MB, just copy paste this into ssh/cli:
printf "\007" > /dev/ttyv6

(should hear a short beep)

Code:
#!/usr/local/bin/bash
if zpool status -v | grep -q DEGRADED; then
echo Degraded Found
logger buzzerAlarm a pool is DEGRADED SOUND MB BUZZER
# run alarm 1800 times every .1 sec = sounds beeper for 180s / 3min exactly
    for i in {1..1800}
    do
    sleep 0.1
    printf "\007" > /dev/ttyv6
    done
# send to local and remote log
logger buzzerAlarm script JUST FINISHED fireing for 3min bc pool DEGRADED
else
echo phrase not found
# only occasionally (1 in 12 chance) send a log msg showing this script is running/working
if (( RANDOM % 12 )); then
logger buzzerAlarm script is running every 5min log msgs are random time
fi
fi


a cool side effect of logger is that the web gui will keep scrolling the DEGRADED message every 3 -5 minutes when degraded. nice to grab attention (in case you miss the red alert in top right, the more alerts the better on a degrade imo)

loggerCapture.PNG



pls lmk any feedback, thanks!
 
Last edited:

SMnasMAN

Contributor
Joined
Dec 2, 2018
Messages
177
am i missing someting (ie does this type of feature already exist somewhere?) or is there a better way to do a beep / alarm?
thanks
 

msturtz

Cadet
Joined
Mar 29, 2018
Messages
6
I landed on this thread looking for this as well. I'm working with an HP MicroServer Gen10 -- it doesn't seem to have a buzzer. I wonder if anybody has tried to do this using an external noise maker like this (or even an interface to a dry-contact that could turn on a buzzer)?

My use-case is simple. I'm a home-user, on a cable-modem. I probably COULD make it send email, but it would need monitoring/testing to make sure it works (for example, every time my password changed it would stop working). Since I'm in the house almost every day, an audible alert would be easy, simple, reliable.

Another option would be integration with a service that would let it send an email or a text message directly. Even still, in this case I'd prefer the beeper.
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
I have created a script file called dk.sh in the pool and added it to execute every 1 minute in the scheduled task, the task also runs successfully, but the buzzer doesn't sound when the pool is degraded. When I use printf "\007" > /dev/ttyv0 to test, I can hear the sound.

Excuse me, where did I go wrong?
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
where did I go wrong?
It's likely to be the path not being the same in the cron context as your interactive shell.

Try identifying the correct full path with which printf and then replace printf in the script with that full path.

On my system, I see that under bash, it's /usr/bin/printf....

However... when I just try that from zsh (the default shell on CORE), I see that it's a builtin function, so actually separate code, which may explain a difference in outcome. Test /usr/bin/printf at a bash shell and see if it works the same.
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
It's likely to be the path not being the same in the cron context as your interactive shell.

Try identifying the correct full path with which printf and then replace printf in the script with that full path.

On my system, I see that under bash, it's /usr/bin/printf....

However... when I just try that from zsh (the default shell on CORE), I see that it's a builtin function, so actually separate code, which may explain a difference in outcome. Test /usr/bin/printf at a bash shell and see if it works the same.
Please forgive me, I am still a novice user, and I don't understand what you said, can you briefly explain how to operate it?
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
printf "\007" > /dev/ttyv0
I would start by trying the script with the line looking like this instead: /usr/bin/printf "\007" > /dev/ttyv0

You could test that manually first by changing the Shell to bash (type bash <ENTER>) then /usr/bin/printf "\007" > /dev/ttyv0 (and exit when done to go back to the default zsh shell)
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
I would start by trying the script with the line looking like this instead: /usr/bin/printf "\007" > /dev/ttyv0

You could test that manually first by changing the Shell to bash (type bash <ENTER>) then /usr/bin/printf "\007" > /dev/ttyv0 (and exit when done to go back to the default zsh shell)
Entering /usr/bin/printf "\007" > /dev/ttyv0 in the shell can indeed hear the buzzer sound, but it does not take effect when put into the script, so there is no sound
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Entering /usr/bin/printf "\007" > /dev/ttyv0 in the shell can indeed hear the buzzer sound
Did you change to the bash shell first?
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
Did you change to the bash shell first?
In the Shell first enter: bash
Then enter: /usr/bin/printf "\007" > /dev/ttyv0
This is with audio feedback.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
OK; so then you change the same line in the script... and it should work.

Is your pool degraded?
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
OK; so then you change the same line in the script... and it should work.

Is your pool degraded?
#!/usr/local/bin/bash
if zpool status -v | grep -q DEGRADED; then
echo Degraded Found
logger buzzerAlarm a pool is DEGRADED SOUND MB BUZZER
# run alarm 1800 times every .1 sec = sounds beeper for 180s / 3min exactly
for i in {1..1800}
do
sleep 0.1
/usr/bin/printf "\007" > /dev/ttyv0
done
# send to local and remote log
logger buzzerAlarm script JUST FINISHED fireing for 3min bc pool DEGRADED
else
echo phrase not found
# only occasionally (1 in 12 chance) send a log msg showing this script is running/working
if (( RANDOM % 12 )); then
logger buzzerAlarm script is running every 5min log msgs are random time
fi
fi

My pool has been downgraded, but no sound is coming out like this
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
can you show the output from zpool status?
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
can you show the output from zpool status?
root@truenas[~]# zpool status
pool: boot-pool
state: ONLINE
scan: scrub repaired 0B in 00:00:28 with 0 errors on Tue Mar 14 03:45:28 2023
config:

NAME STATE READ WRITE CKSUM
boot-pool ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
da1p2 ONLINE 0 0 0
da0p2 ONLINE 0 0 0

errors: No known data errors

pool: zpool
state: DEGRADED
status: One or more devices has been removed by the administrator.
Sufficient replicas exist for the pool to continue functioning in a
degraded state.
action: Online the device using zpool online' or replace the device with
'zpool replace'.
scan: resilvered 472K in 00:00:00 with 0 errors on Tue Mar 14 13:11:41 2023
config:

NAME STATE READ WRITE CKSUM
zpool DEGRADED 0 0 0
mirror-0 DEGRADED 0 0 0
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Do you see "Degraded Found" appear on the screen when the script runs?
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Do you mean these places?
No.

In the same shell where you had tested the printf command, run the script like ./script.sh (whatever you called it)... then see on that same shell screen what comes out.

Also please show how you set the cron command.
 

dktech

Explorer
Joined
May 30, 2019
Messages
69
No.

In the same shell where you had tested the printf command, run the script like ./script.sh (whatever you called it)... then see on that same shell screen what comes out.

Also please show how you set the cron command.
Please forgive me, I still don't understand what you mean, and how should I operate?
 
Top