#!/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.infoblox import *  # pylint: disable=wildcard-import,unused-wildcard-import

# .1.3.6.1.4.1.7779.3.1.1.4.1.3.1.0 0 --> IB-DHCPONE-MIB::ibDhcpTotalNoOfDiscovers.0
# .1.3.6.1.4.1.7779.3.1.1.4.1.3.2.0 0 --> IB-DHCPONE-MIB::ibDhcpTotalNoOfRequests.0
# .1.3.6.1.4.1.7779.3.1.1.4.1.3.3.0 0 --> IB-DHCPONE-MIB::ibDhcpTotalNoOfReleases.0
# .1.3.6.1.4.1.7779.3.1.1.4.1.3.4.0 0 --> IB-DHCPONE-MIB::ibDhcpTotalNoOfOffers.0
# .1.3.6.1.4.1.7779.3.1.1.4.1.3.5.0 0 --> IB-DHCPONE-MIB::ibDhcpTotalNoOfAcks.0
# .1.3.6.1.4.1.7779.3.1.1.4.1.3.6.0 0 --> IB-DHCPONE-MIB::ibDhcpTotalNoOfNacks.0
# .1.3.6.1.4.1.7779.3.1.1.4.1.3.7.0 0 --> IB-DHCPONE-MIB::ibDhcpTotalNoOfDeclines.0
# .1.3.6.1.4.1.7779.3.1.1.4.1.3.8.0 0 --> IB-DHCPONE-MIB::ibDhcpTotalNoOfInforms.0
# .1.3.6.1.4.1.7779.3.1.1.4.1.3.9.0 0 --> IB-DHCPONE-MIB::ibDhcpTotalNoOfOthers.0


def check_infoblox_dhcp_stats(_no_item, _no_params, info):
    discovers, requests, releases, offers, acks, nacks, declines, informs, others = map(
        int, info[0]
    )

    return check_infoblox_statistics(
        "dhcp",
        [
            ("discovery", discovers, "Received", "discovery messages"),
            ("requests", requests, "Received", "requests"),
            ("releases", releases, "Received", "releases"),
            ("declines", declines, "Received", "declines"),
            ("informs", informs, "Received", "informs"),
            ("others", others, "Received", "other messages"),
            ("offers", offers, "Sent", "offers"),
            ("acks", acks, "Sent", "acks"),
            ("nacks", nacks, "Sent", "nacks"),
        ],
    )


check_info["infoblox_dhcp_stats"] = {
    "inventory_function": inventory_infoblox_statistics,
    "check_function": check_infoblox_dhcp_stats,
    "service_description": "DHCP statistics",
    "snmp_info": (
        ".1.3.6.1.4.1.7779.3.1.1.4.1.3",
        [
            "1",  # IB-DHCPONE-MIB::ibDhcpTotalNoOfDiscovers
            "2",  # IB-DHCPONE-MIB::ibDhcpTotalNoOfRequests
            "3",  # IB-DHCPONE-MIB::ibDhcpTotalNoOfReleases
            "4",  # IB-DHCPONE-MIB::ibDhcpTotalNoOfOffers
            "5",  # IB-DHCPONE-MIB::ibDhcpTotalNoOfAcks
            "6",  # IB-DHCPONE-MIB::ibDhcpTotalNoOfNacks
            "7",  # IB-DHCPONE-MIB::ibDhcpTotalNoOfDeclines
            "8",  # IB-DHCPONE-MIB::ibDhcpTotalNoOfInforms
            "9",  # IB-DHCPONE-MIB::ibDhcpTotalNoOfOthers
        ],
    ),
    "snmp_scan_function": scan_infoblox,
    "has_perfdata": True,
}
