Last active
March 10, 2025 19:06
-
-
Save crpb/d3ddea80d9998904c6341bfcde069366 to your computer and use it in GitHub Desktop.
#truenas #midclt #pet #snippets https://github.com/knqyf263/pet https://github.com/truenas/middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[snippets]] | |
description = "truenas upgrade all jails to latest" | |
command = "midclt call jail.query |jq -r '.[]|.id' |while read -r jailid; do midclt call jail.update_to_latest_patch $jailid; done" | |
output = "" | |
[[snippets]] | |
description = "truenas snapshot task overview extended" | |
command = "midclt call pool.snapshottask.query |jq -r '.[]|[(.id|tostring),.dataset,.lifetime_unit,\"\\(.lifetime_value)\",.naming_schema,.schedule.minute + \" \" + .schedule.hour + \" \" + .schedule.dom + \" \" + .schedule.month + \" \" + .schedule.dow]|map(gsub(\"^\\\\s+|\\\\s+$\";\"\"))|@tsv' |sort" | |
output = "" | |
[[snippets]] | |
description = "truenas snapshot task overview" | |
command = "midclt call pool.snapshottask.query |jq -r '.[]|[(.id|tostring),.dataset,.lifetime_unit,\"\\(.lifetime_value)\",.naming_schema]|map(gsub(\"^\\\\s+|\\\\s+$\";\"\"))|@tsv'" | |
output = "" | |
[[snippets]] | |
description = "truenas run latest update and reboot" | |
command = "midclt call update.update '{\"reboot\": true}'" | |
output = "" | |
[[snippets]] | |
description = "truenas replication start all jobs" | |
command = "midclt call replication.query |jq '.[]|.id' |while read -r ID; do midclt call replication.run $ID; done" | |
output = "" | |
[[snippets]] | |
description = "truenas replication running tasks" | |
command = "midclt call replication.query |jq -r '.[]|select(.job.state==\"RUNNING\")|[.name,.job.progress.description]|map(gsub(\"^\\\\s+|\\\\s+$\";\"\"))|@tsv'" | |
output = "" | |
[[snippets]] | |
description = "truenas replication status" | |
command = "midclt call replication.query |jq -r '.[]|[ .id,.source_datasets[]//empty?, .enabled, .state.state?, (.job.time_finished? // null? |.\"$date\" |tostring|.[0:10]?|tonumber|todate ), .job.progress.description? ]|@tsv'" | |
output = "" | |
[[snippets]] | |
description = "truenas list vmware datastores" | |
command = "midclt call vmware.get_datastores \"$(midclt call vmware.query |jq '.[0]|del(.filesystem,.datastore,.id)')\"" | |
output = "" | |
[[snippets]] | |
description = "truenas list snapshot naming schemes" | |
command = "midclt call pool.snapshottask.query |jq -r '.[]|[.dataset,.naming_schema]|@tsv' |sort" | |
output = "" | |
[[snippets]] | |
description = "truenas list running jobs" | |
command = "midclt call core.get_jobs | jq '.[]|select(.state==\"RUNNING\")'" | |
output = "" | |
[[snippets]] | |
description = "truenas list pool: disks" | |
command = "midclt call pool.query |jq -r '.[]|[.name, .id]|@tsv' |while read POOL ID ; do printf \"POOL: %s\\tDISKS: %s\\n\" $POOL \"$(midclt call pool.get_disks $ID|jq -r '.[]'|tr '\\n' ' ')\"; done" | |
output = "" | |
[[snippets]] | |
description = "truenas diskinfos" | |
command = "midclt call disk.query |jq -r '.[]|.model|=gsub(\" \";\"-\")|[ .name,.serial,.model ]|map(gsub(\"^\\\\s+|\\\\s+$\";\"\"))|@tsv' |sed s:nvd:nvme:g| while read device model serial ;do temp=$(midclt call disk.temperature ${device/nvme/nvd}); years=$(smartctl -A /dev/$device |sed s:,::g|awk '/[Pp]ower[_ ][Oo]n/ {sum = $NF/24/365; printf \"%0.2f\", sum}'); firmware=$(smartctl -i /dev/$device |awk '/Firmware Version|Revision/ {print $NF}');size=$(smartctl -i /dev/$device |awk -F'[][]' '!/^Namespace/ && /Capacity:.*\\[/ {print $2}'); echo \"$device;$temp;$model;$serial;$firmware;$size;$years\"; done |sort -V" | |
output = "" | |
[[snippets]] | |
description = "truenas diskinfos new" | |
command = "echo \"device;temperature_in_celsius;model;serial;firmware;size;power_on_years;smartresult\"; ( midclt call disk.query |jq -r '.[]|.model|=gsub(\" \";\"-\")|[ .name,.serial,.model ]|map(gsub(\"^\\\\s+|\\\\s+$\";\"\"))|@tsv' |sed s:nvd:nvme:g| while read device serial model ;do JSON=$(smartctl --json --xall /dev/$device); temp=$(jq .temperature.current <<< $JSON); years=$(jq '( .power_on_time.hours / 24 / 365 | .*100 | floor | ./100 )' <<< $JSON) ; firmware=$(jq -r 'if .firmware_version then .firmware_version else .revision end' <<< $JSON) ; size=$(jq -r '.user_capacity.bytes/1000/1000/1000|floor as $gb| if $gb < 1000 then $gb|tostring+\"GB\" else $gb/1000|floor|tostring+\"TB\" end' <<< $JSON) ; smartresult=$(jq -r '([..|select(.remaining_percent?)]|first?) as $running|$running.string' <<< $JSON) ; echo \"$device;$temp;$model;$serial;$firmware;$size;$years;$smartresult\"; done |sort -V )" | |
output = "" | |
[[snippets]] | |
description = "truenas delete old boot environments" | |
command = "midclt call bootenv.query | jq '.[]|select(.active==\"-\")|.id' | xargs -n 1 midclt call bootenv.delete" | |
output = "" | |
[[snippets]] | |
description = "midclt clear errors" | |
command = "midclt call alert.list |jq -r '.[].uuid' |while read id; do midclt call alert.dismiss $id; done" | |
output = "" | |
[[snippets]] | |
description = "truenas list pool status vdev status disks" | |
command = "midclt call pool.query |jq ' .[] | [ .id , .name , .status , ( .topology.data[]| .type, .status , ( .children[] | .disk ) ) ] |@tsv ' -r" | |
output = "" | |
[[snippets]] | |
description = "zfs zpool free/available space difference" | |
command = "join -j 1 <(zpool list -o name,free) <(zfs list -o name,available -d0)" | |
output = "" | |
[[snippets]] | |
description = "zfs list in more detail" | |
command = "zfs list -o space,refer,lrefer,written,quota,refquota,volsize,written,creation" | |
output = "" | |
[[snippets]] | |
description = "truenas return diskname if smart test failed" | |
command = "midclt call smart.test.results | jq ' . [] | [ select ( .tests[].status != \"SUCCESS\" ) | .disk ]| unique[] '" | |
output = "" | |
[[snippets]] | |
description = "truenas get diskfacts" | |
command = "midclt call disk.query | jq 'map({name,model,serial,size,type,rotationrate})'" | |
output = "" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment