mirror of
https://github.com/prometheus-community/smartctl_exporter.git
synced 2024-12-21 02:21:55 +01:00
Fix #158: collect_fake_json.sh
Signed-off-by: David Randall <David@NiceGuyIT.biz>
This commit is contained in:
parent
784061630a
commit
4fe758eb74
1 changed files with 22 additions and 3 deletions
|
@ -1,6 +1,25 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
for device in $(smartctl --scan | awk '{ print $1}')
|
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||||
do
|
|
||||||
smartctl --json --xall $device | jq > debug/$(basename $device).json
|
# The original script used --xall but that doesn't work
|
||||||
|
# This matches the command in readSMARTctl()
|
||||||
|
smartctl_args="--json --info --health --attributes --tolerance=verypermissive --nocheck=standby --format=brief --log=error"
|
||||||
|
|
||||||
|
[[ ! -d "${script_dir}/debug" ]] && mkdir --parents "${script_dir}/debug"
|
||||||
|
|
||||||
|
if command -v jq >/dev/null; then
|
||||||
|
devices=$(smartctl --scan --json | jq --raw-output '.devices[].name')
|
||||||
|
elif command -v yq >/dev/null; then
|
||||||
|
devices=$(smartctl --scan --json | yq --unwrapScalar '.devices[].name')
|
||||||
|
elif command -v awk >/dev/null; then
|
||||||
|
devices=$(smartctl --scan | awk '{ print($1) }')
|
||||||
|
else
|
||||||
|
devices=$(smartctl --scan | cut -d ' ' -f 1)
|
||||||
|
fi
|
||||||
|
|
||||||
|
for device in $devices; do
|
||||||
|
echo "Collecting data for '${device}'"
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
sudo smartctl $smartctl_args "${device}" > "${script_dir}/debug/$(basename "${device}").json"
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue