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

epson_beamer_lamp_default_levels = (1000 * 3600, 1500 * 3600)


def inventory_epson_beamer_lamp(info):
    if info:
        return [(None, "epson_beamer_lamp_default_levels")]


def check_epson_beamer_lamp(_no_item, params, info):
    lamp_hrs = int(info[0][0])
    lamp_time = lamp_hrs * 3600
    status = 0
    infotext = "Operation time: %d h" % lamp_hrs
    if params:
        warn, crit = params
        levelstext = " (warn/crit at %.0f/%.0f hours)" % tuple(x / 3600.0 for x in params)
        if lamp_time >= crit:
            status = 2
        elif lamp_time >= warn:
            status = 1
        if status:
            infotext += levelstext
    return status, infotext


check_info["epson_beamer_lamp"] = {
    "inventory_function": inventory_epson_beamer_lamp,
    "check_function": check_epson_beamer_lamp,
    "service_description": "Beamer Lamp",
    "snmp_info": (".1.3.6.1.4.1.1248.4.1.1.1.1", ["0"]),
    "snmp_scan_function": lambda oid: "1248" in oid(".1.3.6.1.2.1.1.2.0").lower(),
    "group": "lamp_operation_time",
}
