#!/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.2.1.1.1.0 Linux gateway1 2.6.18-92cp #1 SMP Tue Dec 4 21:44:22 IST 2012 i686
# .1.3.6.1.4.1.2620.1.1.25.3.0 19190

checkpoint_connections_default_levels = (40000, 50000)


def inventory_checkpoint_connections(parsed):
    return [(None, "checkpoint_connections_default_levels")]


def check_checkpoint_connections(_no_item, params, parsed):
    connections = parsed["count"]
    state = 0
    infotext = "%d current connections" % (connections)
    warn, crit = params

    if connections >= crit:
        state = 2
    elif connections >= warn:
        state = 1

    if state > 0:
        infotext += " (warn/crit at %d/%d)" % (warn, crit)

    return state, infotext, [("connections", connections, warn, crit)]


check_info["checkpoint_connections"] = {
    "check_function": check_checkpoint_connections,
    "inventory_function": inventory_checkpoint_connections,
    "service_description": "Connections",
    "has_perfdata": True,
    "group": "checkpoint_connections",
    "snmp_scan_function": lambda oid: False,  # already migrated!
    "snmp_info": (".1.3.6.1.4.1.2620.1.1.25", [3]),
}
