#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2013             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.

# Example output from asmcmd lsdg:
# State    Type    Rebal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Voting_files  Name
# MOUNTED  NORMAL  N         512   4096  1048576    512000    92888                0           46444              0             N  DATA/
# MOUNTED  NORMAL  N         512   4096  1048576      3072     2146              309             918              0             Y  OCR_VOTE/
# The agent section <<<oracle_asm_diskgroup>>> does not output the header line

check_includes['oracle_asm_diskgroup'] = [ "df.include" ]

def inventory_oracle_asm_diskgroup(info):
    return [ (line[-1].rstrip("/"), {}) for line in info ]

def check_oracle_asm_diskgroup(item, params, info):

    for state, typ, rebal, sector, block, au, total_mb,  \
        free_mb, req_mir_free_mb, usable_file_mb, offline_disks, \
        voting_files, name in info:
        if name.rstrip('/') == item:
            return df_check_filesystem(g_hostname, item, int(total_mb),
                                       int(free_mb), params)
    return (3, "UNKNOWN - Disk group not found")

check_info["oracle_asm_diskgroup"] = (check_oracle_asm_diskgroup, "ASM Diskgroup %s", 1, inventory_oracle_asm_diskgroup)
checkgroup_of['oracle_asm_diskgroup']        = "fs"
check_default_levels["oracle_asm_diskgroup"] = "filesystem_default_levels"
