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

factory_settings["pfsense_if_default_levels"] = {
    "ipv4_in_blocked": (100.0, 10000.0),
    "average": 3,
}


def parse_pfsense_if(info):
    parsed = {}
    for line in info:
        parsed[line[0]] = {"ip4_in_blocked": int(line[1])}
    return parsed


def inventory_pfsense_if(parsed):
    for item in parsed:
        yield item, {}


check_info["pfsense_if"] = {
    "parse_function": parse_pfsense_if,
    "inventory_function": inventory_pfsense_if,
    "default_levels_variable": "pfsense_if_default_levels",
    "check_function": check_firewall_if,
    "service_description": "Firewall Interface %s",
    "snmp_info": (
        ".1.3.6.1.4.1.12325.1.200.1.8.2.1",
        [
            "2",  # pfInterfacesIfDescr
            "12",  # pfInterfacesIf4PktsInBlock
        ],
    ),
    "snmp_scan_function": lambda oid: "pfsense" in oid(".1.3.6.1.2.1.1.1.0").lower(),
    "group": "firewall_if",
}
