Scripts to report SMART, ZPool and UPS status, HDD/CPU T°, HDD identification and backup the config

melp

Explorer
Joined
Apr 4, 2014
Messages
55
Hey, I've been using your script and it looks great on my iPhone, much easier to read the info and saves me from opening my normal mail client to view.

Just a question, is there any possibility you can add functionality like @Spearfoot 's script where it automatically detects the drives, pools and hostname? I find that a big quality of life improvement, as it saves me having to adjust my scripts every time I add pools or drives.
Sure! I can work on something like that this week.
 

melp

Explorer
Joined
Apr 4, 2014
Messages
55
e39574a8-908a-42b2-bf17-179842641eb6
Updated version of the report here: https://github.com/edgarsuit/FreeNAS-Report

I added logic to auto-detect drives (omitting SSDs) and pools. I also played around with the columns a bit (added a SMART summary column and last test type column). Let me know if anyone else has suggestions/requests.

xPcW20d.png
 

Xyrgh

Explorer
Joined
Apr 11, 2016
Messages
69
Awesome work @melp!

/edit It's not finding my SSDs that are direct connected to my motherboard, ada0,ada1,ada2,ada3.

Also, it's showing temperatures as '32°C' in Outlook, looks fine on my iPhone though.
 

melp

Explorer
Joined
Apr 4, 2014
Messages
55
Awesome work @melp!

/edit It's not finding my SSDs that are direct connected to my motherboard, ada0,ada1,ada2,ada3.

Also, it's showing temperatures as '32°C' in Outlook, looks fine on my iPhone though.
I have it intentionally omitting SSDs because the SMART data they track doesn't correspond to the values in the table. Any SSDs added to the list will show blanks or zeros for almost all values. If you want to see for yourself, edit line 23 in the script from:

Code:
if ([ "$(smartctl -i /dev/${drive} | grep "SMART support is: Enabled")" ] && ! [ "$(smartctl -i /dev/${drive} | grep "Solid State Device")" ]); then


...to...

Code:
if [ "$(smartctl -i /dev/${drive} | grep "SMART support is: Enabled")" ]; then


Outlook for iOS also renders the degrees symbol weird for me... not sure what's causing that. Outlook 365 seems to render it fine, as does gmail. I'll look into it.
 

Xyrgh

Explorer
Joined
Apr 11, 2016
Messages
69
I have it intentionally omitting SSDs because the SMART data they track doesn't correspond to the values in the table. Any SSDs added to the list will show blanks or zeros for almost all values. If you want to see for yourself, edit line 23 in the script from:

Code:
if ([ "$(smartctl -i /dev/${drive} | grep "SMART support is: Enabled")" ] && ! [ "$(smartctl -i /dev/${drive} | grep "Solid State Device")" ]); then


...to...

Code:
if [ "$(smartctl -i /dev/${drive} | grep "SMART support is: Enabled")" ]; then


Outlook for iOS also renders the degrees symbol weird for me... not sure what's causing that. Outlook 365 seems to render it fine, as does gmail. I'll look into it.

Thanks. Now that I look at my old report, the only values the SSDs give are temperature and power on hours. My two newer SSDs also give me pending sectors and offline uncorrectable, but that's it. Almost not worth having in the report, but thanks for giving me the option :smile:
 
Joined
Jul 3, 2015
Messages
926
This is brill thanks. Im not getting any info in the 'SMART Status Report Summary' however but might be because Im using SAS drives?
 

Chris Moore

Hall of Famer
Joined
May 2, 2015
Messages
10,080
Correct, I haven't done a SAS version for the HTML table-based script.
I have a system with no internet access to be able to send an email. Can you make a version of this that saves a file in a specified location for review?
 

melp

Explorer
Joined
Apr 4, 2014
Messages
55
That's basically what it does already. Delete the last line in the script that removes the logfile and then try to open that file with a web browser. If it doesn't work, you may need to echo some <html> and </html> tags at the beginning and end of the script.
 

Chris Moore

Hall of Famer
Joined
May 2, 2015
Messages
10,080
I got it working by copying report.zip to the server, unzipping it and then editing it with nano.

For some crazy reason, copying it out of my ever reliable text editor and pasting it into nano via the terminal wasn't giving the expected result. I updated the terminal program recently, and I wonder if perhaps something is awry with the new version. Or maybe some arcane preference got changed.

Thanks.
I had the same problem and I fixed it by making my terminal full screen. I use Cygwin Terminal on Windows to SSH into my systems and when it hit the edge of the Cygwin terminal it was word wrapping to the next line when it needed to scroll horizontally. I don't think it is a problem with Cygwin, but a problem with nano in a terminal window. I tried it on a CentOS system logged in at the GUI and had the same problem using nano. If you make the terminal window wider either with Cygwin or with the terminal window on Gnome it works fine to copy and paste. With the word wrap problem, lines that should all be together were being broken in the middle.
 

Chris Moore

Hall of Famer
Joined
May 2, 2015
Messages
10,080
That's basically what it does already. Delete the last line in the script that removes the logfile and then try to open that file with a web browser. If it doesn't work, you may need to echo some <html> and </html> tags at the beginning and end of the script.
You have a great bit of code here. I got it working on both of my FreeNAS systems last night and took it into work with me this morning.
Unfortunately for me, the system I wanted to run this on that has no Internet access is CentOS and this script will not run on it because of the ''sysctl -n kern.disks". It there is no kern.disks in CentOS. I spent some time looking at it today but I have not done any bash scripting in over a decade and even when I was doing it, I never did anything this sophisticated.
CentOS has a directory /dev/disk/by-partid that appears to list only the disks in the zpool.
 
Joined
Jun 26, 2012
Messages
260
e39574a8-908a-42b2-bf17-179842641eb6
Updated version of the report here: https://github.com/edgarsuit/FreeNAS-Report

I added logic to auto-detect drives (omitting SSDs) and pools. I also played around with the columns a bit (added a SMART summary column and last test type column). Let me know if anyone else has suggestions/requests.

xPcW20d.png

This is soooo awesome. The OP and these updates are incredibly helpful.
 
Joined
Jun 26, 2012
Messages
260
Correct, I haven't done a SAS version for the HTML table-based script.
I'm pretty noobish here, but...I have 3 disks on SAS and 5 on SATA, and I got info back on the summary. Was this update made
or am I doing something wrong and I don't actually have SAS drives?

Have a Supermicro X11SSL-CF (6 SATA) and LSI3008 HBA

Code:
SMART Status Report Summary
Device Serial
Number SMART
Status Temperature Power-On
Hours Start/Stop
Count Spin Retry
Count Reallocated
Sectors Reallocation
Events Current
Pending
Sectors Offline
Uncorrectable
Sectors UltraDMA
CRC
Errors Seek
Error
Health Last Test
Age (days) Last Test
Type
/dev/ada1 WD-WCC4N1ZK03JV PASSED 31°C 586 16 0 0 0 0 0 0 200% 0 Short
/dev/ada2 WD-WCC4N2VRX064 PASSED 32°C 586 16 0 0 0 0 0 0 200% 0 Short
/dev/ada3 WD-WCC4N1ZK04H7 PASSED 31°C 384 9 0 0 0 0 0 0 200% 0 Short
/dev/ada4 WD-WCC4N6AJJSUU PASSED 28°C 586 16 0 0 0 0 0 0 200% 0 Short
/dev/ada5 WD-WCC4N5HNTJ9T PASSED 30°C 586 16 0 0 0 0 0 0 200% 0 Short

/dev/da0 WD-WCC4N1ZK0HKS PASSED 31°C 586 17 0 0 0 0 0 0 200% 0 Short
/dev/da1 WD-WCC4N4TU24YJ PASSED 27°C 16739 96 0 0 0 0 0 0 200% 0 Short
/dev/da2 WD-WCC4N6AJJCHJ PASSED 29°C 217 44 0 0 0 0 0 0 200% 0 Short

 

melp

Explorer
Joined
Apr 4, 2014
Messages
55
You have a great bit of code here. I got it working on both of my FreeNAS systems last night and took it into work with me this morning.
Unfortunately for me, the system I wanted to run this on that has no Internet access is CentOS and this script will not run on it because of the ''sysctl -n kern.disks". It there is no kern.disks in CentOS. I spent some time looking at it today but I have not done any bash scripting in over a decade and even when I was doing it, I never did anything this sophisticated.
CentOS has a directory /dev/disk/by-partid that appears to list only the disks in the zpool.

Glad it's working well for you! Spearfoot has another method he uses to gather a list of SMART-capable drives. It's quite a bit longer, but doesn't require sysctl (only smartctl). You can find it here (starting on line 31): https://github.com/Spearfoot/FreeNAS-scripts/blob/master/smart_report.sh

To use it, delete lines 22-24 in my script and copy in lines 31-48 from Spearfoot's script. I'd copy it into my script somewhere around line 30 or 31, but it doesn't really matter.

I'm pretty noobish here, but...I have 3 disks on SAS and 5 on SATA, and I got info back on the summary. Was this update made
or am I doing something wrong and I don't actually have SAS drives?

Have a Supermicro X11SSL-CF (6 SATA) and LSI3008 HBA

Code:
SAS SMART Report

I don't have any SAS drives otherwise I'd be able to help more, but I would look at the code in the awk statement from the SAS script in the OP (starting on line 40): https://pastebin.com/veDv2FfZ

You can run smartctl -a /dev/<drive> to figure out what values you want you want to pull and use the syntax examples on lines 42-50 of OP's script to figure out how to extract them. As an example, in line 44 of that script:
Code:
/start-stop cycles:/{startStop=$4} \
...you're telling awk to search the output of the smartctl call for a line that has the text "start-stop cycles:" and assign the 4th word on that line (as delineated by a space) to the value of variable "startStop". The printf statement at the end uses a bunch of format specifiers to output all the values it picked up. In OP's script, it does so all on one line of text (the numbers control the "column" spacing), and in mine, it drops the values into the code for the HTML table as well as the optional color into the style section of the tag. More info on printf format specifiers here: http://alvinalexander.com/programming/printf-format-cheat-sheet

In my script, all the CSS formatting is in-line because email clients don't support external stylesheets or even <style></style> sections in a block of HTML code. The \ at the end of each line in the awk statement lets the command wrap to the next line.

The code looks intimidating at first (especially with the super-long HTML tags), but once you get your head wrapped around it, it's pretty straight-forward stuff.
 
Joined
Jun 26, 2012
Messages
260
I think I was not clear in my reply/post (or I don't know what I'm talking about)...either one is possible.

I am getting info back in the 'SMART Status Report Summary' for my SAS drives while using the script you provided above. Same info as for my SATA drives and SAS drives are filled in. Based on commentary and posts, I was not expecting any data returned for the SAS drives.

So...was the SAS update made already? Or are these not SAS drives? or...is something weird (and cool) happening?
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
The SAS drives have a very different SMART output so I guess if it works then they aren't SAS drives, or it just doesn't work.
 
Joined
Jun 26, 2012
Messages
260
The SAS drives have a very different SMART output so I guess if it works then they aren't SAS drives, or it just doesn't work.
So...am I doing something wrong then? I have 3 drives connected via the
  • LSI3008 controller for 8 SAS3 (12Gbps) ports; RAID 0,1,10
on my X11SSL-CF...should this move to another thread?
 
Joined
Dec 2, 2015
Messages
730
Joined
Jun 26, 2012
Messages
260
Top