remove python parser for zpool and use json output instead
This commit is contained in:
parent
ac583b5201
commit
85d8972fde
1 changed files with 5 additions and 25 deletions
|
@ -63,32 +63,12 @@ in
|
||||||
};
|
};
|
||||||
exec = [
|
exec = [
|
||||||
{
|
{
|
||||||
commands = [
|
|
||||||
"${pkgs.python3}/bin/python ${pkgs.writeText "zpool.py" ''
|
|
||||||
import json
|
|
||||||
from subprocess import check_output
|
|
||||||
|
|
||||||
columns = ["NAME", "SIZE", "ALLOC", "FREE", "CKPOINT", "EXPANDSZ", "FRAG", "CAP", "DEDUP", "HEALTH", "ALTROOT"]
|
|
||||||
health = {'ONLINE':0, 'DEGRADED':11, 'OFFLINE':21, 'UNAVAIL':22, 'FAULTED':23, 'REMOVED':24}
|
|
||||||
|
|
||||||
stdout = check_output(["${pkgs.zfs}/bin/zpool", "list", "-Hp"],encoding='UTF-8').split('\n')
|
|
||||||
parsed_stdout = list(map(lambda x: dict(zip(columns,x.split('\t'))), stdout))[:-1]
|
|
||||||
|
|
||||||
for pool in parsed_stdout:
|
|
||||||
for item in pool:
|
|
||||||
if item in ["SIZE", "ALLOC", "FREE", "FRAG", "CAP"]:
|
|
||||||
pool[item] = int(pool[item])
|
|
||||||
if item in ["DEDUP"]:
|
|
||||||
pool[item] = float(pool[item])
|
|
||||||
if item == "HEALTH":
|
|
||||||
pool[item] = health[pool[item]]
|
|
||||||
|
|
||||||
print(json.dumps(parsed_stdout))
|
|
||||||
''}"
|
|
||||||
];
|
|
||||||
tag_keys = [ "NAME" ];
|
|
||||||
data_format = "json";
|
|
||||||
name_suffix = "_python_zpool";
|
name_suffix = "_python_zpool";
|
||||||
|
commands = [ "${pkgs.zfs}/bin/zpool list --json --json-int" ];
|
||||||
|
data_format = "json";
|
||||||
|
json_query = "pools.@values.#.{NAME:name,STATE:state,ALLOC:properties.allocated.value,CAP:properties.capacity.value,DEDUP:properties.dedupratio.value,FRAG:properties.fragmentation.value,FREE:properties.free.value,HEALTH:properties.health.value,SIZE:properties.size.value}";
|
||||||
|
json_string_fields = ["STATE", "DEDUP", "HEALTH"];
|
||||||
|
tag_keys = [ "NAME" ];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue