#!/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.

# Example output:
# <<<vxvm_multipath>>>
# sda                  ENABLED      OTHER_DISKS  1      1     0     other_disks
# LIO-Sechs_0          ENABLED      aluadisk     1      1     0     LIO-Sechs
# LIO-Sechs_1          ENABLED      aluadisk     1      1     0     LIO-Sechs
# LIO-Sechs_2          ENABLED      aluadisk     1      1     0     LIO-Sechs
#


def check_vxvm_multipath(item, params, info):
    state = 0
    for disk, status_txt, _enc_type, paths, paths_act, paths_inact, enclosure in info:
        if disk == item:
            if paths_act != paths and float(paths_act) >= float(paths) / 2:
                state = 1
            elif int(paths_inact) > 0 and float(paths_inact) > float(paths) / 2:
                state = 2
            return (state, "Status: %s, (%d/%d) Paths to enclosure %s enabled" %
                    (status_txt, int(paths_act), int(paths), enclosure))

    return (3, "Item not found")


check_info["vxvm_multipath"] = {
    "check_function": check_vxvm_multipath,
    "inventory_function": lambda info: [(item[0], None) for item in info],
    "service_description": "Multipath %s",
}
