Skip to content

Add Drive_Life_Remaining% and Fix parse error #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions smartmon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

parse_smartctl_attributes_awk="$(
cat <<'SMARTCTLAWK'
$1 ~ /^ *[0-9]+$/ && $2 ~ /^[a-zA-Z0-9_-]+$/ {
$1 ~ /^ *[0-9]+$/ && $2 ~ /^[a-zA-Z0-9_-]+.*/ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not open this up to random character matching.

Suggested change
$1 ~ /^ *[0-9]+$/ && $2 ~ /^[a-zA-Z0-9_-]+.*/ {
$1 ~ /^ *[0-9]+$/ && $2 ~ /^[a-zA-Z0-9_-]+%?$/ {

gsub(/-/, "_");
printf "%s_value{%s,smart_id=\"%s\"} %d\n", $2, labels, $1, $4
printf "%s_worst{%s,smart_id=\"%s\"} %d\n", $2, labels, $1, $5
Expand Down Expand Up @@ -62,6 +62,7 @@ unsafe_shutdown_count
workld_host_reads_perc
workld_media_wear_indic
workload_minutes
drive_life_remaining%
SMARTMONATTRS
)"
smartmon_attrs="$(echo ${smartmon_attrs} | xargs | tr ' ' '|')"
Expand Down Expand Up @@ -155,7 +156,7 @@ OUTPUTAWK

format_output() {
sort |
awk -F'{' "${output_format_awk}"
awk -F'{' "${output_format_awk} |sed -e 's/%//g"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this with gsub(/%/, "");, like we do for dash to underscore in the awk.

}

smartctl_version="$(/usr/sbin/smartctl -V | head -n1 | awk '$1 == "smartctl" {print $2}')"
Expand Down