bash - make zpool status output scriptable -


how can turn output of zpool status -v usable, data match row in data.oriented format, instead of silly "visual" output uses, it's scriptable, using standard unix-like utilities? had python script did acceptable, python 3 breaks it, , i'm not fixing have new version of python break again. (after screwing around getting script run no errors, returns nothing :)

bascially space-bar alinged mess:

              pool: data              state: online             status: supported features not enabled on pool. pool can                     still used, features unavailable.             action: enable features using 'zpool upgrade'. once done,                     pool may no longer accessible software not support                     features. see zpool-features(7) details.               scan: scrub repaired 0 in 4h52m 0 errors on fri aug 18 04:52:47 2017             config:                      name                                            state     read write cksum                     data                                            online       0     0     0                       mirror-0                                      online       0     0     0                         gptid/6dfb7dbe-68c5-11e6-982d-00e04c68f511  online       0     0     0                         gptid/27f40ebe-8f1b-11e4-94f8-3085a9405b85  online       0     0     0                         gptid/9244318f-c1b4-11e6-a31d-0cc47ae2abe8  online       0     0     0                       mirror-1                                      online       0     0     0                         gptid/1993f2d7-8f1b-11e4-94f8-3085a9405b85  online       0     0     0                         gptid/529e2c88-f1d1-11e6-89c3-0cc47ae2abe8  online       0     0     0                         gptid/53a09a3e-f1d1-11e6-89c3-0cc47ae2abe8  online       0     0     0                       mirror-2                                      online       0     0     0                         gptid/51f3b377-6a20-11e6-be8c-00e04c68f511  online       0     0     0                         gptid/9fb54bde-1e2d-11e7-a83e-0cc47ae2abe8  online       0     0     0                         gptid/9eebde32-1e2d-11e7-a83e-0cc47ae2abe8  online       0     0     0                     cache                       gptid/63db5172-20bd-11e7-b561-0cc47ae2abe8    online       0     0     0              errors: no known data errors 

to actual columnns this:

            name                                                            state   read    write   cksum             data                                                            online  0       0       0             data    mirror-0                                                online  0       0       0             data    mirror-0    gptid/6dfb7dbe-68c5-11e6-982d-00e04c68f511  online  0       0       0             data    mirror-0    gptid/27f40ebe-8f1b-11e4-94f8-3085a9405b85  online  0       0       0             data    mirror-0    gptid/9244318f-c1b4-11e6-a31d-0cc47ae2abe8  online  0       0       0             data    mirror-1                                                online  0       0       0             data    mirror-1    gptid/1993f2d7-8f1b-11e4-94f8-3085a9405b85  online  0       0       0             data    mirror-1    gptid/529e2c88-f1d1-11e6-89c3-0cc47ae2abe8  online  0       0       0             data    mirror-1    gptid/53a09a3e-f1d1-11e6-89c3-0cc47ae2abe8  online  0       0       0             data    mirror-2                                                online  0       0       0             data    mirror-2    gptid/51f3b377-6a20-11e6-be8c-00e04c68f511  online  0       0       0             data    mirror-2    gptid/9fb54bde-1e2d-11e7-a83e-0cc47ae2abe8  online  0       0       0             data    mirror-2    gptid/9eebde32-1e2d-11e7-a83e-0cc47ae2abe8  online  0       0       0             data    cache             data    cache       gptid/63db5172-20bd-11e7-b561-0cc47ae2abe8  online  0   0   0 

i can use perl remove , rearrange, can't work out how match rows dynamically, in way work mirror/raidz123/stripe/cache.

            datadata                                            online       0     0     0             data  mirror-0                                      online       0     0     0             data    gptid/6dfb7dbe-68c5-11e6-982d-00e04c68f511  online       0     0     0             data    gptid/27f40ebe-8f1b-11e4-94f8-3085a9405b85  online       0     0     0             data    gptid/9244318f-c1b4-11e6-a31d-0cc47ae2abe8  online       0     0     0             data  mirror-1                                      online       0     0     0             data    gptid/1993f2d7-8f1b-11e4-94f8-3085a9405b85  online       0     0     0             data    gptid/529e2c88-f1d1-11e6-89c3-0cc47ae2abe8  online       0     0     0             data    gptid/53a09a3e-f1d1-11e6-89c3-0cc47ae2abe8  online       0     0     0             data  mirror-2                                      online       0     0     0             data    gptid/51f3b377-6a20-11e6-be8c-00e04c68f511  online       0     0     0             data    gptid/9fb54bde-1e2d-11e7-a83e-0cc47ae2abe8  online       0     0     0             data    gptid/9eebde32-1e2d-11e7-a83e-0cc47ae2abe8  online       0     0     0             datacache             data  gptid/63db5172-20bd-11e7-b561-0cc47ae2abe8    online       0     0     0 

this code generates above.

            zpool status -v data | sed '/   data/, $!d' | grep -v errors: > /tmp/diskslistzpoolstatusdata             perl -pi -e 's/^\n$//' /tmp/diskslistzpoolstatusdata  #remove blank lines             perl -pi -e 's/\t$//' /tmp/diskslistzpoolstatusdata             perl -p -i -e 's/\t//g' /tmp/diskslistzpoolstatusdata             perl -pi -e 's/^/data/' /tmp/diskslistzpoolstatusdata 

extra:

include scrub summary , error lines per gptid

            name                                                            state   read    write   cksum             misc                                                            online  0       0       0             misc    mirror-0                                                online  0       0       0             misc    mirror-0    gptid/aefbaf6e-e004-11e6-8f42-0cc47ae2abe8  online  0       0       0       0err/4h52m/0err/fri aug 18 04:52:47 2017    no known data errors             misc    mirror-0    gptid/affc3cac-e004-11e6-8f42-0cc47ae2abe8  online  0       0       0       0err/4h52m/0err/fri aug 18 04:52:47 2017    no known data errors             misc    cache       gptid/3139819b-20bd-11e7-b561-0cc47ae2abe8  online  0       0       0       0err/4h52m/0err/fri aug 18 04:52:47 2017    no known data errors 

unfortunately there no integrated solution available. have 2 options:

  1. parse in language of choice. extracted essential information. layout relatively static, vdevs , pools cannot nested (pools contain vdevs, never pools themselves), order respected (no devices vdev come after vdev b), keywords few , fixed (mirror-n, raidzx-n, etc), , output quite small (less hundreds of lines usually). means have go through each row, read info need, store in nested objects or arrays , go next line.

  2. directly call appropriate c functions status in non-readable form , convert output. this, have @ status_callback(zpool_handle_t *zhp, void *data), printf-output generated pool data. mirror function convert output format instead of indented format, , call mini-application script give data.

if familiar c, option 2 faster think. performance-wise not matter much, data small (even on big systems) , calls infrequent (as pool layouts not change often).


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -