# Path: canaryd/subprocess.py
# def ensure_command_tuple(command):
# def decode_output(output):
# def get_command_output(command, *args, **kwargs):


import sys
from canaryd.subprocess import CalledProcessError, get_command_output
# Run once an hour, smartctl can be intensive
# CANARYD_INTERVAL = 3600

SMART_RETURN_BITS = {
    0: False,  # command line parse error
    1: 'device open failed',
    2: 'SMART command failed',
    3: 'disk failing',
    # We track thresholds via stdout
    4: True,  # pre-fail attrs <= thresh
    5: True,  # pre-fail attrs <= thresh in past
    # We track errors via stdout
    6: True,  # error log
    7: True,  # self-test errors
}


try:
    # Ensure smartctl is present & working
    get_command_output(
        'smartctl --version',
    )

except (CalledProcessError, OSError):
    print('No smartctl found!')
    sys.exit(1)


try:
    # Look for OSX disks first (OSX has /dev/sdt which breaks below)

# Path: canaryd/subprocess.py
# def ensure_command_tuple(command):
# def decode_output(output):
# def get_command_output(command, *args, **kwargs):


# Path: canaryd/scripts/disk_health.py
import sys
from canaryd.subprocess import CalledProcessError, get_command_output

# Run once an hour, smartctl can be intensive
# CANARYD_INTERVAL = 3600

SMART_RETURN_BITS = {
    0: False,  # command line parse error
    1: 'device open failed',
    2: 'SMART command failed',
    3: 'disk failing',
    # We track thresholds via stdout
    4: True,  # pre-fail attrs <= thresh
    5: True,  # pre-fail attrs <= thresh in past
    # We track errors via stdout
    6: True,  # error log
    7: True,  # self-test errors
}


try:
    # Ensure smartctl is present & working
    get_command_output(
        'smartctl --version',
    )

except (CalledProcessError, OSError):
    print('No smartctl found!')
    sys.exit(1)


try:
    # Look for OSX disks first (OSX has /dev/sdt which breaks below)

    disks_data = get_command_output(