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

# .1.3.6.1.4.1.318.1.1.13.3.1.2.1.3.1 Power Source B Failure
# .1.3.6.1.4.1.318.1.1.13.3.1.2.1.3.2 Fan Power Supply Right Fault


def parse_apc_inrow_system_events(info):
    parsed = {"events": []}
    for line in info:
        parsed["events"].append(line[0])
    return parsed


def inventory_apc_inrow_system_events(parsed):
    yield (None, {})


def check_apc_inrow_system_events(_no_item, params, parsed):
    events = parsed.get("events")
    if events:
        return params.get("state", 2), ", ".join(events)
    return 0, "No service events"


check_info["apc_inrow_system_events"] = {
    "parse_function": parse_apc_inrow_system_events,
    "inventory_function": inventory_apc_inrow_system_events,
    "check_function": check_apc_inrow_system_events,
    "service_description": "System events",
    "snmp_info": (".1.3.6.1.4.1.318.1.1.13.3.1.2.1", ["3"]),  # airIRAlarmDescription
    "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.318.1.3"),
    "group": "apc_system_events",
    "handle_empty_info": True,
}
