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

# NOTE: Careful when replacing the *-import below with a more specific import. This can cause
# problems because it might remove variables from the check-context which are necessary for
# resolving legacy discovery results such as [("SUMMARY", "diskstat_default_levels")]. Furthermore,
# it might also remove variables needed for accessing discovery rulesets.
from cmk.base.check_legacy_includes.ups_out_voltage import *  # pylint: disable=wildcard-import,unused-wildcard-import

ups_out_voltage_default_levels = (210, 180)  # warning / critical


def inventory_socomec_ups_out_voltage(info):
    if len(info) > 0:
        return [(x[0], "ups_out_voltage_default_levels") for x in info if int(x[1]) > 0]


def check_socomec_ups_out_voltage(item, params, info):
    conv_info = []
    for line in info:
        conv_info.append([line[0], saveint(line[1]) // 10, line[1]])
    return check_ups_out_voltage(item, params, conv_info)


check_info["ups_socomec_out_voltage"] = {
    "inventory_function": inventory_socomec_ups_out_voltage,
    "check_function": check_socomec_ups_out_voltage,
    "service_description": "OUT voltage phase %s",
    "has_perfdata": True,
    "group": "evolt",
    "snmp_info": (".1.3.6.1.4.1.4555.1.1.1.1.4.4", ["1.1", "1.2"]),
    "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0") == ".1.3.6.1.4.1.4555.1.1.1",
}
