#!/bin/bash
# Written by jpaul, 2017-03
# Extended by El Pinguino, 2017-07

<%
datasetlist = sorted(node.metadata.get('zfs', {}).get('datasets', {}).items())
volumes = []
for dataset, options in datasetlist:
    if options.get('mountpoint', 'none') != 'none':
        volumes.append(dataset)
%>\

exitcode=0
% for volume in volumes:
if [[ "$(zfs get -Hp -o value mounted '${volume}')" != "yes" ]]
then
    echo 'CRITICAL - ${volume} not mounted'
    exitcode=2
fi
% endfor

if (( exitcode == 0 ))
then
    echo OK
fi
exit $exitcode