Last active
June 19, 2025 01:15
-
-
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 hidden or 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 = "zpool list (real space)" | |
Output = "" | |
Tag = ["truenas", "zfs"] | |
command = "zfs list -o space,refer,lrefer,quota,refquota -d0" | |
[[Snippets]] | |
Description = "truenas upgrade all jails to latest" | |
Output = "" | |
Tag = ["midclt", "truenas", "core"] | |
command = "midclt call jail.query |jq -r '.[]|.id' |while read -r jailid; do midclt call jail.update_to_latest_patch $jailid; done" | |
[[Snippets]] | |
Description = "truenas update smart thresholds" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call smart.update '{\"difference\": 10, \"informational\": 30, \"critical\": 40}'" | |
[[Snippets]] | |
Description = "truenas update replication snapshots hold_pending" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call replication.query | jq '.[]|.id' | while read -r ID; do midclt call replication.update $ID '{\"hold_pending_snapshots\": true}' ; done" | |
[[Snippets]] | |
Description = "truenas snapshot task overview extended" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
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" | |
[[Snippets]] | |
Description = "truenas snapshot task overview" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call pool.snapshottask.query |jq -r '.[]|[(.id|tostring),.dataset,.lifetime_unit,\"\\(.lifetime_value)\",.naming_schema]|map(gsub(\"^\\\\s+|\\\\s+$\";\"\"))|@tsv'" | |
[[Snippets]] | |
Description = "truenas scale delete old boot environments" | |
Output = "" | |
Tag = ["midclt", "truenas", "core"] | |
command = "midclt call boot.environment.query | jq '.[]|select(.active==false)|.id' -r | while read -r ID ; do midclt call boot.environment.destroy '{\"id\":\"'$ID'\"}' ; done" | |
[[Snippets]] | |
Description = "truenas run latest update and reboot" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call update.update '{\"reboot\": true}'" | |
[[Snippets]] | |
Description = "truenas return diskname if smart test failed" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call smart.test.results | jq ' . [] | [ select ( .tests[].status != \"SUCCESS\" ) | .disk ]| unique[] '" | |
[[Snippets]] | |
Description = "truenas replication status" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
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'" | |
[[Snippets]] | |
Description = "truenas replication start all jobs" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call replication.query |jq '.[]|.id' |while read -r ID; do midclt call replication.run $ID; done" | |
[[Snippets]] | |
Description = "truenas replication running tasks" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call replication.query |jq -r '.[]|select(.job.state==\"RUNNING\")|[.name,.job.progress.description]|map(gsub(\"^\\\\s+|\\\\s+$\";\"\"))|@tsv'" | |
[[Snippets]] | |
Description = "truenas list vmware datastores" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call vmware.get_datastores \"$(midclt call vmware.query |jq '.[0]|del(.filesystem,.datastore,.id)')\"" | |
[[Snippets]] | |
Description = "truenas list snapshot naming schemes" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call pool.snapshottask.query |jq -r '.[]|[.dataset,.naming_schema]|@tsv' |sort" | |
[[Snippets]] | |
Description = "truenas list running jobs" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call core.get_jobs | jq '.[]|select(.state==\"RUNNING\")'" | |
[[Snippets]] | |
Description = "truenas list pool: disks" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
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" | |
[[Snippets]] | |
Description = "truenas list pool status vdev status disks" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call pool.query |jq ' .[] | [ .id , .name , .status , ( .topology.data[]| .type, .status , ( .children[] | .disk ) ) ] |@tsv ' -r" | |
[[Snippets]] | |
Description = "truenas get diskfacts" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call disk.query | jq 'map({name,model,serial,size,type,rotationrate})'" | |
[[Snippets]] | |
Description = "truenas enable autorim" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call pool.query |jq '.[]|.id' |while read -r ID; do midclt call pool.update $ID '{\"autotrim\": \"ON\"}'; done" | |
[[Snippets]] | |
Description = "truenas diskinfos v3" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "echo \"device;temperature_in_celsius;model;serial;firmware;size;power_on_years;rpm;smartresult\"; ( midclt call disk.query |jq -r '.[]|.model|=gsub(\" \";\"-\")|[ .name,.serial,.model,.rotationrate|tostring ]|map(gsub(\"^\\\\s+|\\\\s+$\";\"\"))|@tsv' |sed s:nvd:nvme:g| while read device serial model rpm;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;$rpm;$smartresult\"; done |sort -V )" | |
[[Snippets]] | |
Description = "truenas diskinfos" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
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" | |
[[Snippets]] | |
Description = "truenas disable empty snapshots" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call pool.snapshottask.query |jq -r '.[]|select(.allow_empty==true)|.id' | while read -r ID ; do midclt call pool.snapshottask.update $ID '{\"allow_empty\": false}'; done" | |
[[Snippets]] | |
Description = "truenas core delete old boot environments" | |
Output = "" | |
Tag = ["midclt", "truenas", "core"] | |
command = "midclt call bootenv.query | jq '.[]|select(.active==\"-\")|.id' | xargs -n 1 midclt call bootenv.delete" | |
[[Snippets]] | |
Description = "midclt clear errors" | |
Output = "" | |
Tag = ["midclt", "truenas"] | |
command = "midclt call alert.list |jq -r '.[].uuid' |while read id; do midclt call alert.dismiss $id; done" | |
[[Snippets]] | |
Description = "iocage pkg-upgrade all jails" | |
Output = "" | |
Tag = ["midclt", "truenas", "core"] | |
command = "iocage list -q -h |cut -f1 |while read -r cage; do echo \"\\033[1m${cage}\\033[0m\"; iocage exec $cage \"pkg update -f && pkg upgrade -y\"; iocage restart --soft $cage ; done" | |
[[Snippets]] | |
Description = "truenas remove ssh pubkey" | |
Output = "" | |
Tag = ["truenas", "midclt"] | |
command = "midclt call user.update 1 \"$(midclt call user.query | jq ' . [] |select ( .username == \"root\" ) | .sshpubkey ' -r |grep -v -i [email protected] | jq --slurp --raw-input '{\"sshpubkey\": .}')\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment