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


def inv_oracle_dataguard_stats(parsed):
    node = inv_tree_list("software.applications.oracle.dataguard_stats:")
    for inst, data in sorted(parsed.items()):
        try:
            db_name, db_unique_name = inst.split(".", 1)
        except ValueError:
            continue
        node.append({
            "sid": db_name,
            "db_unique": "%s.%s" % (db_name, db_unique_name),
            "role": data.get('database_role'),
            "switchover": data.get('switchover_status'),
        })


inv_info['oracle_dataguard_stats'] = {
    'inv_function': inv_oracle_dataguard_stats,
}
