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

Stux

MVP
Joined
Jun 2, 2016
Messages
4,419
I'm in the process of moving my scripts to my pool. It means that my CRON command has to be something like ...

Code:
./../mnt/<pool>/FreeNAS/Scripts/blah.sh

I've also included a 'cd' at the top of my scripts to change the 'active' directory to that scripts directory - then the tmp and Data directories hang off the script directory.

However, that 'cd' means that it throws an error if I execute the script from the CLI. I got around that by wrapping the 'cd' command in an IF statement that checks if that directory (../mnt/<pool>/FreeNAS/Scripts) exists.

Further fun and games (including some comments on some posts over the last few pages) ... the script that reports the GPTID didn't like one of the geom ...

glabel: No such geom: ada1p2.

That was because there wasn't a 2nd partition for that particular drive (the p2 part). Changing it to P1 (ie ada1p1) resulted in no error.

I fudged a test to see if I should be using adaXp1 or adaXp2 ... but it isn't very generic. Is there a way to tell if the 2nd partition exists?

Finally, SSDs do report temps via SMART ... but the grep part (grep "Temperature_Celsius") might not use those exact letters. For example, my Samsung SSD reports temp as something like "Air Flow Temp" ... so you need to modify the grep part.

Second finally, is there a way of being able to tell a SSD from a HDD?

Edit: See here ... http://unix.stackexchange.com/quest...-disk-is-compact-flash-or-standard-hard-drive

Code:
Rotational=`smartctl -a /dev/adaX | grep "Rotation" | awk '{print $3}'`
if [ $Rotational == "Solid" ]
then
   isSSD=1
   isHDD=0
else
   isSSD=0
   isHDD=1
fi

Instead of using a relative path (one which starts with ./ or ../) use an absolute path (one that starts with a /)

/mnt/<pool>/FreeNAS/Scripts/blah.sh

Same for the cd.
 

Ruff.Hi

Patron
Joined
Apr 21, 2015
Messages
271
Duh ... of course that is a much better suggestion. That is what happens when you don't use your knowledge ... it goes stale.

Also ... as I know that the path exists ... I can drop the 'if' statement checking if the path exists.
 

VladTepes

Patron
Joined
May 18, 2016
Messages
287
I've been out of the loop a while and am hoping someone can save me reading a LOT of pages in this thread.

Is there any updated version of this script / these scripts somewhere?
Basically looking for one that reports all the essential info in an easy to read / access manner. Thank you.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
I haven't had any free time recently to do anything but I followed the posts so I know there's some improvements to add to the original scripts in the last 3 or 4 pages.
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
I've been out of the loop a while and am hoping someone can save me reading a LOT of pages in this thread.

Is there any updated version of this script / these scripts somewhere?
Basically looking for one that reports all the essential info in an easy to read / access manner. Thank you.
I've just created a GitHub repository containing my versions of smart_report.sh and zpool_report.sh. You can download them from GitHub here:

https://github.com/Spearfoot/FreeNAS-scripts
 

Xyrgh

Explorer
Joined
Apr 11, 2016
Messages
69
I'm getting an error running these scripts (specifically, @Spearfoot 's scripts) in FreeNAS Corral:

Code:
Traceback (most recent call last):
  File "/etc/find_alias_for_smtplib.py", line 121, in <module>
	main(*sys.argv[1:])
  File "/etc/find_alias_for_smtplib.py", line 39, in main
	connection.connect('127.0.0.1')
  File "/usr/local/lib/python3.6/site-packages/freenas/dispatcher/client.py", line 956, in connect
	self.transport.connect(self.parsed_url, self, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/freenas/dispatcher/transport.py", line 256, in connect
	self.ws.connect()
  File "/usr/local/lib/python3.6/site-packages/ws4py/client/__init__.py", line 230, in connect
	raise OSError('Cannot connect to {}'.format(self.bind_addr[0]))



Is this a configuration issue or a script issue? Scripts were working fine until I updated to Corral.
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
I'm getting an error running these scripts (specifically, @Spearfoot 's scripts) in FreeNAS Corral:

Code:
Traceback (most recent call last):
  File "/etc/find_alias_for_smtplib.py", line 121, in <module>
	main(*sys.argv[1:])
  File "/etc/find_alias_for_smtplib.py", line 39, in main
	connection.connect('127.0.0.1')
  File "/usr/local/lib/python3.6/site-packages/freenas/dispatcher/client.py", line 956, in connect
	self.transport.connect(self.parsed_url, self, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/freenas/dispatcher/transport.py", line 256, in connect
	self.ws.connect()
  File "/usr/local/lib/python3.6/site-packages/ws4py/client/__init__.py", line 230, in connect
	raise OSError('Cannot connect to {}'.format(self.bind_addr[0]))



Is this a configuration issue or a script issue? Scripts were working fine until I updated to Corral.
Hmmm... I dunno. Haven't played with FN10/Corral in a while.

Which script are you running? The Python module name "find_alias_for_smtplib.py" contains 'smtp' - make me think you must be running either zpool_report.sh or smart_report.sh, both of which send an email message. Have you configured and tested the email settings on FN10/Corral? And I assume you edited the scripts and provided a known-good email address.
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
@Xyrgh - Yep, checked the source code and it's definitely something to do with email. So...
  • Check your email settings; make sure you can send a test message.
  • Open a shell prompt and run which sendmail to make sure it's installed and in the path. You should get back something along the lines of /usr/sbin/sendmail.
  • Run the scripts from a shell prompt for testing, before installing as tasks in the GUI.
The devs have been working pretty hard on FN10; surely email is working. It's probably something simple and we'll all slap our heads and say "Why didn't we think of that!" -- once we figure it out. :smile:
 

Xyrgh

Explorer
Joined
Apr 11, 2016
Messages
69
@Spearfoot Sending a test email is working, Output of which sendmail gives me /usr/sbin/sendmail.

I'm running the scripts from the shell first (after initially using the gui) and that's where the error pops up, the GUI reports the script ran without error.
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
@Spearfoot Sending a test email is working, Output of which sendmail gives me /usr/sbin/sendmail.

I'm running the scripts from the shell first (after initially using the gui) and that's where the error pops up, the GUI reports the script ran without error.
I installed Corral on a VM just now... I get a different error to yours:
Code:
[root@freenas] ~# ./zpool_report.sh
Traceback (most recent call last):
  File "/etc/find_alias_for_smtplib.py", line 121, in <module>
  main(*sys.argv[1:])
  File "/etc/find_alias_for_smtplib.py", line 61, in main
  if not to_addrs or not to_addrs[0]:
TypeError: 'map' object is not subscriptable
[root@freenas] ~#


But in my case it's probably because I haven't configured the system email settings... because I can't find where to enter them! Aaargh! Where do I set up the default system email settings?

Anyway... it turns out that for both FN9.10 and Corral, 'sendmail' is really just a link that executes the same Python code.
 

Xyrgh

Explorer
Joined
Apr 11, 2016
Messages
69
But in my case it's probably because I haven't configured the system email settings... because I can't find where to enter them! Aaargh! Where do I set up the default system email settings?

System>Alerts and Reporting>Settings (It's down the bottom under the alert options).
 

HeloJunkie

Patron
Joined
Oct 15, 2014
Messages
300
Upgraded to Corral as well and I too am getting this error:

Code:
[root@plexnas] ~/scripts# ./plexnas_zpool_report.sh
Traceback (most recent call last):
  File "/etc/find_alias_for_smtplib.py", line 121, in <module>
	main(*sys.argv[1:])
  File "/etc/find_alias_for_smtplib.py", line 61, in main
	if not to_addrs or not to_addrs[0]:
TypeError: 'map' object is not subscriptable


I have all of my SMTP setting set and the test email sends from Corral without any problems at all, so this error does not appear to be a problem with SMTP settings.
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
@HeloJunkie, @Xyrgh : There's a bug in Corral's 'sendmail' implementation.

TL;DR: Edit your scripts and change the sendmail command from this: sendmail -t ${logfile} to this: sendmail ${email} < ${logfile}.

Or download updated scripts from my GitHub repository: github.com/Spearfoot/FreeNAS-scripts

The 'sendmail' command is actually a call to /etc/find_alias_for_smtplib.py, a Python module. The '-t' option instructs the code to parse the recipient email address from the message content:
Code:
[root@corral] /mnt/tank/systems/scripts# sendmail --help
usage: find_alias_for_smtplib.py [-h] [-i] [email_addr|user] ..

Process email

optional arguments:
  -h, --help  show this help message and exit
  -i  see sendmail(8) -i
  -t  parse recipients from message
This is what's broken. The Python module works correctly on FreeNAS 9.10, but for some reason isn't able to parse the email address successfully on Corral. Hence the error dump posted by @HeloJunkie above. To make it work, I modified the code to explicity feed it the email address.

I'll file a bug report when I get around to it, and post the bug report link here.

EDIT: Here is the bug report (bug #22575).
 
Last edited:

HeloJunkie

Patron
Joined
Oct 15, 2014
Messages
300

Xyrgh

Explorer
Joined
Apr 11, 2016
Messages
69
Thanks @Spearfoot, but I'm still getting an issue:

Code:
Traceback (most recent call last):
  File "/etc/find_alias_for_smtplib.py", line 121, in <module>
	main(*sys.argv[1:])
  File "/etc/find_alias_for_smtplib.py", line 39, in main
	connection.connect('127.0.0.1')
  File "/usr/local/lib/python3.6/site-packages/freenas/dispatcher/client.py", line 956, in connect
	self.transport.connect(self.parsed_url, self, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/freenas/dispatcher/transport.py", line 256, in connect
	self.ws.connect()
  File "/usr/local/lib/python3.6/site-packages/ws4py/client/__init__.py", line 230, in connect
	raise OSError('Cannot connect to {}'.format(self.bind_addr[0]))
OSError: Cannot connect to 127.0.0.1



Is this possibly something related to my network settings? I can ping 127.0.0.1 and it resolves. I copied your script and created a new file as well.
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
Thanks @Spearfoot, but I'm still getting an issue:

Code:
Traceback (most recent call last):
  File "/etc/find_alias_for_smtplib.py", line 121, in <module>
	main(*sys.argv[1:])
  File "/etc/find_alias_for_smtplib.py", line 39, in main
	connection.connect('127.0.0.1')
  File "/usr/local/lib/python3.6/site-packages/freenas/dispatcher/client.py", line 956, in connect
	self.transport.connect(self.parsed_url, self, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/freenas/dispatcher/transport.py", line 256, in connect
	self.ws.connect()
  File "/usr/local/lib/python3.6/site-packages/ws4py/client/__init__.py", line 230, in connect
	raise OSError('Cannot connect to {}'.format(self.bind_addr[0]))
OSError: Cannot connect to 127.0.0.1



Is this possibly something related to my network settings? I can ping 127.0.0.1 and it resolves. I copied your script and created a new file as well.
Hmmm... you may indeed have network issues.

Pinging 127.0.0.1 doesn't mean anything - that's the loopback address. What's important is being about to connect to a mail server's IP address, in particular, the mail server you configured in the system's settings.

Can you ping any well-known sites -- www.google.com, for example -- from a terminal session?
 

Xyrgh

Explorer
Joined
Apr 11, 2016
Messages
69
Hmmm... you may indeed have network issues.

Pinging 127.0.0.1 doesn't mean anything - that's the loopback address. What's important is being about to connect to a mail server's IP address, in particular, the mail server you configured in the system's settings.

Can you ping any well-known sites -- www.google.com, for example -- from a terminal session?

Yep, pinging google is fine:

Code:
[root@freenas] ~# ping google.com
PING google.com (172.217.25.174): 56 data bytes
64 bytes from 172.217.25.174: icmp_seq=0 ttl=56 time=49.644 ms
64 bytes from 172.217.25.174: icmp_seq=1 ttl=56 time=49.296 ms
64 bytes from 172.217.25.174: icmp_seq=2 ttl=56 time=49.371 ms
64 bytes from 172.217.25.174: icmp_seq=3 ttl=56 time=49.275 ms
64 bytes from 172.217.25.174: icmp_seq=4 ttl=56 time=49.259 ms
64 bytes from 172.217.25.174: icmp_seq=5 ttl=56 time=49.223 ms
64 bytes from 172.217.25.174: icmp_seq=6 ttl=56 time=49.281 ms
64 bytes from 172.217.25.174: icmp_seq=7 ttl=56 time=49.248 ms



Normal FreeNAS email alerts are also working.
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
Yep, pinging google is fine:

Code:
[root@freenas] ~# ping google.com
PING google.com (172.217.25.174): 56 data bytes
64 bytes from 172.217.25.174: icmp_seq=0 ttl=56 time=49.644 ms
64 bytes from 172.217.25.174: icmp_seq=1 ttl=56 time=49.296 ms
64 bytes from 172.217.25.174: icmp_seq=2 ttl=56 time=49.371 ms
64 bytes from 172.217.25.174: icmp_seq=3 ttl=56 time=49.275 ms
64 bytes from 172.217.25.174: icmp_seq=4 ttl=56 time=49.259 ms
64 bytes from 172.217.25.174: icmp_seq=5 ttl=56 time=49.223 ms
64 bytes from 172.217.25.174: icmp_seq=6 ttl=56 time=49.281 ms
64 bytes from 172.217.25.174: icmp_seq=7 ttl=56 time=49.248 ms



Normal FreeNAS email alerts are also working.
Can you ping the hostname of your email server?
 

Xyrgh

Explorer
Joined
Apr 11, 2016
Messages
69
Can you ping the hostname of your email server?

Sure:

Code:
[root@freenas] ~# ping smtp.gmail.com
PING gmail-smtp-msa.l.google.com (74.125.203.108): 56 data bytes
64 bytes from 74.125.203.108: icmp_seq=0 ttl=47 time=172.816 ms
64 bytes from 74.125.203.108: icmp_seq=1 ttl=47 time=172.690 ms
64 bytes from 74.125.203.108: icmp_seq=2 ttl=47 time=172.730 ms
64 bytes from 74.125.203.108: icmp_seq=3 ttl=47 time=172.689 ms
64 bytes from 74.125.203.108: icmp_seq=4 ttl=47 time=172.542 ms
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
Thanks @Spearfoot, but I'm still getting an issue:

Code:
Traceback (most recent call last):
  File "/etc/find_alias_for_smtplib.py", line 121, in <module>
	main(*sys.argv[1:])
  File "/etc/find_alias_for_smtplib.py", line 39, in main
	connection.connect('127.0.0.1')
  File "/usr/local/lib/python3.6/site-packages/freenas/dispatcher/client.py", line 956, in connect
	self.transport.connect(self.parsed_url, self, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/freenas/dispatcher/transport.py", line 256, in connect
	self.ws.connect()
  File "/usr/local/lib/python3.6/site-packages/ws4py/client/__init__.py", line 230, in connect
	raise OSError('Cannot connect to {}'.format(self.bind_addr[0]))
OSError: Cannot connect to 127.0.0.1



Is this possibly something related to my network settings? I can ping 127.0.0.1 and it resolves. I copied your script and created a new file as well.
Baffling!
But you really ought to start a new thread, perhaps in the networking subforum. This thread is too long already, and we're distracting from the intent of the original poster.
 
Top