diff --git a/.gitignore b/.gitignore
index b833677..a153b2b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
install.sh
-*.sublime*
\ No newline at end of file
+*.sublime*
+
+report.cfg
diff --git a/README.md b/README.md
index b2a81ab..644c34e 100644
--- a/README.md
+++ b/README.md
@@ -1,28 +1,106 @@
-# ZPool & SMART status report with FreeNAS config backup
-Original script by joeschmuck, modified by Bidelu0hm, then by melp
+# ZPool, SMART, and UPS Status Report with TrueNAS Config Backup
+Original Script By: joeschmuck
+Modified By: bidelu0hm, melp, fohlsso2, onlinepcwizard, ninpucho, isentropik, rotx, dak180
+Last Edited By: dak180
-Preview of the output here: http://i.imgur.com/t9Mtqyt.png
+**Current Version: v1.8**
-**At a minimum, you will need to enter your email address in user-definable parameter section.** Feel free to edit other user parameters as needed.
+Preview of the output here: https://i.imgur.com/jKwraw4.png
+When a resilver is in progress: https://i.imgur.com/CUNUZ7r.png
+After the resilver is done: https://i.imgur.com/I43MLLf.png
+When a scrub is in progess: https://i.imgur.com/YGmvZT4.png
-**Version: v1.3**
+# SMART Tests
-**Changelog:**
+You should also configure your smart tests otherwise the script will not include smart test results and will generate an additional error unless you checked `Hide Standard Error` in the cron job.
-*v1.3:*
+
+# Getting Started
+
+Place the script under a user `/home/user` or in one of your pools.
+
+Create a Cron Job with the following configuration:
+
+```
+Description: Run Smart Report
+Command: /path/to/script/report.sh -c /path/to/script/report.cfg
+Run as: root
+Schedule: Daily
+Hide Standard Output: **Checked**
+Hide Standard Error: **Unchecked**
+Enabled: **Checked**
+```
+
+Click `Submit` and then `Run Now`.
+
+A configuration file will be generated at `/path/to/script/report.cfg`
+
+**At a minimum, enter an email address for the report to be sent to and set `defaultFile` to `0` in the generated config file. Feel free to edit other user parameters as needed. Backup has been disabled by default so if it is required please set to true.**
+
+Once you have updated the config file, click `Run Now` again to generate your first report.
+
+
+**Changelog**
+
+*v1.8* (dak180)
+ - Accommodate both SSD and HDD temp settings
+ - Keep SAS drives in their own section
+ - Improved support for SAS and NVMe
+ - Remove all awk
+ - Add support for per drive overrides
+
+*v1.7.5* (dak180)
+ - Add initial support for SAS drives
+
+*v1.7* (dak180)
+ - Refactor to reduce dependence on awk
+ - Use a separate config file
+ - Add support for conveyance test
+
+*v1.6.5* (rotx)
+ - HTML boundary fix, proper message ids, support for dma mailer
+ - Better support for NVMe and SSD
+ - Support for new smartmon-tools
+
+*v1.6* (isentropik)
+ - Actually fixed the broken borders in the tables.
+ - Split the SMART table into two tables, one for SSDs and one for HDDs.
+ - Added several options for SSD reporting.
+ - Modified the SSD table in order to capture relevant (seemingly) SSD data.
+ - Changed 'include SSD' default to true.
+ - Cleaned up minor formatting and error handling issues (tried to have the cell fill with "N/A" instead of non-sensical values).
+
+*v1.5* (ninpucho)
+ - Added Frag%, Size, Allocated, Free for ZPool status report summary.
+ - Added Disk Size, RPM, Model to the Smart Report
+ - Added if statment so that if "Model Family" is not present script will use "Device Model"
+ for brand in the SMART Satus report details.
+ - Added Glabel Status Report
+ - Removed Power-On time labels and added ":" as a separator.
+ - Added Power-On format to the Power-On time Header.
+ - Changed Backup deafult to false.
+
+*v1.4* (onlinepcwizard)
+- fixed the broken border on zpool status summary header
+- in statusOutput changed grep to scrub: instead of scrub
+- added elif for resilvered/resilver in progress and scrub in progress with (hopefully) som useful info fields
+- changed the email subject to include hostname and date & time
+- aaand fixed the parser
+
+*v1.3*
- Added scrub duration column
- Fixed for FreeNAS 11.1 (thanks reven!)
- Fixed fields parsed out of zpool status
- Buffered zpool status to reduce calls to script
-*v1.2:*
+*v1.2*
- Added switch for power-on time format
- Slimmed down table columns
- Fixed some shellcheck errors & other misc stuff
- Added .tar.gz to backup file attached to email
- (Still coming) Better SSD SMART support
-*v1.1:*
+*v1.1*
- Config backup now attached to report email
- Added option to turn off config backup
- Added option to save backup configs in a specified directory
@@ -35,9 +113,5 @@ Preview of the output here: http://i.imgur.com/t9Mtqyt.png
- Reformatted user-definable parameters section
- Added more general comments to code
-*v1.0:*
+*v1.0*
- Initial release
-
-**TODO:**
-- Fix SSD SMART reporting
-- Add support for conveyance test
diff --git a/examples/zfs-2.0.7-1-resilvered-days.txt b/examples/zfs-2.0.7-1-resilvered-days.txt
new file mode 100644
index 0000000..14287c5
--- /dev/null
+++ b/examples/zfs-2.0.7-1-resilvered-days.txt
@@ -0,0 +1,29 @@
+ pool: pool1
+ state: ONLINE
+ scan: resilvered 2.31T in 1 days 02:55:32 with 0 errors on Sat Dec 24 02:33:08 2022
+config:
+
+ NAME STATE READ WRITE CKSUM
+ pool1 ONLINE 0 0 0
+ raidz2-0 ONLINE 0 0 0
+ gptid/ef161b9c-99fb-11eb-8c44-8cdcd4a82a00 ONLINE 0 0 0
+ gptid/b2fbf31f-775c-11ea-bfca-8cdcd4a82a00 ONLINE 0 0 0
+ gptid/dabfaddf-a405-11ea-b106-8cdcd4a82a00 ONLINE 0 0 0
+ gptid/389c44fd-d75d-11eb-8c44-8cdcd4a82a00 ONLINE 0 0 0
+ gptid/61a310f2-b648-11eb-8c44-8cdcd4a82a00 ONLINE 0 0 0
+ gptid/9bbeb65a-5a7d-11ea-bfca-8cdcd4a82a00 ONLINE 0 0 0
+ raidz2-3 ONLINE 0 0 0
+ gptid/ddf50f19-3924-11ed-937c-8cdcd4a82a00 ONLINE 0 0 0
+ gptid/261a8ad5-5d32-11ed-937c-8cdcd4a82a00 ONLINE 0 0 0
+ gptid/490f137c-c2f2-11ec-937c-8cdcd4a82a00 ONLINE 0 0 0
+ gptid/3aee2726-8249-11ed-937c-8cdcd4a82a00 ONLINE 0 0 0
+ gptid/cbf18155-1cbf-11e5-a52f-74d02b98b14b ONLINE 0 0 0
+ gptid/cc577a01-1cbf-11e5-a52f-74d02b98b14b ONLINE 0 0 0
+ logs
+ mirror-1 ONLINE 0 0 0
+ gptid/5425d823-5d1b-11ed-937c-8cdcd4a82a00 ONLINE 0 0 0
+ gptid/79af7112-758b-11ec-b210-8cdcd4a82a00 ONLINE 0 0 0
+ cache
+ gptid/6f326eed-6dcd-11e6-92ad-74d02b98b14b ONLINE 0 0 0
+
+errors: No known data errors
diff --git a/examples/zfs-2.1.6-1-resilver-progress.txt b/examples/zfs-2.1.6-1-resilver-progress.txt
new file mode 100644
index 0000000..6eb9aa4
--- /dev/null
+++ b/examples/zfs-2.1.6-1-resilver-progress.txt
@@ -0,0 +1,29 @@
+ pool: data
+ state: ONLINE
+status: One or more devices is currently being resilvered. The pool will
+ continue to function, possibly in a degraded state.
+action: Wait for the resilver to complete.
+ scan: resilver in progress since Sat Dec 31 21:46:04 2022
+ 14.9T scanned at 19.3G/s, 14.9T issued at 19.3G/s, 20.5T total
+ 0B resilvered, 72.80% done, 00:04:56 to go
+config:
+
+ NAME STATE READ WRITE CKSUM
+ data ONLINE 0 0 0
+ raidz3-0 ONLINE 0 0 0
+ gptid/95378d35-7b98-11ed-b486-d05099c13d03 ONLINE 0 0 0
+ gptid/4b4c3c38-6e06-11ed-a9d5-d05099c13d03 ONLINE 0 0 0
+ gptid/9b844178-2482-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/f0affe10-321b-11ec-ba66-d05099c13d03 ONLINE 0 0 0
+ gptid/e5f87be0-27e7-11ec-96bc-d05099c13d03 ONLINE 0 0 0
+ gptid/e9d6ea26-25dc-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/a02741cb-2527-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/33fe635d-2713-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ logs
+ mirror-6 ONLINE 0 0 0
+ gptid/e2c3914f-8596-11ed-bce6-d05099c13d03 ONLINE 0 0 0
+ gptid/6f5748eb-897e-11ed-aa49-d05099c13d03 ONLINE 0 0 0
+ cache
+ gptid/b2daa313-80d2-11ed-b9fa-d05099c13d03 ONLINE 0 0 0
+
+errors: No known data errors
diff --git a/examples/zfs-2.1.6-1-resilvered.txt b/examples/zfs-2.1.6-1-resilvered.txt
new file mode 100644
index 0000000..2705f97
--- /dev/null
+++ b/examples/zfs-2.1.6-1-resilvered.txt
@@ -0,0 +1,29 @@
+ pool: data
+ state: ONLINE
+status: Some supported and requested features are not enabled on the pool.
+ The pool can still be used, but some features are unavailable.
+action: Enable all features using 'zpool upgrade'. Once this is done,
+ the pool may no longer be accessible by software that does not support
+ the features. See zpool-features(7) for details.
+ scan: resilvered 132K in 00:00:02 with 0 errors on Mon Jan 2 17:44:21 2023
+config:
+
+ NAME STATE READ WRITE CKSUM
+ data ONLINE 0 0 0
+ raidz3-0 ONLINE 0 0 0
+ gptid/95378d35-7b98-11ed-b486-d05099c13d03 ONLINE 0 0 0
+ gptid/4b4c3c38-6e06-11ed-a9d5-d05099c13d03 ONLINE 0 0 0
+ gptid/9b844178-2482-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/f0affe10-321b-11ec-ba66-d05099c13d03 ONLINE 0 0 0
+ gptid/e5f87be0-27e7-11ec-96bc-d05099c13d03 ONLINE 0 0 0
+ gptid/e9d6ea26-25dc-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/a02741cb-2527-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/33fe635d-2713-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ logs
+ mirror-7 ONLINE 0 0 0
+ gptid/5055ae20-8aed-11ed-9195-d05099c13d03 ONLINE 0 0 0
+ gptid/50543165-8aed-11ed-9195-d05099c13d03 ONLINE 0 0 0
+ cache
+ gptid/5052b77e-8aed-11ed-9195-d05099c13d03 ONLINE 0 0 0
+
+errors: No known data errors
diff --git a/examples/zfs-2.1.6-1-scrub-progress-days.txt b/examples/zfs-2.1.6-1-scrub-progress-days.txt
new file mode 100644
index 0000000..d7659d0
--- /dev/null
+++ b/examples/zfs-2.1.6-1-scrub-progress-days.txt
@@ -0,0 +1,31 @@
+ pool: data
+ state: ONLINE
+status: Some supported and requested features are not enabled on the pool.
+ The pool can still be used, but some features are unavailable.
+action: Enable all features using 'zpool upgrade'. Once this is done,
+ the pool may no longer be accessible by software that does not support
+ the features. See zpool-features(7) for details.
+ scan: scrub in progress since Sun Jan 15 23:29:50 2023
+ 12.8T scanned at 45.4G/s, 50.9G issued at 180M/s, 20.7T total
+ 0B repaired, 0.24% done, 1 days 09:15:46 to go
+config:
+
+ NAME STATE READ WRITE CKSUM
+ data ONLINE 0 0 0
+ raidz3-0 ONLINE 0 0 0
+ gptid/95378d35-7b98-11ed-b486-d05099c13d03 ONLINE 0 0 0
+ gptid/4b4c3c38-6e06-11ed-a9d5-d05099c13d03 ONLINE 0 0 0
+ gptid/9b844178-2482-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/f0affe10-321b-11ec-ba66-d05099c13d03 ONLINE 0 0 0
+ gptid/e5f87be0-27e7-11ec-96bc-d05099c13d03 ONLINE 0 0 0
+ gptid/e9d6ea26-25dc-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/a02741cb-2527-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/33fe635d-2713-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ logs
+ mirror-7 ONLINE 0 0 0
+ gptid/5055ae20-8aed-11ed-9195-d05099c13d03 ONLINE 0 0 0
+ gptid/50543165-8aed-11ed-9195-d05099c13d03 ONLINE 0 0 0
+ cache
+ gptid/5052b77e-8aed-11ed-9195-d05099c13d03 ONLINE 0 0 0
+
+errors: No known data errors
diff --git a/examples/zfs-2.1.6-1-scrub-progress-faulted.txt b/examples/zfs-2.1.6-1-scrub-progress-faulted.txt
new file mode 100644
index 0000000..a2c90e2
--- /dev/null
+++ b/examples/zfs-2.1.6-1-scrub-progress-faulted.txt
@@ -0,0 +1,29 @@
+ pool: data
+ state: DEGRADED
+status: One or more devices are faulted in response to persistent errors.
+ Sufficient replicas exist for the pool to continue functioning in a
+ degraded state.
+action: Replace the faulted device, or use 'zpool clear' to mark the device
+ repaired.
+ scan: scrub in progress since Mon Nov 7 16:49:08 2022
+ 13.0T scanned at 897M/s, 12.3T issued at 844M/s, 19.6T total
+ 0B repaired, 62.53% done, 02:32:21 to go
+config:
+
+ NAME STATE READ WRITE CKSUM
+ data DEGRADED 0 0 0
+ raidz3-0 DEGRADED 0 0 0
+ gptid/9ad22988-32e1-11ec-ba66-d05099c13d03 ONLINE 0 0 0
+ gptid/4543d53c-584a-11ed-9456-d05099c13d03 FAULTED 17 134 0 too many errors
+ gptid/9b844178-2482-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/f0affe10-321b-11ec-ba66-d05099c13d03 ONLINE 0 0 0
+ gptid/e5f87be0-27e7-11ec-96bc-d05099c13d03 ONLINE 0 0 0
+ gptid/e9d6ea26-25dc-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/a02741cb-2527-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/33fe635d-2713-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ logs
+ gptid/d0e8b937-6a7f-11ec-b0e6-d05099c13d03 ONLINE 0 0 0
+ cache
+ gptid/a228d8bb-56ec-11eb-9900-d05099c13d03 ONLINE 0 0 0
+
+errors: No known data errors
diff --git a/examples/zfs-2.1.6-1-scrub-progress-no.txt b/examples/zfs-2.1.6-1-scrub-progress-no.txt
new file mode 100644
index 0000000..34a51fa
--- /dev/null
+++ b/examples/zfs-2.1.6-1-scrub-progress-no.txt
@@ -0,0 +1,31 @@
+ pool: data
+ state: ONLINE
+status: Some supported and requested features are not enabled on the pool.
+ The pool can still be used, but some features are unavailable.
+action: Enable all features using 'zpool upgrade'. Once this is done,
+ the pool may no longer be accessible by software that does not support
+ the features. See zpool-features(7) for details.
+ scan: scrub in progress since Sun Jan 15 23:29:50 2023
+ 3.54G scanned at 117M/s, 3.09M issued at 102K/s, 20.7T total
+ 0B repaired, 0.00% done, no estimated completion time
+config:
+
+ NAME STATE READ WRITE CKSUM
+ data ONLINE 0 0 0
+ raidz3-0 ONLINE 0 0 0
+ gptid/95378d35-7b98-11ed-b486-d05099c13d03 ONLINE 0 0 0
+ gptid/4b4c3c38-6e06-11ed-a9d5-d05099c13d03 ONLINE 0 0 0
+ gptid/9b844178-2482-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/f0affe10-321b-11ec-ba66-d05099c13d03 ONLINE 0 0 0
+ gptid/e5f87be0-27e7-11ec-96bc-d05099c13d03 ONLINE 0 0 0
+ gptid/e9d6ea26-25dc-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/a02741cb-2527-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ gptid/33fe635d-2713-11ec-8714-d05099c13d03 ONLINE 0 0 0
+ logs
+ mirror-7 ONLINE 0 0 0
+ gptid/5055ae20-8aed-11ed-9195-d05099c13d03 ONLINE 0 0 0
+ gptid/50543165-8aed-11ed-9195-d05099c13d03 ONLINE 0 0 0
+ cache
+ gptid/5052b77e-8aed-11ed-9195-d05099c13d03 ONLINE 0 0 0
+
+errors: No known data errors
diff --git a/examples/zfs-2.1.6-1-scrub.txt b/examples/zfs-2.1.6-1-scrub.txt
new file mode 100644
index 0000000..2d9534c
--- /dev/null
+++ b/examples/zfs-2.1.6-1-scrub.txt
@@ -0,0 +1,22 @@
+ pool: jails
+ state: ONLINE
+status: Some supported and requested features are not enabled on the pool.
+ The pool can still be used, but some features are unavailable.
+action: Enable all features using 'zpool upgrade'. Once this is done,
+ the pool may no longer be accessible by software that does not support
+ the features. See zpool-features(7) for details.
+ scan: scrub repaired 0B in 00:37:54 with 0 errors on Thu Dec 15 02:37:58 2022
+config:
+
+ NAME STATE READ WRITE CKSUM
+ jails ONLINE 0 0 0
+ mirror-0 ONLINE 0 0 0
+ gptid/5af3b112-ae22-11ec-b1df-d05099c13d03 ONLINE 0 0 0
+ gptid/eb3d01ce-ad8c-11ec-b1df-d05099c13d03 ONLINE 0 0 0
+ mirror-1 ONLINE 0 0 0
+ gptid/6f46a30c-0366-11ec-9de4-d05099c13d03 ONLINE 0 0 0
+ gptid/dda6dac8-0382-11ec-9de4-d05099c13d03 ONLINE 0 0 0
+ cache
+ gptid/3dce1035-8aea-11ed-b30b-d05099c13d03 ONLINE 0 0 0
+
+errors: No known data errors
diff --git a/report.sh b/report.sh
old mode 100644
new mode 100755
index 0b7f098..5fa4ca8
--- a/report.sh
+++ b/report.sh
@@ -1,25 +1,67 @@
#!/bin/bash
+# shellcheck disable=SC1004,SC2236
-###### ZPool & SMART status report with FreeNAS config backup
-### Original script by joeschmuck, modified by Bidelu0hm, then by melp (me)
+#set -euxo pipefail
-### At a minimum, enter email address in user-definable parameter section. Feel free to edit other user parameters as needed.
-### If you find any errors, feel free to contact me on the FreeNAS forums (username melp) or email me at jason at jro dot io.
+###### ZPool, SMART, and UPS Status Report with TrueNAS Config Backup
+### Original Script By: joeschmuck
+### Modified By: bidelu0hm, melp, fohlsso2, onlinepcwizard, ninpucho, isentropik, dak180
+### Last Edited By: dak180
+
+### At a minimum, enter email address and set defaultFile to 0 in the config file.
+### Feel free to edit other user parameters as needed.
+
+### Current Version: v1.8
+### https://github.com/dak180/FreeNAS-Report
-### Version: v1.3
### Changelog:
-# v1.3:
+# v1.8
+# - Accommodate both SSD and HDD temp settings
+# - Keep SAS drives in their own section
+# - Improved support for SAS and NVMe
+# - Remove all awk
+# - Add support for per drive overrides
+# v1.7.5
+# - Add initial support for SAS drives
+# v1.7
+# - Refactor to reduce dependence on awk
+# - Use a separate config file
+# - Add support for conveyance test
+# v1.6.5
+# - HTML boundary fix, proper message ids, support for dma mailer
+# - Better support for NVMe and SSD
+# - Support for new smartmon-tools
+# v1.6
+# - Actually fixed the broken borders in the tables.
+# - Split the SMART table into two tables, one for SSDs and one for HDDs.
+# - Added several options for SSD reporting.
+# - Modified the SSD table in order to capture relevant (seemingly) SSD data.
+# - Changed 'include SSD' default to true.
+# - Cleaned up minor formatting and error handling issues (tried to have the cell fill with "N/A" instead of non-sensical values).
+# v1.5
+# - Added Frag%, Size, Allocated, Free for ZPool status report summary.
+# - Added Disk Size, RPM, Model to the Smart Report
+# - Added if statment so that if "Model Family" is not present script will use "Device Model" for brand in the SMART Satus report details.
+# - Added Glabel Status Report
+# - Removed Power-On time labels and added ":" as a separator.
+# - Added Power-On format to the Power-On time Header.
+# - Changed Backup default to false.
+# v1.4
+# - in statusOutput changed grep to scrub: instead of scrub
+# - added elif for resilvered/resilver in progress and scrub in progress with (hopefully) som useful info fields
+# - changed the email subject to include hostname and date & time
+# v1.3
# - Added scrub duration column
# - Fixed for FreeNAS 11.1 (thanks reven!)
# - Fixed fields parsed out of zpool status
# - Buffered zpool status to reduce calls to script
-# v1.2:
+# v1.2
# - Added switch for power-on time format
# - Slimmed down table columns
# - Fixed some shellcheck errors & other misc stuff
# - Added .tar.gz to backup file attached to email
# - (Still coming) Better SSD SMART support
-# v1.1:
+# v1.1
# - Config backup now attached to report email
# - Added option to turn off config backup
# - Added option to save backup configs in a specified directory
@@ -31,391 +73,2316 @@
# - Added most recent Extended & Short SMART tests in drive details section (only listed one before, whichever was more recent)
# - Reformatted user-definable parameters section
# - Added more general comments to code
-# v1.0:
+# v1.0
# - Initial release
-### TODO:
-# - Fix SSD SMART reporting
-# - Add support for conveyance test
+# Defaults
+LANG="en_US.UTF-8" # Ensure date works as expected.
+
+# Functions
+function rpConfig () {
+ # Write out a default config file
+ tee > "${configFile}" <<"EOF"
+# Set this to 0 to enable
+defaultFile="1"
###### User-definable Parameters
### Email Address
email="email@address.com"
### Global table colors
-okColor="#c9ffcc" # Hex code for color to use in SMART Status column if drives pass (default is light green, #c9ffcc)
-warnColor="#ffd6d6" # Hex code for WARN color (default is light red, #ffd6d6)
-critColor="#ff0000" # Hex code for CRITICAL color (default is bright red, #ff0000)
-altColor="#f4f4f4" # Table background alternates row colors between white and this color (default is light gray, #f4f4f4)
+okColor="#c9ffcc" # Hex code for color to use in SMART Status column if drives pass (default is light green, #c9ffcc)
+warnColor="#ffd6d6" # Hex code for WARN color (default is light red, #ffd6d6)
+critColor="#ff0000" # Hex code for CRITICAL color (default is bright red, #ff0000)
+altColor="#f4f4f4" # Table background alternates row colors between white and this color (default is light gray, #f4f4f4)
### zpool status summary table settings
-usedWarn=90 # Pool used percentage for CRITICAL color to be used
-scrubAgeWarn=30 # Maximum age (in days) of last pool scrub before CRITICAL color will be used
+usedWarn="90" # Pool used percentage for CRITICAL color to be used
+scrubAgeWarn="30" # Maximum age (in days) of last pool scrub before CRITICAL color will be used
### SMART status summary table settings
-includeSSD="false" # [NOTE: Currently this is pretty much useless] Change to "true" to include SSDs in SMART status summary table; "false" to disable
-tempWarn=40 # Drive temp (in C) at which WARNING color will be used
-tempCrit=45 # Drive temp (in C) at which CRITICAL color will be used
-sectorsCrit=10 # Number of sectors per drive with errors before CRITICAL color will be used
-testAgeWarn=5 # Maximum age (in days) of last SMART test before CRITICAL color will be used
+includeSSD="true" # Change to "true" to include SSDs in SMART status summary table; "false" to disable
+includeSAS="false" # Change to "true" to include SAS drives in SMART status summary table; "false" to disable
+lifeRemainWarn="75" # Life remaining in the SSD at which WARNING color will be used
+lifeRemainCrit="50" # Life remaining in the SSD at which CRITICAL color will be used
+totalBWWarn="100" # Total bytes written (in TB) to the SSD at which WARNING color will be used
+totalBWCrit="200" # Total bytes written (in TB) to the SSD at which CRITICAL color will be used
+tempWarn="35" # Drive temp (in C) at which WARNING color will be used
+tempCrit="40" # Drive temp (in C) at which CRITICAL color will be used
+ssdTempWarn="40" # SSD drive temp (in C) at which WARNING color will be used
+ssdTempCrit="45" # SSD drive temp (in C) at which CRITICAL color will be used
+sectorsCrit="10" # Number of sectors per drive with errors before CRITICAL color will be used
+testAgeWarn="5" # Maximum age (in days) of last SMART test before CRITICAL color will be used
powerTimeFormat="ymdh" # Format for power-on hours string, valid options are "ymdh", "ymd", "ym", or "y" (year month day hour)
-### FreeNAS config backup settings
-configBackup="true" # Change to "false" to skip config backup (which renders next two options meaningless); "true" to keep config backups enabled
-saveBackup="true" # Change to "false" to delete FreeNAS config backup after mail is sent; "true" to keep it in dir below
-backupLocation="/path/to/config/backup" # Directory in which to save FreeNAS config backups
+### TrueNAS config backup settings
+configBackup="false" # Change to "false" to skip config backup (which renders next two options meaningless); "true" to keep config backups enabled
+emailBackup="false" # Change to "true" to email TrueNAS config backup
+saveBackup="true" # Change to "false" to delete TrueNAS config backup after mail is sent; "true" to keep it in dir below
+backupLocation="/root/backup" # Directory in which to save TrueNAS config backups
+
+### UPS status summary settings
+reportUPS="false" # Change to "false" to skip reporting the status of the UPS
+
+### General script settings
+logfileLocation="/tmp" # Directory in which to save TrueNAS log file. Can be set to /tmp.
+logfileName="logfilename" # Log file name
+saveLogfile="true" # Change to "false" to delete the log file after creation
+
+##### Drive Overrides
+# In the form: declare -A _
+# And then for each override: _[]=""
+# Replace any non ascii alphanumeric characters with _ in the serial.
+
+
+
+EOF
+ echo "Please edit the config file for your setup" >&2
+ exit 0
+}
+
+function ConfigBackup () {
+ local tarfile
+ local fnconfigdest_version
+ local fnconfigdest_date
+ local filename
+
+
+ # Set up file names, etc for later
+ tarfile="/tmp/config_backup.tar.gz"
+ fnconfigdest_version="$(< /etc/version sed -e 's:)::' -e 's:(::' -e 's: :-:' | tr -d '\n')"
+ if [ "${systemType}" = "BSD" ]; then
+ fnconfigdest_date="$(date -r "${runDate}" '+%Y%m%d%H%M%S')"
+ else
+ fnconfigdest_date="$(date -d "@${runDate}" '+%Y%m%d%H%M%S')"
+ fi
+ filename="${fnconfigdest_date}_${fnconfigdest_version}"
+
+ ### Test config integrity
+ if [ ! "$(sqlite3 "/data/freenas-v1.db" "pragma integrity_check;")" = "ok" ]; then
+
+ # Config integrity check failed, set MIME content type to html and print warning
+ {
+ tee <<- EOF
+ --${boundary}
+ Content-Transfer-Encoding: 8bit
+ Content-Type: text/html; charset=utf-8
+
+ Automatic backup of TrueNAS configuration has failed! The configuration file is corrupted!
+ You should correct this problem as soon as possible!
+
+EOF
+ } >> "${logfile}"
+ else
+ # Config integrity check passed; copy config db, generate checksums, make .tar.gz archive
+ sqlite3 "/data/freenas-v1.db" ".backup main /tmp/${filename}.db"
+ cp -f "/data/pwenc_secret" "/tmp/"
+ if [ ! -z "${MD5SUM}" ]; then
+ ${MD5SUM} "/tmp/${filename}.db" > /tmp/config_backup.md5
+ else
+ md5sum "/tmp/${filename}.db" > /tmp/config_backup.md5
+ fi
+ if [ ! -z "${SHA256SUM}" ]; then
+ ${SHA256SUM} "/tmp/${filename}.db" > /tmp/config_backup.sha256
+ else
+ sha256sum "/tmp/${filename}.db" > /tmp/config_backup.sha256
+ fi
+ (
+ cd "/tmp/" || exit;
+ tar -czf "${tarfile}" "./${filename}.db" "./config_backup.md5" "./config_backup.sha256" "./pwenc_secret"
+ )
+ {
+ if [ "${emailBackup}" = "true" ]; then
+ # Write MIME section header for file attachment (encoded with base64)
+ tee <<- EOF
+ --${boundary}
+ Content-Type: application/tar+gzip name="${filename}.tar.gz"
+ Content-Disposition: attachment; filename="${filename}.tar.gz"
+ Content-Transfer-Encoding: base64
+
+EOF
+ base64 "${tarfile}"
+ fi
+
+ # Write MIME section header for html content to come below
+ tee <<- EOF
+ --${boundary}
+ Content-Transfer-Encoding: 8bit
+ Content-Type: text/html; charset="utf-8"
+
+EOF
+ } >> "${logfile}"
+
+ # If logfile saving is enabled, copy .tar.gz file to specified location before it (and everything else) is removed below
+ if [ "${saveBackup}" = "true" ]; then
+ if [ ! -d "backupLocation/" ]; then
+ mkdir -p "${backupLocation}/"
+ fi
+ cp "${tarfile}" "${backupLocation}/${filename}.tar.gz"
+ fi
+ rm "/tmp/${filename}.db"
+ rm "/tmp/config_backup.md5"
+ rm "/tmp/config_backup.sha256"
+ rm "${tarfile}"
+ fi
+}
+
+function ZpoolSummary () {
+ {
+ local pool
+ local status
+ local frag
+ local size
+ local allocated
+ local free
+ local errors
+ local readErrors
+ local err
+ local writeErrors
+ local cksumErrors
+ local used
+ local scrubRepBytes
+ local scrubErrors
+ local scrubAge
+ local scrubDuration
+ local resilver
+ local statusOutput
+ local bgColor
+ local statusColor
+ local readErrorsColor
+ local writeErrorsColor
+ local cksumErrorsColor
+ local usedColor
+ local scrubRepBytesColor
+ local scrubErrorsColor
+ local scrubAgeColor
+ local multiDay
+ local altRow
+ local zfsVersion
+ }
+
+ zfsVersion="$(zpool version 2> /dev/null | head -n 1 | sed -e 's:zfs-::')"
+
+ ### zpool status summary table
+ {
+ # Write HTML table headers to log file; HTML in an email requires 100% in-line styling (no CSS or