#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.


def check_disk_smb_arguments(params):
    args = []
    args += ["-a", "$HOSTADDRESS$"]
    args += ["-s", params["share"]]

    warn, crit = params["levels"]
    args += ["-w%d%%" % warn]
    args += ["-c%d%%" % crit]

    if "workgroup" in params:
        args += ["-W", params["workgroup"]]

    if "port" in params:
        args += ["-p", params["port"]]

    if "auth" in params:
        username, password = params["auth"]
        args += ["-u", username, "-p", password]

    if "host" in params:
        args += ["-H", params["host"]]
    else:
        args += ["-H", "$HOSTADDRESS$"]

    return args


active_check_info["disk_smb"] = {
    "command_line": "check_disk_smb $ARG1$",
    "argument_function": check_disk_smb_arguments,
    "service_description": lambda params: "SMB Share " + params["share"].replace("$", ""),
    "has_perfdata": True,
}
