#!/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: This check (and associated special agent) is deprecated and will be
#       removed in Checkmk version 2.2.
###########################################################################


def inventory_k8s_stateful_set_replicas(parsed):
    if parsed:
        yield (None, {})


def check_k8s_stateful_set_replicas(_no_item, _params, parsed):
    ready, total = parsed["ready_replicas"], parsed["replicas"]
    # If set, strategy may be one of RollingUpdate or OnDelete.
    strategy = parsed["strategy_type"]
    partition = parsed.get("partition")
    infotext = "Ready: %s/%s" % (ready, total)
    perfdata = [
        ("ready_replicas", ready),
        ("total_replicas", total),
    ]
    yield 0 if ready == total else 1, infotext, perfdata

    if strategy:
        infodata = ["Strategy: %s" % strategy]
        if partition is not None:
            infodata.append("Partition: %s" % partition)
        yield 0, ", ".join(infodata)


check_info["k8s_stateful_set_replicas"] = {
    # section is already migrated
    "inventory_function": inventory_k8s_stateful_set_replicas,
    "check_function": check_k8s_stateful_set_replicas,
    "service_description": "Replicas",
}
