#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |          _           _           _       _   __   _______        |
# |       __| |_  ___ __| |__  _ __ | |__   / | /  \ |__ / _ \       |
# |      / _| ' \/ -_) _| / / | '  \| / /   | || () | |_ \_, /       |
# |      \__|_||_\___\__|_\_\_|_|_|_|_\_\   |_(_)__(_)___//_/        |
# |                                            check_mk 1.0.39       |
# |                                                                  |
# | Copyright Mathias Kettner 2009                mk@mathias-kettner |
# +------------------------------------------------------------------+
# 
# This file is part of check_mk 1.0.39.
# 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.


oracle_asm_dg_default_levels       = (80, 90)

def inventory_oracle_asm_dg(checkname, info):
    return [ (line[0], "", "oracle_asm_dg_default_levels") for line in info ]

def check_oracle_asm_dg(name, params, info):
    (warn, crit) = params
    for line in info:
        if line[0] == name:
            size_mb = int(line[2])
            free_mb = int(line[3])
            used_mb = size_mb - free_mb
            used_perc = float(used_mb) / float(size_mb) * 100.0;
            warn_mb = size_mb * warn / 100;
            crit_mb = size_mb * crit / 100;
            
            perfdata = [(name, str(used_mb) + 'MB', warn_mb, crit_mb, 0, size_mb)]
            
            if used_perc >= crit:
                return (2, "CRIT - %.1f%% used (critical at %d%%)" % (used_perc, crit), perfdata)
            elif used_perc >= warn:
                return (1, "WARNING - %.1f%% used (warning at %d%%)" % (used_perc, warn), perfdata)
            else:
                return (0, "OK - %.1f%% used" % used_perc, perfdata)
    return (3, "UNKNOWN - disk group not found")
        
check_info['oracle_asm_dg'] = (
    check_oracle_asm_dg,
    "ASM disk group %s",
    1,
    inventory_oracle_asm_dg)
